ITK  4.3.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  /* Set/get images */
358  itkSetConstObjectMacro(FixedImage, FixedImageType);
359 
361  itkGetConstObjectMacro(FixedImage, FixedImageType);
362 
364  itkSetConstObjectMacro(MovingImage, MovingImageType);
365 
367  itkGetConstObjectMacro(MovingImage, MovingImageType);
368 
370  itkSetObjectMacro(FixedInterpolator, FixedInterpolatorType);
371 
373  itkGetConstObjectMacro(FixedInterpolator, FixedInterpolatorType);
374 
376  itkSetObjectMacro(MovingInterpolator, MovingInterpolatorType);
377 
379  itkGetConstObjectMacro(MovingInterpolator, MovingInterpolatorType);
380 
382  itkSetObjectMacro(MovingImageMask, MovingImageMaskType);
383  itkSetConstObjectMacro(MovingImageMask, MovingImageMaskType);
384  itkGetConstObjectMacro(MovingImageMask, MovingImageMaskType);
386 
388  itkSetObjectMacro(FixedImageMask, FixedImageMaskType);
389  itkSetConstObjectMacro(FixedImageMask, FixedImageMaskType);
390  itkGetConstObjectMacro(FixedImageMask, FixedImageMaskType);
392 
396  itkSetObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
397  itkSetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
398  itkGetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
400 
402  itkSetMacro(UseFixedSampledPointSet, bool);
403  itkGetConstReferenceMacro(UseFixedSampledPointSet, bool);
404  itkBooleanMacro(UseFixedSampledPointSet);
406 
408  itkGetConstObjectMacro(VirtualSampledPointSet, VirtualPointSetType);
409 
411  itkSetObjectMacro( FixedImageGradientFilter, FixedImageGradientFilterType );
412  itkGetObjectMacro( FixedImageGradientFilter, FixedImageGradientFilterType );
413  itkSetObjectMacro( MovingImageGradientFilter, MovingImageGradientFilterType );
414  itkGetObjectMacro( MovingImageGradientFilter, MovingImageGradientFilterType );
416 
418  itkSetObjectMacro( FixedImageGradientCalculator, FixedImageGradientCalculatorType);
419  itkGetObjectMacro( FixedImageGradientCalculator, FixedImageGradientCalculatorType);
420  itkSetObjectMacro( MovingImageGradientCalculator, MovingImageGradientCalculatorType);
421  itkGetObjectMacro( MovingImageGradientCalculator, MovingImageGradientCalculatorType);
423 
426  itkSetMacro(UseFixedImageGradientFilter, bool);
427  itkGetConstReferenceMacro(UseFixedImageGradientFilter, bool);
428  itkBooleanMacro(UseFixedImageGradientFilter);
430 
432  itkSetMacro(UseMovingImageGradientFilter, bool);
433  itkGetConstReferenceMacro(UseMovingImageGradientFilter, bool);
434  itkBooleanMacro(UseMovingImageGradientFilter);
436 
440  virtual ThreadIdType GetNumberOfThreadsUsed() const;
441 
445  virtual void SetMaximumNumberOfThreads( const ThreadIdType threads );
446  virtual ThreadIdType GetMaximumNumberOfThreads() const;
448 
450  itkGetConstObjectMacro(FixedImageGradientImage, FixedImageGradientImageType);
451 
453  itkGetConstObjectMacro(MovingImageGradientImage, MovingImageGradientImageType);
454 
456  itkGetConstMacro( NumberOfValidPoints, SizeValueType );
457 
462  SizeValueType GetNumberOfDomainPoints() const;
463 
477  itkSetMacro(UseFloatingPointCorrection, bool);
478  itkGetConstReferenceMacro(UseFloatingPointCorrection, bool);
479  itkBooleanMacro(UseFloatingPointCorrection);
481 
486  itkSetMacro( FloatingPointCorrectionResolution, DerivativeValueType );
487  itkGetConstMacro( FloatingPointCorrectionResolution, DerivativeValueType );
489 
490  /* Initialize the metric before calling GetValue or GetDerivative.
491  * Derived classes must call this Superclass version if they override
492  * this to perform their own initialization.
493  * \note This is meant to be called once for a particular metric setup.
494  * That is, when used in registration, this method would be called once
495  * before entering the registration loop, during which GetValue or
496  * GetDerivative will be called repeatedly. It must be called again if
497  * metric settings are changed before beginning a new registration. */
498  virtual void Initialize(void) throw ( itk::ExceptionObject );
499 
500  virtual MeasureType GetValue() const;
501 
502  virtual void GetDerivative( DerivativeType & ) const;
503 
509  virtual void GetValueAndDerivative( MeasureType & value, DerivativeType & derivative ) const;
510 
514  itkGetConstReferenceMacro(NumberOfSkippedFixedSampledPoints, SizeValueType);
515 
516  virtual bool SupportsArbitraryVirtualDomainSamples( void ) const
517  {
518  return true;
519  }
520 
521 protected:
522  /* Interpolators for image gradient filters. */
523  typedef LinearInterpolateImageFunction< FixedImageGradientImageType,
524  CoordinateRepresentationType >
529 
534 
535  /* A DenseGetValueAndDerivativeThreader
536  * Derived classes must define this class and assign it in their constructor
537  * if threaded processing in GetValueAndDerivative is performed. */
539  /* A SparseGetValueAndDerivativeThreader
540  * Derived classes must define this class and assign it in their constructor
541  * if threaded processing in GetValueAndDerivative is performed. */
543 
548  virtual void InitializeForIteration() const;
549 
557  bool TransformAndEvaluateFixedPoint(
558  const VirtualPointType & virtualPoint,
559  FixedImagePointType & mappedFixedPoint,
560  FixedImagePixelType & mappedFixedPixelValue ) const;
561 
563  bool TransformAndEvaluateMovingPoint(
564  const VirtualPointType & virtualPoint,
565  MovingImagePointType & mappedMovingPoint,
566  MovingImagePixelType & mappedMovingPixelValue ) const;
567 
569  virtual void ComputeFixedImageGradientAtPoint( const FixedImagePointType & mappedPoint, FixedImageGradientType & gradient ) const;
570 
572  virtual void ComputeMovingImageGradientAtPoint( const MovingImagePointType & mappedPoint, MovingImageGradientType & gradient ) const;
573 
577  virtual void ComputeFixedImageGradientFilterImage();
578 
582  virtual void ComputeMovingImageGradientFilterImage() const;
583 
590  virtual void GetValueAndDerivativeExecute() const;
591 
594  virtual void InitializeDefaultFixedImageGradientFilter(void);
595  virtual void InitializeDefaultMovingImageGradientFilter(void);
597 
599  itkGetConstMacro( ComputeDerivative, bool );
600 
603 
609 
614 
618 
621  typename DefaultFixedImageGradientFilter::Pointer
625 
628  typename DefaultFixedImageGradientCalculator::Pointer
632 
636 
640 
648 
652 
656 
659 
661  virtual ~ImageToImageMetricv4();
662 
663  void PrintSelf(std::ostream& os, Indent indent) const;
664 
665 private:
667  void MapFixedSampledPointSetToVirtual( void );
668 
672 
673  ImageToImageMetricv4(const Self &); //purposely not implemented
674  void operator=(const Self &); //purposely not implemented
675 
680 
683 
685 
687  mutable bool m_ComputeDerivative;
688 
691  #ifdef ITK_USE_CONCEPT_CHECKING
694  itkConceptMacro( OnlyDefinedForFloatingPointTypes0, ( itk::Concept::IsFloatingPoint<FixedImagePixelValueType> ) );
695  itkConceptMacro( OnlyDefinedForFloatingPointTypes1, ( itk::Concept::IsFloatingPoint<MovingImagePixelValueType> ) );
696  #endif // ITK_USE_CONCEPT_CHECKING
697 
698 
699 };
700 }//namespace itk
701 
702 #ifndef ITK_MANUAL_INSTANTIATION
703 #include "itkImageToImageMetricv4.hxx"
704 #endif
705 
706 #endif
707