34#ifndef __itkBSplineKernelFunction2_h
35#define __itkBSplineKernelFunction2_h
38#include "vnl/vnl_math.h"
58template<
unsigned int VSplineOrder = 3 >
78 typedef FixedArray<
double,
82 inline double Evaluate(
const double & u )
const override
84 return this->Evaluate( Dispatch< VSplineOrder >(), u );
91 inline void Evaluate(
const double & u,
double * weights )
const override
93 this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
102 void PrintSelf( std::ostream & os, Indent indent )
const override
104 Superclass::PrintSelf( os, indent );
105 os << indent <<
"Spline Order: " << SplineOrder << std::endl;
115 struct DispatchBase {};
116 template<
unsigned int >
117 struct Dispatch : DispatchBase {};
124 inline double Evaluate(
const Dispatch< 0 > &,
const double & u )
const
126 const double absValue = std::abs( u );
128 if( absValue < 0.5 ) {
return NumericTraits< double >::OneValue(); }
129 else if( absValue == 0.5 ) {
return 0.5; }
130 else {
return NumericTraits< double >::ZeroValue(); }
135 inline double Evaluate(
const Dispatch< 1 > &,
const double & u )
const
137 const double absValue = std::abs( u );
139 if( absValue < 1.0 ) {
return NumericTraits< double >::OneValue() - absValue; }
140 else {
return NumericTraits< double >::ZeroValue(); }
145 inline double Evaluate(
const Dispatch< 2 > &,
const double & u )
const
147 const double absValue = std::abs( u );
151 return 0.75 - absValue * absValue;
153 else if( absValue < 1.5 )
155 return ( 9.0 - 12.0 * absValue + 4.0 * absValue * absValue ) / 8.0;
157 else {
return NumericTraits< double >::ZeroValue(); }
162 inline double Evaluate(
const Dispatch< 3 > &,
const double & u )
const
164 const double absValue = std::abs( u );
165 const double sqrValue = u * u;
169 return ( 4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue ) / 6.0;
171 else if( absValue < 2.0 )
173 return ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue ) / 6.0;
175 else {
return NumericTraits< double >::ZeroValue(); }
180 inline double Evaluate(
const DispatchBase &,
const double & )
const
182 itkExceptionMacro( <<
"Evaluate not implemented for spline order " << SplineOrder );
192 inline void Evaluate(
const Dispatch< 0 > &,
const double & u,
193 double * weights )
const
195 const double absValue = std::abs( u );
197 if( absValue < 0.5 ) { weights[ 0 ] = NumericTraits< double >::OneValue(); }
198 else if( absValue == 0.5 ) { weights[ 0 ] = 0.5; }
199 else { weights[ 0 ] = NumericTraits< double >::ZeroValue(); }
204 inline void Evaluate(
const Dispatch< 1 > &,
const double & u,
205 double * weights )
const
207 const double absValue = std::abs( u );
209 weights[ 0 ] = NumericTraits< double >::OneValue() - absValue;
210 weights[ 1 ] = absValue;
215 inline void Evaluate(
const Dispatch< 2 > &,
const double & u,
216 double * weights )
const
218 const double absValue = std::abs( u );
219 const double sqrValue = u * u;
221 weights[ 0 ] = ( 9.0 - 12.0 * absValue + 4.0 * sqrValue ) / 8.0;
222 weights[ 1 ] = -0.25 + 2.0 * absValue - sqrValue;
223 weights[ 2 ] = ( 1.0 - 4.0 * absValue + 4.0 * sqrValue ) / 8.0;
228 inline void Evaluate(
const Dispatch< 3 > &,
const double & u,
229 double * weights )
const
231 const double absValue = std::abs( u );
232 const double sqrValue = u * u;
233 const double uuu = sqrValue * absValue;
237 static const double onesixth = 1.0 / 6.0;
238 weights[ 0 ] = ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - uuu ) * onesixth;
239 weights[ 1 ] = ( -5.0 + 21.0 * absValue - 15.0 * sqrValue + 3.0 * uuu ) * onesixth;
240 weights[ 2 ] = ( 4.0 - 12.0 * absValue + 12.0 * sqrValue - 3.0 * uuu ) * onesixth;
241 weights[ 3 ] = ( -1.0 + 3.0 * absValue - 3.0 * sqrValue + uuu ) * onesixth;
246 inline double Evaluate(
const DispatchBase &,
const double &,
double * )
const
248 itkExceptionMacro( <<
"Evaluate not implemented for spline order " << SplineOrder );
B-spline kernel used for density estimation and nonparameteric regression.
void Evaluate(const double &u, double *weights) const override
void Evaluate(const Dispatch< 3 > &, const double &u, double *weights) const
void operator=(const Self &)
void PrintSelf(std::ostream &os, Indent indent) const override
double Evaluate(const DispatchBase &, const double &) const
void Evaluate(const Dispatch< 0 > &, const double &u, double *weights) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
FixedArray< double, itkGetStaticConstMacro(SplineOrder)+1 > WeightArrayType
void Evaluate(const Dispatch< 2 > &, const double &u, double *weights) const
KernelFunctionBase2< double > Superclass
SmartPointer< Self > Pointer
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const DispatchBase &, const double &, double *) const
double Evaluate(const Dispatch< 0 > &, const double &u) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
~BSplineKernelFunction2() override
BSplineKernelFunction2 Self
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
void Evaluate(const Dispatch< 1 > &, const double &u, double *weights) const
BSplineKernelFunction2(const Self &)
double Evaluate(const double &u) const override
Kernel used for density estimation and nonparameteric regression.