Go to the documentation of this file.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 #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 }
00186
00187 #include "cmtkImagePairAffineRegistrationFunctionalTemplate.txx"
00188
00189 #endif // #ifndef __cmtkImagePairAffineRegistrationFunctionalTemplate_h_included_