cmtkMultiChannelRMIRegistrationFunctionalMetricData.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2731 $
00026 //
00027 //  $LastChangedDate: 2011-01-13 16:22:47 -0800 (Thu, 13 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkMultiChannelRMIRegistrationFunctional.h"
00034 
00035 #include <algorithm>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 template<class TRealType,class TDataType,class TInterpolator>
00045 void
00046 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData
00047 ::Init( Parent *const parent )
00048 {
00049   const size_t nref = parent->m_ReferenceChannels.size();
00050   const size_t nflt = parent->m_FloatingChannels.size();
00051 
00052   this->m_Sums.resize( nref + nflt );
00053   std::fill( this->m_Sums.begin(), this->m_Sums.end(), static_cast<TRealType>( 0.0 ) );
00054 
00055   this->m_Products.resize( ((nref+nflt) * (nref+nflt+1)) / 2 );
00056   std::fill( this->m_Products.begin(), this->m_Products.end(), static_cast<TRealType>( 0.0 ) );
00057 
00058   this->m_CovarianceMatrix.Resize( nref+nflt, nref+nflt ); // needs no reset
00059   this->m_CovarianceMatrixRef.Resize( nref, nref ); // needs no reset
00060   this->m_CovarianceMatrixFlt.Resize( nflt, nflt ); // needs no reset
00061   
00062   this->m_TotalNumberOfSamples = 0;
00063 }
00064 
00065 template<class TRealType,class TDataType,class TInterpolator>
00066 typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& 
00067 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData::operator=
00068 ( const typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& source )
00069 {
00070   this->m_Sums.resize( source.m_Sums.size() );
00071   std::copy( source.m_Sums.begin(), source.m_Sums.end(), this->m_Sums.begin() );
00072 
00073   this->m_Products.resize( source.m_Products.size() );
00074   std::copy( source.m_Products.begin(), source.m_Products.end(), this->m_Products.begin() );
00075     
00076   // covariance matrices need not be copied as they only provide temporary storage for GetMetric()
00077 
00078   this->m_TotalNumberOfSamples = source.m_TotalNumberOfSamples;
00079   
00080   return *this;
00081 }
00082 
00083 template<class TRealType,class TDataType,class TInterpolator>
00084 typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& 
00085 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData::operator+=
00086 ( const typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& other )
00087 {
00088   assert( this->m_Sums.size() == other.m_Sums.size() );
00089   assert( this->m_Products.size() == other.m_Products.size() );
00090   
00091   for ( size_t idx = 0; idx < this->m_Sums.size(); ++idx )
00092     this->m_Sums[idx] += other.m_Sums[idx];
00093 
00094   for ( size_t idx = 0; idx < this->m_Products.size(); ++idx )
00095     this->m_Products[idx] += other.m_Products[idx];
00096 
00097   // covariance matrices need not be treated as they only provide temporary storage for GetMetric()
00098 
00099   this->m_TotalNumberOfSamples += other.m_TotalNumberOfSamples;
00100   
00101   return *this;
00102 }
00103 
00104 template<class TRealType,class TDataType,class TInterpolator>
00105 typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& 
00106 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData::operator-=
00107 ( const typename MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData& other )
00108 {
00109   assert( this->m_Sums.size() == other.m_Sums.size() );
00110   assert( this->m_Products.size() == other.m_Products.size() );
00111   
00112   for ( size_t idx = 0; idx < this->m_Sums.size(); ++idx )
00113     this->m_Sums[idx] -= other.m_Sums[idx];
00114 
00115   for ( size_t idx = 0; idx < this->m_Products.size(); ++idx )
00116     this->m_Products[idx] -= other.m_Products[idx];
00117 
00118   // covariance matrices need not be treated as they only provide temporary storage for GetMetric()
00119 
00120   this->m_TotalNumberOfSamples -= other.m_TotalNumberOfSamples;
00121   
00122   return *this;
00123 }
00124 
00125 template<class TRealType,class TDataType,class TInterpolator>
00126 void
00127 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData::operator+=
00128 ( const Types::DataItem* values )
00129 {
00130   const size_t numberOfChannels = this->m_Sums.size();
00131   for ( size_t j = 0; j < numberOfChannels; ++j )
00132     {
00133     this->m_Sums[j] += values[j];
00134     }
00135     
00136   size_t idx = 0;
00137   for ( size_t j = 0; j < numberOfChannels; ++j )
00138     {
00139     for ( size_t i = 0; i <= j; ++i, ++idx )
00140       {
00141       this->m_Products[idx] += values[i] * values[j];
00142       }
00143     }
00144 
00145   ++this->m_TotalNumberOfSamples;
00146 }
00147 
00148 template<class TRealType,class TDataType,class TInterpolator>
00149 void
00150 MultiChannelRMIRegistrationFunctional<TRealType,TDataType,TInterpolator>::MetricData::operator-=
00151 ( const Types::DataItem* values )
00152 {
00153   const size_t numberOfChannels = this->m_Sums.size();
00154   for ( size_t j = 0; j < numberOfChannels; ++j )
00155     {
00156     this->m_Sums[j] -= values[j];
00157     }
00158     
00159   size_t idx = 0;
00160   for ( size_t j = 0; j < numberOfChannels; ++j )
00161     {
00162     for ( size_t i = 0; i <= j; ++i, ++idx )
00163       {
00164       this->m_Products[idx] -= values[i] * values[j];
00165       }
00166     }
00167 
00168   --this->m_TotalNumberOfSamples;
00169 }
00170 
00171 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines