ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkImageToImageMetricv4.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkImageToImageMetricv4_h
19 #define __itkImageToImageMetricv4_h
20 
21 #include "itkCovariantVector.h"
22 #include "itkImageFunction.h"
25 #include "itkSpatialObject.h"
26 #include "itkResampleImageFilter.h"
29 #include "itkImageToImageFilter.h"
31 #include "itkPointSet.h"
34 
35 namespace itk
36 {
167 template<class TFixedImage,class TMovingImage,class TVirtualImage = TFixedImage,
168  typename TMetricTraits = DefaultImageToImageMetricTraitsv4< TFixedImage, TMovingImage, TVirtualImage > >
169 class ITK_EXPORT ImageToImageMetricv4 : public ObjectToObjectMetric<TFixedImage::ImageDimension, TMovingImage::ImageDimension, TVirtualImage>
170 {
171 public:
172 
178 
181 
183  typedef typename Superclass::InternalComputationValueType InternalComputationValueType;
184 
186  typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
187 
189  typedef typename Superclass::ParametersType ParametersType;
190  typedef typename Superclass::ParametersValueType ParametersValueType;
191 
193  typedef typename Superclass::GradientSourceType GradientSourceType;
194 
196  typedef typename Superclass::DimensionType DimensionType;
197  typedef typename Superclass::DimensionType ImageDimensionType;
198 
200  typedef typename Superclass::FixedTransformType FixedTransformType;
201  typedef typename Superclass::FixedTransformPointer FixedTransformPointer;
202  typedef typename Superclass::FixedInputPointType FixedInputPointType;
203  typedef typename Superclass::FixedOutputPointType FixedOutputPointType;
204  typedef typename Superclass::FixedTransformParametersType FixedTransformParametersType;
205 
206  typedef typename Superclass::MovingTransformType MovingTransformType;
207  typedef typename Superclass::MovingTransformPointer MovingTransformPointer;
208  typedef typename Superclass::MovingInputPointType MovingInputPointType;
209  typedef typename Superclass::MovingOutputPointType MovingOutputPointType;
210  typedef typename Superclass::MovingTransformParametersType MovingTransformParametersType;
211 
212  typedef typename Superclass::JacobianType JacobianType;
213  typedef typename Superclass::FixedTransformJacobianType FixedTransformJacobianType;
214  typedef typename Superclass::MovingTransformJacobianType MovingTransformJacobianType;
215 
217  typedef TFixedImage FixedImageType;
218  typedef typename FixedImageType::PixelType FixedImagePixelType;
220  typedef typename FixedImageType::Pointer FixedImagePointer;
221  typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
222  typedef typename FixedImageType::PointType FixedImagePointType;
223  typedef typename FixedImageType::IndexType FixedImageIndexType;
224  typedef TMovingImage MovingImageType;
225  typedef typename MovingImageType::PixelType MovingImagePixelType;
227  typedef typename MovingImageType::Pointer MovingImagePointer;
228  typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
229  typedef typename MovingImageType::PointType MovingImagePointType;
230  typedef typename MovingImageType::RegionType MovingImageRegionType;
231  typedef typename MovingImageType::IndexType MovingImageIndexType;
232 
234  typedef typename Superclass::VirtualImageType VirtualImageType;
235  typedef typename Superclass::VirtualImagePointer VirtualImagePointer;
236  typedef typename Superclass::VirtualPixelType VirtualPixelType;
237  typedef typename Superclass::VirtualRegionType VirtualRegionType;
238  typedef typename Superclass::VirtualSizeType VirtualSizeType;
239  typedef typename Superclass::VirtualSpacingType VirtualSpacingType;
240  typedef typename Superclass::VirtualPointType VirtualOriginType;
241  typedef typename Superclass::VirtualPointType VirtualPointType;
242  typedef typename Superclass::VirtualDirectionType VirtualDirectionType;
243  typedef typename Superclass::VirtualSizeType VirtualRadiusType;
244  typedef typename Superclass::VirtualIndexType VirtualIndexType;
245  typedef typename Superclass::VirtualPointSetType VirtualPointSetType;
246  typedef typename Superclass::VirtualPointSetPointer VirtualPointSetPointer;
247 
249  typedef TMetricTraits MetricTraits;
250 
251  /* Image dimension accessors */
252  itkStaticConstMacro(FixedImageDimension, DimensionType, Superclass::FixedDimension);
253  itkStaticConstMacro(MovingImageDimension, DimensionType, Superclass::MovingDimension);
254  itkStaticConstMacro(VirtualImageDimension, DimensionType, Superclass::VirtualDimension);
255 
261 
267 
273 
283 
288 
291 
294 
297 
303 
306 
309 
312 
313  typedef typename FixedImageGradientImageType::Pointer FixedImageGradientImagePointer;
315 
318 
319  typedef typename FixedImageGradientFilterType::Pointer
323 
324 
328 
335 
336  typedef typename FixedImageGradientCalculatorType::Pointer
340 
344 
346  typedef typename Superclass::MeasureType MeasureType;
347 
349  typedef typename Superclass::DerivativeType DerivativeType;
350  typedef typename DerivativeType::ValueType DerivativeValueType;
351 
354  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
355 
356  /* Get/Set the Fixed Image. */
357  itkSetConstObjectMacro(FixedImage, FixedImageType);
358  itkGetConstObjectMacro(FixedImage, FixedImageType);
359 
361  itkSetConstObjectMacro(MovingImage, MovingImageType);
362  itkGetConstObjectMacro(MovingImage, MovingImageType);
364 
366  itkSetObjectMacro(FixedInterpolator, FixedInterpolatorType);
367 
369  itkGetModifiableObjectMacro(FixedInterpolator, FixedInterpolatorType);
370 
372  itkSetObjectMacro(MovingInterpolator, MovingInterpolatorType);
373 
375  itkGetModifiableObjectMacro(MovingInterpolator, MovingInterpolatorType);
376 
378  itkSetObjectMacro(MovingImageMask, MovingImageMaskType);
379  itkSetConstObjectMacro(MovingImageMask, MovingImageMaskType);
380  itkGetConstObjectMacro(MovingImageMask, MovingImageMaskType);
382 
384  itkSetObjectMacro(FixedImageMask, FixedImageMaskType);
385  itkSetConstObjectMacro(FixedImageMask, FixedImageMaskType);
386  itkGetConstObjectMacro(FixedImageMask, FixedImageMaskType);
388 
392  itkSetObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
393  itkSetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
394  itkGetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
396 
398  itkSetMacro(UseFixedSampledPointSet, bool);
399  itkGetConstReferenceMacro(UseFixedSampledPointSet, bool);
400  itkBooleanMacro(UseFixedSampledPointSet);
402 
404  itkGetModifiableObjectMacro(VirtualSampledPointSet, VirtualPointSetType);
405 
407  itkSetObjectMacro( FixedImageGradientFilter, FixedImageGradientFilterType );
408  itkGetModifiableObjectMacro(FixedImageGradientFilter, FixedImageGradientFilterType );
409  itkSetObjectMacro( MovingImageGradientFilter, MovingImageGradientFilterType );
410  itkGetModifiableObjectMacro(MovingImageGradientFilter, MovingImageGradientFilterType );
412 
414  itkSetObjectMacro( FixedImageGradientCalculator, FixedImageGradientCalculatorType);
415  itkGetModifiableObjectMacro(FixedImageGradientCalculator, FixedImageGradientCalculatorType);
416  itkSetObjectMacro( MovingImageGradientCalculator, MovingImageGradientCalculatorType);
417  itkGetModifiableObjectMacro(MovingImageGradientCalculator, MovingImageGradientCalculatorType);
419 
422  itkSetMacro(UseFixedImageGradientFilter, bool);
423  itkGetConstReferenceMacro(UseFixedImageGradientFilter, bool);
424  itkBooleanMacro(UseFixedImageGradientFilter);
426 
428  itkSetMacro(UseMovingImageGradientFilter, bool);
429  itkGetConstReferenceMacro(UseMovingImageGradientFilter, bool);
430  itkBooleanMacro(UseMovingImageGradientFilter);
432 
436  virtual ThreadIdType GetNumberOfThreadsUsed() const;
437 
441  virtual void SetMaximumNumberOfThreads( const ThreadIdType threads );
442  virtual ThreadIdType GetMaximumNumberOfThreads() const;
444 
446  itkGetModifiableObjectMacro(FixedImageGradientImage, FixedImageGradientImageType);
447 
449  itkGetModifiableObjectMacro(MovingImageGradientImage, MovingImageGradientImageType);
450 
452  itkGetConstMacro( NumberOfValidPoints, SizeValueType );
453 
458  SizeValueType GetNumberOfDomainPoints() const;
459 
473  itkSetMacro(UseFloatingPointCorrection, bool);
474  itkGetConstReferenceMacro(UseFloatingPointCorrection, bool);
475  itkBooleanMacro(UseFloatingPointCorrection);
477 
482  itkSetMacro( FloatingPointCorrectionResolution, DerivativeValueType );
483  itkGetConstMacro( FloatingPointCorrectionResolution, DerivativeValueType );
485 
486  /* Initialize the metric before calling GetValue or GetDerivative.
487  * Derived classes must call this Superclass version if they override
488  * this to perform their own initialization.
489  * \note This is meant to be called once for a particular metric setup.
490  * That is, when used in registration, this method would be called once
491  * before entering the registration loop, during which GetValue or
492  * GetDerivative will be called repeatedly. It must be called again if
493  * metric settings are changed before beginning a new registration. */
494  virtual void Initialize(void) throw ( itk::ExceptionObject );
495 
496  virtual MeasureType GetValue() const;
497 
498  virtual void GetDerivative( DerivativeType & ) const;
499 
505  virtual void GetValueAndDerivative( MeasureType & value, DerivativeType & derivative ) const;
506 
510  itkGetConstReferenceMacro(NumberOfSkippedFixedSampledPoints, SizeValueType);
511 
512  virtual bool SupportsArbitraryVirtualDomainSamples( void ) const
513  {
514  return true;
515  }
516 
517 protected:
518  /* Interpolators for image gradient filters. */
519  typedef LinearInterpolateImageFunction< FixedImageGradientImageType,
520  CoordinateRepresentationType >
525 
530 
531  /* A DenseGetValueAndDerivativeThreader
532  * Derived classes must define this class and assign it in their constructor
533  * if threaded processing in GetValueAndDerivative is performed. */
535  /* A SparseGetValueAndDerivativeThreader
536  * Derived classes must define this class and assign it in their constructor
537  * if threaded processing in GetValueAndDerivative is performed. */
539 
544  virtual void InitializeForIteration() const;
545 
553  bool TransformAndEvaluateFixedPoint(
554  const VirtualPointType & virtualPoint,
555  FixedImagePointType & mappedFixedPoint,
556  FixedImagePixelType & mappedFixedPixelValue ) const;
557 
559  bool TransformAndEvaluateMovingPoint(
560  const VirtualPointType & virtualPoint,
561  MovingImagePointType & mappedMovingPoint,
562  MovingImagePixelType & mappedMovingPixelValue ) const;
563 
565  virtual void ComputeFixedImageGradientAtPoint( const FixedImagePointType & mappedPoint, FixedImageGradientType & gradient ) const;
566 
568  virtual void ComputeMovingImageGradientAtPoint( const MovingImagePointType & mappedPoint, MovingImageGradientType & gradient ) const;
569 
573  virtual void ComputeFixedImageGradientFilterImage();
574 
578  virtual void ComputeMovingImageGradientFilterImage() const;
579 
586  virtual void GetValueAndDerivativeExecute() const;
587 
590  virtual void InitializeDefaultFixedImageGradientFilter(void);
591  virtual void InitializeDefaultMovingImageGradientFilter(void);
593 
595  itkGetConstMacro( ComputeDerivative, bool );
596 
599 
605 
610 
614 
617  typename DefaultFixedImageGradientFilter::Pointer
621 
624  typename DefaultFixedImageGradientCalculator::Pointer
628 
632 
636 
644 
648 
652 
655 
657  virtual ~ImageToImageMetricv4();
658 
659  void PrintSelf(std::ostream& os, Indent indent) const;
660 
661 private:
663  void MapFixedSampledPointSetToVirtual( void );
664 
668 
669  ImageToImageMetricv4(const Self &); //purposely not implemented
670  void operator=(const Self &); //purposely not implemented
671 
676 
679 
681 
683  mutable bool m_ComputeDerivative;
684 
687  #ifdef ITK_USE_CONCEPT_CHECKING
690  itkConceptMacro( OnlyDefinedForFloatingPointTypes0, ( itk::Concept::IsFloatingPoint<FixedImagePixelValueType> ) );
691  itkConceptMacro( OnlyDefinedForFloatingPointTypes1, ( itk::Concept::IsFloatingPoint<MovingImagePixelValueType> ) );
692  #endif // ITK_USE_CONCEPT_CHECKING
693 
694 
695 };
696 }//namespace itk
697 
698 #ifndef ITK_MANUAL_INSTANTIATION
699 #include "itkImageToImageMetricv4.hxx"
700 #endif
701 
702 #endif
703