cmtkImagePairAffineRegistrationFunctionalTemplate.h

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: 2752 $
00026 //
00027 //  $LastChangedDate: 2011-01-17 11:33:31 -0800 (Mon, 17 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkImagePairAffineRegistrationFunctionalTemplate_h_included_
00034 #define __cmtkImagePairAffineRegistrationFunctionalTemplate_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Registration/cmtkImagePairAffineRegistrationFunctional.h>
00039 
00040 #include <Base/cmtkInterpolator.h>
00041 #include <Base/cmtkTransformedVolumeAxes.h>
00042 
00043 #ifdef CMTK_BUILD_DEMO
00044 #  include <IO/cmtkXformIO.h>
00045 #endif // #ifdef CMTK_BUILD_DEMO
00046 
00047 namespace
00048 cmtk
00049 {
00050 
00053 
00063 template<class VM>
00064 class ImagePairAffineRegistrationFunctionalTemplate :
00066   public ImagePairAffineRegistrationFunctional
00067 {
00068 public:
00070   typedef ImagePairAffineRegistrationFunctionalTemplate<VM> Self;
00071 
00073   typedef SmartPointer<Self> SmartPtr;
00074 
00076   typedef ImagePairAffineRegistrationFunctional Superclass;
00077 
00079   typedef Functional::ReturnType ReturnType;
00080 
00090   ImagePairAffineRegistrationFunctionalTemplate( UniformVolume::SmartPtr& reference, 
00091                                                  UniformVolume::SmartPtr& floating, 
00092                                                  const Interpolators::InterpolationEnum interpolation,
00093                                                  AffineXform::SmartPtr& affineXform )
00094     : ImagePairAffineRegistrationFunctional( reference, floating, affineXform ),
00095       m_NumberOfThreads( ThreadPool::GetGlobalThreadPool().GetNumberOfThreads() )
00096   {
00097     this->m_Metric = ImagePairSimilarityMeasure::SmartPtr( new VM( reference, floating, interpolation ) );
00098     this->m_ThreadMetric.resize( m_NumberOfThreads, dynamic_cast<const VM&>( *(this->m_Metric) ) );
00099   }
00100 
00102   virtual ~ImagePairAffineRegistrationFunctionalTemplate() {}
00103 
00105   virtual typename Self::ReturnType EvaluateAt ( CoordinateVector& v ) 
00106   {
00107     this->m_AffineXform->SetParamVector( v );
00108     return this->Evaluate();
00109   }
00110 
00111 #ifdef CMTK_BUILD_DEMO
00112 
00113   virtual void SnapshotAt( ParameterVectorType& v )
00114   {
00115     this->m_AffineXform->SetParamVector( v );
00116     static int it = 0;
00117     char path[PATH_MAX];
00118     snprintf( path, PATH_MAX, "registration-%03d.xform", it++ );
00119     XformIO::Write( this->m_AffineXform, path );
00120   }
00121 #endif
00122 
00135   virtual typename Self::ReturnType Evaluate();
00136   
00144   size_t m_NumberOfThreads;
00145 
00147   std::vector<VM> m_ThreadMetric;
00148 
00150   MutexLock m_MetricMutex;
00151 
00157   typedef struct 
00158   {
00160     Self *thisObject;
00162     const TransformedVolumeAxes* AxesHash;
00164     DataGrid::IndexType::ValueType StartZ;
00166     DataGrid::IndexType::ValueType EndZ;
00167   } EvaluateTaskInfo;
00168  
00170   std::vector<typename Self::EvaluateTaskInfo> m_EvaluateTaskInfo;
00171 
00180   static void EvaluateThread( void *const args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00181 };
00182 
00184 
00185 } // namespace cmtk
00186 
00187 #include "cmtkImagePairAffineRegistrationFunctionalTemplate.txx"
00188 
00189 #endif // #ifndef __cmtkImagePairAffineRegistrationFunctionalTemplate_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines