Skip to content

Commit

Permalink
STYLE: Remove AdvancedCombinationTransform member function pointers
Browse files Browse the repository at this point in the history
Removed those nine member function pointers as well as the 28 member functions that they could point to, and added nine `switch (m_SelectedMethod)` statements instead.
  • Loading branch information
N-Dekker committed Mar 23, 2023
1 parent 38b6152 commit 4a80e38
Show file tree
Hide file tree
Showing 2 changed files with 353 additions and 1,151 deletions.
297 changes: 8 additions & 289 deletions Common/Transforms/itkAdvancedCombinationTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,236 +316,6 @@ class ITK_TEMPLATE_EXPORT AdvancedCombinationTransform : public AdvancedTransfor
void
UpdateCombinationMethod();

/** ************************************************
* Methods to transform a point.
*/

/** ADDITION: \f$T(x) = T_0(x) + T_1(x) - x\f$ */
OutputPointType
TransformPointUseAddition(const InputPointType & point) const;

/** COMPOSITION: \f$T(x) = T_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
OutputPointType
TransformPointUseComposition(const InputPointType & point) const;

/** CURRENT ONLY: \f$T(x) = T_1(x)\f$ */
OutputPointType
TransformPointNoInitialTransform(const InputPointType & point) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
OutputPointType
TransformPointNoCurrentTransform(const InputPointType & point) const;

/** ************************************************
* Methods to compute the sparse Jacobian.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
GetJacobianUseAddition(const InputPointType &, JacobianType &, NonZeroJacobianIndicesType &) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
GetJacobianUseComposition(const InputPointType &, JacobianType &, NonZeroJacobianIndicesType &) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
GetJacobianNoInitialTransform(const InputPointType &, JacobianType &, NonZeroJacobianIndicesType &) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
GetJacobianNoCurrentTransform(const InputPointType &, JacobianType &, NonZeroJacobianIndicesType &) const;

/** ************************************************
* Methods to compute the inner product of the Jacobian with the moving image gradient.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
EvaluateJacobianWithImageGradientProductUseAddition(const InputPointType &,
const MovingImageGradientType &,
DerivativeType &,
NonZeroJacobianIndicesType &) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
EvaluateJacobianWithImageGradientProductUseComposition(const InputPointType &,
const MovingImageGradientType &,
DerivativeType &,
NonZeroJacobianIndicesType &) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
EvaluateJacobianWithImageGradientProductNoInitialTransform(const InputPointType &,
const MovingImageGradientType &,
DerivativeType &,
NonZeroJacobianIndicesType &) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
EvaluateJacobianWithImageGradientProductNoCurrentTransform(const InputPointType &,
const MovingImageGradientType &,
DerivativeType &,
NonZeroJacobianIndicesType &) const;

/** ************************************************
* Methods to compute the spatial Jacobian.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
GetSpatialJacobianUseAddition(const InputPointType & inputPoint, SpatialJacobianType & sj) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
GetSpatialJacobianUseComposition(const InputPointType & inputPoint, SpatialJacobianType & sj) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
GetSpatialJacobianNoInitialTransform(const InputPointType & inputPoint, SpatialJacobianType & sj) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
GetSpatialJacobianNoCurrentTransform(const InputPointType & inputPoint, SpatialJacobianType & sj) const;

/** ************************************************
* Methods to compute the spatial Hessian.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
GetSpatialHessianUseAddition(const InputPointType & inputPoint, SpatialHessianType & sh) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
GetSpatialHessianUseComposition(const InputPointType & inputPoint, SpatialHessianType & sh) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
GetSpatialHessianNoInitialTransform(const InputPointType & inputPoint, SpatialHessianType & sh) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
GetSpatialHessianNoCurrentTransform(const InputPointType & inputPoint, SpatialHessianType & sh) const;

/** ************************************************
* Methods to compute the Jacobian of the spatial Jacobian.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
GetJacobianOfSpatialJacobianUseAddition(const InputPointType & inputPoint,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialJacobianUseAddition(const InputPointType & inputPoint,
SpatialJacobianType & sj,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
GetJacobianOfSpatialJacobianUseComposition(const InputPointType & inputPoint,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialJacobianUseComposition(const InputPointType & inputPoint,
SpatialJacobianType & sj,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
GetJacobianOfSpatialJacobianNoInitialTransform(const InputPointType & inputPoint,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialJacobianNoInitialTransform(const InputPointType & inputPoint,
SpatialJacobianType & sj,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
GetJacobianOfSpatialJacobianNoCurrentTransform(const InputPointType & inputPoint,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialJacobianNoCurrentTransform(const InputPointType & inputPoint,
SpatialJacobianType & sj,
JacobianOfSpatialJacobianType & jsj,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** ************************************************
* Methods to compute the Jacobian of the spatial Hessian.
*/

