cmtkSplineWarpMultiChannelIntensityCorrectionRegistrationFunctional.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2004-2010 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 2398 $
00025 //
00026 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
00029 //
00030 */
00031 
00032 #include <Base/cmtkMathUtil.h>
00033 
00034 namespace
00035 cmtk
00036 {
00037 
00040 
00041 template<class TMetricFunctional>
00042 void
00043 SplineWarpMultiChannelIntensityCorrectionRegistrationFunctional<TMetricFunctional>
00044 ::ContinueMetric( MetricData& metricData, const size_t rindex, const Vector3D& fvector )
00045 {
00046 #ifdef CMTK_VAR_AUTO_ARRAYSIZE
00047   Types::DataItem values[ this->m_NumberOfChannels ];
00048 #else
00049   std::vector<Types::DataItem> values( this->m_NumberOfChannels );
00050 #endif
00051   
00052   size_t idx = 0;
00053   for ( size_t ref = 0; ref < this->m_ReferenceChannels.size(); ++ref )
00054     {
00055     if ( !this->m_ReferenceChannels[ref]->GetDataAt( values[idx++], rindex ) ) return;
00056     }
00057   
00058   for ( size_t flt = 0; flt < this->m_FloatingChannels.size(); ++flt )
00059     {
00060     if ( !this->m_FloatingInterpolators[flt]->GetDataAt( fvector, values[idx++] ) )
00061       return;
00062     }
00063   
00064   const int planeSize = this->m_ReferenceDims[0] * this->m_ReferenceDims[1];
00065   const int z = rindex / planeSize;
00066   const int y = (rindex % planeSize) / this->m_ReferenceDims[0];
00067   const int x = rindex % this->m_ReferenceDims[0];
00068   const Types::DataItem jacobian = static_cast<Types::DataItem>( this->m_Transformation.GetJacobianDeterminant( x, y, z ) );
00069 
00070   for ( size_t flt = 0; flt < this->m_FloatingChannels.size(); ++flt, ++idx )
00071     {
00072     values[idx] *= jacobian;
00073     }
00074   
00075   metricData += &(values[0]);
00076 }
00077 
00078 template<class TMetricFunctional>
00079 void
00080 SplineWarpMultiChannelIntensityCorrectionRegistrationFunctional<TMetricFunctional>
00081 ::ContinueMetricStoreReformatted( MetricData& metricData, const size_t rindex, const Vector3D& fvector )
00082 {
00083 #ifdef CMTK_VAR_AUTO_ARRAYSIZE
00084   Types::DataItem values[ this->m_NumberOfChannels ];
00085 #else
00086   std::vector<Types::DataItem> values( this->m_NumberOfChannels );
00087 #endif
00088   
00089   size_t idx = 0;
00090   for ( size_t ref = 0; ref < this->m_ReferenceChannels.size(); ++ref )
00091     {
00092     if ( !this->m_ReferenceChannels[ref]->GetDataAt( values[idx++], rindex ) ) return;
00093     }
00094   
00095   for ( size_t flt = 0; flt < this->m_FloatingChannels.size(); ++flt )
00096     {
00097     if ( !this->m_FloatingInterpolators[flt]->GetDataAt( fvector, values[idx++] ) )
00098       {
00099       for ( size_t f = 0; f < this->m_FloatingChannels.size(); ++f )
00100         this->m_ReformattedFloatingChannels[f][rindex] = MathUtil::GetFloatNaN();
00101       return;
00102       }
00103     }
00104   
00105   const int planeSize = this->m_ReferenceDims[0] * this->m_ReferenceDims[1];
00106   const int z = rindex / planeSize;
00107   const int y = (rindex % planeSize) / this->m_ReferenceDims[0];
00108   const int x = rindex % this->m_ReferenceDims[0];
00109   const Types::DataItem jacobian = static_cast<Types::DataItem>( this->m_Transformation.GetJacobianDeterminant( x, y, z ) );
00110   for ( size_t flt = 0; flt < this->m_FloatingChannels.size(); ++flt, ++idx )
00111     {
00112     values[idx] *= jacobian;
00113     this->m_ReformattedFloatingChannels[flt][rindex] = static_cast<float>( values[idx] );
00114     }
00115   
00116   metricData += &(values[0]);
00117 }
00118 
00119 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines