Skip to content

Commit

Permalink
ENH: Add static FastEvaluate(u) to BSplineDerivativeKernelFunction
Browse files Browse the repository at this point in the history
Follow-up to pull request #2716
commit 99f04d7
"ENH: Add static member function `BSplineKernelFunction::FastEvaluate(u)`"
  • Loading branch information
N-Dekker authored and dzenanz committed Sep 14, 2021
1 parent 8f7a832 commit 760ae12
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Modules/Core/Common/include/itkBSplineDerivativeKernelFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
/** 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 @@ -87,15 +95,15 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
{};

/** Evaluate the function: zeroth order spline. */
inline TRealValueType
Evaluate(const Dispatch<0> &, const TRealValueType & itkNotUsed(u)) const
inline static TRealValueType
Evaluate(const Dispatch<0> &, const TRealValueType & itkNotUsed(u))
{
return TRealValueType{ 0.0 };
}

/** Evaluate the function: first order spline */
inline TRealValueType
Evaluate(const Dispatch<1> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<1> &, const TRealValueType & u)
{
if (Math::ExactlyEquals(u, TRealValueType{ -1.0 }))
{
Expand Down Expand Up @@ -124,8 +132,8 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
}

/** Evaluate the function: second order spline. */
inline TRealValueType
Evaluate(const Dispatch<2> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<2> &, const TRealValueType & u)
{
if ((u > TRealValueType{ -0.5 }) && (u < TRealValueType{ 0.5 }))
{
Expand All @@ -146,8 +154,8 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
}

/** Evaluate the function: third order spline. */
inline TRealValueType
Evaluate(const Dispatch<3> &, const TRealValueType & u) const
inline static TRealValueType
Evaluate(const Dispatch<3> &, const TRealValueType & u)
{
if ((u >= TRealValueType{ 0.0 }) && (u < TRealValueType{ 1.0 }))
{
Expand All @@ -172,10 +180,10 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
}

/** Evaluate the function: 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

0 comments on commit 760ae12

Please sign in to comment.