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.
1 /*======================================================================
2 
3  This file is part of the elastix software.
4 
5  Copyright (c) University Medical Center Utrecht. All rights reserved.
6  See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
7  details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 ======================================================================*/
14 #ifndef __itkAdvancedImageToImageMetric_h
15 #define __itkAdvancedImageToImageMetric_h
16 
17 #include "itkImageToImageMetric.h"
18 
19 #include "itkImageSamplerBase.h"
20 #include "itkGradientImageFilter.h"
21 #include "itkBSplineInterpolateImageFunction.h"
24 #include "itkLimiterFunctionBase.h"
25 #include "itkFixedArray.h"
26 #include "itkAdvancedTransform.h"
27 #include "vnl/vnl_sparse_matrix.h"
28 
29 // Needed for checking for B-spline for faster implementation
32 
33 #include "itkMultiThreader.h"
34 
35 namespace itk
36 {
37 
74 template< class TFixedImage, class TMovingImage >
76  public ImageToImageMetric< TFixedImage, TMovingImage >
77 {
78 public:
79 
82  typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
83  typedef SmartPointer< Self > Pointer;
84  typedef SmartPointer< const Self > ConstPointer;
85 
87  itkTypeMacro( AdvancedImageToImageMetric, ImageToImageMetric );
88 
90  itkStaticConstMacro( MovingImageDimension, unsigned int,
91  TMovingImage::ImageDimension );
92  itkStaticConstMacro( FixedImageDimension, unsigned int,
93  TFixedImage::ImageDimension );
94 
96  typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
97  typedef typename Superclass::MovingImageType MovingImageType;
98  typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
99  typedef typename MovingImageType::Pointer MovingImagePointer;
100  typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer;
101  typedef typename Superclass::FixedImageType FixedImageType;
102  typedef typename FixedImageType::Pointer FixedImagePointer;
103  typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
104  typedef typename Superclass::FixedImageRegionType FixedImageRegionType;
105  typedef typename Superclass::TransformType TransformType;
106  typedef typename Superclass::TransformPointer TransformPointer;
107  typedef typename Superclass::InputPointType InputPointType;
108  typedef typename Superclass::OutputPointType OutputPointType;
109  typedef typename Superclass::TransformParametersType TransformParametersType;
110  typedef typename Superclass::TransformJacobianType TransformJacobianType;
111  typedef typename Superclass::InterpolatorType InterpolatorType;
112  typedef typename Superclass::InterpolatorPointer InterpolatorPointer;
113  typedef typename Superclass::RealType RealType;
114  typedef typename Superclass::GradientPixelType GradientPixelType;
115  typedef typename Superclass::GradientImageType GradientImageType;
116  typedef typename Superclass::GradientImagePointer GradientImagePointer;
117  typedef typename Superclass::GradientImageFilterType GradientImageFilterType;
118  typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
119  typedef typename Superclass::FixedImageMaskType FixedImageMaskType;
120  typedef typename Superclass::FixedImageMaskPointer FixedImageMaskPointer;
121  typedef typename Superclass::MovingImageMaskType MovingImageMaskType;
122  typedef typename Superclass::MovingImageMaskPointer MovingImageMaskPointer;
123  typedef typename Superclass::MeasureType MeasureType;
124  typedef typename Superclass::DerivativeType DerivativeType;
125  typedef typename DerivativeType::ValueType DerivativeValueType;
126  typedef typename Superclass::ParametersType ParametersType;
127 
129  typedef typename FixedImageType::PixelType FixedImagePixelType;
130  typedef typename MovingImageType::RegionType MovingImageRegionType;
132 
138 
146 
148  typedef typename TransformType::ScalarType ScalarType;
149  typedef AdvancedTransform<
150  ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType;
152 
158 
160  typedef typename DerivativeType::ValueType HessianValueType;
161  typedef vnl_sparse_matrix< HessianValueType > HessianType;
162 
164  typedef itk::MultiThreader ThreaderType;
165  typedef typename ThreaderType::ThreadInfoStruct ThreadInfoType;
166 
170  virtual void SetTransform( AdvancedTransformType * arg )
171  {
172  this->Superclass::SetTransform( arg );
173  if( this->m_AdvancedTransform != arg )
174  {
175  this->m_AdvancedTransform = arg;
176  this->Modified();
177  }
178  }
179 
180 
182  const AdvancedTransformType * GetTransform( void ) const
183  {
184  return this->m_AdvancedTransform.GetPointer();
185  }
186 
187 
189  itkSetObjectMacro( ImageSampler, ImageSamplerType );
190  virtual ImageSamplerType * GetImageSampler( void ) const
191  {
192  return this->m_ImageSampler.GetPointer();
193  }
194 
195 
198  itkGetConstMacro( UseImageSampler, bool );
199 
203  itkSetMacro( RequiredRatioOfValidSamples, double );
204  itkGetConstMacro( RequiredRatioOfValidSamples, double );
205 
208  itkSetObjectMacro( MovingImageLimiter, MovingImageLimiterType );
209  itkGetConstObjectMacro( MovingImageLimiter, MovingImageLimiterType );
210  itkSetObjectMacro( FixedImageLimiter, FixedImageLimiterType );
211  itkGetConstObjectMacro( FixedImageLimiter, FixedImageLimiterType );
212 
219  itkSetMacro( MovingLimitRangeRatio, double );
220  itkGetConstMacro( MovingLimitRangeRatio, double );
221  itkSetMacro( FixedLimitRangeRatio, double );
222  itkGetConstMacro( FixedLimitRangeRatio, double );
223 
226  itkGetConstMacro( UseFixedImageLimiter, bool );
227  itkGetConstMacro( UseMovingImageLimiter, bool );
228 
236  itkSetMacro( UseMovingImageDerivativeScales, bool );
237  itkGetConstMacro( UseMovingImageDerivativeScales, bool );
238  itkSetMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
239  itkGetConstReferenceMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
240 
249  virtual void Initialize( void ) throw ( ExceptionObject );
250 
254  virtual void GetSelfHessian( const TransformParametersType & parameters, HessianType & H ) const;
255 
257  virtual void SetNumberOfThreads( ThreadIdType numberOfThreads );
258 
260  itkSetMacro( UseMetricSingleThreaded, bool );
261  itkGetConstReferenceMacro( UseMetricSingleThreaded, bool );
262  itkBooleanMacro( UseMetricSingleThreaded );
263 
265  // \todo: maybe these can be united, check base class.
266  itkSetMacro( UseMultiThread, bool );
267  itkGetConstReferenceMacro( UseMultiThread, bool );
268  itkBooleanMacro( UseMultiThread );
269 
276  const TransformParametersType & parameters ) const;
277 
278 protected:
279 
282 
284  virtual ~AdvancedImageToImageMetric();
285 
287  void PrintSelf( std::ostream & os, Indent indent ) const;
288 
292  typedef typename FixedImageType::IndexType FixedImageIndexType;
293  typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
294  typedef typename MovingImageType::IndexType MovingImageIndexType;
297  typedef typename InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType;
298 
300  typedef BSplineInterpolateImageFunction<
302  typedef typename BSplineInterpolatorType::Pointer BSplineInterpolatorPointer;
303  typedef BSplineInterpolateImageFunction<
305  typedef typename BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer;
308  typedef typename ReducedBSplineInterpolatorType::Pointer ReducedBSplineInterpolatorPointer;
311  typedef typename LinearInterpolatorType::Pointer LinearInterpolatorPointer;
312  typedef typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType;
313  typedef GradientImageFilter<
315  typedef typename CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer;
316 
318  typedef typename
320 
327 
333  BSplineInterpolatorPointer m_BSplineInterpolator;
334  BSplineInterpolatorFloatPointer m_BSplineInterpolatorFloat;
335  ReducedBSplineInterpolatorPointer m_ReducedBSplineInterpolator;
336  LinearInterpolatorPointer m_LinearInterpolator;
337  CentralDifferenceGradientFilterPointer m_CentralDifferenceGradientFilter;
338 
343 
355 
359  virtual inline void ThreadedGetValueAndDerivative(
360  ThreadIdType threadID ){}
361 
364  MeasureType & value, DerivativeType & derivative ) const {}
365 
367  static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeThreaderCallback( void * arg );
368 
371 
373  static ITK_THREAD_RETURN_TYPE AccumulateDerivativesThreaderCallback( void * arg );
374 
379 
384  {
385  // To give the threads access to all members.
387  // Used for accumulating derivatives
390  };
391  mutable MultiThreaderParameterType m_ThreaderMetricParameters;
392 
402  // test per thread struct with padding and alignment
404  {
409  };
410  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, GetValueAndDerivativePerThreadStruct,
411  PaddedGetValueAndDerivativePerThreadStruct );
412  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct,
413  AlignedGetValueAndDerivativePerThreadStruct );
414  mutable AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables;
416 
418  virtual void InitializeThreadingParameters( void ) const;
419 
425  virtual void InitializeImageSampler( void ) throw ( ExceptionObject );
426 
429  itkSetMacro( UseImageSampler, bool );
430 
433  virtual void CheckNumberOfSamples(
434  unsigned long wanted, unsigned long found ) const;
435 
440  virtual void CheckForBSplineInterpolator( void );
441 
451  const MovingImagePointType & mappedPoint,
452  RealType & movingImageValue,
453  MovingImageDerivativeType * gradient ) const;
454 
460  const TransformJacobianType & jacobian,
461  const MovingImageDerivativeType & movingImageDerivative,
462  DerivativeType & imageJacobian ) const;
463 
467  virtual void CheckForAdvancedTransform( void );
468 
470  virtual void CheckForBSplineTransform( void );
471 
476  virtual bool TransformPoint(
477  const FixedImagePointType & fixedImagePoint,
478  MovingImagePointType & mappedPoint ) const;
479 
486  virtual bool EvaluateTransformJacobian(
487  const FixedImagePointType & fixedImagePoint,
488  TransformJacobianType & jacobian,
489  NonZeroJacobianIndicesType & nzji ) const;
490 
492  virtual bool IsInsideMovingMask( const MovingImagePointType & point ) const;
493 
499  virtual void ComputeFixedImageExtrema(
500  const FixedImageType * image,
501  const FixedImageRegionType & region );
502 
506  virtual void ComputeMovingImageExtrema(
507  const MovingImageType * image,
508  const MovingImageRegionType & region );
509 
512  virtual void InitializeLimiters( void );
513 
516  itkSetMacro( UseFixedImageLimiter, bool );
517  itkSetMacro( UseMovingImageLimiter, bool );
518 
519 private:
520 
521  AdvancedImageToImageMetric( const Self & ); // purposely not implemented
522  void operator=( const Self & ); // purposely not implemented
523 
533 
534 };
535 
536 } // end namespace itk
537 
538 #ifndef ITK_MANUAL_INSTANTIATION
539 #include "itkAdvancedImageToImageMetric.hxx"
540 #endif
541 
542 #endif // end #ifndef __itkAdvancedImageToImageMetric_h
void PrintSelf(std::ostream &os, Indent indent) const
This class combines two transforms: an 'initial transform' with a 'current transform'.
ImageToImageMetric< TFixedImage, TMovingImage > Superclass
virtual bool TransformPoint(const FixedImagePointType &fixedImagePoint, MovingImagePointType &mappedPoint) const
AdvancedTransformType::NumberOfParametersType NumberOfParametersType
const AdvancedTransformType * GetTransform(void) const
MovingImageDerivativeScalesType m_MovingImageDerivativeScales
AdvancedTransform< ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType
Deformable transform using a B-spline representation.
virtual void CheckForAdvancedTransform(void)
virtual bool IsInsideMovingMask(const MovingImagePointType &point) const
LimiterFunctionBase< RealType, FixedImageDimension > FixedImageLimiterType
Superclass::CoordinateRepresentationType CoordinateRepresentationType
Superclass::TransformParametersType TransformParametersType
Superclass::MovingImageType MovingImageType
Superclass::FixedImageMaskPointer FixedImageMaskPointer
An extension of the ITK ImageToImageMetric. It is the intended base class for all elastix metrics...
virtual void CheckForBSplineInterpolator(void)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct, AlignedGetValueAndDerivativePerThreadStruct)
virtual void ComputeFixedImageExtrema(const FixedImageType *image, const FixedImageRegionType &region)
virtual void InitializeLimiters(void)
virtual void ThreadedGetValueAndDerivative(ThreadIdType threadID)
AdvancedCombinationTransform< ScalarType, FixedImageDimension > CombinationTransformType
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, float > BSplineInterpolatorFloatType
Superclass::GradientPixelType GradientPixelType
static ITK_THREAD_RETURN_TYPE AccumulateDerivativesThreaderCallback(void *arg)
FixedImageLimiterOutputType m_FixedImageMinLimit
FixedImageLimiterType::OutputType FixedImageLimiterOutputType
SmartPointer< Self > Pointer
Superclass::FixedImageRegionType FixedImageRegionType
AdvancedTransformType::Pointer m_AdvancedTransform
virtual void AfterThreadedGetValueAndDerivative(MeasureType &value, DerivativeType &derivative) const
ImageSamplerType::OutputVectorContainerType ImageSampleContainerType
SmartPointer< Self > Pointer
virtual void BeforeThreadedGetValueAndDerivative(const TransformParametersType &parameters) const
AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables
FixedArray< double, Self::MovingImageDimension > MovingImageDerivativeScalesType
This class is a base class for any image sampler.
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > BSplineInterpolatorType
ImageSamplerBase< FixedImageType > ImageSamplerType
FixedImageLimiterOutputType m_FixedImageMaxLimit
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
MovingImageLimiterOutputType m_MovingImageMaxLimit
Superclass::InterpolatorPointer InterpolatorPointer
BSplineInterpolatorFloatPointer m_BSplineInterpolatorFloat
Transform maps points, vectors and covariant vectors from an input space to an output space...
Superclass::OutputVectorContainerPointer OutputVectorContainerPointer
BSplineInterpolatorPointer m_BSplineInterpolator
Superclass::NumberOfParametersType NumberOfParametersType
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 3 > BSplineOrder3TransformType
Superclass::MovingImageMaskType MovingImageMaskType
ReducedBSplineInterpolatorPointer m_ReducedBSplineInterpolator
LimiterFunctionBase< RealType, MovingImageDimension > MovingImageLimiterType
Superclass::GradientImageType GradientImageType
Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
Superclass::TransformPointer TransformPointer
virtual void SetNumberOfThreads(ThreadIdType numberOfThreads)
virtual void EvaluateTransformJacobianInnerProduct(const TransformJacobianType &jacobian, const MovingImageDerivativeType &movingImageDerivative, DerivativeType &imageJacobian) const
Superclass::GradientImageFilterType GradientImageFilterType
MovingImageType::RegionType MovingImageRegionType
MovingImageLimiterOutputType m_MovingImageMinLimit
Superclass::InterpolatorType InterpolatorType
Base class for all ITK limiter function objects.
Superclass::TransformJacobianType TransformJacobianType
virtual void CheckForBSplineTransform(void)
virtual void CheckNumberOfSamples(unsigned long wanted, unsigned long found) const
MovingImageLimiterType::Pointer MovingImageLimiterPointer
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 1 > BSplineOrder1TransformType
virtual void ComputeMovingImageExtrema(const MovingImageType *image, const MovingImageRegionType &region)
FixedImageLimiterType::Pointer FixedImageLimiterPointer
static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeThreaderCallback(void *arg)
Superclass::MovingImagePixelType MovingImagePixelType
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 2 > BSplineOrder2TransformType
virtual bool EvaluateMovingImageValueAndDerivative(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient) const
virtual void GetSelfHessian(const TransformParametersType &parameters, HessianType &H) const
Superclass::MovingImageMaskPointer MovingImageMaskPointer
MovingImageLimiterType::OutputType MovingImageLimiterOutputType
ThreaderType::ThreadInfoStruct ThreadInfoType
virtual void Initialize(void)
void LaunchGetValueAndDerivativeThreaderCallback(void) const
virtual void InitializeThreadingParameters(void) const
ImageSamplerType::OutputVectorContainerPointer ImageSampleContainerPointer
Superclass::FixedImageMaskType FixedImageMaskType
virtual ImageSamplerType * GetImageSampler(void) const
MultiThreaderParameterType m_ThreaderMetricParameters
CentralDifferenceGradientFilterPointer m_CentralDifferenceGradientFilter
itkStaticConstMacro(MovingImageDimension, unsigned int, TMovingImage::ImageDimension)
Superclass::OutputType OutputType
Superclass::FixedImageConstPointer FixedImageConstPointer
Superclass::MovingImageConstPointer MovingImageConstPointer
virtual void InitializeImageSampler(void)
Linearly interpolate an image at specified positions.
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValueAndDerivativePerThreadStruct, PaddedGetValueAndDerivativePerThreadStruct)
virtual void SetTransform(AdvancedTransformType *arg)
virtual bool EvaluateTransformJacobian(const FixedImagePointType &fixedImagePoint, TransformJacobianType &jacobian, NonZeroJacobianIndicesType &nzji) const
Superclass::GradientImageFilterPointer GradientImageFilterPointer
vnl_sparse_matrix< HessianValueType > HessianType
Superclass::GradientImagePointer GradientImagePointer


Generated on 27-04-2014 for elastix by doxygen 1.8.6 elastix logo