cmtkMultiChannelHistogramRegistrationFunctionalMetricData.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 "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 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines