From acd1d62f2ca7b191eb5c11577571ce8603cbc0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Mon, 26 Feb 2024 12:27:30 -0500 Subject: [PATCH] ENH: Support averaging affine transforms with float parameters So far, this was only possible with double parameters. --- Utilities/itkAverageAffineTransformFunction.h | 39 +++++++-------- .../itkAverageAffineTransformFunction.hxx | 48 ++++++++++++------- ...itkAverageAffineTransformNoRigidFunction.h | 39 +++++++-------- ...kAverageAffineTransformNoRigidFunction.hxx | 48 ++++++++++++------- 4 files changed, 104 insertions(+), 70 deletions(-) diff --git a/Utilities/itkAverageAffineTransformFunction.h b/Utilities/itkAverageAffineTransformFunction.h index b82b446fe..0f1118ffa 100644 --- a/Utilities/itkAverageAffineTransformFunction.h +++ b/Utilities/itkAverageAffineTransformFunction.h @@ -55,7 +55,7 @@ struct HelperCommonType unsigned int iEnd); }; -template +template class HelperType; // { @@ -63,18 +63,18 @@ class HelperType; // }; // explicit specialization for 2D affine transform -template <> -class HelperType> +template +class HelperType, TParametersValueType> { public: - typedef ANTSCenteredAffine2DTransform InternalAffineTransformType; + typedef ANTSCenteredAffine2DTransform InternalAffineTransformType; - typedef HelperCommonType::InternalAffineTransformPointerType + typedef typename HelperCommonType::InternalAffineTransformPointerType InternalAffineTransformPointerType; - typedef HelperCommonType::SingleInternalTransformItemType - SingleInternalTransformItemType; - typedef HelperCommonType::InternalTransformListType InternalTransformListType; - typedef HelperCommonType::ParametersType ParametersType; + typedef typename HelperCommonType::SingleInternalTransformItemType + SingleInternalTransformItemType; + typedef typename HelperCommonType::InternalTransformListType InternalTransformListType; + typedef typename HelperCommonType::ParametersType ParametersType; static void ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters); @@ -90,18 +90,18 @@ class HelperType> }; // explicit specialization for 3D affine transform -template <> -class HelperType> +template +class HelperType, TParametersValueType> { public: - typedef ANTSAffine3DTransform InternalAffineTransformType; + typedef ANTSAffine3DTransform InternalAffineTransformType; - typedef HelperCommonType::InternalAffineTransformPointerType + typedef typename HelperCommonType::InternalAffineTransformPointerType InternalAffineTransformPointerType; - typedef HelperCommonType::SingleInternalTransformItemType - SingleInternalTransformItemType; - typedef HelperCommonType::InternalTransformListType InternalTransformListType; - typedef HelperCommonType::ParametersType ParametersType; + typedef typename HelperCommonType::SingleInternalTransformItemType + SingleInternalTransformItemType; + typedef typename HelperCommonType::InternalTransformListType InternalTransformListType; + typedef typename HelperCommonType::ParametersType ParametersType; static void ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters); @@ -127,7 +127,7 @@ class AverageAffineTransformFunction static constexpr unsigned int OutputSpaceDimension = GenericAffineTransformType::OutputSpaceDimension; static constexpr unsigned int SpaceDimension = InputSpaceDimension; - typedef double InternalScalarType; + typedef typename TTransform::ParametersValueType InternalScalarType; typedef Point PointType; AverageAffineTransformFunction(); @@ -171,7 +171,8 @@ class AverageAffineTransformFunction // type declaration to include support both 2D and 3D affine transform protected: typedef typename ::itk::AverageAffineTransformFunctionHelperNameSpace::HelperType< - ::itk::AverageAffineTransformFunctionHelperNameSpace::Dispatcher> + ::itk::AverageAffineTransformFunctionHelperNameSpace::Dispatcher, + InternalScalarType> HelperType; typedef typename HelperType::InternalAffineTransformType InternalAffineTransformType; diff --git a/Utilities/itkAverageAffineTransformFunction.hxx b/Utilities/itkAverageAffineTransformFunction.hxx index 706c6236b..11b6e011c 100644 --- a/Utilities/itkAverageAffineTransformFunction.hxx +++ b/Utilities/itkAverageAffineTransformFunction.hxx @@ -203,9 +203,11 @@ HelperCommonType::ComputeAveragePartialParameters(InternalTransformList return; } +template void -HelperType>::ComputeAverageScaleParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageScaleParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 1; unsigned int iend = 2; @@ -216,9 +218,11 @@ HelperType>::ComputeAverageScaleParameters(InternalTransformListTy transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageShearingParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageShearingParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 3; unsigned int iend = 3; @@ -229,9 +233,11 @@ HelperType>::ComputeAverageShearingParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageRotationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageRotationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 0; unsigned int iend = 0; @@ -242,9 +248,11 @@ HelperType>::ComputeAverageRotationParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageTranslationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 6; unsigned int iend = 7; @@ -255,9 +263,11 @@ HelperType>::ComputeAverageTranslationParameters(InternalTransform transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageScaleParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageScaleParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 4; unsigned int iend = 6; @@ -268,9 +278,11 @@ HelperType>::ComputeAverageScaleParameters(InternalTransformListTy transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageShearingParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageShearingParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 7; unsigned int iend = 9; @@ -281,9 +293,11 @@ HelperType>::ComputeAverageShearingParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageRotationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageRotationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 0; unsigned int iend = 3; @@ -307,9 +321,11 @@ HelperType>::ComputeAverageRotationParameters(InternalTransformLis } } +template void -HelperType>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageTranslationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 10; unsigned int iend = 12; diff --git a/Utilities/itkAverageAffineTransformNoRigidFunction.h b/Utilities/itkAverageAffineTransformNoRigidFunction.h index 72d5658b6..c84899fc2 100644 --- a/Utilities/itkAverageAffineTransformNoRigidFunction.h +++ b/Utilities/itkAverageAffineTransformNoRigidFunction.h @@ -55,7 +55,7 @@ struct HelperCommonType unsigned int iEnd); }; -template +template class HelperType; // { @@ -63,18 +63,18 @@ class HelperType; // }; // explicit specialization for 2D affine transform -template <> -class HelperType> +template +class HelperType, TParametersValueType> { public: - typedef ANTSCenteredAffine2DTransform InternalAffineTransformType; + typedef ANTSCenteredAffine2DTransform InternalAffineTransformType; - typedef HelperCommonType::InternalAffineTransformPointerType + typedef typename HelperCommonType::InternalAffineTransformPointerType InternalAffineTransformPointerType; - typedef HelperCommonType::SingleInternalTransformItemType - SingleInternalTransformItemType; - typedef HelperCommonType::InternalTransformListType InternalTransformListType; - typedef HelperCommonType::ParametersType ParametersType; + typedef typename HelperCommonType::SingleInternalTransformItemType + SingleInternalTransformItemType; + typedef typename HelperCommonType::InternalTransformListType InternalTransformListType; + typedef typename HelperCommonType::ParametersType ParametersType; static void ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters); @@ -90,18 +90,18 @@ class HelperType> }; // explicit specialization for 3D affine transform -template <> -class HelperType> +template +class HelperType, TParametersValueType> { public: - typedef ANTSAffine3DTransform InternalAffineTransformType; + typedef ANTSAffine3DTransform InternalAffineTransformType; - typedef HelperCommonType::InternalAffineTransformPointerType + typedef typename HelperCommonType::InternalAffineTransformPointerType InternalAffineTransformPointerType; - typedef HelperCommonType::SingleInternalTransformItemType - SingleInternalTransformItemType; - typedef HelperCommonType::InternalTransformListType InternalTransformListType; - typedef HelperCommonType::ParametersType ParametersType; + typedef typename HelperCommonType::SingleInternalTransformItemType + SingleInternalTransformItemType; + typedef typename HelperCommonType::InternalTransformListType InternalTransformListType; + typedef typename HelperCommonType::ParametersType ParametersType; static void ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters); @@ -127,7 +127,7 @@ class AverageAffineTransformNoRigidFunction static constexpr unsigned int OutputSpaceDimension = GenericAffineTransformType::OutputSpaceDimension; static constexpr unsigned int SpaceDimension = InputSpaceDimension; - typedef double InternalScalarType; + typedef typename TTransform::ParametersValueType InternalScalarType; typedef Point PointType; AverageAffineTransformNoRigidFunction(); @@ -171,7 +171,8 @@ class AverageAffineTransformNoRigidFunction // type declaration to include support both 2D and 3D affine transform protected: typedef typename ::itk::AverageAffineTransformNoRigidFunctionHelperNameSpace::HelperType< - ::itk::AverageAffineTransformNoRigidFunctionHelperNameSpace::Dispatcher> + ::itk::AverageAffineTransformNoRigidFunctionHelperNameSpace::Dispatcher, + InternalScalarType> HelperType; typedef typename HelperType::InternalAffineTransformType InternalAffineTransformType; diff --git a/Utilities/itkAverageAffineTransformNoRigidFunction.hxx b/Utilities/itkAverageAffineTransformNoRigidFunction.hxx index 39b412be4..636e94fc4 100644 --- a/Utilities/itkAverageAffineTransformNoRigidFunction.hxx +++ b/Utilities/itkAverageAffineTransformNoRigidFunction.hxx @@ -206,9 +206,11 @@ HelperCommonType::ComputeAveragePartialParameters(InternalTransformList return; } +template void -HelperType>::ComputeAverageScaleParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageScaleParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 1; unsigned int iend = 2; @@ -219,9 +221,11 @@ HelperType>::ComputeAverageScaleParameters(InternalTransformListTy transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageShearingParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageShearingParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 3; unsigned int iend = 3; @@ -232,9 +236,11 @@ HelperType>::ComputeAverageShearingParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageRotationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageRotationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 0; unsigned int iend = 0; @@ -245,9 +251,11 @@ HelperType>::ComputeAverageRotationParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageTranslationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 6; unsigned int iend = 7; @@ -258,9 +266,11 @@ HelperType>::ComputeAverageTranslationParameters(InternalTransform transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageScaleParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageScaleParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 4; unsigned int iend = 6; @@ -271,9 +281,11 @@ HelperType>::ComputeAverageScaleParameters(InternalTransformListTy transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageShearingParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageShearingParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 7; unsigned int iend = 9; @@ -284,9 +296,11 @@ HelperType>::ComputeAverageShearingParameters(InternalTransformLis transform_list, average_parameters, istart, iend); } +template void -HelperType>::ComputeAverageRotationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageRotationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 0; unsigned int iend = 3; @@ -310,9 +324,11 @@ HelperType>::ComputeAverageRotationParameters(InternalTransformLis } } +template void -HelperType>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list, - ParametersType & average_parameters) +HelperType, TParametersValueType>::ComputeAverageTranslationParameters( + InternalTransformListType & transform_list, + ParametersType & average_parameters) { unsigned int istart = 10; unsigned int iend = 12;