33#ifndef itkBSplineDerivativeKernelFunction2_h
34#define itkBSplineDerivativeKernelFunction2_h
37#include <vnl/vnl_math.h>
57template <
unsigned int VSplineOrder = 3>
82 return Self::Evaluate(Dispatch<VSplineOrder>(), u);
91 return Self::Evaluate(Dispatch<VSplineOrder>(), u, weights);
99 return Self::FastEvaluate(u);
105 Evaluate(
const double & u,
double * weights)
const override
107 return Self::FastEvaluate(u, weights);
116 PrintSelf(std::ostream & os, Indent indent)
const override
118 Superclass::PrintSelf(os, indent);
119 os << indent <<
"Spline Order: " << SplineOrder << std::endl;
125 template <
unsigned int>
126 struct ITK_TEMPLATE_EXPORT Dispatch
136 const double absValue = std::abs(u);
140 return -vnl_math::sgn(u);
142 else if (absValue == 1.0)
144 return -vnl_math::sgn(u) / 2.0;
154 Evaluate(
const Dispatch<1> &,
const double u,
double * weights)
157 const double absValue = std::abs(u);
159 if (absValue < 1.0 && absValue > 0.0)
164 else if (absValue == 1)
181 double absValue = std::abs(u);
187 else if (absValue < 1.5)
189 return u - 1.5 * vnl_math::sgn(u);
199 Evaluate(
const Dispatch<2> &,
const double u,
double * weights)
202 weights[0] = u - 1.5;
203 weights[1] = -2.0 * u + 2.0;
204 weights[2] = u - 0.5;
212 const double absValue = std::abs(u);
213 const double sqrValue = u * u;
219 const double dummy = std::abs(u + 0.5);
220 return (6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
224 const double dummy = std::abs(u - 0.5);
225 return -(6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
228 else if (absValue < 2.0)
232 const double dummy = std::abs(u - 0.5);
233 return (u - sqrValue + 3.0 * dummy - 2.5) / 2.0;
237 const double dummy = std::abs(u + 0.5);
238 return (u + sqrValue - 3.0 * dummy + 2.5) / 2.0;
249 Evaluate(
const Dispatch<3> &,
const double u,
double * weights)
251 const double absValue = std::abs(u);
252 const double sqrValue = u * u;
254 weights[0] = 0.5 * sqrValue - 2.0 * absValue + 2.0;
255 weights[1] = -1.5 * sqrValue + 5.0 * absValue - 3.5;
256 weights[2] = 1.5 * sqrValue - 4.0 * absValue + 2.0;
257 weights[3] = -0.5 * sqrValue + absValue - 0.5;
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
void Evaluate(const double &u, double *weights) const override
static void Evaluate(const Dispatch< 2 > &, const double u, double *weights)
void PrintSelf(std::ostream &os, Indent indent) const override
static double Evaluate(const Dispatch< 3 > &, const double u)
~BSplineDerivativeKernelFunction2() override=default
static double FastEvaluate(const double u)
static double Evaluate(const Dispatch< 2 > &, const double u)
static void Evaluate(const Dispatch< 1 > &, const double u, double *weights)
BSplineDerivativeKernelFunction2()=default
static double Evaluate(const Dispatch< 1 > &, const double u)
double Evaluate(const double &u) const override
static void FastEvaluate(const double u, double *const weights)
static void Evaluate(const Dispatch< 3 > &, const double u, double *weights)
ITK_DISALLOW_COPY_AND_MOVE(BSplineDerivativeKernelFunction2)
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
Kernel used for density estimation and nonparameteric regression.