ITK  4.2.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"
32 #include "itkPointSet.h"
33 
34 namespace itk
35 {
155 template<class TFixedImage,class TMovingImage,class TVirtualImage = TFixedImage>
156 class ITK_EXPORT ImageToImageMetricv4 :
157  public ObjectToObjectMetric<TFixedImage::ImageDimension, TMovingImage::ImageDimension, TVirtualImage>
158 {
159 public:
160 
166 
169 
171  typedef typename Superclass::InternalComputationValueType InternalComputationValueType;
172 
174  typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
175 
177  typedef typename Superclass::ParametersType ParametersType;
178  typedef typename Superclass::ParametersValueType ParametersValueType;
179 
181  typedef typename Superclass::GradientSourceType GradientSourceType;
182 
184  typedef typename Superclass::DimensionType DimensionType;
185  typedef typename Superclass::DimensionType ImageDimensionType;
186 
188  typedef typename Superclass::FixedTransformType FixedTransformType;
189  typedef typename Superclass::FixedTransformPointer FixedTransformPointer;
190  typedef typename Superclass::FixedInputPointType FixedInputPointType;
191  typedef typename Superclass::FixedOutputPointType FixedOutputPointType;
192  typedef typename Superclass::FixedTransformParametersType FixedTransformParametersType;
193 
194  typedef typename Superclass::MovingTransformType MovingTransformType;
195  typedef typename Superclass::MovingTransformPointer MovingTransformPointer;
196  typedef typename Superclass::MovingInputPointType MovingInputPointType;
197  typedef typename Superclass::MovingOutputPointType MovingOutputPointType;
198  typedef typename Superclass::MovingTransformParametersType MovingTransformParametersType;
199 
200  typedef typename Superclass::JacobianType JacobianType;
201  typedef typename Superclass::FixedTransformJacobianType FixedTransformJacobianType;
202  typedef typename Superclass::MovingTransformJacobianType MovingTransformJacobianType;
203 
205  typedef TFixedImage FixedImageType;
206  typedef typename FixedImageType::PixelType FixedImagePixelType;
208  typedef typename FixedImageType::Pointer FixedImagePointer;
209  typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
210  typedef typename FixedImageType::PointType FixedImagePointType;
211  typedef typename FixedImageType::IndexType FixedImageIndexType;
212  typedef TMovingImage MovingImageType;
213  typedef typename MovingImageType::PixelType MovingImagePixelType;
215  typedef typename MovingImageType::Pointer MovingImagePointer;
216  typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
217  typedef typename MovingImageType::PointType MovingImagePointType;
218  typedef typename MovingImageType::RegionType MovingImageRegionType;
219  typedef typename MovingImageType::IndexType MovingImageIndexType;
220 
222  typedef typename Superclass::VirtualImageType VirtualImageType;
223  typedef typename Superclass::VirtualImagePointer VirtualImagePointer;
224  typedef typename Superclass::VirtualPixelType VirtualPixelType;
225  typedef typename Superclass::VirtualRegionType VirtualRegionType;
226  typedef typename Superclass::VirtualSizeType VirtualSizeType;
227  typedef typename Superclass::VirtualSpacingType VirtualSpacingType;
228  typedef typename Superclass::VirtualPointType VirtualOriginType;
229  typedef typename Superclass::VirtualPointType VirtualPointType;
230  typedef typename Superclass::VirtualDirectionType VirtualDirectionType;
231  typedef typename Superclass::VirtualSizeType VirtualRadiusType;
232  typedef typename Superclass::VirtualIndexType VirtualIndexType;
233  typedef typename Superclass::VirtualPointSetType VirtualPointSetType;
234  typedef typename Superclass::VirtualPointSetPointer VirtualPointSetPointer;
235 
236  /* Image dimension accessors */
237  itkStaticConstMacro(FixedImageDimension, DimensionType, Superclass::FixedDimension);
238  itkStaticConstMacro(MovingImageDimension, DimensionType, Superclass::MovingDimension);
239  itkStaticConstMacro(VirtualImageDimension, DimensionType, Superclass::VirtualDimension);
240 
246 
252 
258 
268 
271  itkGetStaticConstMacro(FixedImageDimension) >
274  itkGetStaticConstMacro(MovingImageDimension) >
277 
279  itkGetStaticConstMacro(VirtualImageDimension) >
281 
288  itkGetStaticConstMacro(FixedImageDimension) >
290  typedef Image< FixedGradientPixelType,
291  itkGetStaticConstMacro(FixedImageDimension) >
293  typedef typename FixedImageGradientImageType::Pointer
296 
299 
303  itkGetStaticConstMacro(MovingImageDimension) >
306  itkGetStaticConstMacro(MovingImageDimension) >
309 
316 
324 
328  CovariantVector<double,
329  itkGetStaticConstMacro( FixedImageDimension )>,
333  CovariantVector<double,
334  itkGetStaticConstMacro( MovingImageDimension )>,
338 
343 
345  typedef typename Superclass::MeasureType MeasureType;
346 
348  typedef typename Superclass::DerivativeType DerivativeType;
349  typedef typename DerivativeType::ValueType DerivativeValueType;
350 
353  typedef typename Superclass::NumberOfParametersType NumberOfParametersType;
354 
355  /* Set/get images */
357  itkSetConstObjectMacro(FixedImage, FixedImageType);
358 
360  itkGetConstObjectMacro(FixedImage, FixedImageType);
361 
363  itkSetConstObjectMacro(MovingImage, MovingImageType);
364 
366  itkGetConstObjectMacro(MovingImage, MovingImageType);
367 
369  itkSetObjectMacro(FixedInterpolator, FixedInterpolatorType);
370 
372  itkGetConstObjectMacro(FixedInterpolator, FixedInterpolatorType);
373 
375  itkSetObjectMacro(MovingInterpolator, MovingInterpolatorType);
376 
378  itkGetConstObjectMacro(MovingInterpolator, MovingInterpolatorType);
379 
381  itkSetObjectMacro(MovingImageMask, MovingImageMaskType);
382  itkSetConstObjectMacro(MovingImageMask, MovingImageMaskType);
383  itkGetConstObjectMacro(MovingImageMask, MovingImageMaskType);
385 
387  itkSetObjectMacro(FixedImageMask, FixedImageMaskType);
388  itkSetConstObjectMacro(FixedImageMask, FixedImageMaskType);
389  itkGetConstObjectMacro(FixedImageMask, FixedImageMaskType);
391 
395  itkSetObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
396  itkSetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
397  itkGetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
399 
401  itkSetMacro(UseFixedSampledPointSet, bool);
402  itkGetConstReferenceMacro(UseFixedSampledPointSet, bool);
403  itkBooleanMacro(UseFixedSampledPointSet);
405 
407  itkGetConstObjectMacro(VirtualSampledPointSet, VirtualPointSetType);
408 
410  itkSetObjectMacro( FixedImageGradientFilter, FixedImageGradientFilterType );
411  itkGetObjectMacro( FixedImageGradientFilter, FixedImageGradientFilterType );
412  itkSetObjectMacro( MovingImageGradientFilter, MovingImageGradientFilterType );
413  itkGetObjectMacro( MovingImageGradientFilter, MovingImageGradientFilterType );
415 
417  itkSetObjectMacro( FixedImageGradientCalculator, FixedImageGradientCalculatorType);
418  itkGetObjectMacro( FixedImageGradientCalculator, FixedImageGradientCalculatorType);
419  itkSetObjectMacro( MovingImageGradientCalculator, MovingImageGradientCalculatorType);
420  itkGetObjectMacro( MovingImageGradientCalculator, MovingImageGradientCalculatorType);
422 
425  itkSetMacro(UseFixedImageGradientFilter, bool);
426  itkGetConstReferenceMacro(UseFixedImageGradientFilter, bool);
427  itkBooleanMacro(UseFixedImageGradientFilter);
429 
431  itkSetMacro(UseMovingImageGradientFilter, bool);
432  itkGetConstReferenceMacro(UseMovingImageGradientFilter, bool);
433  itkBooleanMacro(UseMovingImageGradientFilter);
435 
438  virtual ThreadIdType GetNumberOfThreadsUsed() const;
439 
443  virtual void SetMaximumNumberOfThreads( const ThreadIdType threads );
444  virtual ThreadIdType GetMaximumNumberOfThreads() const;
446 
448  itkGetConstObjectMacro(FixedImageGradientImage, FixedImageGradientImageType);
449 
451  itkGetConstObjectMacro(MovingImageGradientImage, MovingImageGradientImageType);
452 
454  itkGetConstMacro( NumberOfValidPoints, SizeValueType );
455 
460  SizeValueType GetNumberOfDomainPoints() const;
461 
475  itkSetMacro(UseFloatingPointCorrection, bool);
476  itkGetConstReferenceMacro(UseFloatingPointCorrection, bool);
477  itkBooleanMacro(UseFloatingPointCorrection);
479 
484  itkSetMacro( FloatingPointCorrectionResolution, DerivativeValueType );
485  itkGetConstMacro( FloatingPointCorrectionResolution, DerivativeValueType );
487 
488  /* Initialize the metric before calling GetValue or GetDerivative.
489  * Derived classes must call this Superclass version if they override
490  * this to perform their own initialization.
491  * \note This is meant to be called once for a particular metric setup.
492  * That is, when used in registration, this method would be called once
493  * before entering the registration loop, during which GetValue or
494  * GetDerivative will be called repeatedly. It must be called again if
495  * metric settings are changed before beginning a new registration. */
496  virtual void Initialize(void) throw ( itk::ExceptionObject );
497 
498  virtual MeasureType GetValue() const;
499 
500  virtual void GetDerivative( DerivativeType & ) const;
501 
507  virtual void GetValueAndDerivative( MeasureType & value, DerivativeType & derivative ) const;
508 
512  itkGetConstReferenceMacro(NumberOfSkippedFixedSampledPoints, SizeValueType);
513 
514  virtual bool SupportsArbitraryVirtualDomainSamples( void ) const
515  {
516  return true;
517  }
518 
519 protected:
520  /* Interpolators for image gradient filters. */
521  typedef LinearInterpolateImageFunction< FixedImageGradientImageType,
522  CoordinateRepresentationType >
527 
532 
533  /* A DenseGetValueAndDerivativeThreader
534  * Derived classes must define this class and assign it in their constructor
535  * if threaded processing in GetValueAndDerivative is performed. */
537  /* A SparseGetValueAndDerivativeThreader
538  * Derived classes must define this class and assign it in their constructor
539  * if threaded processing in GetValueAndDerivative is performed. */
541 
546  virtual void InitializeForIteration() const;
547 
560  bool TransformAndEvaluateFixedPoint(
561  const VirtualIndexType & index,
562  const VirtualPointType & point,
563  const bool computeImageGradient,
564  FixedImagePointType & mappedFixedPoint,
565  FixedImagePixelType & mappedFixedPixelValue,
566  FixedImageGradientType & mappedFixedImageGradient ) const;
567 
569  bool TransformAndEvaluateMovingPoint(
570  const VirtualIndexType & index,
571  const VirtualPointType & point,
572  const bool computeImageGradient,
573  MovingImagePointType & mappedMovingPoint,
574  MovingImagePixelType & mappedMovingPixelValue,
575  MovingImageGradientType & mappedMovingImageGradient ) const;
576 
581  virtual void ComputeFixedImageGradientAtPoint(
582  const FixedImagePointType & mappedPoint,
583  FixedImageGradientType & gradient ) const;
584 
586  virtual void ComputeMovingImageGradientAtPoint(
587  const MovingImagePointType & mappedPoint,
588  MovingImageGradientType & gradient ) const;
589 
595  virtual void ComputeFixedImageGradientAtIndex(
596  const VirtualIndexType & index,
597  FixedImageGradientType & gradient ) const;
598 
600  virtual void ComputeMovingImageGradientAtIndex(
601  const VirtualIndexType & index,
602  MovingImageGradientType & gradient ) const;
603 
607  virtual void ComputeFixedImageGradientFilterImage();
608 
612  virtual void ComputeMovingImageGradientFilterImage() const;
613 
620  virtual void GetValueAndDerivativeExecute() const;
621 
624  virtual void InitializeDefaultFixedImageGradientFilter(void);
625  virtual void InitializeDefaultMovingImageGradientFilter(void);
627 
630 
636 
641 
645 
652 
656 
660 
668 
672 
676 
679 
681  virtual ~ImageToImageMetricv4();
682 
683  void PrintSelf(std::ostream& os, Indent indent) const;
684 
685 private:
687  void MapFixedSampledPointSetToVirtual( void );
688 
692 
693  ImageToImageMetricv4(const Self &); //purposely not implemented
694  void operator=(const Self &); //purposely not implemented
695 
696  /* Keep track of the number of sampled fixed points that are
697  * deemed invalid during conversion to virtual domain.
698  * For informational purposes. */
700 
703 
706  #ifdef ITK_USE_CONCEPT_CHECKING
709  itkConceptMacro( OnlyDefinedForFloatingPointTypes0, ( itk::Concept::IsFloatingPoint<FixedImagePixelValueType> ) );
710  itkConceptMacro( OnlyDefinedForFloatingPointTypes1, ( itk::Concept::IsFloatingPoint<MovingImagePixelValueType> ) );
711  #endif // ITK_USE_CONCEPT_CHECKING
712 
713 
714 };
715 }//namespace itk
716 
717 #ifndef ITK_MANUAL_INSTANTIATION
718 #include "itkImageToImageMetricv4.hxx"
719 #endif
720 
721 #endif
722