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 __cmtkSplineWarpCongealingFunctional_h_included_
00034 #define __cmtkSplineWarpCongealingFunctional_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Registration/cmtkCongealingFunctional.h>
00039
00040 #include <System/cmtkSmartPtr.h>
00041 #include <System/cmtkThreads.h>
00042 #include <System/cmtkMutexLock.h>
00043 #include <System/cmtkThreadSemaphore.h>
00044
00045 #include <Base/cmtkUniformVolume.h>
00046 #include <Base/cmtkSplineWarpXform.h>
00047 #include <Base/cmtkHistogram.h>
00048
00049 #include <IO/cmtkClassStream.h>
00050
00051 #include <vector>
00052
00053 namespace
00054 cmtk
00055 {
00056
00059
00070 class SplineWarpCongealingFunctional :
00071 public CongealingFunctional<SplineWarpXform>
00072 {
00073 public:
00075 typedef CongealingFunctional<SplineWarpXform> Superclass;
00076
00078 typedef Superclass::HistogramType HistogramType;
00079
00081 typedef SplineWarpCongealingFunctional Self;
00082
00084 typedef SmartPointer<Self> SmartPtr;
00085
00088 virtual void InitializeXformsFromAffine( const Types::Coordinate gridSpacing,
00089 std::vector<AffineXform::SmartPtr> initialAffineXformsVector,
00090 const bool exactSpacing = true
00091 );
00092
00094 virtual void RefineTransformationGrids();
00095
00097 virtual void SetTemplateGrid( UniformVolume::SmartPtr& templateGrid, const int downsample = 1, const bool useTemplateData = false );
00098
00100 virtual Self::ReturnType Evaluate();
00101
00103 virtual Self::ReturnType EvaluateAt( CoordinateVector& v )
00104 {
00105 return this->Superclass::EvaluateAt( v );
00106 }
00107
00115 virtual Self::ReturnType EvaluateWithGradient( CoordinateVector& v, CoordinateVector& g, const Types::Coordinate step = 1 );
00116
00117 private:
00119 virtual void UpdateActiveControlPoints();
00120
00122 virtual void UpdateStandardDeviationByPixel();
00123
00125 std::vector<double> m_EntropyByPixel;
00126
00127 #ifdef CMTK_BUILD_MPI
00128
00129 std::vector<double> m_EntropyByPixelMPI;
00130 #endif
00131
00133 class EvaluateThreadParameters :
00135 public ThreadParameters<Self>
00136 {
00137 public:
00139 double m_Entropy;
00140
00145 unsigned int m_Count;
00146 };
00147
00149 static void EvaluateThread( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t );
00150
00152 class EvaluateLocalGradientThreadParameters :
00154 public ThreadParameters<Self>
00155 {
00156 public:
00158 Types::Coordinate m_Step;
00159
00161 Types::Coordinate* m_Gradient;
00162
00163 #ifdef CMTK_BUILD_MPI
00164
00165 size_t m_FirstIndexToCompute;
00166
00167 #endif
00168 };
00169
00171 size_t m_ControlPointIndexNext;
00172
00174 size_t m_ControlPointIndexLast;
00175
00177 MutexLock m_ControlPointIndexLock;
00178
00180 class StaticThreadStorage
00181 {
00182 public:
00184 void Initialize( const Self* This );
00185
00187 std::vector<Self::ReturnType> m_FPlus;
00188
00190 std::vector<Self::ReturnType> m_FMinus;
00191
00193 std::vector<unsigned int> m_CountByParameterPlus;
00194
00196 std::vector<unsigned int> m_CountByParameterMinus;
00197
00199 std::vector<SplineWarpXform::SmartPtr> m_Xforms;
00200
00202 std::vector<Vector3D> m_VectorList;
00203
00205 std::vector<size_t> m_Count;
00206
00208 std::vector<HistogramType> m_Histogram;
00209
00211 bool m_NeedToCopyXformParameters;
00212 };
00213
00215 std::vector<StaticThreadStorage> m_StaticThreadStorage;
00216
00222 static CMTK_THREAD_RETURN_TYPE EvaluateLocalGradientThreadFunc( void* args );
00223
00224 #ifdef CMTK_BUILD_MPI
00225
00226 typedef enum {
00227 MESSAGE_TAG_COMPUTE = 1,
00228 MESSAGE_TAG_RESULTS = 2,
00229 MESSAGE_TAG_FINISHED = 3
00230 } MessageTagMPI;
00231
00233 ThreadSemaphore m_ThreadWorkSemaphore;
00234
00236 ThreadSemaphore m_ThreadReadySemaphore;
00237
00239 void ReorderGradientComponents( Types::Coordinate *const dst, const Types::Coordinate* src, const size_t fromCpIdx, const size_t toCpIdx );
00240 #endif
00241 };
00242
00244
00245 }
00246
00247 #endif // #ifndef __cmtkSplineWarpCongealingFunctional_h_included_