34#ifndef __itkBSplineDerivativeKernelFunction2_h
35#define __itkBSplineDerivativeKernelFunction2_h
38#include "vnl/vnl_math.h"
58template<
unsigned int VSplineOrder = 3 >
78 inline double Evaluate(
const double & u )
const override
80 return this->Evaluate( Dispatch< VSplineOrder >(), u );
85 inline void Evaluate(
const double & u,
double * weights )
const override
87 return this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
96 void PrintSelf( std::ostream & os, Indent indent )
const override
98 Superclass::PrintSelf( os, indent );
99 os << indent <<
"Spline Order: " << SplineOrder << std::endl;
109 struct DispatchBase {};
110 template<
unsigned int >
111 struct Dispatch : DispatchBase {};
117 inline double Evaluate(
const Dispatch< 1 > &,
const double & u )
const
119 const double absValue = std::abs( u );
121 if( absValue < NumericTraits< double >::OneValue() )
123 return -vnl_math::sgn( u );
125 else if( absValue == NumericTraits< double >::OneValue() )
127 return -vnl_math::sgn( u ) / 2.0;
129 else {
return NumericTraits< double >::ZeroValue(); }
133 inline void Evaluate(
const Dispatch< 1 > &,
const double & u,
double * weights )
const
136 const double absValue = std::abs( u );
138 if( absValue < 1.0 && absValue > 0.0 )
143 else if( absValue == 1 )
158 inline double Evaluate(
const Dispatch< 2 > &,
const double & u )
const
160 double absValue = std::abs( u );
166 else if( absValue < 1.5 )
168 return u - 1.5 * vnl_math::sgn( u );
172 return NumericTraits< double >::ZeroValue();
177 inline void Evaluate(
const Dispatch< 2 > &,
const double & u,
double * weights )
const
180 weights[ 0 ] = u - 1.5;
181 weights[ 1 ] = -2.0 * u + 2.0;
182 weights[ 2 ] = u - 0.5;
187 inline double Evaluate(
const Dispatch< 3 > &,
const double & u )
const
189 const double absValue = std::abs( u );
190 const double sqrValue = u * u;
196 const double dummy = std::abs( u + 0.5 );
197 return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
201 const double dummy = std::abs( u - 0.5 );
202 return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
205 else if( absValue < 2.0 )
209 const double dummy = std::abs( u - 0.5 );
210 return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
214 const double dummy = std::abs( u + 0.5 );
215 return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
225 inline void Evaluate(
const Dispatch< 3 > &,
const double & u,
double * weights )
const
227 const double absValue = std::abs( u );
228 const double sqrValue = u * u;
230 weights[ 0 ] = 0.5 * sqrValue - 2.0 * absValue + 2.0;
231 weights[ 1 ] = -1.5 * sqrValue + 5.0 * absValue - 3.5;
232 weights[ 2 ] = 1.5 * sqrValue - 4.0 * absValue + 2.0;
233 weights[ 3 ] = -0.5 * sqrValue + absValue - 0.5;
238 inline double Evaluate(
const DispatchBase &,
const double & )
const
240 itkExceptionMacro(
"Evaluate not implemented for spline order " << SplineOrder );
247 inline void Evaluate(
const DispatchBase &,
const double &,
double * )
const
249 itkExceptionMacro(
"Evaluate not implemented for spline order " << SplineOrder );
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
BSplineDerivativeKernelFunction2 Self
void Evaluate(const double &u, double *weights) const override
void PrintSelf(std::ostream &os, Indent indent) const override
void Evaluate(const DispatchBase &, const double &, double *) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
void Evaluate(const Dispatch< 2 > &, const double &u, double *weights) const
BSplineDerivativeKernelFunction2()
void Evaluate(const Dispatch< 3 > &, const double &u, double *weights) const
~BSplineDerivativeKernelFunction2() override
double Evaluate(const DispatchBase &, const double &) const
void operator=(const Self &)
double Evaluate(const double &u) const override
void Evaluate(const Dispatch< 1 > &, const double &u, double *weights) const
double Evaluate(const Dispatch< 2 > &, const double &u) const
KernelFunctionBase2< double > Superclass
BSplineDerivativeKernelFunction2(const Self &)
double Evaluate(const Dispatch< 1 > &, const double &u) const
SmartPointer< Self > Pointer
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
Kernel used for density estimation and nonparameteric regression.