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 "itkKernelFunctionBase.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 KernelFunctionBase< double >
43 {
44 public:
45 
49  typedef SmartPointer< Self > Pointer;
50 
52  itkNewMacro( Self );
53 
56 
58  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
59 
61  typedef FixedArray< double,
62  itkGetStaticConstMacro( SplineOrder ) + 1 > WeightArrayType;
63 
65  inline double Evaluate( const double & u ) const
66  {
67  return this->Evaluate( Dispatch< VSplineOrder >(), u );
68  }
69 
70 
74  inline void Evaluate( const double & u, WeightArrayType & weights ) const
75  {
76  this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
77  }
78 
79 
80 protected:
81 
84 
85  void PrintSelf( std::ostream & os, Indent indent ) const
86  {
87  Superclass::PrintSelf( os, indent );
88  os << indent << "Spline Order: " << SplineOrder << std::endl;
89  }
90 
91 
92 private:
93 
94  BSplineKernelFunction2( const Self & ); //purposely not implemented
95  void operator=( const Self & ); //purposely not implemented
96 
98  struct DispatchBase {};
99  template< unsigned int >
100  struct Dispatch : DispatchBase {};
101 
107  inline double Evaluate( const Dispatch< 0 > &, const double & u ) const
108  {
109  double absValue = vnl_math_abs( u );
110 
111  if( absValue < 0.5 ) { return 1.0; }
112  else if( absValue == 0.5 ) { return 0.5; }
113  else { return 0.0; }
114  }
115 
116 
118  inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
119  {
120  double absValue = vnl_math_abs( u );
121 
122  if( absValue < 1.0 ) { return 1.0 - absValue; }
123  else { return 0.0; }
124  }
125 
126 
128  inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
129  {
130  double absValue = vnl_math_abs( u );
131 
132  if( absValue < 0.5 )
133  {
134  return 0.75 - vnl_math_sqr( absValue );
135  }
136  else if( absValue < 1.5 )
137  {
138  return ( 9.0 - 12.0 * absValue + 4.0 * vnl_math_sqr( absValue ) ) / 8.0;
139  }
140  else { return 0.0; }
141  }
142 
143 
145  inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
146  {
147  double absValue = vnl_math_abs( u );
148  double sqrValue = vnl_math_sqr( u );
149 
150  if( absValue < 1.0 )
151  {
152  return ( 4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue ) / 6.0;
153  }
154  else if( absValue < 2.0 )
155  {
156  return ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue ) / 6.0;
157  }
158  else { return 0.0; }
159  }
160 
161 
163  inline double Evaluate( const DispatchBase &, const double & ) const
164  {
165  itkExceptionMacro( << "Evaluate not implemented for spline order "
166  << SplineOrder );
167  return 0.0;
168  }
169 
170 
176  inline void Evaluate( const Dispatch< 0 > &, const double & u,
177  WeightArrayType & weights ) const
178  {
179  if( u < 0.5 ) { weights[ 0 ] = 1.0; }
180  else { weights[ 0 ] = 0.5; }
181  }
182 
183 
185  inline void Evaluate( const Dispatch< 1 > &, const double & u,
186  WeightArrayType & weights ) const
187  {
188  weights[ 0 ] = 1.0 - u;
189  weights[ 1 ] = u;
190  }
191 
192 
194  inline void Evaluate( const Dispatch< 2 > &, const double & u,
195  WeightArrayType & weights ) const
196  {
197  const double uu = vnl_math_sqr( u );
198 
199  weights[ 0 ] = ( 9.0 - 12.0 * u + 4.0 * uu ) / 8.0;
200  weights[ 1 ] = -0.25 + 2.0 * u - uu;
201  weights[ 2 ] = ( 1.0 - 4.0 * u + 4.0 * uu ) / 8.0;
202  }
203 
204 
206  inline void Evaluate( const Dispatch< 3 > &, const double & u,
207  WeightArrayType & weights ) const
208  {
209  const double uu = vnl_math_sqr( u );
210  const double uuu = uu * u;
211 
212  weights[ 0 ] = ( 8.0 - 12 * u + 6.0 * uu - uuu ) / 6.0;
213  weights[ 1 ] = ( -5.0 + 21.0 * u - 15.0 * uu + 3.0 * uuu ) / 6.0;
214  weights[ 2 ] = ( 4.0 - 12.0 * u + 12.0 * uu - 3.0 * uuu ) / 6.0;
215  weights[ 3 ] = ( -1.0 + 3.0 * u - 3.0 * uu + uuu ) / 6.0;
216  }
217 
218 
220  inline double Evaluate( const DispatchBase &, const double &,
221  WeightArrayType & ) const
222  {
223  itkExceptionMacro( << "Evaluate not implemented for spline order "
224  << SplineOrder );
225  return 0.0;
226  }
227 
228 
229 };
230 
231 } // end namespace itk
232 
233 #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
KernelFunctionBase< double > Superclass
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 27-04-2014 for elastix by doxygen 1.8.6 elastix logo