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 "itkLimiterFunctionBase.h"
00024 #include "itkFixedArray.h"
00025 #include "itkAdvancedTransform.h"
00026 
00027 namespace itk
00028 {
00029 
00060 template <class TFixedImage, class TMovingImage>
00061 class AdvancedImageToImageMetric :
00062   public ImageToImageMetric< TFixedImage, TMovingImage >
00063 {
00064 public:
00066   typedef AdvancedImageToImageMetric  Self;
00067   typedef ImageToImageMetric<
00068     TFixedImage, TMovingImage >           Superclass;
00069   typedef SmartPointer<Self>              Pointer;
00070   typedef SmartPointer<const Self>        ConstPointer;
00071 
00073   itkTypeMacro( AdvancedImageToImageMetric, ImageToImageMetric );
00074 
00076   itkStaticConstMacro( MovingImageDimension, unsigned int,
00077     TMovingImage::ImageDimension );
00078   itkStaticConstMacro( FixedImageDimension, unsigned int,
00079     TFixedImage::ImageDimension );
00080 
00082   typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
00083   typedef typename Superclass::MovingImageType            MovingImageType;
00084   typedef typename Superclass::MovingImagePixelType       MovingImagePixelType;
00085   typedef typename MovingImageType::Pointer               MovingImagePointer;
00086   typedef typename Superclass::MovingImageConstPointer    MovingImageConstPointer;
00087   typedef typename Superclass::FixedImageType             FixedImageType;
00088   typedef typename FixedImageType::Pointer                FixedImagePointer;
00089   typedef typename Superclass::FixedImageConstPointer     FixedImageConstPointer;
00090   typedef typename Superclass::FixedImageRegionType       FixedImageRegionType;
00091   typedef typename Superclass::TransformType              TransformType;
00092   typedef typename Superclass::TransformPointer           TransformPointer;
00093   typedef typename Superclass::InputPointType             InputPointType;
00094   typedef typename Superclass::OutputPointType            OutputPointType;
00095   typedef typename Superclass::TransformParametersType    TransformParametersType;
00096   typedef typename Superclass::TransformJacobianType      TransformJacobianType;
00097   typedef typename Superclass::InterpolatorType           InterpolatorType;
00098   typedef typename Superclass::InterpolatorPointer        InterpolatorPointer;
00099   typedef typename Superclass::RealType                   RealType;
00100   typedef typename Superclass::GradientPixelType          GradientPixelType;
00101   typedef typename Superclass::GradientImageType          GradientImageType;
00102   typedef typename Superclass::GradientImagePointer       GradientImagePointer;
00103   typedef typename Superclass::GradientImageFilterType    GradientImageFilterType;
00104   typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
00105   typedef typename Superclass::FixedImageMaskType         FixedImageMaskType;
00106   typedef typename Superclass::FixedImageMaskPointer      FixedImageMaskPointer;
00107   typedef typename Superclass::MovingImageMaskType        MovingImageMaskType;
00108   typedef typename Superclass::MovingImageMaskPointer     MovingImageMaskPointer;
00109   typedef typename Superclass::MeasureType                MeasureType;
00110   typedef typename Superclass::DerivativeType             DerivativeType;
00111   typedef typename DerivativeType::ValueType              DerivativeValueType;
00112   typedef typename Superclass::ParametersType             ParametersType;
00113 
00115   typedef typename FixedImageType::PixelType              FixedImagePixelType;
00116   typedef typename MovingImageType::RegionType            MovingImageRegionType;
00117   typedef FixedArray< double,
00118     itkGetStaticConstMacro(MovingImageDimension) >        MovingImageDerivativeScalesType;
00119 
00121   typedef ImageSamplerBase< FixedImageType >              ImageSamplerType;
00122   typedef typename ImageSamplerType::Pointer              ImageSamplerPointer;
00123   typedef typename
00124     ImageSamplerType::OutputVectorContainerType           ImageSampleContainerType;
00125   typedef typename
00126     ImageSamplerType::OutputVectorContainerPointer        ImageSampleContainerPointer;
00127 
00129   typedef LimiterFunctionBase<
00130     RealType, FixedImageDimension>                        FixedImageLimiterType;
00131   typedef typename FixedImageLimiterType::OutputType      FixedImageLimiterOutputType;
00132   typedef LimiterFunctionBase<
00133     RealType, MovingImageDimension>                       MovingImageLimiterType;
00134   typedef typename MovingImageLimiterType::OutputType     MovingImageLimiterOutputType;
00135 
00137   typedef typename TransformType::ScalarType              ScalarType;
00138   typedef AdvancedTransform<
00139     ScalarType,
00140     FixedImageDimension,
00141     MovingImageDimension >                                AdvancedTransformType;
00142 
00144   typedef typename DerivativeType::ValueType              HessianValueType;
00145   typedef Array2D<HessianValueType>                       HessianType;
00146 
00149   virtual void SetTransform( AdvancedTransformType * arg )
00150   {
00151     this->Superclass::SetTransform( arg );
00152     if ( this->m_AdvancedTransform != arg )
00153     {
00154       this->m_AdvancedTransform = arg;
00155       this->Modified();
00156     }
00157   }
00158   const AdvancedTransformType * GetTransform( void ) const
00159   {
00160     return this->m_AdvancedTransform.GetPointer();
00161   }
00162 
00164   itkSetObjectMacro( ImageSampler, ImageSamplerType );
00165   virtual ImageSamplerType * GetImageSampler( void ) const
00166   {
00167     return this->m_ImageSampler.GetPointer();
00168   };
00169 
00172   itkGetConstMacro( UseImageSampler, bool );
00173 
00177   itkSetMacro( RequiredRatioOfValidSamples, double );
00178   itkGetConstMacro( RequiredRatioOfValidSamples, double );
00179 
00182   itkSetObjectMacro( MovingImageLimiter, MovingImageLimiterType );
00183   itkGetConstObjectMacro( MovingImageLimiter, MovingImageLimiterType );
00184   itkSetObjectMacro( FixedImageLimiter, FixedImageLimiterType );
00185   itkGetConstObjectMacro( FixedImageLimiter, FixedImageLimiterType );
00186 
00193   itkSetMacro( MovingLimitRangeRatio, double );
00194   itkGetConstMacro( MovingLimitRangeRatio, double );
00195   itkSetMacro( FixedLimitRangeRatio, double );
00196   itkGetConstMacro( FixedLimitRangeRatio, double );
00197 
00200   itkGetConstMacro( UseFixedImageLimiter, bool );
00201   itkGetConstMacro( UseMovingImageLimiter, bool );
00202 
00209   itkSetMacro( UseMovingImageDerivativeScales, bool );
00210   itkGetConstMacro( UseMovingImageDerivativeScales, bool );
00211   itkSetMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
00212   itkGetConstReferenceMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
00213 
00222   virtual void Initialize( void ) throw ( ExceptionObject );
00223 
00226   virtual void GetSelfHessian( const TransformParametersType & parameters, HessianType & H ) const;
00227 
00228 protected:
00229 
00231   AdvancedImageToImageMetric();
00232 
00234   virtual ~AdvancedImageToImageMetric() {};
00235 
00237   void PrintSelf( std::ostream& os, Indent indent ) const;
00238 
00242   typedef typename FixedImageType::IndexType                    FixedImageIndexType;
00243   typedef typename FixedImageIndexType::IndexValueType          FixedImageIndexValueType;
00244   typedef typename MovingImageType::IndexType                   MovingImageIndexType;
00245   typedef typename TransformType::InputPointType                FixedImagePointType;
00246   typedef typename TransformType::OutputPointType               MovingImagePointType;
00247   typedef typename InterpolatorType::ContinuousIndexType        MovingImageContinuousIndexType;
00248 
00250   typedef BSplineInterpolateImageFunction<
00251     MovingImageType, CoordinateRepresentationType, double>      BSplineInterpolatorType;
00252   typedef BSplineInterpolateImageFunction<
00253     MovingImageType, CoordinateRepresentationType, float>       BSplineInterpolatorFloatType;
00254   typedef typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType;
00255   typedef GradientImageFilter<
00256     MovingImageType, RealType, RealType>                        CentralDifferenceGradientFilterType;
00257 
00259   typedef typename
00260     AdvancedTransformType::NonZeroJacobianIndicesType           NonZeroJacobianIndicesType;
00261 
00266   mutable ImageSamplerPointer   m_ImageSampler;
00267 
00269   bool m_InterpolatorIsBSpline;
00270   bool m_InterpolatorIsBSplineFloat;
00271   typename BSplineInterpolatorType::Pointer             m_BSplineInterpolator;
00272   typename BSplineInterpolatorFloatType::Pointer             m_BSplineInterpolatorFloat;
00273   typename CentralDifferenceGradientFilterType::Pointer m_CentralDifferenceGradientFilter;
00274 
00276   bool m_TransformIsAdvanced;
00277   typename AdvancedTransformType::Pointer           m_AdvancedTransform;
00278 
00280   typename FixedImageLimiterType::Pointer            m_FixedImageLimiter;
00281   typename MovingImageLimiterType::Pointer           m_MovingImageLimiter;
00282   FixedImagePixelType                                m_FixedImageTrueMin;
00283   FixedImagePixelType                                m_FixedImageTrueMax;
00284   MovingImagePixelType                               m_MovingImageTrueMin;
00285   MovingImagePixelType                               m_MovingImageTrueMax;
00286   FixedImageLimiterOutputType                        m_FixedImageMinLimit;
00287   FixedImageLimiterOutputType                        m_FixedImageMaxLimit;
00288   MovingImageLimiterOutputType                       m_MovingImageMinLimit;
00289   MovingImageLimiterOutputType                       m_MovingImageMaxLimit;
00290 
00296   virtual void InitializeImageSampler( void ) throw ( ExceptionObject );
00297 
00300   itkSetMacro( UseImageSampler, bool );
00301 
00304   virtual void CheckNumberOfSamples(
00305     unsigned long wanted, unsigned long found ) const;
00306 
00311   virtual void CheckForBSplineInterpolator( void );
00312 
00320   virtual bool EvaluateMovingImageValueAndDerivative(
00321     const MovingImagePointType & mappedPoint,
00322     RealType & movingImageValue,
00323     MovingImageDerivativeType * gradient ) const;
00324 
00328   virtual void CheckForAdvancedTransform( void );
00329 
00334   virtual bool TransformPoint(
00335     const FixedImagePointType & fixedImagePoint,
00336     MovingImagePointType & mappedPoint ) const;
00337 
00344   virtual bool EvaluateTransformJacobian(
00345     const FixedImagePointType & fixedImagePoint,
00346     TransformJacobianType & jacobian,
00347     NonZeroJacobianIndicesType & nzji ) const;
00348 
00350   virtual bool IsInsideMovingMask( const MovingImagePointType & point ) const;
00351 
00357   virtual void ComputeFixedImageExtrema(
00358     const FixedImageType * image,
00359     const FixedImageRegionType & region );
00360 
00364   virtual void ComputeMovingImageExtrema(
00365     const MovingImageType * image,
00366     const MovingImageRegionType & region );
00367 
00370   virtual void InitializeLimiters( void );
00371 
00374   itkSetMacro( UseFixedImageLimiter, bool );
00375   itkSetMacro( UseMovingImageLimiter, bool );
00376 
00377 private:
00378   AdvancedImageToImageMetric(const Self&); //purposely not implemented
00379   void operator=(const Self&); //purposely not implemented
00380 
00382   bool    m_UseImageSampler;
00383   double  m_FixedLimitRangeRatio;
00384   double  m_MovingLimitRangeRatio;
00385   bool    m_UseFixedImageLimiter;
00386   bool    m_UseMovingImageLimiter;
00387   double  m_RequiredRatioOfValidSamples;
00388   bool    m_UseMovingImageDerivativeScales;
00389   MovingImageDerivativeScalesType m_MovingImageDerivativeScales;
00390 
00391 }; // end class AdvancedImageToImageMetric
00392 
00393 } // end namespace itk
00394 
00395 #ifndef ITK_MANUAL_INSTANTIATION
00396 #include "itkAdvancedImageToImageMetric.hxx"
00397 #endif
00398 
00399 #endif // end #ifndef __itkAdvancedImageToImageMetric_h
00400 


Generated on 11-05-2011 for elastix by doxygen 1.7.4 elastix logo