Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageToImageMetric.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageToImageMetric.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-08-20 09:08:41 $
00007   Version:   $Revision: 1.26 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkImageToImageMetric_h
00018 #define __itkImageToImageMetric_h
00019 
00020 // First make sure that the configuration is available.
00021 // This line can be removed once the optimized versions
00022 // gets integrated into the main directories.
00023 #include "itkConfigure.h"
00024 
00025 #ifdef ITK_USE_OPTIMIZED_REGISTRATION_METHODS
00026 #include "itkOptImageToImageMetric.h"
00027 #else
00028 
00029 #include "itkImageBase.h"
00030 #include "itkTransform.h"
00031 #include "itkInterpolateImageFunction.h"
00032 #include "itkSingleValuedCostFunction.h"
00033 #include "itkExceptionObject.h"
00034 #include "itkGradientRecursiveGaussianImageFilter.h"
00035 #include "itkSpatialObject.h"
00036 
00037 namespace itk
00038 {
00039   
00059 template <class TFixedImage,  class TMovingImage> 
00060 class ITK_EXPORT ImageToImageMetric : public SingleValuedCostFunction 
00061 {
00062 public:
00064   typedef ImageToImageMetric           Self;
00065   typedef SingleValuedCostFunction     Superclass;
00066   typedef SmartPointer<Self>           Pointer;
00067   typedef SmartPointer<const Self>     ConstPointer;
00068 
00070   typedef typename Superclass::ParametersValueType CoordinateRepresentationType;
00071 
00073   itkTypeMacro(ImageToImageMetric, SingleValuedCostFunction);
00074 
00076   typedef TMovingImage                               MovingImageType;
00077   typedef typename TMovingImage::PixelType           MovingImagePixelType;
00078   typedef typename MovingImageType::ConstPointer     MovingImageConstPointer;
00079 
00081   typedef TFixedImage                                FixedImageType;
00082   typedef typename FixedImageType::ConstPointer      FixedImageConstPointer;
00083   typedef typename FixedImageType::RegionType        FixedImageRegionType;
00084 
00086   itkStaticConstMacro(MovingImageDimension, 
00087                       unsigned int,
00088                       TMovingImage::ImageDimension);
00089   itkStaticConstMacro(FixedImageDimension, 
00090                       unsigned int,
00091                       TFixedImage::ImageDimension);
00093 
00095   typedef Transform<CoordinateRepresentationType, 
00096                     itkGetStaticConstMacro(MovingImageDimension),
00097                     itkGetStaticConstMacro(FixedImageDimension)> 
00098                                                      TransformType;
00099 
00100   typedef typename TransformType::Pointer            TransformPointer;
00101   typedef typename TransformType::InputPointType     InputPointType;
00102   typedef typename TransformType::OutputPointType    OutputPointType;
00103   typedef typename TransformType::ParametersType     TransformParametersType;
00104   typedef typename TransformType::JacobianType       TransformJacobianType;
00105 
00107   typedef InterpolateImageFunction<
00108     MovingImageType,
00109     CoordinateRepresentationType > InterpolatorType;
00110 
00111 
00113   typedef typename NumericTraits<MovingImagePixelType>::RealType 
00114                                                      RealType;
00115   typedef CovariantVector<RealType,
00116                           itkGetStaticConstMacro(MovingImageDimension)>
00117                                                      GradientPixelType;
00118   typedef Image<GradientPixelType,
00119                 itkGetStaticConstMacro(MovingImageDimension)> 
00120                                                      GradientImageType;
00121   typedef SmartPointer<GradientImageType>            GradientImagePointer;
00122   typedef GradientRecursiveGaussianImageFilter< MovingImageType,
00123                                                 GradientImageType >
00124                                                      GradientImageFilterType;  
00125   typedef typename GradientImageFilterType::Pointer  GradientImageFilterPointer;
00127 
00128 
00129   typedef typename InterpolatorType::Pointer         InterpolatorPointer;
00130 
00131 
00134   typedef SpatialObject< itkGetStaticConstMacro(FixedImageDimension) >
00135                                                      FixedImageMaskType;
00136   typedef typename FixedImageMaskType::Pointer       FixedImageMaskPointer;
00137   typedef typename FixedImageMaskType::ConstPointer  FixedImageMaskConstPointer;
00138 
00139 
00142   typedef SpatialObject< itkGetStaticConstMacro(MovingImageDimension) >
00143                                                      MovingImageMaskType;
00144   typedef typename MovingImageMaskType::Pointer      MovingImageMaskPointer;
00145   typedef typename MovingImageMaskType::ConstPointer MovingImageMaskConstPointer;
00146 
00147 
00149   typedef typename Superclass::MeasureType                    MeasureType;
00150 
00152   typedef typename Superclass::DerivativeType                 DerivativeType;
00153 
00155   typedef typename Superclass::ParametersType                 ParametersType;
00156 
00158   itkSetConstObjectMacro( FixedImage, FixedImageType );
00159 
00161   itkGetConstObjectMacro( FixedImage, FixedImageType );
00162 
00164   itkSetConstObjectMacro( MovingImage, MovingImageType );
00165 
00167   itkGetConstObjectMacro( MovingImage, MovingImageType );
00168 
00170   itkSetObjectMacro( Transform, TransformType );
00171 
00173   itkGetConstObjectMacro( Transform, TransformType );
00174 
00176   itkSetObjectMacro( Interpolator, InterpolatorType );
00177 
00179   itkGetConstObjectMacro( Interpolator, InterpolatorType );
00180 
00182   itkGetConstReferenceMacro( NumberOfPixelsCounted, unsigned long );
00183 
00185   itkSetMacro( FixedImageRegion, FixedImageRegionType );
00186 
00188   itkGetConstReferenceMacro( FixedImageRegion, FixedImageRegionType );
00189 
00191   itkSetObjectMacro( MovingImageMask, MovingImageMaskType );
00192 #ifdef ITK_LEGACY_REMOVE
00193   itkSetConstObjectMacro( MovingImageMask, MovingImageMaskType );
00194 #else
00195   virtual void SetMovingImageMask( const MovingImageMaskType* mask )
00196     { this->SetMovingImageMask(const_cast<MovingImageMaskType*>(mask)); }
00197 #endif
00198   itkGetConstObjectMacro( MovingImageMask, MovingImageMaskType );
00200 
00202   itkSetObjectMacro( FixedImageMask, FixedImageMaskType );
00203 #ifdef ITK_LEGACY_REMOVE
00204   itkSetConstObjectMacro( FixedImageMask, FixedImageMaskType );
00205 #else
00206   virtual void SetFixedImageMask( const FixedImageMaskType* mask )
00207     { this->SetFixedImageMask(const_cast<FixedImageMaskType*>(mask)); }
00208 #endif
00209   itkGetConstObjectMacro( FixedImageMask, FixedImageMaskType );
00211 
00213   itkSetMacro( ComputeGradient, bool);
00214   itkGetConstReferenceMacro( ComputeGradient, bool);
00215   itkBooleanMacro(ComputeGradient);
00217 
00219   virtual void ComputeGradient();
00220 
00222   itkGetConstObjectMacro( GradientImage, GradientImageType );
00223 
00225   void SetTransformParameters( const ParametersType & parameters ) const;
00226 
00228   unsigned int GetNumberOfParameters(void) const 
00229     { return m_Transform->GetNumberOfParameters(); }
00230 
00233   virtual void Initialize(void) throw ( ExceptionObject );
00234 
00235 protected:
00236   ImageToImageMetric();
00237   virtual ~ImageToImageMetric();
00238   void PrintSelf(std::ostream& os, Indent indent) const;
00239 
00240   mutable unsigned long       m_NumberOfPixelsCounted;
00241 
00242   FixedImageConstPointer      m_FixedImage;
00243   MovingImageConstPointer     m_MovingImage;
00244 
00245   mutable TransformPointer    m_Transform;
00246   InterpolatorPointer         m_Interpolator;
00247 
00248   bool                        m_ComputeGradient;
00249   GradientImagePointer        m_GradientImage;
00250 
00251 #ifdef ITK_LEGACY_REMOVE
00252   FixedImageMaskConstPointer  m_FixedImageMask;
00253   MovingImageMaskConstPointer m_MovingImageMask;
00254 #else
00255   mutable FixedImageMaskPointer   m_FixedImageMask;
00256   mutable MovingImageMaskPointer  m_MovingImageMask;
00257 #endif
00258 
00259 private:
00260   ImageToImageMetric(const Self&); //purposely not implemented
00261   void operator=(const Self&); //purposely not implemented
00262   
00263   FixedImageRegionType        m_FixedImageRegion;  
00264 
00265 };
00266 
00267 } // end namespace itk
00268 
00269 #ifndef ITK_MANUAL_INSTANTIATION
00270 #include "itkImageToImageMetric.txx"
00271 #endif
00272 
00273 #endif
00274 
00275 #endif
00276 

Generated at Mon Jul 12 2010 18:47:15 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000