ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMIRegistrationFunction.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 __itkMIRegistrationFunction_h
00019 #define __itkMIRegistrationFunction_h
00020 
00021 #include "itkPDEDeformableRegistrationFunction.h"
00022 #include "itkPoint.h"
00023 #include "itkLinearInterpolateImageFunction.h"
00024 #include "itkCentralDifferenceImageFunction.h"
00025 
00026 namespace itk
00027 {
00052 template< class TFixedImage, class TMovingImage, class TDisplacementField >
00053 class ITK_EXPORT MIRegistrationFunction:
00054   public PDEDeformableRegistrationFunction< TFixedImage,
00055                                             TMovingImage, TDisplacementField >
00056 {
00057 public:
00058 
00060   typedef MIRegistrationFunction Self;
00061   typedef PDEDeformableRegistrationFunction< TFixedImage,
00062                                              TMovingImage, TDisplacementField >    Superclass;
00063   typedef SmartPointer< Self >       Pointer;
00064   typedef SmartPointer< const Self > ConstPointer;
00065 
00067   itkNewMacro(Self);
00068 
00070   itkTypeMacro(MIRegistrationFunction,
00071                PDEDeformableRegistrationFunction);
00072 
00074   typedef typename Superclass::MovingImageType    MovingImageType;
00075   typedef typename Superclass::MovingImagePointer MovingImagePointer;
00076 
00078   typedef typename Superclass::FixedImageType    FixedImageType;
00079   typedef typename Superclass::FixedImagePointer FixedImagePointer;
00080   typedef typename FixedImageType::IndexType     IndexType;
00081   typedef typename FixedImageType::SizeType      SizeType;
00082   typedef typename FixedImageType::SpacingType   SpacingType;
00083 
00085   typedef typename Superclass::DisplacementFieldType DisplacementFieldType;
00086   typedef typename Superclass::DisplacementFieldTypePointer
00087   DisplacementFieldTypePointer;
00088 
00090   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00091 
00093   typedef typename Superclass::PixelType        PixelType;
00094   typedef typename Superclass::RadiusType       RadiusType;
00095   typedef typename Superclass::NeighborhoodType NeighborhoodType;
00096   typedef typename Superclass::FloatOffsetType  FloatOffsetType;
00097   typedef typename Superclass::TimeStepType     TimeStepType;
00098 
00100   typedef double                                                    CoordRepType;
00101   typedef InterpolateImageFunction< MovingImageType, CoordRepType > InterpolatorType;
00102   typedef typename InterpolatorType::Pointer                        InterpolatorPointer;
00103   typedef typename InterpolatorType::PointType                      PointType;
00104   typedef LinearInterpolateImageFunction< MovingImageType, CoordRepType >
00105   DefaultInterpolatorType;
00106 
00108   typedef CovariantVector< double, itkGetStaticConstMacro(ImageDimension) > CovariantVectorType;
00109 
00111   typedef CentralDifferenceImageFunction< FixedImageType > GradientCalculatorType;
00112   typedef typename GradientCalculatorType::Pointer         GradientCalculatorPointer;
00113 
00115   void SetMovingImageInterpolator(InterpolatorType *ptr)
00116   { m_MovingImageInterpolator = ptr; }
00117 
00119   InterpolatorType * GetMovingImageInterpolator(void)
00120   { return m_MovingImageInterpolator; }
00121 
00123   virtual TimeStepType ComputeGlobalTimeStep( void *itkNotUsed(GlobalData) ) const
00124   { return m_TimeStep; }
00125 
00128   virtual void * GetGlobalDataPointer() const
00129   {
00130     GlobalDataStruct *global = new GlobalDataStruct();
00131 
00132     return global;
00133   }
00134 
00136   virtual void ReleaseGlobalDataPointer(void *GlobalData) const
00137   { delete (GlobalDataStruct *)GlobalData;  }
00138 
00140   virtual void InitializeIteration();
00141 
00144   virtual PixelType  ComputeUpdate( const NeighborhoodType & neighborhood,
00145                                     void *globalData,
00146                                     const FloatOffsetType & offset = FloatOffsetType(0.0) );
00147 
00148   void SetMinNorm(float ts = 1.0) { m_Minnorm = ts; }
00149 
00150   void SetDoInverse(bool b = false) { m_DoInverse = b; }
00151 protected:
00152   MIRegistrationFunction();
00153   ~MIRegistrationFunction() {}
00154   void PrintSelf(std::ostream & os, Indent indent) const;
00155 
00157   typedef ConstNeighborhoodIterator< FixedImageType > FixedImageNeighborhoodIteratorType;
00158 
00161   struct GlobalDataStruct {
00162     FixedImageNeighborhoodIteratorType m_FixedImageIterator;
00163   };
00164 
00166   TimeStepType m_TimeStep;
00167 private:
00168   MIRegistrationFunction(const Self &); //purposely not implemented
00169   void operator=(const Self &);         //purposely not implemented
00171 
00173   SpacingType m_FixedImageSpacing;
00174   PointType   m_FixedImageOrigin;
00175 
00177   GradientCalculatorPointer m_FixedImageGradientCalculator;
00178 
00180   GradientCalculatorPointer m_MovingImageGradientCalculator;
00181 
00183   InterpolatorPointer m_MovingImageInterpolator;
00184 
00186   double m_DenominatorThreshold;
00187 
00189   double m_IntensityDifferenceThreshold;
00190 
00191   mutable double m_MetricTotal;
00192 
00193   unsigned int m_NumberOfSamples;
00194   unsigned int m_NumberOfBins;
00195   float        m_Minnorm;
00196 
00197   bool m_DoInverse;
00198 };
00199 } // end namespace itk
00200 
00201 #ifndef ITK_MANUAL_INSTANTIATION
00202 #include "itkMIRegistrationFunction.hxx"
00203 #endif
00204 
00205 #endif
00206