Skip to content

Commit

Permalink
ENH: Support averaging affine transforms with float parameters
Browse files Browse the repository at this point in the history
So far, this was only possible with double parameters.
  • Loading branch information
dzenanz committed Feb 26, 2024
1 parent 4a0fb48 commit acd1d62
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 70 deletions.
39 changes: 20 additions & 19 deletions Utilities/itkAverageAffineTransformFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ struct HelperCommonType
unsigned int iEnd);
};

template <typename T>
template <typename T, typename TParametersValueType>
class HelperType;

// {
// // purposely not include any types
// };

// explicit specialization for 2D affine transform
template <>
class HelperType<Dispatcher<2>>
template <typename TParametersValueType>
class HelperType<Dispatcher<2>, TParametersValueType>
{
public:
typedef ANTSCenteredAffine2DTransform<double> InternalAffineTransformType;
typedef ANTSCenteredAffine2DTransform<TParametersValueType> InternalAffineTransformType;

typedef HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
typedef typename HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
InternalAffineTransformPointerType;
typedef HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;
typedef typename HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef typename HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef typename HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;

static void
ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters);
Expand All @@ -90,18 +90,18 @@ class HelperType<Dispatcher<2>>
};

// explicit specialization for 3D affine transform
template <>
class HelperType<Dispatcher<3>>
template <typename TParametersValueType>
class HelperType<Dispatcher<3>, TParametersValueType>
{
public:
typedef ANTSAffine3DTransform<double> InternalAffineTransformType;
typedef ANTSAffine3DTransform<TParametersValueType> InternalAffineTransformType;

typedef HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
typedef typename HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
InternalAffineTransformPointerType;
typedef HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;
typedef typename HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef typename HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef typename HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;

static void
ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters);
Expand All @@ -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<InternalScalarType, SpaceDimension> PointType;

AverageAffineTransformFunction();
Expand Down Expand Up @@ -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<SpaceDimension>>
::itk::AverageAffineTransformFunctionHelperNameSpace::Dispatcher<SpaceDimension>,
InternalScalarType>
HelperType;

