Skip to content

Commit

Permalink
WIP: COMP: Upgrade ITK from v5.2.0 to v5.3rc02
Browse files Browse the repository at this point in the history
Upgraded to ITK version 5.3 (RC02), which was released on 11 November 2021.

Including upgrade to C++14, and various performance improvements:

InsightSoftwareConsortium/ITK@6a8569e Use the faster `TransformPhysicalPointToContinuousIndex` overload
InsightSoftwareConsortium/ITK@eb6ac88 Use the faster `TransformPhysicalPointToIndex` overload in filter
InsightSoftwareConsortium/ITK@0539a2c Remove protected `itk::Transform` data member `m_DirectionChange`
InsightSoftwareConsortium/ITK@eec9fe6 Remove unnecessary `IdentityTransform::m_ZeroJacobian`
InsightSoftwareConsortium/ITK@9961ccd Use FastEvaluate in MattesMutualInformationImageToImageMetric + v4
InsightSoftwareConsortium/ITK@9745409 Use FixedArray for table within BSplineInterpolationWeightFunction
InsightSoftwareConsortium/ITK@c23944b Remove BSplineInterpolationWeightFunction Kernel, use FastEvaluate
InsightSoftwareConsortium/ITK@bc7c5df Use FixedArray for BSplineBaseTransform ParameterIndexArrayType
InsightSoftwareConsortium/ITK@9bf745b Use FixedArray for BSplineInterpolationWeightFunction OutputType
InsightSoftwareConsortium/ITK@c64a58d Make `ResampleImageFilter::LinearThreadedGenerateData` faster

Release Notes: https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.3rc02

Follow-up to pull request #475 commit 6803b26 "COMP: Upgrade ITK from v5.1.1 to v5.2.0" (merged on 31 May 2021).
  • Loading branch information
N-Dekker committed Jan 2, 2022
1 parent c9a0db8 commit e2071d8
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 92 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ElastixGitHubActions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ jobs:
- os: ubuntu-18.04
c-compiler: "gcc"
cxx-compiler: "g++"
itk-git-tag: "v5.2.0"
itk-git-tag: "v5.3rc02"
cmake-build-type: "Release"
ANNLib: "libANNlib-5.0.so"
ANNLib2: "libANNlib-5.0.so.1"
- os: windows-2019
c-compiler: "cl.exe"
cxx-compiler: "cl.exe"
itk-git-tag: "v5.2.0"
itk-git-tag: "v5.3rc02"
cmake-build-type: "Release"
ANNLib: "ANNlib-5.0.dll"
vcvars64: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
- os: macos-10.15
c-compiler: "clang"
cxx-compiler: "clang++"
itk-git-tag: "v5.2.0"
itk-git-tag: "v5.3rc02"
cmake-build-type: "Release"
ANNLib: "libANNlib-5.0.1.dylib"
ANNLib2: "libANNlib-5.0.dylib"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(ELASTIX_USE_OPENCL)
endif()

