ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageToImageMetricv4.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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"
31#include "itkPointSet.h"
34
35namespace itk
36{
168template <typename TFixedImage,
169 typename TMovingImage,
170 typename TVirtualImage = TFixedImage,
171 typename TInternalComputationValueType = double,
172 typename TMetricTraits =
174class ITK_TEMPLATE_EXPORT ImageToImageMetricv4
175 : public ObjectToObjectMetric<TFixedImage::ImageDimension,
176 TMovingImage::ImageDimension,
177 TVirtualImage,
178 TInternalComputationValueType>
179{
180public:
181 ITK_DISALLOW_COPY_AND_MOVE(ImageToImageMetricv4);
182
185 using Superclass = ObjectToObjectMetric<TFixedImage::ImageDimension,
186 TMovingImage::ImageDimension,
187 TVirtualImage,
188 TInternalComputationValueType>;
191
193 itkOverrideGetNameOfClassMacro(ImageToImageMetricv4);
194
196
198 using InternalComputationValueType = TInternalComputationValueType;
199
202
204 using typename Superclass::ParametersType;
205 using typename Superclass::ParametersValueType;
206
208 using typename Superclass::GradientSourceEnum;
209
211 using typename Superclass::DimensionType;
213
215 using typename Superclass::FixedTransformType;
217 using typename Superclass::FixedInputPointType;
220
221 using typename Superclass::MovingTransformType;
226
227 using typename Superclass::JacobianType;
230
232
234 using FixedImageType = TFixedImage;
235 using FixedImagePixelType = typename FixedImageType::PixelType;
237 using FixedImagePointer = typename FixedImageType::Pointer;
238 using FixedImageConstPointer = typename FixedImageType::ConstPointer;
239 using FixedImagePointType = typename FixedImageType::PointType;
240 using FixedImageIndexType = typename FixedImageType::IndexType;
241 using MovingImageType = TMovingImage;
242 using MovingImagePixelType = typename MovingImageType::PixelType;
244 using MovingImagePointer = typename MovingImageType::Pointer;
245 using MovingImageConstPointer = typename MovingImageType::ConstPointer;
246 using MovingImagePointType = typename MovingImageType::PointType;
247 using MovingImageRegionType = typename MovingImageType::RegionType;
248 using MovingImageIndexType = typename MovingImageType::IndexType;
249
252 using typename Superclass::VirtualImagePointer;
253 using typename Superclass::VirtualPixelType;
254 using typename Superclass::VirtualRegionType;
255 using typename Superclass::VirtualSizeType;
256 using typename Superclass::VirtualSpacingType;
258 using typename Superclass::VirtualPointType;
261 using typename Superclass::VirtualIndexType;
262 using typename Superclass::VirtualPointSetType;
264
266 using MetricTraits = TMetricTraits;
267
268 /* Image dimension accessors */
272
278
284
289
295
297 using FixedImageGradientType = typename MetricTraits::FixedImageGradientType;
298 using MovingImageGradientType = typename MetricTraits::MovingImageGradientType;
299 using VirtualImageGradientType = typename MetricTraits::VirtualImageGradientType;
300
303
306
309
313 using FixedRealType = typename MetricTraits::FixedRealType;
314 using MovingRealType = typename MetricTraits::MovingRealType;
315
318
319 using FixedGradientPixelType = typename MetricTraits::FixedGradientPixelType;
320 using MovingGradientPixelType = typename MetricTraits::MovingGradientPixelType;
321
322 using FixedImageGradientImageType = typename MetricTraits::FixedImageGradientImageType;
323 using MovingImageGradientImageType = typename MetricTraits::MovingImageGradientImageType;
324
325 using FixedImageGradientImagePointer = typename FixedImageGradientImageType::Pointer;
326 using MovingImageGradientImagePointer = typename MovingImageGradientImageType::Pointer;
327
328 using FixedImageGradientFilterType = typename MetricTraits::FixedImageGradientFilterType;
329 using MovingImageGradientFilterType = typename MetricTraits::MovingImageGradientFilterType;
330
331 using FixedImageGradientFilterPointer = typename FixedImageGradientFilterType::Pointer;
332 using MovingImageGradientFilterPointer = typename MovingImageGradientFilterType::Pointer;
333
334
336 using DefaultFixedImageGradientFilter = typename MetricTraits::DefaultFixedImageGradientFilter;
337 using DefaultMovingImageGradientFilter = typename MetricTraits::DefaultMovingImageGradientFilter;
338
341 using FixedImageGradientCalculatorType = typename MetricTraits::FixedImageGradientCalculatorType;
342 using MovingImageGradientCalculatorType = typename MetricTraits::MovingImageGradientCalculatorType;
343
344 using FixedImageGradientCalculatorPointer = typename FixedImageGradientCalculatorType::Pointer;
345 using MovingImageGradientCalculatorPointer = typename MovingImageGradientCalculatorType::Pointer;
346
348 using DefaultFixedImageGradientCalculator = typename MetricTraits::DefaultFixedImageGradientCalculator;
349 using DefaultMovingImageGradientCalculator = typename MetricTraits::DefaultMovingImageGradientCalculator;
350
352 using typename Superclass::MeasureType;
353
355 using typename Superclass::DerivativeType;
357
361
363 void
364 SetFixedObject(const ObjectType * object) override
365 {
366 auto * image = dynamic_cast<FixedImageType *>(const_cast<ObjectType *>(object));
367 if (image != nullptr)
368 {
369 this->SetFixedImage(image);
370 }
371 else
372 {
373 itkExceptionMacro("Incorrect object type. Should be an image.");
374 }
375 }
376
377
379 void
380 SetMovingObject(const ObjectType * object) override
381 {
382 auto * image = dynamic_cast<MovingImageType *>(const_cast<ObjectType *>(object));
383 if (image != nullptr)
384 {
385 this->SetMovingImage(image);
386 }
387 else
388 {
389 itkExceptionMacro("Incorrect object type. Should be an image.");
390 }
391 }
392
393
394 /* Get/Set the Fixed Image. */
395 itkSetConstObjectMacro(FixedImage, FixedImageType);
396 itkGetConstObjectMacro(FixedImage, FixedImageType);
397
399 itkSetConstObjectMacro(MovingImage, MovingImageType);
400 itkGetConstObjectMacro(MovingImage, MovingImageType);
402
404 itkSetObjectMacro(FixedInterpolator, FixedInterpolatorType);
405
407 itkGetModifiableObjectMacro(FixedInterpolator, FixedInterpolatorType);
408
410 itkSetObjectMacro(MovingInterpolator, MovingInterpolatorType);
411
413 itkGetModifiableObjectMacro(MovingInterpolator, MovingInterpolatorType);
414
416#ifndef ITK_FUTURE_LEGACY_REMOVE
417 virtual void
419 {
420 const auto * const constArg = arg;
421 // Call the overload defined by itkSetConstObjectMacro, or an override.
422 this->SetMovingImageMask(constArg);
423 }
424#endif
425 itkSetConstObjectMacro(MovingImageMask, MovingImageMaskType);
426 itkGetConstObjectMacro(MovingImageMask, MovingImageMaskType);
428
430#ifndef ITK_FUTURE_LEGACY_REMOVE
431 virtual void
433 {
434 const auto * const constArg = arg;
435 // Call the overload defined by itkSetConstObjectMacro, or an override.
436 this->SetFixedImageMask(constArg);
437 }
438#endif
439 itkSetConstObjectMacro(FixedImageMask, FixedImageMaskType);
440 itkGetConstObjectMacro(FixedImageMask, FixedImageMaskType);
442
446#ifndef ITK_FUTURE_LEGACY_REMOVE
447 virtual void
449 {
450 const auto * const constArg = arg;
451 // Call the overload defined by itkSetConstObjectMacro, or an override.
452 this->SetFixedSampledPointSet(constArg);
453 }
454#endif
455 itkSetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
456 itkGetConstObjectMacro(FixedSampledPointSet, FixedSampledPointSetType);
458
460 itkSetObjectMacro(VirtualSampledPointSet, VirtualPointSetType);
461 itkGetConstObjectMacro(VirtualSampledPointSet, VirtualPointSetType);
463
465 itkSetMacro(UseSampledPointSet, bool);
466 itkGetConstReferenceMacro(UseSampledPointSet, bool);
467 itkBooleanMacro(UseSampledPointSet);
469
472 itkSetMacro(UseVirtualSampledPointSet, bool);
473 itkGetConstReferenceMacro(UseVirtualSampledPointSet, bool);
474 itkBooleanMacro(UseVirtualSampledPointSet);
476
477#if !defined(ITK_LEGACY_REMOVE)
480 itkLegacyMacro(virtual void SetUseFixedSampledPointSet(bool v))
481 {
482 this->SetUseSampledPointSet(v);
483 }
484 itkLegacyMacro(virtual bool GetUseFixedSampledPointSet() const)
485 {
486 return this->GetUseSampledPointSet();
487 }
488 itkLegacyMacro(virtual void UseFixedSampledPointSetOn())
489 {
490 return this->UseSampledPointSetOn();
491 }
492 itkLegacyMacro(virtual void UseFixedSampledPointSetOff())
493 {
494 return this->UseSampledPointSetOff();
495 }
496#endif
498
499
501 itkSetObjectMacro(FixedImageGradientFilter, FixedImageGradientFilterType);
502 itkGetModifiableObjectMacro(FixedImageGradientFilter, FixedImageGradientFilterType);
503 itkSetObjectMacro(MovingImageGradientFilter, MovingImageGradientFilterType);
504 itkGetModifiableObjectMacro(MovingImageGradientFilter, MovingImageGradientFilterType);
506
508 itkSetObjectMacro(FixedImageGradientCalculator, FixedImageGradientCalculatorType);
509 itkGetModifiableObjectMacro(FixedImageGradientCalculator, FixedImageGradientCalculatorType);
510 itkSetObjectMacro(MovingImageGradientCalculator, MovingImageGradientCalculatorType);
511 itkGetModifiableObjectMacro(MovingImageGradientCalculator, MovingImageGradientCalculatorType);
513
516 itkSetMacro(UseFixedImageGradientFilter, bool);
517 itkGetConstReferenceMacro(UseFixedImageGradientFilter, bool);
518 itkBooleanMacro(UseFixedImageGradientFilter);
520
522 itkSetMacro(UseMovingImageGradientFilter, bool);
523 itkGetConstReferenceMacro(UseMovingImageGradientFilter, bool);
524 itkBooleanMacro(UseMovingImageGradientFilter);
526
530 virtual ThreadIdType
532
536 virtual void
538 virtual ThreadIdType
541
542#if !defined(ITK_LEGACY_REMOVE)
548 itkLegacyMacro(virtual ThreadIdType GetNumberOfThreadsUsed() const)
549 {
550 return this->GetNumberOfWorkUnitsUsed();
551 }
552
559 itkLegacyMacro(virtual void SetMaximumNumberOfThreads(const ThreadIdType count))
560 {
561 this->SetMaximumNumberOfWorkUnits(count);
562 }
563 itkLegacyMacro(virtual ThreadIdType GetMaximumNumberOfThreads() const)
564 {
565 return this->GetMaximumNumberOfWorkUnits();
566 }
567#endif // !ITK_LEGACY_REMOVE
569
570
578 virtual void
579 FinalizeThread(const ThreadIdType /*threadId*/)
580 { /*Do nothing by default */
581 }
582
584 itkGetModifiableObjectMacro(FixedImageGradientImage, FixedImageGradientImageType);
585
587 itkGetModifiableObjectMacro(MovingImageGradientImage, MovingImageGradientImageType);
588
595
609 itkSetMacro(UseFloatingPointCorrection, bool);
610 itkGetConstReferenceMacro(UseFloatingPointCorrection, bool);
611 itkBooleanMacro(UseFloatingPointCorrection);
613
618 itkSetMacro(FloatingPointCorrectionResolution, DerivativeValueType);
619 itkGetConstMacro(FloatingPointCorrectionResolution, DerivativeValueType);
621
622 /* Initialize the metric before calling GetValue or GetDerivative.
623 * Derived classes must call this Superclass version if they override
624 * this to perform their own initialization.
625 * \note This is meant to be called once for a particular metric setup.
626 * That is, when used in registration, this method would be called once
627 * before entering the registration loop, during which GetValue or
628 * GetDerivative will be called repeatedly. It must be called again if
629 * metric settings are changed before beginning a new registration. */
630 void
631 Initialize() override;
632
634 GetValue() const override;
635
636 void
637 GetDerivative(DerivativeType &) const override;
638
644 void
645 GetValueAndDerivative(MeasureType & value, DerivativeType & derivative) const override;
646
650 itkGetConstReferenceMacro(NumberOfSkippedFixedSampledPoints, SizeValueType);
651
652 bool
654 {
655 return true;
656 }
657
658 using typename Superclass::MetricCategoryType;
659
661 MetricCategoryType
662 GetMetricCategory() const override
663 {
664 return MetricCategoryType::IMAGE_METRIC;
665 }
666
667protected:
668 /* Interpolators for image gradient filters. */
673
676 Self>;
679 Self>;
681
682 /* A DenseGetValueAndDerivativeThreader
683 * Derived classes must define this class and assign it in their constructor
684 * if threaded processing in GetValueAndDerivative is performed. */
687 /* A SparseGetValueAndDerivativeThreader
688 * Derived classes must define this class and assign it in their constructor
689 * if threaded processing in GetValueAndDerivative is performed. */
692
697 virtual void
699
707 bool
709 FixedImagePointType & mappedFixedPoint,
710 FixedImagePixelType & mappedFixedPixelValue) const;
711
713 bool
715 MovingImagePointType & mappedMovingPoint,
716 MovingImagePixelType & mappedMovingPixelValue) const;
717
719 virtual void
721
723 virtual void
725
729 virtual void
731
735 virtual void
737
744 virtual void
746
749 virtual void
751 virtual void
754
756 itkGetConstMacro(ComputeDerivative, bool);
757
760
766
771
775
778 typename DefaultFixedImageGradientFilter::Pointer m_DefaultFixedImageGradientFilter{};
779 typename DefaultMovingImageGradientFilter::Pointer m_DefaultMovingImageGradientFilter{};
780
783 typename DefaultFixedImageGradientCalculator::Pointer m_DefaultFixedImageGradientCalculator{};
784 typename DefaultMovingImageGradientCalculator::Pointer m_DefaultMovingImageGradientCalculator{};
785
789
793
801
805
809
812
816
818 ~ImageToImageMetricv4() override = default;
819
820 void
821 PrintSelf(std::ostream & os, Indent indent) const override;
822
823private:
825 void
827
829 void
831 typename FixedTransformType::OutputPointType & mappedFixedPoint) const
832 {
833 mappedFixedPoint = this->m_FixedTransform->TransformPoint(virtualPoint);
834 }
835 // cast the virtual point
836 template <typename TVirtualPoint>
837 void
838 LocalTransformPoint(const TVirtualPoint & virtualPoint,
839 typename FixedTransformType::OutputPointType & mappedFixedPoint) const
840 {
841 typename FixedTransformType::OutputPointType localVirtualPoint;
843
844 localVirtualPoint.CastFrom(virtualPoint);
845
846 mappedFixedPoint = this->m_FixedTransform->TransformPoint(localVirtualPoint);
847 }
848 // cast the mapped Fixed Point
849 template <typename TFixedImagePoint>
850 void
852 TFixedImagePoint & mappedFixedPoint) const
853 {
854 typename FixedTransformType::OutputPointType localMappedFixedPoint;
855 localMappedFixedPoint.CastFrom(mappedFixedPoint);
856 localMappedFixedPoint = this->m_FixedTransform->TransformPoint(virtualPoint);
857 mappedFixedPoint.CastFrom(localMappedFixedPoint);
858 }
859 // cast both mapped and fixed point.
860 template <typename TVirtualPoint, typename TFixedImagePoint>
861 void
862 LocalTransformPoint(const TVirtualPoint & virtualPoint, TFixedImagePoint & mappedFixedPoint) const
863 {
864 typename FixedTransformType::OutputPointType localVirtualPoint;
865 typename FixedTransformType::OutputPointType localMappedFixedPoint;
866
867 localVirtualPoint.CastFrom(virtualPoint);
868 localMappedFixedPoint.CastFrom(mappedFixedPoint);
869
870 localMappedFixedPoint = this->m_FixedTransform->TransformPoint(localVirtualPoint);
871 mappedFixedPoint.CastFrom(localMappedFixedPoint);
872 }
873
877
882
885
887
889 mutable bool m_ComputeDerivative{};
890
897};
898} // namespace itk
900
901#ifndef ITK_MANUAL_INSTANTIATION
902# include "itkImageToImageMetricv4.hxx"
903#endif
904
905#endif
TInternalComputationValueType ValueType
Definition itkArray.h:52
OptimizerParameters< TInternalComputationValueType > ParametersType
TInternalComputationValueType ParametersValueType
A templated class holding a n-Dimensional covariant vector.
A simple structure holding type information for ImageToImageMetricv4 classes.
Provides threading for ImageToImageMetricv4::GetValueAndDerivative.
void LocalTransformPoint(const TVirtualPoint &virtualPoint, TFixedImagePoint &mappedFixedPoint) const
virtual void ComputeFixedImageGradientAtPoint(const FixedImagePointType &mappedPoint, FixedImageGradientType &gradient) const
~ImageToImageMetricv4() override=default
virtual void InitializeDefaultFixedImageGradientFilter()
virtual void ComputeMovingImageGradientFilterImage() const
ImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< VirtualImageDimension >, Self >::Pointer m_DenseGetValueAndDerivativeThreader
virtual void InitializeForIteration() const
ObjectToObjectMetric< TFixedImage::ImageDimension, TMovingImage::ImageDimension, TVirtualImage, TInternalComputationValueType > Superclass
void Initialize() override
CovariantVector< typename MovingImageGradientType::ValueType, MovingImageDimension > MovingImageComponentGradientType
bool TransformAndEvaluateFixedPoint(const VirtualPointType &virtualPoint, FixedImagePointType &mappedFixedPoint, FixedImagePixelType &mappedFixedPixelValue) const
void SetFixedObject(const ObjectType *object) override
MetricCategoryType GetMetricCategory() const override
MeasureType GetValue() const override
void GetDerivative(DerivativeType &) const override
CovariantVector< typename FixedImageGradientType::ValueType, FixedImageDimension > FixedImageComponentGradientType
virtual void SetMaximumNumberOfWorkUnits(const ThreadIdType number)
void GetValueAndDerivative(MeasureType &value, DerivativeType &derivative) const override
LinearInterpolateImageFunction< FixedImageGradientImageType, CoordinateRepresentationType > FixedImageGradientInterpolatorType
SizeValueType GetNumberOfDomainPoints() const
virtual void ComputeFixedImageGradientFilterImage()
virtual void GetValueAndDerivativeExecute() const
bool TransformAndEvaluateMovingPoint(const VirtualPointType &virtualPoint, MovingImagePointType &mappedMovingPoint, MovingImagePixelType &mappedMovingPixelValue) const
LinearInterpolateImageFunction< MovingImageGradientImageType, CoordinateRepresentationType > MovingImageGradientInterpolatorType
void LocalTransformPoint(const typename FixedTransformType::OutputPointType &virtualPoint, typename FixedTransformType::OutputPointType &mappedFixedPoint) const
void LocalTransformPoint(const TVirtualPoint &virtualPoint, typename FixedTransformType::OutputPointType &mappedFixedPoint) const
ImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Self >::Pointer m_SparseGetValueAndDerivativeThreader
virtual ThreadIdType GetMaximumNumberOfWorkUnits() const
CovariantVector< typename VirtualImageGradientType::ValueType, VirtualImageDimension > VirtualImageComponentGradientType
void LocalTransformPoint(const typename FixedTransformType::OutputPointType &virtualPoint, TFixedImagePoint &mappedFixedPoint) const
void PrintSelf(std::ostream &os, Indent indent) const override
void SetMovingObject(const ObjectType *object) override
bool SupportsArbitraryVirtualDomainSamples() const override
virtual void FinalizeThread(const ThreadIdType)
virtual ThreadIdType GetNumberOfWorkUnitsUsed() const
virtual void ComputeMovingImageGradientAtPoint(const MovingImagePointType &mappedPoint, MovingImageGradientType &gradient) const
virtual void InitializeDefaultMovingImageGradientFilter()
Control indentation during Print() invocation.
Definition itkIndent.h:50
Base class for all image interpolators.
Linearly interpolate an image at specified positions.
Transform< TInternalComputationValueType, TVirtualImage::ImageDimension, TMovingDimension > MovingTransformType
typename TPixelType::ValueType ValueType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition itkPointSet.h:82
void CastFrom(const Point< TCoordinateB, VPointDimension > &pa)
Definition itkPoint.h:269
Array< TInternalComputationValueType > DerivativeType
Implements transparent reference counting.
Implementation of the composite pattern.
Class for partitioning of an ImageRegion.
Point< TParametersValueType, VOutputDimension > OutputPointType
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
unsigned long SizeValueType
Definition itkIntTypes.h:86