typedef typename HelperType::InternalAffineTransformType InternalAffineTransformType;
Expand Down
48 changes: 32 additions & 16 deletions Utilities/itkAverageAffineTransformFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ HelperCommonType<TAffine>::ComputeAveragePartialParameters(InternalTransformList
return;
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageScaleParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageScaleParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 1;
unsigned int iend = 2;
Expand All @@ -216,9 +218,11 @@ HelperType<Dispatcher<2>>::ComputeAverageScaleParameters(InternalTransformListTy
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageShearingParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageShearingParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 3;
unsigned int iend = 3;
Expand All @@ -229,9 +233,11 @@ HelperType<Dispatcher<2>>::ComputeAverageShearingParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageRotationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageRotationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 0;
unsigned int iend = 0;
Expand All @@ -242,9 +248,11 @@ HelperType<Dispatcher<2>>::ComputeAverageRotationParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageTranslationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 6;
unsigned int iend = 7;
Expand All @@ -255,9 +263,11 @@ HelperType<Dispatcher<2>>::ComputeAverageTranslationParameters(InternalTransform
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageScaleParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageScaleParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 4;
unsigned int iend = 6;
Expand All @@ -268,9 +278,11 @@ HelperType<Dispatcher<3>>::ComputeAverageScaleParameters(InternalTransformListTy
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageShearingParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageShearingParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 7;
unsigned int iend = 9;
Expand All @@ -281,9 +293,11 @@ HelperType<Dispatcher<3>>::ComputeAverageShearingParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageRotationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageRotationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 0;
unsigned int iend = 3;
Expand All @@ -307,9 +321,11 @@ HelperType<Dispatcher<3>>::ComputeAverageRotationParameters(InternalTransformLis
}
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageTranslationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 10;
unsigned int iend = 12;
Expand Down
39 changes: 20 additions & 19 deletions Utilities/itkAverageAffineTransformNoRigidFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ struct HelperCommonType
unsigned int iEnd);
};

template <typename T>
template <typename T, typename TParametersValueType>
class HelperType;

// {
// // purposely not include any types
// };

// explicit specialization for 2D affine transform
template <>
class HelperType<Dispatcher<2>>
template <typename TParametersValueType>
class HelperType<Dispatcher<2>, TParametersValueType>
{
public:
typedef ANTSCenteredAffine2DTransform<double> InternalAffineTransformType;
typedef ANTSCenteredAffine2DTransform<TParametersValueType> InternalAffineTransformType;

typedef HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
typedef typename HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
InternalAffineTransformPointerType;
typedef HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;
typedef typename HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef typename HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef typename HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;

static void
ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters);
Expand All @@ -90,18 +90,18 @@ class HelperType<Dispatcher<2>>
};

// explicit specialization for 3D affine transform
template <>
class HelperType<Dispatcher<3>>
template <typename TParametersValueType>
class HelperType<Dispatcher<3>, TParametersValueType>
{
public:
typedef ANTSAffine3DTransform<double> InternalAffineTransformType;
typedef ANTSAffine3DTransform<TParametersValueType> InternalAffineTransformType;

typedef HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
typedef typename HelperCommonType<InternalAffineTransformType>::InternalAffineTransformPointerType
InternalAffineTransformPointerType;
typedef HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;
typedef typename HelperCommonType<InternalAffineTransformType>::SingleInternalTransformItemType
SingleInternalTransformItemType;
typedef typename HelperCommonType<InternalAffineTransformType>::InternalTransformListType InternalTransformListType;
typedef typename HelperCommonType<InternalAffineTransformType>::ParametersType ParametersType;

static void
ComputeAverageScaleParameters(InternalTransformListType & transform_list, ParametersType & average_parameters);
Expand All @@ -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<InternalScalarType, SpaceDimension> PointType;

AverageAffineTransformNoRigidFunction();
Expand Down Expand Up @@ -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<SpaceDimension>>
::itk::AverageAffineTransformNoRigidFunctionHelperNameSpace::Dispatcher<SpaceDimension>,
InternalScalarType>
HelperType;

typedef typename HelperType::InternalAffineTransformType InternalAffineTransformType;
Expand Down
48 changes: 32 additions & 16 deletions Utilities/itkAverageAffineTransformNoRigidFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ HelperCommonType<TAffine>::ComputeAveragePartialParameters(InternalTransformList
return;
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageScaleParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageScaleParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 1;
unsigned int iend = 2;
Expand All @@ -219,9 +221,11 @@ HelperType<Dispatcher<2>>::ComputeAverageScaleParameters(InternalTransformListTy
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageShearingParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageShearingParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 3;
unsigned int iend = 3;
Expand All @@ -232,9 +236,11 @@ HelperType<Dispatcher<2>>::ComputeAverageShearingParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageRotationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageRotationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 0;
unsigned int iend = 0;
Expand All @@ -245,9 +251,11 @@ HelperType<Dispatcher<2>>::ComputeAverageRotationParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<2>>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<2>, TParametersValueType>::ComputeAverageTranslationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 6;
unsigned int iend = 7;
Expand All @@ -258,9 +266,11 @@ HelperType<Dispatcher<2>>::ComputeAverageTranslationParameters(InternalTransform
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageScaleParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageScaleParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 4;
unsigned int iend = 6;
Expand All @@ -271,9 +281,11 @@ HelperType<Dispatcher<3>>::ComputeAverageScaleParameters(InternalTransformListTy
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageShearingParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageShearingParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 7;
unsigned int iend = 9;
Expand All @@ -284,9 +296,11 @@ HelperType<Dispatcher<3>>::ComputeAverageShearingParameters(InternalTransformLis
transform_list, average_parameters, istart, iend);
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageRotationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageRotationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 0;
unsigned int iend = 3;
Expand All @@ -310,9 +324,11 @@ HelperType<Dispatcher<3>>::ComputeAverageRotationParameters(InternalTransformLis
}
}

template <typename TParametersValueType>
void
HelperType<Dispatcher<3>>::ComputeAverageTranslationParameters(InternalTransformListType & transform_list,
ParametersType & average_parameters)
HelperType<Dispatcher<3>, TParametersValueType>::ComputeAverageTranslationParameters(
InternalTransformListType & transform_list,
ParametersType & average_parameters)
{
unsigned int istart = 10;
unsigned int iend = 12;
Expand Down

0 comments on commit acd1d62

Please sign in to comment.