00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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 );
00059 this->m_CovarianceMatrixRef.Resize( nref, nref );
00060 this->m_CovarianceMatrixFlt.Resize( nflt, nflt );
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
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
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
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 }