/** ADDITION: \f$J(x) = J_1(x)\f$ */
void
GetJacobianOfSpatialHessianUseAddition(const InputPointType & inputPoint,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialHessianUseAddition(const InputPointType & inputPoint,
SpatialHessianType & sh,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** COMPOSITION: \f$J(x) = J_1( T_0(x) )\f$
* \warning: assumes that input and output point type are the same.
*/
void
GetJacobianOfSpatialHessianUseComposition(const InputPointType & inputPoint,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialHessianUseComposition(const InputPointType & inputPoint,
SpatialHessianType & sh,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** CURRENT ONLY: \f$J(x) = J_1(x)\f$ */
void
GetJacobianOfSpatialHessianNoInitialTransform(const InputPointType & inputPoint,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialHessianNoInitialTransform(const InputPointType & inputPoint,
SpatialHessianType & sh,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

/** NO CURRENT TRANSFORM SET: throw an exception. */
void
GetJacobianOfSpatialHessianNoCurrentTransform(const InputPointType & inputPoint,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

void
GetJacobianOfSpatialHessianNoCurrentTransform(const InputPointType & inputPoint,
SpatialHessianType & sh,
JacobianOfSpatialHessianType & jsh,
NonZeroJacobianIndicesType & nonZeroJacobianIndices) const;

private:
/** Exception text. */
constexpr static const char * NoCurrentTransformSet = "No current transform set in the AdvancedCombinationTransform";
Expand All @@ -554,68 +324,17 @@ class ITK_TEMPLATE_EXPORT AdvancedCombinationTransform : public AdvancedTransfor
InitialTransformPointer m_InitialTransform{ nullptr };
CurrentTransformPointer m_CurrentTransform{ nullptr };

/** Typedefs for function pointers. */
using TransformPointFunctionPointer = OutputPointType (Self::*)(const InputPointType &) const;
using GetSparseJacobianFunctionPointer = void (Self::*)(const InputPointType &,
JacobianType &,
NonZeroJacobianIndicesType &) const;
using EvaluateJacobianWithImageGradientProductFunctionPointer = void (Self::*)(const InputPointType &,
const MovingImageGradientType &,
DerivativeType &,
NonZeroJacobianIndicesType &) const;
using GetSpatialJacobianFunctionPointer = void (Self::*)(const InputPointType &, SpatialJacobianType &) const;
using GetSpatialHessianFunctionPointer = void (Self::*)(const InputPointType &, SpatialHessianType &) const;
using GetJacobianOfSpatialJacobianFunctionPointer = void (Self::*)(const InputPointType &,
JacobianOfSpatialJacobianType &,
NonZeroJacobianIndicesType &) const;
using GetJacobianOfSpatialJacobianFunctionPointer2 = void (Self::*)(const InputPointType &,
SpatialJacobianType &,
JacobianOfSpatialJacobianType &,
NonZeroJacobianIndicesType &) const;
using GetJacobianOfSpatialHessianFunctionPointer = void (Self::*)(const InputPointType &,
JacobianOfSpatialHessianType &,
NonZeroJacobianIndicesType &) const;
using GetJacobianOfSpatialHessianFunctionPointer2 = void (Self::*)(const InputPointType &,
SpatialHessianType &,
JacobianOfSpatialHessianType &,
NonZeroJacobianIndicesType &) const;

/** A pointer to one of the following functions:
* - TransformPointUseAddition,
* - TransformPointUseComposition,
* - TransformPointNoCurrentTransform
* - TransformPointNoInitialTransform.
*/
TransformPointFunctionPointer m_SelectedTransformPointFunction{ &Self::TransformPointNoCurrentTransform };

/** A pointer to one of the following functions:
* - GetJacobianUseAddition,
* - GetJacobianUseComposition,
* - GetJacobianNoCurrentTransform
* - GetJacobianNoInitialTransform.
*/
// GetJacobianFunctionPointer m_SelectedGetJacobianFunction;

/** More of these. Set everything to have no current transform. */
GetSparseJacobianFunctionPointer m_SelectedGetSparseJacobianFunction{ &Self::GetJacobianNoCurrentTransform };
EvaluateJacobianWithImageGradientProductFunctionPointer m_SelectedEvaluateJacobianWithImageGradientProductFunction{
&Self::EvaluateJacobianWithImageGradientProductNoInitialTransform
};
GetSpatialJacobianFunctionPointer m_SelectedGetSpatialJacobianFunction{ &Self::GetSpatialJacobianNoCurrentTransform };
GetSpatialHessianFunctionPointer m_SelectedGetSpatialHessianFunction{ &Self::GetSpatialHessianNoCurrentTransform };
GetJacobianOfSpatialJacobianFunctionPointer m_SelectedGetJacobianOfSpatialJacobianFunction{
&Self::GetJacobianOfSpatialJacobianNoCurrentTransform
};
GetJacobianOfSpatialJacobianFunctionPointer2 m_SelectedGetJacobianOfSpatialJacobianFunction2{
&Self::GetJacobianOfSpatialJacobianNoCurrentTransform
};
GetJacobianOfSpatialHessianFunctionPointer m_SelectedGetJacobianOfSpatialHessianFunction{
&Self::GetJacobianOfSpatialHessianNoCurrentTransform
};
GetJacobianOfSpatialHessianFunctionPointer2 m_SelectedGetJacobianOfSpatialHessianFunction2{
&Self::GetJacobianOfSpatialHessianNoCurrentTransform
enum class SelectedMethod
{
NoInitialTransform,
UseComposition,
UseAddition,
NoCurrentTransform
};

SelectedMethod m_SelectedMethod{};

/** How to combine the transformations. Composition by default. */
bool m_UseAddition{ false };
bool m_UseComposition{ true };
Expand Down
Loading

0 comments on commit 4a80e38

Please sign in to comment.