Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Common/Transforms/itkBSplineInterpolationWeightFunctionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -131,16 +130,16 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunctionBase
void
PrintSelf(std::ostream & os, Indent indent) const override;

/** Member variables. */
vnl_matrix<unsigned long> 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<IndexType, NumberOfWeights>;

/** Table mapping linear offset to indices. */
const TableType m_OffsetToIndexTable{ [] {
TableType table;
std::copy_n(ZeroBasedIndexRange<SpaceDimension>(SupportSize).cbegin(), NumberOfWeights, table.begin());
return table;
}() };
};

} // end namespace itk
Expand Down
56 changes: 2 additions & 54 deletions Common/Transforms/itkBSplineInterpolationWeightFunctionBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,10 @@
#define itkBSplineInterpolationWeightFunctionBase_hxx

#include "itkBSplineInterpolationWeightFunctionBase.h"
#include "itkImage.h"
#include "itkMatrix.h"
#include "itkImageRegionConstIteratorWithIndex.h"

namespace itk
{

/**
* ****************** Constructor *******************************
*/

template <typename TCoordinate, unsigned int VSpaceDimension, unsigned int VSplineOrder>
BSplineInterpolationWeightFunctionBase<TCoordinate, VSpaceDimension, VSplineOrder>::
BSplineInterpolationWeightFunctionBase()
{
/** Initialize members. */
this->InitializeOffsetToIndexTable();

} // end Constructor


/**
* ******************* InitializeOffsetToIndexTable *******************
*/

template <typename TCoordinate, unsigned int VSpaceDimension, unsigned int VSplineOrder>
void
BSplineInterpolationWeightFunctionBase<TCoordinate, VSpaceDimension, VSplineOrder>::InitializeOffsetToIndexTable()
{
/** Create a temporary image. */
using CharImageType = Image<char, SpaceDimension>;
auto tempImage = CharImageType::New();
tempImage->SetRegions(SupportSize);
tempImage->Allocate();

/** Create an iterator over the image. */
ImageRegionConstIteratorWithIndex<CharImageType> 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 *******************
*/
Expand Down Expand Up @@ -153,8 +101,8 @@ BSplineInterpolationWeightFunctionBase<TCoordinate, VSpaceDimension, VSplineOrde
/** Compute the vector of weights. */
for (unsigned int k = 0; k < NumberOfWeights; ++k)
{
double tmp1 = 1.0;
const unsigned long * tmp2 = this->m_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]];
Expand Down
Loading