diff --git a/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h b/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h index 79dfed6f1..9d8b00269 100644 --- a/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h +++ b/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h @@ -20,8 +20,7 @@ #include "itkFunctionBase.h" #include "itkContinuousIndex.h" -#include "itkArray.h" -#include "itkArray2D.h" +#include "itkIndexRange.h" #include "itkMath.h" #include "itkMatrix.h" #include "itkBSplineKernelFunction2.h" @@ -103,7 +102,7 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunctionBase static constexpr SizeType SupportSize{ SizeType::Filled(VSplineOrder + 1) }; protected: - BSplineInterpolationWeightFunctionBase(); + BSplineInterpolationWeightFunctionBase() = default; ~BSplineInterpolationWeightFunctionBase() override = default; /** Interpolation kernel types. */ @@ -131,16 +130,16 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunctionBase void PrintSelf(std::ostream & os, Indent indent) const override; - /** Member variables. */ - vnl_matrix m_OffsetToIndexTable{}; - private: - /** Function to initialize the offset table. - * The offset table is a convenience table, just to - * keep track where is what. - */ - void - InitializeOffsetToIndexTable(); + /** Lookup table type. */ + using TableType = FixedArray; + + /** Table mapping linear offset to indices. */ + const TableType m_OffsetToIndexTable{ [] { + TableType table; + std::copy_n(ZeroBasedIndexRange(SupportSize).cbegin(), NumberOfWeights, table.begin()); + return table; + }() }; }; } // end namespace itk diff --git a/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.hxx b/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.hxx index c87806ba6..668f8b5bc 100644 --- a/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.hxx +++ b/Common/Transforms/itkBSplineInterpolationWeightFunctionBase.hxx @@ -19,62 +19,10 @@ #define itkBSplineInterpolationWeightFunctionBase_hxx #include "itkBSplineInterpolationWeightFunctionBase.h" -#include "itkImage.h" -#include "itkMatrix.h" -#include "itkImageRegionConstIteratorWithIndex.h" namespace itk { -/** - * ****************** Constructor ******************************* - */ - -template -BSplineInterpolationWeightFunctionBase:: - BSplineInterpolationWeightFunctionBase() -{ - /** Initialize members. */ - this->InitializeOffsetToIndexTable(); - -} // end Constructor - - -/** - * ******************* InitializeOffsetToIndexTable ******************* - */ - -template -void -BSplineInterpolationWeightFunctionBase::InitializeOffsetToIndexTable() -{ - /** Create a temporary image. */ - using CharImageType = Image; - auto tempImage = CharImageType::New(); - tempImage->SetRegions(SupportSize); - tempImage->Allocate(); - - /** Create an iterator over the image. */ - ImageRegionConstIteratorWithIndex it(tempImage, tempImage->GetBufferedRegion()); - - /** Fill the OffsetToIndexTable. */ - this->m_OffsetToIndexTable.set_size(NumberOfWeights, SpaceDimension); - unsigned long counter = 0; - while (!it.IsAtEnd()) - { - IndexType ind = it.GetIndex(); - for (unsigned int i = 0; i < SpaceDimension; ++i) - { - this->m_OffsetToIndexTable[counter][i] = ind[i]; - } - - ++counter; - ++it; - } - -} // end InitializeOffsetToIndexTable() - - /** * ******************* PrintSelf ******************* */ @@ -153,8 +101,8 @@ BSplineInterpolationWeightFunctionBasem_OffsetToIndexTable[k]; + double tmp1 = 1.0; + const auto tmp2 = m_OffsetToIndexTable[k]; for (unsigned int j = 0; j < SpaceDimension; ++j) { tmp1 *= weights1D[j][tmp2[j]];