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 "cmtkMultiChannelHistogramRegistrationFunctional.h"
00034
00035 #include <algorithm>
00036
00037 namespace
00038 cmtk
00039 {
00040
00043
00044 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00045 void
00046 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData
00047 ::Init( Parent *const parent )
00048 {
00049 this->m_Parent = parent;
00050
00051 this->m_JointHash.clear();
00052 this->m_ReferenceHash.clear();
00053 this->m_FloatingHash.clear();
00054
00055 this->m_TotalNumberOfSamples = 0;
00056 }
00057
00058 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00059 typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData&
00060 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData::operator=
00061 ( const typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData& source )
00062 {
00063 this->m_JointHash = source.m_JointHash;
00064 this->m_ReferenceHash = source.m_ReferenceHash;
00065 this->m_FloatingHash = source.m_FloatingHash;
00066
00067 this->m_TotalNumberOfSamples = source.m_TotalNumberOfSamples;
00068
00069 return *this;
00070 }
00071
00072 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00073 typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData&
00074 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData::operator+=
00075 ( const typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData& other )
00076 {
00077 for ( typename HashTableType::const_iterator it = other.m_JointHash.begin(); it != other.m_JointHash.end(); ++it )
00078 {
00079 this->m_JointHash[it->first] += it->second;
00080 }
00081 for ( typename HashTableType::const_iterator it = other.m_ReferenceHash.begin(); it != other.m_ReferenceHash.end(); ++it )
00082 {
00083 this->m_ReferenceHash[it->first] += it->second;
00084 }
00085 for ( typename HashTableType::const_iterator it = other.m_FloatingHash.begin(); it != other.m_FloatingHash.end(); ++it )
00086 {
00087 this->m_FloatingHash[it->first] += it->second;
00088 }
00089
00090 this->m_TotalNumberOfSamples += other.m_TotalNumberOfSamples;
00091
00092 return *this;
00093 }
00094
00095 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00096 typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData&
00097 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData::operator-=
00098 ( const typename MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData& other )
00099 {
00100 for ( typename HashTableType::const_iterator it = other.m_JointHash.begin(); it != other.m_JointHash.end(); ++it )
00101 {
00102 this->m_JointHash[it->first] -= it->second;
00103 }
00104 for ( typename HashTableType::const_iterator it = other.m_ReferenceHash.begin(); it != other.m_ReferenceHash.end(); ++it )
00105 {
00106 this->m_ReferenceHash[it->first] -= it->second;
00107 }
00108 for ( typename HashTableType::const_iterator it = other.m_FloatingHash.begin(); it != other.m_FloatingHash.end(); ++it )
00109 {
00110 this->m_FloatingHash[it->first] -= it->second;
00111 }
00112
00113 this->m_TotalNumberOfSamples -= other.m_TotalNumberOfSamples;
00114
00115 return *this;
00116 }
00117
00118 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00119 void
00120 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData::operator+=
00121 ( const Types::DataItem* values )
00122 {
00123 THashKeyType hashKeyRef = 0, hashKeyFlt = 0;
00124 size_t idx = 0;
00125 for ( size_t ref = 0; ref < m_Parent->m_ReferenceChannels.size(); ++ref, ++idx )
00126 {
00127 hashKeyRef |= static_cast<THashKeyType>(m_Parent->m_HashKeyScaleRef[ref] * values[idx] + m_Parent->m_HashKeyOffsRef[ref] ) << (NBitsPerChannel*ref);
00128 }
00129 for ( size_t flt = 0; flt < m_Parent->m_FloatingChannels.size(); ++flt, ++idx )
00130 {
00131 hashKeyFlt |= static_cast<THashKeyType>(m_Parent->m_HashKeyScaleFlt[flt] * values[idx] + m_Parent->m_HashKeyOffsFlt[flt] ) <<( NBitsPerChannel*flt);
00132 }
00133
00134 THashKeyType hashKeyJnt = (hashKeyFlt << m_Parent->m_HashKeyShiftRef) + hashKeyRef;
00135
00136 ++this->m_ReferenceHash[hashKeyRef];
00137 ++this->m_FloatingHash[hashKeyFlt];
00138 ++this->m_JointHash[hashKeyJnt];
00139
00140 ++this->m_TotalNumberOfSamples;
00141 }
00142
00143 template<class TDataType,class TInterpolator,class THashKeyType,char NBitsPerChannel>
00144 void
00145 MultiChannelHistogramRegistrationFunctional<TDataType,TInterpolator,THashKeyType,NBitsPerChannel>::MetricData::operator-=
00146 ( const Types::DataItem* values )
00147 {
00148 THashKeyType hashKeyRef = 0, hashKeyFlt = 0;
00149 size_t idx = 0;
00150 for ( size_t ref = 0; ref < m_Parent->m_ReferenceChannels.size(); ++ref, ++idx )
00151 {
00152 hashKeyRef |= static_cast<THashKeyType>(m_Parent->m_HashKeyScaleRef[ref] * values[idx] + m_Parent->m_HashKeyOffsRef[ref] ) << (NBitsPerChannel*ref);
00153 }
00154 for ( size_t flt = 0; flt < m_Parent->m_FloatingChannels.size(); ++flt, ++idx )
00155 {
00156 hashKeyFlt |= static_cast<THashKeyType>(m_Parent->m_HashKeyScaleFlt[flt] * values[idx] + m_Parent->m_HashKeyOffsFlt[flt] ) << (NBitsPerChannel*flt);
00157 }
00158
00159 THashKeyType hashKeyJnt = (hashKeyFlt << m_Parent->m_HashKeyShiftRef) + hashKeyRef;
00160
00161 --this->m_ReferenceHash[hashKeyRef];
00162 --this->m_FloatingHash[hashKeyFlt];
00163 --this->m_JointHash[hashKeyJnt];
00164
00165 --this->m_TotalNumberOfSamples;
00166 }
00167
00168 }