# Find ITK.
find_package( ITK 5.2.0 REQUIRED COMPONENTS
find_package( ITK 5.3 REQUIRED COMPONENTS
ITKCommon
ITKDisplacementField
ITKDistanceMap
Expand Down
65 changes: 26 additions & 39 deletions Common/Transforms/itkAdvancedBSplineDeformableTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "itkImageScanlineConstIterator.h"
#include "itkIdentityTransform.h"
#include <vnl/vnl_math.h>
#include <array>
#include <vector>
#include <algorithm> // For std::copy_n.

Expand Down Expand Up @@ -291,9 +292,8 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::Tran
{
/** Allocate memory on the stack: */
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
typename ParameterIndexArrayType::ValueType indicesArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;
ParameterIndexArrayType indices(indicesArray, numberOfWeights, false);

OutputPointType outputPoint;
Expand Down Expand Up @@ -379,9 +379,8 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
/** Compute the number of affected B-spline parameters.
* Allocate memory on the stack.
*/
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsType weights;

/** Compute the weights. */
IndexType supportIndex;
Expand Down Expand Up @@ -446,9 +445,7 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::Eval
/** Compute the number of affected B-spline parameters.
* Allocate memory on the stack.
*/
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;

/** Compute the B-spline derivative weights. */
IndexType supportIndex;
Expand Down Expand Up @@ -504,20 +501,18 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetS

/** Compute the number of affected B-spline parameters. */
/** Allocate memory on the stack: */
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsType weights;

/** Array for CoefficientImage values */
typename WeightsType::ValueType coeffArray[numberOfWeights * SpaceDimension];
WeightsType coeffs(coeffArray, numberOfWeights * SpaceDimension, false);
std::array<typename WeightsType::ValueType, numberOfWeights * SpaceDimension> coeffs;

IndexType supportIndex;
this->m_DerivativeWeightsFunctions[0]->ComputeStartIndex(cindex, supportIndex);
const RegionType supportRegion(supportIndex, Superclass::m_SupportSize);

/** Copy values from coefficient image to linear coeffs array. */
typename WeightsType::iterator itCoeffsLinear = coeffs.begin();
auto itCoeffsLinear = coeffs.begin();
for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
{
ImageScanlineConstIterator<ImageType> itCoef(this->m_CoefficientImages[dim], supportRegion);
Expand All @@ -544,7 +539,7 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetS
this->m_DerivativeWeightsFunctions[i]->Evaluate(cindex, supportIndex, weights);

/** Create an iterator over the coeffs vector. */
typename WeightsType::const_iterator itCoeffs = coeffs.begin();
auto itCoeffs = coeffs.cbegin();

/** Compute the spatial Jacobian sj:
* dT_{dim} / dx_i = \sum coefs_{dim} * weights.
Expand Down Expand Up @@ -610,19 +605,17 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetS
/** Helper variables. */
/** Allocate memory on the stack: */
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;

/** Array for CoefficientImage values */
WeightsValueType coeffArray[numberOfWeights * SpaceDimension];
WeightsType coeffs(coeffArray, numberOfWeights * SpaceDimension, false);
std::array<WeightsValueType, numberOfWeights * SpaceDimension> coeffs;

IndexType supportIndex;
this->m_SODerivativeWeightsFunctions[0][0]->ComputeStartIndex(cindex, supportIndex);
const RegionType supportRegion(supportIndex, Superclass::m_SupportSize);

/** Copy values from coefficient image to linear coeffs array. */
typename WeightsType::iterator itCoeffsLinear = coeffs.begin();
auto itCoeffsLinear = coeffs.begin();
for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
{
ImageScanlineConstIterator<ImageType> itCoef(this->m_CoefficientImages[dim], supportRegion);
Expand Down Expand Up @@ -653,7 +646,7 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetS
this->m_SODerivativeWeightsFunctions[i][j]->Evaluate(cindex, supportIndex, weights);

/** Create an iterator over the coeffs vector. */
typename WeightsType::const_iterator itCoeffs = coeffs.begin();
auto itCoeffs = coeffs.cbegin();

/** Compute d^2T_{dim} / dx_i dx_j = \sum coefs_{dim} * weights. */
for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
Expand Down Expand Up @@ -735,9 +728,8 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
/** Helper variables. */

/** Allocate memory on the stack: */
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsType weights;

IndexType supportIndex;
this->m_DerivativeWeightsFunctions[0]->ComputeStartIndex(cindex, supportIndex);
Expand Down Expand Up @@ -840,16 +832,14 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
/** Allocate weight on the stack. */
typedef typename WeightsType::ValueType WeightsValueType;
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;

/** Allocate coefficients on the stack. */
WeightsValueType coeffArray[numberOfWeights * SpaceDimension];
WeightsType coeffs(coeffArray, numberOfWeights * SpaceDimension, false);
std::array<WeightsValueType, numberOfWeights * SpaceDimension> coeffs;

/** Copy values from coefficient image to linear coeffs array. */
// takes considerable amount of time : 27% of this function. // with old region iterator, check with new
typename WeightsType::iterator itCoeffsLinear = coeffs.begin();
auto itCoeffsLinear = coeffs.begin();
for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
{
ImageScanlineConstIterator<ImageType> itCoef(this->m_CoefficientImages[dim], supportRegion);
Expand Down Expand Up @@ -887,7 +877,7 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
std::copy_n(weights.begin(), numberOfWeights, weightVector + i * numberOfWeights);

/** Reset coeffs iterator */
typename WeightsType::const_iterator itCoeffs = coeffs.begin();
auto itCoeffs = coeffs.cbegin();

/** Compute the spatial Jacobian sj:
* dT_{dim} / dx_i = delta_{dim,i} + \sum coefs_{dim} * weights.
Expand Down Expand Up @@ -993,9 +983,8 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
/** Compute the number of affected B-spline parameters. */

/** Allocate memory on the stack: */
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsType weights;

IndexType supportIndex;
this->m_SODerivativeWeightsFunctions[0][0]->ComputeStartIndex(cindex, supportIndex);
Expand Down Expand Up @@ -1119,16 +1108,14 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
/** Allocate weight on the stack. */
typedef typename WeightsType::ValueType WeightsValueType;
const unsigned long numberOfWeights = WeightsFunctionType::NumberOfWeights;
WeightsValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;

/** Allocate coefficients on the stack. */
WeightsValueType coeffArray[numberOfWeights * SpaceDimension];
WeightsType coeffs(coeffArray, numberOfWeights * SpaceDimension, false);
std::array<WeightsValueType, numberOfWeights * SpaceDimension> coeffs;

/** Copy values from coefficient image to linear coeffs array. */
// takes considerable amount of time : 27% of this function. // with old region iterator, check with new
typename WeightsType::iterator itCoeffsLinear = coeffs.begin();
auto itCoeffsLinear = coeffs.begin();
for (unsigned int dim = 0; dim < SpaceDimension; ++dim)
{
ImageScanlineConstIterator<ImageType> itCoef(this->m_CoefficientImages[dim], supportRegion);
Expand Down Expand Up @@ -1168,7 +1155,7 @@ AdvancedBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetJ
count++;

/** Reset coeffs iterator */
typename WeightsType::const_iterator itCoeffs = coeffs.begin();
auto itCoeffs = coeffs.cbegin();

/** Compute the spatial Hessian sh:
* d^2T_{dim} / dx_i dx_j = \sum coefs_{dim} * weights.
Expand Down
15 changes: 9 additions & 6 deletions Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ namespace itk
*/
template <class TCoordRep = float, unsigned int VSpaceDimension = 2, unsigned int VSplineOrder = 3>
class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunctionBase
: public FunctionBase<ContinuousIndex<TCoordRep, VSpaceDimension>, Array<double>>
: public FunctionBase<ContinuousIndex<TCoordRep, VSpaceDimension>,
FixedArray<double, Math::UnsignedPower(VSplineOrder + 1, VSpaceDimension)>>
{
public:
/** Standard class typedefs. */
typedef BSplineInterpolationWeightFunctionBase Self;
typedef FunctionBase<ContinuousIndex<TCoordRep, VSpaceDimension>, Array<double>> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
typedef BSplineInterpolationWeightFunctionBase Self;
typedef FunctionBase<ContinuousIndex<TCoordRep, VSpaceDimension>,
FixedArray<double, Math::UnsignedPower(VSplineOrder + 1, VSpaceDimension)>>
Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;

/** Run-time type information (and related methods). */
itkTypeMacro(BSplineInterpolationWeightFunctionBase, FunctionBase);
Expand All @@ -70,7 +73,7 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunctionBase
static constexpr unsigned long NumberOfWeights = Math::UnsignedPower(VSplineOrder + 1, VSpaceDimension);

/** OutputType typedef support. */
typedef Array<double> WeightsType;
typedef FixedArray<double, NumberOfWeights> WeightsType;

/** Index and size typedef support. */
typedef Index<VSpaceDimension> IndexType;
Expand Down
4 changes: 1 addition & 3 deletions Common/Transforms/itkCyclicBSplineDeformableTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ CyclicBSplineDeformableTransform<TScalarType, NDimensions, VSplineOrder>::GetSpa

/** Compute the number of affected B-spline parameters. */
/** Allocate memory on the stack: */
const SizeValueType numberOfWeights = WeightsFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray[numberOfWeights];
WeightsType weights(weightsArray, numberOfWeights, false);
WeightsType weights;

IndexType supportIndex;
this->m_DerivativeWeightsFunctions[0]->ComputeStartIndex(cindex, supportIndex);
Expand Down
52 changes: 15 additions & 37 deletions Common/Transforms/itkRecursiveBSplineTransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ auto
RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::TransformPoint(const InputPointType & point) const
-> OutputPointType
{
/** Define some constants. */
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;

/** Initialize output point. */
OutputPointType outputPoint;

/** Allocate weights on the stack: */
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
WeightsType weights1D;

/** Check if the coefficient image has been set. */
if (!this->m_CoefficientImages[0])
Expand Down Expand Up @@ -156,10 +152,8 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::GetJacobian(
* In contrast to the normal B-spline weights function, the recursive version
* returns the individual weights instead of the multiplied ones.
*/
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
IndexType supportIndex;
WeightsType weights1D;
IndexType supportIndex;
this->m_RecursiveBSplineWeightFunction->Evaluate(cindex, weights1D, supportIndex);

/** Recursively compute the first numberOfIndices entries of the Jacobian.
Expand Down Expand Up @@ -215,10 +209,8 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::EvaluateJacobianW
* In contrast to the normal B-spline weights function, the recursive version
* returns the individual weights instead of the multiplied ones.
*/
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
IndexType supportIndex;
WeightsType weights1D;
IndexType supportIndex;
this->m_RecursiveBSplineWeightFunction->Evaluate(cindex, weights1D, supportIndex);

/** Recursively compute the inner product of the Jacobian and the moving image gradient.
Expand Down Expand Up @@ -269,11 +261,8 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::GetSpatialJacobia
}

/** Create storage for the B-spline interpolation weights. */
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType derivativeWeightsArray1D[numberOfWeights];
WeightsType derivativeWeights1D(derivativeWeightsArray1D, numberOfWeights, false);
WeightsType weights1D;
WeightsType derivativeWeights1D;

double * weightsPointer = &(weights1D[0]);
double * derivativeWeightsPointer = &(derivativeWeights1D[0]);
Expand Down Expand Up @@ -357,13 +346,9 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::GetSpatialHessian
}

/** Create storage for the B-spline interpolation weights. */
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType derivativeWeightsArray1D[numberOfWeights];
WeightsType derivativeWeights1D(derivativeWeightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType hessianWeightsArray1D[numberOfWeights];
WeightsType hessianWeights1D(hessianWeightsArray1D, numberOfWeights, false);
WeightsType weights1D;
WeightsType derivativeWeights1D;
WeightsType hessianWeights1D;

double * weightsPointer = &(weights1D[0]);
double * derivativeWeightsPointer = &(derivativeWeights1D[0]);
Expand Down Expand Up @@ -477,11 +462,8 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::GetJacobianOfSpat
}

/** Create storage for the B-spline interpolation weights. */
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType derivativeWeightsArray1D[numberOfWeights];
WeightsType derivativeWeights1D(derivativeWeightsArray1D, numberOfWeights, false);
WeightsType weights1D;
WeightsType derivativeWeights1D;

double * weightsPointer = &(weights1D[0]);
double * derivativeWeightsPointer = &(derivativeWeights1D[0]);
Expand Down Expand Up @@ -577,13 +559,9 @@ RecursiveBSplineTransform<TScalar, NDimensions, VSplineOrder>::GetJacobianOfSpat
}

/** Create storage for the B-spline interpolation weights. */
const unsigned int numberOfWeights = RecursiveBSplineWeightFunctionType::NumberOfWeights;
typename WeightsType::ValueType weightsArray1D[numberOfWeights];
WeightsType weights1D(weightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType derivativeWeightsArray1D[numberOfWeights];
WeightsType derivativeWeights1D(derivativeWeightsArray1D, numberOfWeights, false);
typename WeightsType::ValueType hessianWeightsArray1D[numberOfWeights];
WeightsType hessianWeights1D(hessianWeightsArray1D, numberOfWeights, false);
WeightsType weights1D;
WeightsType derivativeWeights1D;
WeightsType hessianWeights1D;

double * weightsPointer = &(weights1D[0]);
double * derivativeWeightsPointer = &(derivativeWeights1D[0]);
Expand Down
2 changes: 1 addition & 1 deletion Testing/CI/Azure/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
ITKv5_VERSION: v5.2.0
ITKv5_VERSION: v5.3rc02
ITK_GIT_URL: https://github.com/InsightSoftwareConsortium/ITK
ITK_SOURCE_DIR: $(Agent.BuildDirectory)/ITK-source
ITK_BINARY_DIR: $(Agent.BuildDirectory)/ITK-build
Expand Down
Loading

0 comments on commit e2071d8

Please sign in to comment.