ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkFastSymmetricForcesDemonsRegistrationFunction.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 __itkFastSymmetricForcesDemonsRegistrationFunction_h
00019 #define __itkFastSymmetricForcesDemonsRegistrationFunction_h
00020 
00021 #include "itkPDEDeformableRegistrationFunction.h"
00022 #include "itkPoint.h"
00023 #include "itkInterpolateImageFunction.h"
00024 #include "itkCentralDifferenceImageFunction.h"
00025 #include "itkWarpImageFilter.h"
00026 
00027 namespace itk
00028 {
00045 template< class TFixedImage, class TMovingImage, class TDisplacementField >
00046 class ITK_EXPORT FastSymmetricForcesDemonsRegistrationFunction:
00047   public PDEDeformableRegistrationFunction< TFixedImage,
00048                                             TMovingImage, TDisplacementField >
00049 {
00050 public:
00051 
00053   typedef FastSymmetricForcesDemonsRegistrationFunction Self;
00054   typedef PDEDeformableRegistrationFunction< TFixedImage,
00055                                              TMovingImage, TDisplacementField >
00056   Superclass;
00057   typedef SmartPointer< Self >       Pointer;
00058   typedef SmartPointer< const Self > ConstPointer;
00059 
00061   itkNewMacro(Self);
00062 
00064   itkTypeMacro(FastSymmetricForcesDemonsRegistrationFunction,
00065                PDEDeformableRegistrationFunction);
00066 
00068   typedef typename Superclass::MovingImageType    MovingImageType;
00069   typedef typename Superclass::MovingImagePointer MovingImagePointer;
00070 
00072   typedef typename Superclass::FixedImageType    FixedImageType;
00073   typedef typename Superclass::FixedImagePointer FixedImagePointer;
00074   typedef typename FixedImageType::IndexType     IndexType;
00075   typedef typename FixedImageType::SizeType      SizeType;
00076   typedef typename FixedImageType::SpacingType   SpacingType;
00077 
00079   typedef typename Superclass::DisplacementFieldType DisplacementFieldType;
00080   typedef typename Superclass::DisplacementFieldTypePointer
00081   DisplacementFieldTypePointer;
00082 
00083 #ifdef ITKV3_COMPATIBILITY
00084   typedef typename Superclass::DeformationFieldType        DeformationFieldType;
00085   typedef typename Superclass::DeformationFieldTypePointer DeformationFieldTypePointer;
00086 #endif
00087 
00089   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00090 
00092   typedef typename Superclass::PixelType        PixelType;
00093   typedef typename Superclass::RadiusType       RadiusType;
00094   typedef typename Superclass::NeighborhoodType NeighborhoodType;
00095   typedef typename Superclass::FloatOffsetType  FloatOffsetType;
00096   typedef typename Superclass::TimeStepType     TimeStepType;
00097 
00099   typedef double                                                          CoordRepType;
00100   typedef InterpolateImageFunction< MovingImageType, CoordRepType >       InterpolatorType;
00101   typedef typename InterpolatorType::Pointer                              InterpolatorPointer;
00102   typedef typename InterpolatorType::PointType                            PointType;
00103   typedef LinearInterpolateImageFunction< MovingImageType, CoordRepType > DefaultInterpolatorType;
00104 
00106   typedef WarpImageFilter< MovingImageType, MovingImageType, DisplacementFieldType > WarperType;
00107   typedef typename WarperType::Pointer                                              WarperPointer;
00108 
00110   typedef CovariantVector< double, itkGetStaticConstMacro(ImageDimension) > CovariantVectorType;
00111 
00113   typedef CentralDifferenceImageFunction< FixedImageType > GradientCalculatorType;
00114   typedef typename GradientCalculatorType::Pointer         GradientCalculatorPointer;
00115 
00116   typedef CentralDifferenceImageFunction< MovingImageType > MovingGradientCalculatorType;
00117   typedef typename MovingGradientCalculatorType::Pointer    MovingGradientCalculatorPointer;
00118 
00120   void SetMovingImageInterpolator(InterpolatorType *ptr)
00121   {
00122     m_MovingImageInterpolator = ptr; m_MovingImageWarper->SetInterpolator(ptr);
00123   }
00124 
00126   InterpolatorType * GetMovingImageInterpolator(void)
00127   {
00128     return m_MovingImageInterpolator;
00129   }
00130 
00132   virtual TimeStepType ComputeGlobalTimeStep( void *itkNotUsed(GlobalData) ) const
00133   {
00134     return m_TimeStep;
00135   }
00136 
00139   virtual void * GetGlobalDataPointer() const
00140   {
00141     GlobalDataStruct *global = new GlobalDataStruct();
00142 
00143     global->m_SumOfSquaredDifference  = 0.0;
00144     global->m_NumberOfPixelsProcessed = 0L;
00145     global->m_SumOfSquaredChange      = 0;
00146     return global;
00147   }
00148 
00150   virtual void ReleaseGlobalDataPointer(void *GlobalData) const;
00151 
00153   virtual void InitializeIteration();
00154 
00157   virtual PixelType  ComputeUpdate( const NeighborhoodType & neighborhood,
00158                                     void *globalData,
00159                                     const FloatOffsetType & offset = FloatOffsetType(0.0) );
00160 
00164   virtual double GetMetric() const
00165   {
00166     return m_Metric;
00167   }
00168 
00170   virtual const double & GetRMSChange() const
00171   {
00172     return m_RMSChange;
00173   }
00174 
00179   virtual void SetIntensityDifferenceThreshold(double);
00180 
00181   virtual double GetIntensityDifferenceThreshold() const;
00182 
00183 protected:
00184   FastSymmetricForcesDemonsRegistrationFunction();
00185   ~FastSymmetricForcesDemonsRegistrationFunction() {}
00186   void PrintSelf(std::ostream & os, Indent indent) const;
00187 
00189   typedef ConstNeighborhoodIterator< FixedImageType > FixedImageNeighborhoodIteratorType;
00190 
00193   struct GlobalDataStruct {
00194     double m_SumOfSquaredDifference;
00195     SizeValueType m_NumberOfPixelsProcessed;
00196     double m_SumOfSquaredChange;
00197   };
00198 private:
00199   FastSymmetricForcesDemonsRegistrationFunction(const Self &); //purposely not
00200                                                                // implemented
00201   void operator=(const Self &);                                //purposely not
00203 
00204   // implemented
00205 
00207   double m_Normalizer;
00208 
00210   GradientCalculatorPointer m_FixedImageGradientCalculator;
00211 
00213   MovingGradientCalculatorPointer m_WarpedMovingImageGradientCalculator;
00214 
00216   InterpolatorPointer m_MovingImageInterpolator;
00217 
00219   WarperPointer m_MovingImageWarper;
00220 
00222   TimeStepType m_TimeStep;
00223 
00225   double m_DenominatorThreshold;
00226 
00228   double m_IntensityDifferenceThreshold;
00229 
00233   mutable double        m_Metric;
00234   mutable double        m_SumOfSquaredDifference;
00235   mutable SizeValueType m_NumberOfPixelsProcessed;
00236   mutable double        m_RMSChange;
00237   mutable double        m_SumOfSquaredChange;
00238 
00240   mutable SimpleFastMutexLock m_MetricCalculationLock;
00241 };
00242 } // end namespace itk
00243 
00244 #ifndef ITK_MANUAL_INSTANTIATION
00245 #include "itkFastSymmetricForcesDemonsRegistrationFunction.hxx"
00246 #endif
00247 
00248 #endif
00249