go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkAdvancedImageToImageMetric.h
Go to the documentation of this file.
00001 /*======================================================================
00002 
00003   This file is part of the elastix software.
00004 
00005   Copyright (c) University Medical Center Utrecht. All rights reserved.
00006   See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
00007   details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE. See the above copyright notices for more information.
00012 
00013 ======================================================================*/
00014 
00015 #ifndef __itkAdvancedImageToImageMetric_h
00016 #define __itkAdvancedImageToImageMetric_h
00017 
00018 #include "itkImageToImageMetric.h"
00019 
00020 #include "itkImageSamplerBase.h"
00021 #include "itkGradientImageFilter.h"
00022 #include "itkBSplineInterpolateImageFunction.h"
00023 #include "itkReducedDimensionBSplineInterpolateImageFunction.h"
00024 #include "itkLimiterFunctionBase.h"
00025 #include "itkFixedArray.h"
00026 #include "itkAdvancedTransform.h"
00027 #include "vnl/vnl_sparse_matrix.h"
00028 
00029 namespace itk
00030 {
00031 
00068 template <class TFixedImage, class TMovingImage>
00069 class AdvancedImageToImageMetric :
00070   public ImageToImageMetric< TFixedImage, TMovingImage >
00071 {
00072 public:
00074   typedef AdvancedImageToImageMetric  Self;
00075   typedef ImageToImageMetric<
00076     TFixedImage, TMovingImage >           Superclass;
00077   typedef SmartPointer<Self>              Pointer;
00078   typedef SmartPointer<const Self>        ConstPointer;
00079 
00081   itkTypeMacro( AdvancedImageToImageMetric, ImageToImageMetric );
00082 
00084   itkStaticConstMacro( MovingImageDimension, unsigned int,
00085     TMovingImage::ImageDimension );
00086   itkStaticConstMacro( FixedImageDimension, unsigned int,
00087     TFixedImage::ImageDimension );
00088 
00090   typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
00091   typedef typename Superclass::MovingImageType            MovingImageType;
00092   typedef typename Superclass::MovingImagePixelType       MovingImagePixelType;
00093   typedef typename MovingImageType::Pointer               MovingImagePointer;
00094   typedef typename Superclass::MovingImageConstPointer    MovingImageConstPointer;
00095   typedef typename Superclass::FixedImageType             FixedImageType;
00096   typedef typename FixedImageType::Pointer                FixedImagePointer;
00097   typedef typename Superclass::FixedImageConstPointer     FixedImageConstPointer;
00098   typedef typename Superclass::FixedImageRegionType       FixedImageRegionType;
00099   typedef typename Superclass::TransformType              TransformType;
00100   typedef typename Superclass::TransformPointer           TransformPointer;
00101   typedef typename Superclass::InputPointType             InputPointType;
00102   typedef typename Superclass::OutputPointType            OutputPointType;
00103   typedef typename Superclass::TransformParametersType    TransformParametersType;
00104   typedef typename Superclass::TransformJacobianType      TransformJacobianType;
00105   typedef typename Superclass::InterpolatorType           InterpolatorType;
00106   typedef typename Superclass::InterpolatorPointer        InterpolatorPointer;
00107   typedef typename Superclass::RealType                   RealType;
00108   typedef typename Superclass::GradientPixelType          GradientPixelType;
00109   typedef typename Superclass::GradientImageType          GradientImageType;
00110   typedef typename Superclass::GradientImagePointer       GradientImagePointer;
00111   typedef typename Superclass::GradientImageFilterType    GradientImageFilterType;
00112   typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
00113   typedef typename Superclass::FixedImageMaskType         FixedImageMaskType;
00114   typedef typename Superclass::FixedImageMaskPointer      FixedImageMaskPointer;
00115   typedef typename Superclass::MovingImageMaskType        MovingImageMaskType;
00116   typedef typename Superclass::MovingImageMaskPointer     MovingImageMaskPointer;
00117   typedef typename Superclass::MeasureType                MeasureType;
00118   typedef typename Superclass::DerivativeType             DerivativeType;
00119   typedef typename DerivativeType::ValueType              DerivativeValueType;
00120   typedef typename Superclass::ParametersType             ParametersType;
00121 
00123   typedef typename FixedImageType::PixelType              FixedImagePixelType;
00124   typedef typename MovingImageType::RegionType            MovingImageRegionType;
00125   typedef FixedArray< double,
00126     itkGetStaticConstMacro(MovingImageDimension) >        MovingImageDerivativeScalesType;
00127 
00129   typedef ImageSamplerBase< FixedImageType >              ImageSamplerType;
00130   typedef typename ImageSamplerType::Pointer              ImageSamplerPointer;
00131   typedef typename
00132     ImageSamplerType::OutputVectorContainerType           ImageSampleContainerType;
00133   typedef typename
00134     ImageSamplerType::OutputVectorContainerPointer        ImageSampleContainerPointer;
00135 
00137   typedef LimiterFunctionBase<
00138     RealType, FixedImageDimension>                        FixedImageLimiterType;
00139   typedef typename FixedImageLimiterType::OutputType      FixedImageLimiterOutputType;
00140   typedef LimiterFunctionBase<
00141     RealType, MovingImageDimension>                       MovingImageLimiterType;
00142   typedef typename MovingImageLimiterType::OutputType     MovingImageLimiterOutputType;
00143 
00145   typedef typename TransformType::ScalarType              ScalarType;
00146   typedef AdvancedTransform<
00147     ScalarType,
00148     FixedImageDimension,
00149     MovingImageDimension >                                AdvancedTransformType;
00150 
00152   typedef typename DerivativeType::ValueType              HessianValueType;
00153   //typedef Array2D<HessianValueType>                       HessianType;
00154   typedef vnl_sparse_matrix<HessianValueType>             HessianType;
00155 
00158   virtual void SetTransform( AdvancedTransformType * arg )
00159   {
00160     this->Superclass::SetTransform( arg );
00161     if ( this->m_AdvancedTransform != arg )
00162     {
00163       this->m_AdvancedTransform = arg;
00164       this->Modified();
00165     }
00166   }
00167   const AdvancedTransformType * GetTransform( void ) const
00168   {
00169     return this->m_AdvancedTransform.GetPointer();
00170   }
00171 
00173   itkSetObjectMacro( ImageSampler, ImageSamplerType );
00174   virtual ImageSamplerType * GetImageSampler( void ) const
00175   {
00176     return this->m_ImageSampler.GetPointer();
00177   };
00178 
00181   itkGetConstMacro( UseImageSampler, bool );
00182 
00186   itkSetMacro( RequiredRatioOfValidSamples, double );
00187   itkGetConstMacro( RequiredRatioOfValidSamples, double );
00188 
00191   itkSetObjectMacro( MovingImageLimiter, MovingImageLimiterType );
00192   itkGetConstObjectMacro( MovingImageLimiter, MovingImageLimiterType );
00193   itkSetObjectMacro( FixedImageLimiter, FixedImageLimiterType );
00194   itkGetConstObjectMacro( FixedImageLimiter, FixedImageLimiterType );
00195 
00202   itkSetMacro( MovingLimitRangeRatio, double );
00203   itkGetConstMacro( MovingLimitRangeRatio, double );
00204   itkSetMacro( FixedLimitRangeRatio, double );
00205   itkGetConstMacro( FixedLimitRangeRatio, double );
00206 
00209   itkGetConstMacro( UseFixedImageLimiter, bool );
00210   itkGetConstMacro( UseMovingImageLimiter, bool );
00211 
00218   itkSetMacro( UseMovingImageDerivativeScales, bool );
00219   itkGetConstMacro( UseMovingImageDerivativeScales, bool );
00220   itkSetMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
00221   itkGetConstReferenceMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
00222 
00231   virtual void Initialize( void ) throw ( ExceptionObject );
00232 
00235   virtual void GetSelfHessian( const TransformParametersType & parameters, HessianType & H ) const;
00236 
00237 protected:
00238 
00240   AdvancedImageToImageMetric();
00241 
00243   virtual ~AdvancedImageToImageMetric() {};
00244 
00246   void PrintSelf( std::ostream& os, Indent indent ) const;
00247 
00251   typedef typename FixedImageType::IndexType                    FixedImageIndexType;
00252   typedef typename FixedImageIndexType::IndexValueType          FixedImageIndexValueType;
00253   typedef typename MovingImageType::IndexType                   MovingImageIndexType;
00254   typedef typename TransformType::InputPointType                FixedImagePointType;
00255   typedef typename TransformType::OutputPointType               MovingImagePointType;
00256   typedef typename InterpolatorType::ContinuousIndexType        MovingImageContinuousIndexType;
00257 
00259   typedef BSplineInterpolateImageFunction<
00260     MovingImageType, CoordinateRepresentationType, double>      BSplineInterpolatorType;
00261   typedef BSplineInterpolateImageFunction<
00262     MovingImageType, CoordinateRepresentationType, float>       BSplineInterpolatorFloatType;
00263   typedef ReducedDimensionBSplineInterpolateImageFunction<
00264     MovingImageType, CoordinateRepresentationType, double>      ReducedBSplineInterpolatorType;
00265   typedef typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType;
00266   typedef GradientImageFilter<
00267     MovingImageType, RealType, RealType>                        CentralDifferenceGradientFilterType;
00268 
00270   typedef typename
00271     AdvancedTransformType::NonZeroJacobianIndicesType           NonZeroJacobianIndicesType;
00272 
00277   mutable ImageSamplerPointer   m_ImageSampler;
00278 
00280   bool m_InterpolatorIsBSpline;
00281   bool m_InterpolatorIsBSplineFloat;
00282   bool m_InterpolatorIsReducedBSpline;
00283   typename BSplineInterpolatorType::Pointer             m_BSplineInterpolator;
00284   typename BSplineInterpolatorFloatType::Pointer        m_BSplineInterpolatorFloat;
00285   typename ReducedBSplineInterpolatorType::Pointer      m_ReducedBSplineInterpolator;
00286   typename CentralDifferenceGradientFilterType::Pointer m_CentralDifferenceGradientFilter;
00287 
00289   bool m_TransformIsAdvanced;
00290   typename AdvancedTransformType::Pointer           m_AdvancedTransform;
00291 
00293   typename FixedImageLimiterType::Pointer            m_FixedImageLimiter;
00294   typename MovingImageLimiterType::Pointer           m_MovingImageLimiter;
00295   FixedImagePixelType                                m_FixedImageTrueMin;
00296   FixedImagePixelType                                m_FixedImageTrueMax;
00297   MovingImagePixelType                               m_MovingImageTrueMin;
00298   MovingImagePixelType                               m_MovingImageTrueMax;
00299   FixedImageLimiterOutputType                        m_FixedImageMinLimit;
00300   FixedImageLimiterOutputType                        m_FixedImageMaxLimit;
00301   MovingImageLimiterOutputType                       m_MovingImageMinLimit;
00302   MovingImageLimiterOutputType                       m_MovingImageMaxLimit;
00303 
00309   virtual void InitializeImageSampler( void ) throw ( ExceptionObject );
00310 
00313   itkSetMacro( UseImageSampler, bool );
00314 
00317   virtual void CheckNumberOfSamples(
00318     unsigned long wanted, unsigned long found ) const;
00319 
00324   virtual void CheckForBSplineInterpolator( void );
00325 
00333   virtual bool EvaluateMovingImageValueAndDerivative(
00334     const MovingImagePointType & mappedPoint,
00335     RealType & movingImageValue,
00336     MovingImageDerivativeType * gradient ) const;
00337 
00341   virtual void CheckForAdvancedTransform( void );
00342 
00347   virtual bool TransformPoint(
00348     const FixedImagePointType & fixedImagePoint,
00349     MovingImagePointType & mappedPoint ) const;
00350 
00357   virtual bool EvaluateTransformJacobian(
00358     const FixedImagePointType & fixedImagePoint,
00359     TransformJacobianType & jacobian,
00360     NonZeroJacobianIndicesType & nzji ) const;
00361 
00363   virtual bool IsInsideMovingMask( const MovingImagePointType & point ) const;
00364 
00370   virtual void ComputeFixedImageExtrema(
00371     const FixedImageType * image,
00372     const FixedImageRegionType & region );
00373 
00377   virtual void ComputeMovingImageExtrema(
00378     const MovingImageType * image,
00379     const MovingImageRegionType & region );
00380 
00383   virtual void InitializeLimiters( void );
00384 
00387   itkSetMacro( UseFixedImageLimiter, bool );
00388   itkSetMacro( UseMovingImageLimiter, bool );
00389 
00390 private:
00391   AdvancedImageToImageMetric(const Self&); //purposely not implemented
00392   void operator=(const Self&); //purposely not implemented
00393 
00395   bool    m_UseImageSampler;
00396   double  m_FixedLimitRangeRatio;
00397   double  m_MovingLimitRangeRatio;
00398   bool    m_UseFixedImageLimiter;
00399   bool    m_UseMovingImageLimiter;
00400   double  m_RequiredRatioOfValidSamples;
00401   bool    m_UseMovingImageDerivativeScales;
00402   MovingImageDerivativeScalesType m_MovingImageDerivativeScales;
00403 
00404 }; // end class AdvancedImageToImageMetric
00405 
00406 } // end namespace itk
00407 
00408 #ifndef ITK_MANUAL_INSTANTIATION
00409 #include "itkAdvancedImageToImageMetric.hxx"
00410 #endif
00411 
00412 #endif // end #ifndef __itkAdvancedImageToImageMetric_h
00413 


Generated on 24-10-2011 for elastix by doxygen 1.7.4 elastix logo