17 #ifndef __itkBSplineDerivativeKernelFunction2_h
18 #define __itkBSplineDerivativeKernelFunction2_h
20 #include "itkKernelFunctionBase.h"
21 #include "vnl/vnl_math.h"
42 template <
unsigned int VSplineOrder = 3>
58 itkStaticConstMacro( SplineOrder,
unsigned int, VSplineOrder );
67 inline double Evaluate(
const double & u )
const
69 return this->Evaluate( Dispatch<VSplineOrder>(), u );
76 void PrintSelf(std::ostream& os, Indent indent)
const
78 Superclass::PrintSelf( os, indent );
79 os << indent <<
"Spline Order: " << SplineOrder << std::endl;
84 void operator=(
const Self&);
87 struct DispatchBase {};
88 template<
unsigned int>
89 struct Dispatch : DispatchBase {};
113 inline double Evaluate (
const Dispatch<1>&,
const double& u)
const
116 double absValue = vnl_math_abs( u );
118 if ( absValue < 1.0 )
120 return -vnl_math_sgn( u );
122 else if ( absValue == 1.0 )
124 return -vnl_math_sgn( u ) / 2.0;
134 inline double Evaluate (
const Dispatch<2>&,
const double& u)
const
136 double absValue = vnl_math_abs( u );
138 if ( absValue < 0.5 )
142 else if ( absValue < 1.5 )
144 return u - 1.5 * vnl_math_sgn( u );
154 inline double Evaluate (
const Dispatch<3>&,
const double& u)
const
156 const double absValue = vnl_math_abs( u );
157 const double sqrValue = vnl_math_sqr( u );
159 if ( absValue < 1.0 )
163 const double dummy = vnl_math_abs( u + 0.5 );
164 return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
168 const double dummy = vnl_math_abs( u - 0.5 );
169 return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
172 else if ( absValue < 2.0 )
176 const double dummy = vnl_math_abs( u - 0.5 );
177 return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
181 const double dummy = vnl_math_abs( u + 0.5 );
182 return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
193 inline double Evaluate (
const DispatchBase&,
const double&)
const
195 itkExceptionMacro(
"Evaluate not implemented for spline\
196 order " << SplineOrder);
double Evaluate(const double &u) const
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
KernelFunctionBase< double > Superclass
BSplineDerivativeKernelFunction2 Self
void PrintSelf(std::ostream &os, Indent indent) const
double Evaluate(const DispatchBase &, const double &) const
~BSplineDerivativeKernelFunction2()
double Evaluate(const Dispatch< 3 > &, const double &u) const
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
SmartPointer< Self > Pointer
BSplineDerivativeKernelFunction2()