ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkESMDemonsRegistrationFunction.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkESMDemonsRegistrationFunction_h
00019 #define __itkESMDemonsRegistrationFunction_h
00020 
00021 #include "itkPDEDeformableRegistrationFunction.h"
00022 #include "itkCentralDifferenceImageFunction.h"
00023 #include "itkWarpImageFilter.h"
00024 
00025 namespace itk
00026 {
00059 template< class TFixedImage, class TMovingImage, class TDisplacementField >
00060 class ITK_EXPORT ESMDemonsRegistrationFunction:
00061   public PDEDeformableRegistrationFunction< TFixedImage,
00062                                             TMovingImage, TDisplacementField >
00063 {
00064 public:
00065 
00067   typedef ESMDemonsRegistrationFunction Self;
00068   typedef PDEDeformableRegistrationFunction<
00069     TFixedImage, TMovingImage, TDisplacementField >    Superclass;
00070 
00071   typedef SmartPointer< Self >       Pointer;
00072   typedef SmartPointer< const Self > ConstPointer;
00073 
00075   itkNewMacro(Self);
00076 
00078   itkTypeMacro(ESMDemonsRegistrationFunction,
00079                PDEDeformableRegistrationFunction);
00080 
00082   typedef typename Superclass::MovingImageType    MovingImageType;
00083   typedef typename Superclass::MovingImagePointer MovingImagePointer;
00084   typedef typename MovingImageType::PixelType     MovingPixelType;
00085 
00087   typedef typename Superclass::FixedImageType    FixedImageType;
00088   typedef typename Superclass::FixedImagePointer FixedImagePointer;
00089   typedef typename FixedImageType::IndexType     IndexType;
00090   typedef typename FixedImageType::SizeType      SizeType;
00091   typedef typename FixedImageType::SpacingType   SpacingType;
00092   typedef typename FixedImageType::DirectionType DirectionType;
00093 
00095   typedef typename Superclass::DisplacementFieldType DisplacementFieldType;
00096   typedef typename Superclass::DisplacementFieldTypePointer
00097   DisplacementFieldTypePointer;
00098 
00100   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00101 
00103   typedef typename Superclass::PixelType        PixelType;
00104   typedef typename Superclass::RadiusType       RadiusType;
00105   typedef typename Superclass::NeighborhoodType NeighborhoodType;
00106   typedef typename Superclass::FloatOffsetType  FloatOffsetType;
00107   typedef typename Superclass::TimeStepType     TimeStepType;
00108 
00110   typedef double CoordRepType;
00111   typedef InterpolateImageFunction<
00112     MovingImageType, CoordRepType >                   InterpolatorType;
00113   typedef typename InterpolatorType::Pointer   InterpolatorPointer;
00114   typedef typename InterpolatorType::PointType PointType;
00115   typedef LinearInterpolateImageFunction<
00116     MovingImageType, CoordRepType >                   DefaultInterpolatorType;
00117 
00119   typedef WarpImageFilter<
00120     MovingImageType,
00121     MovingImageType, DisplacementFieldType >           WarperType;
00122 
00123   typedef typename WarperType::Pointer WarperPointer;
00124 
00126   typedef CovariantVector< double, itkGetStaticConstMacro(ImageDimension) > CovariantVectorType;
00127 
00129   typedef CentralDifferenceImageFunction< FixedImageType > GradientCalculatorType;
00130   typedef typename GradientCalculatorType::Pointer         GradientCalculatorPointer;
00131 
00133   typedef CentralDifferenceImageFunction< MovingImageType, CoordRepType >
00134   MovingImageGradientCalculatorType;
00135   typedef typename MovingImageGradientCalculatorType::Pointer
00136   MovingImageGradientCalculatorPointer;
00137 
00139   void SetMovingImageInterpolator(InterpolatorType *ptr)
00140   { m_MovingImageInterpolator = ptr; m_MovingImageWarper->SetInterpolator(ptr); }
00141 
00143   InterpolatorType * GetMovingImageInterpolator(void)
00144   { return m_MovingImageInterpolator; }
00145 
00147   virtual TimeStepType ComputeGlobalTimeStep( void *itkNotUsed(GlobalData) ) const
00148   { return m_TimeStep; }
00149 
00152   virtual void * GetGlobalDataPointer() const
00153   {
00154     GlobalDataStruct *global = new GlobalDataStruct();
00155 
00156     global->m_SumOfSquaredDifference  = 0.0;
00157     global->m_NumberOfPixelsProcessed = 0L;
00158     global->m_SumOfSquaredChange      = 0;
00159     return global;
00160   }
00161 
00163   virtual void ReleaseGlobalDataPointer(void *GlobalData) const;
00164 
00166   virtual void InitializeIteration();
00167 
00170   virtual PixelType  ComputeUpdate( const NeighborhoodType & neighborhood,
00171                                     void *globalData,
00172                                     const FloatOffsetType & offset = FloatOffsetType(0.0) );
00173 
00177   virtual double GetMetric() const
00178   { return m_Metric; }
00179 
00181   virtual const double & GetRMSChange() const
00182   { return m_RMSChange; }
00183 
00188   virtual void SetIntensityDifferenceThreshold(double);
00189 
00190   virtual double GetIntensityDifferenceThreshold() const;
00191 
00195   virtual void SetMaximumUpdateStepLength(double sm)
00196   {
00197     this->m_MaximumUpdateStepLength = sm;
00198   }
00199 
00200   virtual double GetMaximumUpdateStepLength() const
00201   {
00202     return this->m_MaximumUpdateStepLength;
00203   }
00204 
00206   enum GradientType {
00207     Symmetric = 0,
00208     Fixed = 1,
00209     WarpedMoving = 2,
00210     MappedMoving = 3
00211     };
00212 
00214   virtual void SetUseGradientType(GradientType gtype)
00215   { m_UseGradientType = gtype; }
00216   virtual GradientType GetUseGradientType() const
00217   { return m_UseGradientType; }
00218 protected:
00219   ESMDemonsRegistrationFunction();
00220   ~ESMDemonsRegistrationFunction() {}
00221   void PrintSelf(std::ostream & os, Indent indent) const;
00223 
00225   typedef ConstNeighborhoodIterator< FixedImageType > FixedImageNeighborhoodIteratorType;
00226 
00229   struct GlobalDataStruct {
00230     double m_SumOfSquaredDifference;
00231     SizeValueType m_NumberOfPixelsProcessed;
00232     double m_SumOfSquaredChange;
00233   };
00234 private:
00235   ESMDemonsRegistrationFunction(const Self &); //purposely not implemented
00236   void operator=(const Self &);                //purposely not implemented
00238 
00240   PointType     m_FixedImageOrigin;
00241   SpacingType   m_FixedImageSpacing;
00242   DirectionType m_FixedImageDirection;
00243   double        m_Normalizer;
00244 
00246   GradientCalculatorPointer m_FixedImageGradientCalculator;
00247 
00249   MovingImageGradientCalculatorPointer m_MappedMovingImageGradientCalculator;
00250 
00251   GradientType m_UseGradientType;
00252 
00254   InterpolatorPointer m_MovingImageInterpolator;
00255 
00257   WarperPointer m_MovingImageWarper;
00258 
00260   TimeStepType m_TimeStep;
00261 
00263   double m_DenominatorThreshold;
00264 
00266   double m_IntensityDifferenceThreshold;
00267 
00269   double m_MaximumUpdateStepLength;
00270 
00274   mutable double        m_Metric;
00275   mutable double        m_SumOfSquaredDifference;
00276   mutable SizeValueType m_NumberOfPixelsProcessed;
00277   mutable double        m_RMSChange;
00278   mutable double        m_SumOfSquaredChange;
00279 
00281   mutable SimpleFastMutexLock m_MetricCalculationLock;
00282 };
00283 } // end namespace itk
00284 
00285 #ifndef ITK_MANUAL_INSTANTIATION
00286 #include "itkESMDemonsRegistrationFunction.hxx"
00287 #endif
00288 
00289 #endif
00290