go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkBSplineKernelFunction2.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkBSplineKernelFunction.h,v $
5  Language: C++
6  Date: $Date: 2006-03-18 20:13:35 $
7  Version: $Revision: 1.7 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkBSplineKernelFunction2_h
18 #define __itkBSplineKernelFunction2_h
19 
20 #include "itkKernelFunction.h"
21 #include "vnl/vnl_math.h"
22 
23 namespace itk
24 {
25 
41 template <unsigned int VSplineOrder = 3>
42 class ITK_EXPORT BSplineKernelFunction2 : public KernelFunction
43 {
44 public:
47  typedef KernelFunction Superclass;
48  typedef SmartPointer<Self> Pointer;
49 
51  itkNewMacro( Self );
52 
54  itkTypeMacro( BSplineKernelFunction2, KernelFunction );
55 
57  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
58 
60  typedef FixedArray< double,
61  itkGetStaticConstMacro( SplineOrder ) + 1 > WeightArrayType;
62 
64  inline double Evaluate( const double & u ) const
65  {
66  return this->Evaluate( Dispatch<VSplineOrder>(), u );
67  }
68 
72  inline void Evaluate( const double & u, WeightArrayType & weights ) const
73  {
74  this->Evaluate( Dispatch<VSplineOrder>(), u, weights );
75  }
76 
77 protected:
80 
81  void PrintSelf( std::ostream & os, Indent indent ) const
82  {
83  Superclass::PrintSelf( os, indent );
84  os << indent << "Spline Order: " << SplineOrder << std::endl;
85  }
86 
87 private:
88  BSplineKernelFunction2(const Self&); //purposely not implemented
89  void operator=(const Self&); //purposely not implemented
90 
92  struct DispatchBase {};
93  template<unsigned int>
94  struct Dispatch : DispatchBase {};
95 
101  inline double Evaluate( const Dispatch<0> &, const double & u ) const
102  {
103  double absValue = vnl_math_abs( u );
104 
105  if ( absValue < 0.5 ) return 1.0;
106  else if ( absValue == 0.5 ) return 0.5;
107  else return 0.0;
108  }
109 
111  inline double Evaluate( const Dispatch<1> &, const double & u ) const
112  {
113  double absValue = vnl_math_abs( u );
114 
115  if ( absValue < 1.0 ) return 1.0 - absValue;
116  else return 0.0;
117  }
118 
120  inline double Evaluate( const Dispatch<2> &, const double & u ) const
121  {
122  double absValue = vnl_math_abs( u );
123 
124  if ( absValue < 0.5 )
125  {
126  return 0.75 - vnl_math_sqr( absValue );
127  }
128  else if ( absValue < 1.5 )
129  {
130  return ( 9.0 - 12.0 * absValue + 4.0 * vnl_math_sqr( absValue ) ) / 8.0;
131  }
132  else return 0.0;
133  }
134 
136  inline double Evaluate( const Dispatch<3> &, const double & u ) const
137  {
138  double absValue = vnl_math_abs( u );
139  double sqrValue = vnl_math_sqr( u );
140 
141  if ( absValue < 1.0 )
142  {
143  return ( 4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue ) / 6.0;
144  }
145  else if ( absValue < 2.0 )
146  {
147  return ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue ) / 6.0;
148  }
149  else return 0.0;
150  }
151 
153  inline double Evaluate( const DispatchBase &, const double & ) const
154  {
155  itkExceptionMacro( << "Evaluate not implemented for spline order "
156  << SplineOrder );
157  return 0.0;
158  }
159 
165  inline void Evaluate( const Dispatch<0> &, const double & u,
166  WeightArrayType & weights ) const
167  {
168  if ( u < 0.5 ) weights[ 0 ] = 1.0;
169  else weights[ 0 ] = 0.5;
170  }
171 
173  inline void Evaluate( const Dispatch<1> &, const double & u,
174  WeightArrayType & weights ) const
175  {
176  weights[ 0 ] = 1.0 - u;
177  weights[ 1 ] = u - 1.0;
178  }
179 
181  inline void Evaluate( const Dispatch<2> &, const double & u,
182  WeightArrayType & weights ) const
183  {
184  const double uu = vnl_math_sqr( u );
185 
186  weights[ 0 ] = ( 9.0 - 12.0 * u + 4.0 * uu ) / 8.0;
187  weights[ 1 ] = -0.25 + 2.0 * u - uu;
188  weights[ 2 ] = ( 1.0 - 4.0 * u + 4.0 * uu ) / 8.0;
189  }
190 
192  inline void Evaluate ( const Dispatch<3> &, const double & u,
193  WeightArrayType & weights ) const
194  {
195  const double uu = vnl_math_sqr( u );
196  const double uuu = uu * u;
197 
198  weights[ 0 ] = ( 8.0 - 12 * u + 6.0 * uu - uuu ) / 6.0;
199  weights[ 1 ] = ( -5.0 + 21.0 * u - 15.0 * uu + 3.0 * uuu ) / 6.0;
200  weights[ 2 ] = ( 4.0 - 12.0 * u + 12.0 * uu - 3.0 * uuu ) / 6.0;
201  weights[ 3 ] = ( -1.0 + 3.0 * u - 3.0 * uu + uuu ) / 6.0;
202  }
203 
205  inline double Evaluate( const DispatchBase &, const double &,
206  WeightArrayType & ) const
207  {
208  itkExceptionMacro( << "Evaluate not implemented for spline order "
209  << SplineOrder );
210  return 0.0;
211  }
212 
213 };
214 
215 
216 } // end namespace itk
217 
218 #endif
void Evaluate(const double &u, WeightArrayType &weights) const
void Evaluate(const Dispatch< 3 > &, const double &u, WeightArrayType &weights) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
void Evaluate(const Dispatch< 0 > &, const double &u, WeightArrayType &weights) const
double Evaluate(const DispatchBase &, const double &, WeightArrayType &) const
void Evaluate(const Dispatch< 2 > &, const double &u, WeightArrayType &weights) const
void PrintSelf(std::ostream &os, Indent indent) const
FixedArray< double, itkGetStaticConstMacro(SplineOrder)+1 > WeightArrayType
B-spline kernel used for density estimation and nonparameteric regression.
void Evaluate(const Dispatch< 1 > &, const double &u, WeightArrayType &weights) const
double Evaluate(const Dispatch< 0 > &, const double &u) const
double Evaluate(const double &u) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const DispatchBase &, const double &) const


Generated on 05-12-2013 for elastix by doxygen 1.8.5 elastix logo