Skip to content

Commit

Permalink
PERF: Use FixedArray for table within BSplineInterpolationWeightFunction
Browse files Browse the repository at this point in the history
Replaced `itk::Array2D` by `itk::FixedArray`, used as private `TableType`
of `BSplineInterpolationWeightFunction`. This is the type of a table,
used internally by its `Evaluate` member function.

Declared this table `const`, and initialized the table by an in-class
default-member-initializer. Defaulted the default-constructor.

Follow-up to pull request #2712
commit bc7c5df
"PERF: Use FixedArray for BSplineBaseTransform ParameterIndexArrayType"
commit 9bf745b
"PERF: Use FixedArray for BSplineInterpolationWeightFunction OutputType"
  • Loading branch information
N-Dekker authored and hjmjohnson committed Sep 9, 2021
1 parent c9b05ab commit 9745409
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "itkContinuousIndex.h"
#include "itkArray.h"
#include "itkArray2D.h"
#include "itkIndexRange.h"
#include "itkMath.h"

namespace itk
Expand Down Expand Up @@ -112,15 +113,21 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction
#endif

protected:
BSplineInterpolationWeightFunction();
BSplineInterpolationWeightFunction() = default;
~BSplineInterpolationWeightFunction() override = default;

private:
/** Lookup table type. */
using TableType = Array2D<unsigned int>;
using TableType = FixedArray<IndexType, NumberOfWeights>;

/** Table mapping linear offset to indices. */
TableType m_OffsetToIndexTable;
const TableType m_OffsetToIndexTable{ [] {
TableType table;
// Note: Copied the constexpr value `SupportSize` to a temporary, `SizeType{ SupportSize }`, to prevent a GCC
// (Ubuntu 7.5.0-3ubuntu1~18.04) link error, "undefined reference to `SupportSize`".
std::copy_n(ZeroBasedIndexRange<SpaceDimension>(SizeType{ SupportSize }).cbegin(), NumberOfWeights, table.begin());
return table;
}() };
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,9 @@
#include "itkImage.h"
#include "itkMatrix.h"
#include "itkMath.h"
#include "itkIndexRange.h"

namespace itk
{
/** Constructor */
template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::BSplineInterpolationWeightFunction()
{
// Initialize offset to index lookup table
m_OffsetToIndexTable.set_size(Self::NumberOfWeights, SpaceDimension);

constexpr auto supportSize = Self::SupportSize;
unsigned int counter = 0;

for (const IndexType index : ZeroBasedIndexRange<VSpaceDimension>(supportSize))
{
for (unsigned int j = 0; j < SpaceDimension; ++j)
{
m_OffsetToIndexTable[counter][j] = index[j];
}
++counter;
}
}

/** Compute weights for interpolation at continuous index position */
template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
typename BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::WeightsType
Expand Down

0 comments on commit 9745409

Please sign in to comment.