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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "itkFunctionBase.h"
#include "itkContinuousIndex.h"
#include "itkBSplineKernelFunction.h"
#include "itkArray.h"
#include "itkArray2D.h"
#include "itkMath.h"
Expand Down Expand Up @@ -122,12 +121,6 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction

/** Table mapping linear offset to indices. */
TableType m_OffsetToIndexTable;

/** Interpolation kernel type. */
using KernelType = BSplineKernelFunction<Self::SplineOrder>;

/** Interpolation kernel. */
typename KernelType::Pointer m_Kernel;
};
} // end namespace itk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define itkBSplineInterpolationWeightFunction_hxx

#include "itkBSplineInterpolationWeightFunction.h"
#include "itkBSplineKernelFunction.h"
#include "itkImage.h"
#include "itkMatrix.h"
#include "itkMath.h"
Expand All @@ -44,10 +45,6 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::BS
}
++counter;
}


// Initialize the interpolation kernel
m_Kernel = KernelType::New();
}

/**
Expand Down Expand Up @@ -104,7 +101,7 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev

for (k = 0; k <= SplineOrder; ++k)
{
weights1D[j][k] = m_Kernel->Evaluate(x);
weights1D[j][k] = BSplineKernelFunction<SplineOrder>::FastEvaluate(x);
x -= 1.0;
}
}
Expand Down
32 changes: 20 additions & 12 deletions Modules/Core/Common/include/itkBSplineKernelFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
/** Enum of for spline order. */
static constexpr unsigned int SplineOrder = VSplineOrder;

/** Evaluate the function. Faster than the `Evaluate` member function, because it is static (while `Evaluate` is
* virtual). */
static TRealValueType
FastEvaluate(const TRealValueType u)
{
return Self::Evaluate(Dispatch<VSplineOrder>(), u);
}

/** Evaluate the function. */
TRealValueType
Evaluate(const TRealValueType & u) const override
{
return this->Evaluate(Dispatch<VSplineOrder>(), u);
return Self::FastEvaluate(u);
}

protected:
Expand All @@ -86,8 +94,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
{};

/** Zeroth order spline. */
inline TRealValueType
Evaluate(const Dispatch<0> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<0> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
if (absValue < static_cast<TRealValueType>(0.5))
Expand All @@ -105,8 +113,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
}

/** First order spline */
inline TRealValueType
Evaluate(const Dispatch<1> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<1> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
if (absValue < NumericTraits<TRealValueType>::OneValue())
Expand All @@ -120,8 +128,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
}

/** Second order spline. */
inline TRealValueType
Evaluate(const Dispatch<2> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<2> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
if (absValue < static_cast<TRealValueType>(0.5))
Expand All @@ -144,8 +152,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
}

/** Third order spline. */
inline TRealValueType
Evaluate(const Dispatch<3> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<3> &, const TRealValueType & u)
{
const TRealValueType absValue = itk::Math::abs(u);
if (absValue < NumericTraits<TRealValueType>::OneValue())
Expand All @@ -169,10 +177,10 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
}

/** Unimplemented spline order */
inline TRealValueType
Evaluate(const DispatchBase &, const TRealValueType &) const
inline static TRealValueType
Evaluate(const DispatchBase &, const TRealValueType &)
{
itkExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
itkGenericExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
}
};
} // end namespace itk
Expand Down