00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _itkDemonsRegistrationFunction_h_
00018 #define _itkDemonsRegistrationFunction_h_
00019
00020 #include "itkPDEDeformableRegistrationFunction.h"
00021 #include "itkPoint.h"
00022 #include "itkCovariantVector.h"
00023 #include "itkInterpolateImageFunction.h"
00024 #include "itkLinearInterpolateImageFunction.h"
00025 #include "itkCentralDifferenceImageFunction.h"
00026
00027 namespace itk {
00028
00052 template<class TFixedImage, class TMovingImage, class TDeformationField>
00053 class ITK_EXPORT DemonsRegistrationFunction :
00054 public PDEDeformableRegistrationFunction< TFixedImage,
00055 TMovingImage,
00056 TDeformationField>
00057 {
00058 public:
00060 typedef DemonsRegistrationFunction Self;
00061 typedef PDEDeformableRegistrationFunction< TFixedImage,
00062 TMovingImage, TDeformationField
00063 > Superclass;
00064 typedef SmartPointer<Self> Pointer;
00065 typedef SmartPointer<const Self> ConstPointer;
00066
00068 itkNewMacro(Self);
00069
00071 itkTypeMacro( DemonsRegistrationFunction,
00072 PDEDeformableRegistrationFunction );
00073
00075 typedef typename Superclass::MovingImageType MovingImageType;
00076 typedef typename Superclass::MovingImagePointer MovingImagePointer;
00077
00079 typedef typename Superclass::FixedImageType FixedImageType;
00080 typedef typename Superclass::FixedImagePointer FixedImagePointer;
00081 typedef typename FixedImageType::IndexType IndexType;
00082 typedef typename FixedImageType::SizeType SizeType;
00083 typedef typename FixedImageType::SpacingType SpacingType;
00084
00086 typedef typename Superclass::DeformationFieldType DeformationFieldType;
00087 typedef typename Superclass::DeformationFieldTypePointer
00088 DeformationFieldTypePointer;
00089
00091 itkStaticConstMacro(ImageDimension, unsigned
00092 int,Superclass::ImageDimension);
00093
00095 typedef typename Superclass::PixelType PixelType;
00096 typedef typename Superclass::RadiusType RadiusType;
00097 typedef typename Superclass::NeighborhoodType NeighborhoodType;
00098 typedef typename Superclass::FloatOffsetType FloatOffsetType;
00099 typedef typename Superclass::TimeStepType TimeStepType;
00100
00102 typedef double CoordRepType;
00103 typedef InterpolateImageFunction<MovingImageType,CoordRepType>
00104 InterpolatorType;
00105 typedef typename InterpolatorType::Pointer InterpolatorPointer;
00106 typedef typename InterpolatorType::PointType PointType;
00107 typedef LinearInterpolateImageFunction<MovingImageType,CoordRepType>
00108 DefaultInterpolatorType;
00109
00111 typedef CovariantVector<double,itkGetStaticConstMacro(ImageDimension)>
00112 CovariantVectorType;
00113
00115 typedef CentralDifferenceImageFunction<FixedImageType>
00116 GradientCalculatorType;
00117 typedef typename GradientCalculatorType::Pointer
00118 GradientCalculatorPointer;
00119
00121 typedef CentralDifferenceImageFunction<MovingImageType,CoordRepType>
00122 MovingImageGradientCalculatorType;
00123 typedef typename MovingImageGradientCalculatorType::Pointer
00124 MovingImageGradientCalculatorPointer;
00125
00127 void SetMovingImageInterpolator( InterpolatorType * ptr )
00128 { m_MovingImageInterpolator = ptr; }
00129
00131 InterpolatorType * GetMovingImageInterpolator(void)
00132 { return m_MovingImageInterpolator; }
00133
00135 virtual TimeStepType ComputeGlobalTimeStep(void * itkNotUsed(GlobalData))
00136 const
00137 { return m_TimeStep; }
00138
00141 virtual void *GetGlobalDataPointer() const
00142 {
00143 GlobalDataStruct *global = new GlobalDataStruct();
00144 global->m_SumOfSquaredDifference = 0.0;
00145 global->m_NumberOfPixelsProcessed = 0L;
00146 global->m_SumOfSquaredChange = 0;
00147 return global;
00148 }
00149
00151 virtual void ReleaseGlobalDataPointer( void *GlobalData ) const;
00152
00154 virtual void InitializeIteration();
00155
00158 virtual PixelType ComputeUpdate(const NeighborhoodType &neighborhood,
00159 void *globalData,
00160 const FloatOffsetType &offset =
00161 FloatOffsetType(0.0));
00162
00166 virtual double GetMetric() const
00167 { return m_Metric; }
00168
00170 virtual double GetRMSChange() const
00171 { return m_RMSChange; }
00172
00176 virtual void SetUseMovingImageGradient( bool flag )
00177 { m_UseMovingImageGradient = flag; }
00178 virtual bool GetUseMovingImageGradient() const
00179 { return m_UseMovingImageGradient; }
00180
00185 virtual void SetIntensityDifferenceThreshold(double);
00186 virtual double GetIntensityDifferenceThreshold() const;
00187
00188 protected:
00189 DemonsRegistrationFunction();
00190 ~DemonsRegistrationFunction() {}
00191 void PrintSelf(std::ostream& os, Indent indent) const;
00192
00194 typedef ConstNeighborhoodIterator<FixedImageType>
00195 FixedImageNeighborhoodIteratorType;
00196
00199 struct GlobalDataStruct
00200 {
00201 double m_SumOfSquaredDifference;
00202 unsigned long m_NumberOfPixelsProcessed;
00203 double m_SumOfSquaredChange;
00204 };
00205
00206 private:
00207 DemonsRegistrationFunction(const Self&);
00208 void operator=(const Self&);
00209
00211 SpacingType m_FixedImageSpacing;
00212 PointType m_FixedImageOrigin;
00213 double m_Normalizer;
00214
00216 GradientCalculatorPointer m_FixedImageGradientCalculator;
00217
00219 MovingImageGradientCalculatorPointer m_MovingImageGradientCalculator;
00220 bool m_UseMovingImageGradient;
00221
00223 InterpolatorPointer m_MovingImageInterpolator;
00224
00226 TimeStepType m_TimeStep;
00227
00229 double m_DenominatorThreshold;
00230
00232 double m_IntensityDifferenceThreshold;
00233
00237 mutable double m_Metric;
00238 mutable double m_SumOfSquaredDifference;
00239 mutable unsigned long m_NumberOfPixelsProcessed;
00240 mutable double m_RMSChange;
00241 mutable double m_SumOfSquaredChange;
00242
00244 mutable SimpleFastMutexLock m_MetricCalculationLock;
00245
00246 };
00247
00248
00249 }
00250
00251 #ifndef ITK_MANUAL_INSTANTIATION
00252 #include "itkDemonsRegistrationFunction.txx"
00253 #endif
00254
00255 #endif
00256