18#ifndef itkAdvancedImageToImageMetric_h
19#define itkAdvancedImageToImageMetric_h
21#include "itkImageToImageMetric.h"
24#include "itkGradientImageFilter.h"
25#include "itkBSplineInterpolateImageFunction.h"
29#include "itkFixedArray.h"
31#include <vnl/vnl_sparse_matrix.h>
33#include "itkImageMaskSpatialObject.h"
39#include "itkPlatformMultiThreader.h"
82template <
class TFixedImage,
class TMovingImage>
90 using Superclass = ImageToImageMetric<TFixedImage, TMovingImage>;
98 itkStaticConstMacro(MovingImageDimension,
unsigned int, TMovingImage::ImageDimension);
99 itkStaticConstMacro(FixedImageDimension,
unsigned int, TFixedImage::ImageDimension);
102 using typename Superclass::CoordinateRepresentationType;
103 using typename Superclass::MovingImageType;
104 using typename Superclass::MovingImagePixelType;
106 using typename Superclass::MovingImageConstPointer;
107 using typename Superclass::FixedImageType;
109 using typename Superclass::FixedImageConstPointer;
110 using typename Superclass::FixedImageRegionType;
111 using typename Superclass::TransformType;
112 using typename Superclass::TransformPointer;
113 using typename Superclass::InputPointType;
114 using typename Superclass::OutputPointType;
115 using typename Superclass::TransformParametersType;
116 using typename Superclass::TransformJacobianType;
117 using typename Superclass::InterpolatorType;
118 using typename Superclass::InterpolatorPointer;
119 using typename Superclass::RealType;
120 using typename Superclass::GradientPixelType;
121 using typename Superclass::GradientImageType;
122 using typename Superclass::GradientImagePointer;
123 using typename Superclass::GradientImageFilterType;
124 using typename Superclass::GradientImageFilterPointer;
125 using typename Superclass::FixedImageMaskType;
126 using typename Superclass::FixedImageMaskPointer;
127 using typename Superclass::MovingImageMaskType;
128 using typename Superclass::MovingImageMaskPointer;
129 using typename Superclass::MeasureType;
130 using typename Superclass::DerivativeType;
132 using typename Superclass::ParametersType;
184 this->Superclass::SetTransform(arg);
185 if (this->m_AdvancedTransform != arg)
187 this->m_AdvancedTransform = arg;
197 return this->m_AdvancedTransform.GetPointer();
204 GetImageSampler()
const
206 return this->m_ImageSampler.GetPointer();
212 itkGetConstMacro(UseImageSampler,
bool);
217 itkSetMacro(RequiredRatioOfValidSamples,
double);
218 itkGetConstMacro(RequiredRatioOfValidSamples,
double);
233 itkSetMacro(MovingLimitRangeRatio,
double);
234 itkGetConstMacro(MovingLimitRangeRatio,
double);
235 itkSetMacro(FixedLimitRangeRatio,
double);
236 itkGetConstMacro(FixedLimitRangeRatio,
double);
240 itkGetConstMacro(UseFixedImageLimiter,
bool);
241 itkGetConstMacro(UseMovingImageLimiter,
bool);
250 itkSetMacro(UseMovingImageDerivativeScales,
bool);
251 itkGetConstMacro(UseMovingImageDerivativeScales,
bool);
253 itkSetMacro(ScaleGradientWithRespectToMovingImageOrientation,
bool);
254 itkGetConstMacro(ScaleGradientWithRespectToMovingImageOrientation,
bool);
281 itkSetMacro(UseMetricSingleThreaded,
bool);
282 itkGetConstReferenceMacro(UseMetricSingleThreaded,
bool);
283 itkBooleanMacro(UseMetricSingleThreaded);
287 itkSetMacro(UseMultiThread,
bool);
288 itkGetConstReferenceMacro(UseMultiThread,
bool);
289 itkBooleanMacro(UseMultiThread);
308 PrintSelf(std::ostream & os, Indent indent)
const override;
322 BSplineInterpolateImageFunction<MovingImageType, CoordinateRepresentationType, double>;
325 BSplineInterpolateImageFunction<MovingImageType, CoordinateRepresentationType, float>;
347 bool m_InterpolatorIsLinear{
false };
348 bool m_InterpolatorIsBSpline{
false };
349 bool m_InterpolatorIsBSplineFloat{
false };
350 bool m_InterpolatorIsReducedBSpline{
false };
359 bool m_TransformIsAdvanced{
false };
361 mutable bool m_TransformIsBSpline{
false };
388 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
406 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
414 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
418 bool m_UseMetricSingleThreaded{
true };
419 bool m_UseMultiThread{
false };
451 itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct, AlignedGetValuePerThreadStruct);
452 mutable std::unique_ptr<AlignedGetValuePerThreadStruct[]> m_GetValuePerThreadVariables{
nullptr };
453 mutable ThreadIdType m_GetValuePerThreadVariablesSize{ 0 };
464 PaddedGetValueAndDerivativePerThreadStruct);
466 PaddedGetValueAndDerivativePerThreadStruct,
467 AlignedGetValueAndDerivativePerThreadStruct);
468 mutable std::unique_ptr<AlignedGetValueAndDerivativePerThreadStruct[]> m_GetValueAndDerivativePerThreadVariables{
471 mutable ThreadIdType m_GetValueAndDerivativePerThreadVariablesSize{ 0 };
487 itkSetMacro(UseImageSampler,
bool);
511 RealType & movingImageValue,
514 return EvaluateMovingImageValueAndDerivativeWithOptionalThreadId(mappedPoint, movingImageValue, gradient);
521 RealType & movingImageValue,
523 const ThreadIdType threadId)
const
525 return EvaluateMovingImageValueAndDerivativeWithOptionalThreadId(mappedPoint, movingImageValue, gradient, threadId);
535 DerivativeType & imageJacobian)
const;
562 TransformJacobianType & jacobian,
576 itkSetMacro(UseFixedImageLimiter,
bool);
577 itkSetMacro(UseMovingImageLimiter,
bool);
579 double m_FixedLimitRangeRatio{ 0.01 };
580 double m_MovingLimitRangeRatio{ 0.01 };
583 template <
typename... TOptionalThreadId>
586 RealType & movingImageValue,
588 const TOptionalThreadId... optionalThreadId)
const;
591 bool m_UseImageSampler{
false };
592 bool m_UseFixedImageLimiter{
false };
593 bool m_UseMovingImageLimiter{
false };
594 double m_RequiredRatioOfValidSamples{ 0.25 };
595 bool m_UseMovingImageDerivativeScales{
false };
596 bool m_ScaleGradientWithRespectToMovingImageOrientation{
false };
603#ifndef ITK_MANUAL_INSTANTIATION
604# include "itkAdvancedImageToImageMetric.hxx"
An extension of the ITK ImageToImageMetric. It is the intended base class for all elastix metrics.
virtual bool IsInsideMovingMask(const MovingImagePointType &point) const
typename BSplineOrder1TransformType::Pointer BSplineOrder1TransformPointer
void Initialize() override
typename TransformType::OutputPointType MovingImagePointType
void PrintSelf(std::ostream &os, Indent indent) const override
virtual bool EvaluateTransformJacobian(const FixedImagePointType &fixedImagePoint, TransformJacobianType &jacobian, NonZeroJacobianIndicesType &nzji) const
typename MovingImageType::RegionType MovingImageRegionType
typename AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct, AlignedGetValuePerThreadStruct)
virtual bool EvaluateMovingImageValueAndDerivative(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient) const
virtual void CheckForAdvancedTransform()
typename FixedImageType::PixelType FixedImagePixelType
typename DerivativeType::ValueType DerivativeValueType
virtual void AfterThreadedGetValue(MeasureType &value) const
typename DerivativeType::ValueType HessianValueType
typename FixedImageLimiterType::Pointer FixedImageLimiterPointer
GradientImageFilter< MovingImageType, RealType, RealType > CentralDifferenceGradientFilterType
virtual void CheckForBSplineTransform() const
virtual void InitializeImageSampler()
typename FixedImageIndexType::IndexValueType FixedImageIndexValueType
typename MovingImageType::IndexType MovingImageIndexType
void LaunchGetValueAndDerivativeThreaderCallback() const
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueAndDerivativeThreaderCallback(void *arg)
virtual void ThreadedGetValue(ThreadIdType threadID)
typename MovingImageType::Pointer MovingImagePointer
bool FastEvaluateMovingImageValueAndDerivative(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient, const ThreadIdType threadId) const
typename BSplineOrder3TransformType::Pointer BSplineOrder3TransformPointer
void LaunchGetValueThreaderCallback() const
virtual void ThreadedGetValueAndDerivative(ThreadIdType threadID)
virtual void InitializeThreadingParameters() const
~AdvancedImageToImageMetric() override=default
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > BSplineInterpolatorType
typename FixedImageType::Pointer FixedImagePointer
virtual void CheckNumberOfSamples(unsigned long wanted, unsigned long found) const
typename ThreaderType::WorkUnitInfo ThreadInfoType
typename ReducedBSplineInterpolatorType::Pointer ReducedBSplineInterpolatorPointer
virtual void BeforeThreadedGetValueAndDerivative(const TransformParametersType ¶meters) const
typename BSplineOrder2TransformType::Pointer BSplineOrder2TransformPointer
itk::PlatformMultiThreader ThreaderType
typename FixedImageType::IndexType FixedImageIndexType
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct, AlignedGetValueAndDerivativePerThreadStruct)
AdvancedImageToImageMetric()
typename BSplineInterpolatorType::Pointer BSplineInterpolatorPointer
bool EvaluateMovingImageValueAndDerivativeWithOptionalThreadId(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient, const TOptionalThreadId... optionalThreadId) const
typename CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValuePerThreadStruct, PaddedGetValuePerThreadStruct)
typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType
virtual void AfterThreadedGetValueAndDerivative(MeasureType &value, DerivativeType &derivative) const
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, float > BSplineInterpolatorFloatType
ImageMaskSpatialObject< Self::FixedImageDimension > FixedImageMaskSpatialObject2Type
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION AccumulateDerivativesThreaderCallback(void *arg)
virtual void EvaluateTransformJacobianInnerProduct(const TransformJacobianType &jacobian, const MovingImageDerivativeType &movingImageDerivative, DerivativeType &imageJacobian) const
SmartPointer< const Self > ConstPointer
MovingImagePointType TransformPoint(const FixedImagePointType &fixedImagePoint) const
typename MovingImageLimiterType::OutputType MovingImageLimiterOutputType
typename TransformType::InputPointType FixedImagePointType
const AdvancedTransformType * GetTransform() const override
vnl_sparse_matrix< HessianValueType > HessianType
typename FixedImageLimiterType::OutputType FixedImageLimiterOutputType
ImageMaskSpatialObject< Self::MovingImageDimension > MovingImageMaskSpatialObject2Type
typename BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer
virtual void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
typename TransformType::ScalarType ScalarType
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueThreaderCallback(void *arg)
virtual void InitializeLimiters()
typename ImageSamplerType::Pointer ImageSamplerPointer
typename InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType
typename AdvancedTransformType::NumberOfParametersType NumberOfParametersType
typename MovingImageLimiterType::Pointer MovingImageLimiterPointer
virtual void GetSelfHessian(const TransformParametersType ¶meters, HessianType &H) const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValueAndDerivativePerThreadStruct, PaddedGetValueAndDerivativePerThreadStruct)
MultiThreaderParameterType m_ThreaderMetricParameters
virtual void CheckForBSplineInterpolator()
typename LinearInterpolatorType::Pointer LinearInterpolatorPointer
Linearly interpolate an image at specified positions.
SmartPointer< Self > Pointer
typename FixedImageType::PixelType FixedImagePixelType
typename ImageSamplerType::OutputVectorContainerType ImageSampleContainerType
This class is a base class for any image sampler.
Base class for all ITK limiter function objects.
SmartPointer< Self > Pointer
typename ImageSamplerType::OutputVectorContainerPointer ImageSampleContainerPointer
typename MovingImageLimiterType::OutputType MovingImageLimiterOutputType
Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
SmartPointer< Self > Pointer
typename ImageSamplerType::Pointer ImageSamplerPointer
TOutputVectorContainer OutputVectorContainerType
typename OutputVectorContainerType::Pointer OutputVectorContainerPointer
DerivativeType st_Derivative
SizeValueType st_NumberOfPixelsCounted
SizeValueType st_NumberOfPixelsCounted
DerivativeValueType st_NormalizationFactor
DerivativeValueType * st_DerivativePointer
AdvancedImageToImageMetric * st_Metric