go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkBSplineDerivativeKernelFunction2.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkBSplineDerivativeKernelFunction2.h,v $
5  Language: C++
6  Date: $Date: 2008-06-25 11:00:19 $
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 __itkBSplineDerivativeKernelFunction2_h
18 #define __itkBSplineDerivativeKernelFunction2_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 BSplineDerivativeKernelFunction2 : 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  //inline double Evaluate( const double & u ) const
62  // {
63  // return ( m_KernelFunction->Evaluate( u + 0.5 ) -
64  // m_KernelFunction->Evaluate( u - 0.5 ) );
65  // }
67  inline double Evaluate( const double & u ) const
68  {
69  return this->Evaluate( Dispatch< VSplineOrder >(), u );
70  }
71 
72 
73 protected:
74 
77 
78  void PrintSelf( std::ostream & os, Indent indent ) const
79  {
80  Superclass::PrintSelf( os, indent );
81  os << indent << "Spline Order: " << SplineOrder << std::endl;
82  }
83 
84 
85 private:
86 
87  BSplineDerivativeKernelFunction2( const Self & ); //purposely not implemented
88  void operator=( const Self & ); //purposely not implemented
89 
91  struct DispatchBase {};
92  template< unsigned int >
93  struct Dispatch : DispatchBase {};
94 
117  inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
118  {
119 
120  double absValue = vnl_math_abs( u );
121 
122  if( absValue < 1.0 )
123  {
124  return -vnl_math_sgn( u );
125  }
126  else if( absValue == 1.0 )
127  {
128  return -vnl_math_sgn( u ) / 2.0;
129  }
130  else
131  {
132  return 0.0;
133  }
134 
135  }
136 
137 
139  inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
140  {
141  double absValue = vnl_math_abs( u );
142 
143  if( absValue < 0.5 )
144  {
145  return -2.0 * u;
146  }
147  else if( absValue < 1.5 )
148  {
149  return u - 1.5 * vnl_math_sgn( u );
150  }
151  else
152  {
153  return 0.0;
154  }
155 
156  }
157 
158 
160  inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
161  {
162  const double absValue = vnl_math_abs( u );
163  const double sqrValue = vnl_math_sqr( u );
164 
165  if( absValue < 1.0 )
166  {
167  if( u > 0.0 )
168  {
169  const double dummy = vnl_math_abs( u + 0.5 );
170  return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
171  }
172  else
173  {
174  const double dummy = vnl_math_abs( u - 0.5 );
175  return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
176  }
177  }
178  else if( absValue < 2.0 )
179  {
180  if( u > 0.0 )
181  {
182  const double dummy = vnl_math_abs( u - 0.5 );
183  return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
184  }
185  else
186  {
187  const double dummy = vnl_math_abs( u + 0.5 );
188  return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
189  }
190  }
191  else
192  {
193  return 0.0;
194  }
195 
196  }
197 
198 
200  inline double Evaluate( const DispatchBase &, const double & ) const
201  {
202  itkExceptionMacro( "Evaluate not implemented for spline\
203  order " << SplineOrder );
204  return 0.0; // This is to avoid compiler warning about missing
205  // return statement. It should never be evaluated.
206  }
207 
208 
209 };
210 
211 } // end namespace itk
212 
213 #endif
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
void PrintSelf(std::ostream &os, Indent indent) const
double Evaluate(const DispatchBase &, const double &) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
Derivative of a B-spline kernel used for density estimation and nonparametric regression.


Generated on 27-04-2014 for elastix by doxygen 1.8.6 elastix logo