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 "itkKernelFunction.h"
21 #include "vnl/vnl_math.h"
22 
23 
24 namespace itk
25 {
26 
42 template <unsigned int VSplineOrder = 3>
43 class ITK_EXPORT BSplineDerivativeKernelFunction2 : public KernelFunction
44 {
45 public:
48  typedef KernelFunction Superclass;
49  typedef SmartPointer<Self> Pointer;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(BSplineDerivativeKernelFunction2, KernelFunction);
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 protected:
75 
76  void PrintSelf(std::ostream& os, Indent indent) const
77  {
78  Superclass::PrintSelf( os, indent );
79  os << indent << "Spline Order: " << SplineOrder << std::endl;
80  }
81 
82 private:
83  BSplineDerivativeKernelFunction2(const Self&); //purposely not implemented
84  void operator=(const Self&); //purposely not implemented
85 
87  struct DispatchBase {};
88  template<unsigned int>
89  struct Dispatch : DispatchBase {};
90 
113  inline double Evaluate ( const Dispatch<1>&, const double& u) const
114  {
115 
116  double absValue = vnl_math_abs( u );
117 
118  if ( absValue < 1.0 )
119  {
120  return -vnl_math_sgn( u );
121  }
122  else if ( absValue == 1.0 )
123  {
124  return -vnl_math_sgn( u ) / 2.0;
125  }
126  else
127  {
128  return 0.0;
129  }
130 
131  }
132 
134  inline double Evaluate ( const Dispatch<2>&, const double& u) const
135  {
136  double absValue = vnl_math_abs( u );
137 
138  if ( absValue < 0.5 )
139  {
140  return -2.0 * u;
141  }
142  else if ( absValue < 1.5 )
143  {
144  return u - 1.5 * vnl_math_sgn( u );
145  }
146  else
147  {
148  return 0.0;
149  }
150 
151  }
152 
154  inline double Evaluate ( const Dispatch<3>&, const double& u) const
155  {
156  const double absValue = vnl_math_abs( u );
157  const double sqrValue = vnl_math_sqr( u );
158 
159  if ( absValue < 1.0 )
160  {
161  if ( u > 0.0)
162  {
163  const double dummy = vnl_math_abs( u + 0.5 );
164  return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
165  }
166  else
167  {
168  const double dummy = vnl_math_abs( u - 0.5 );
169  return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
170  }
171  }
172  else if ( absValue < 2.0 )
173  {
174  if ( u > 0.0 )
175  {
176  const double dummy = vnl_math_abs( u - 0.5 );
177  return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
178  }
179  else
180  {
181  const double dummy = vnl_math_abs( u + 0.5 );
182  return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
183  }
184  }
185  else
186  {
187  return 0.0;
188  }
189 
190  }
191 
193  inline double Evaluate ( const DispatchBase&, const double&) const
194  {
195  itkExceptionMacro("Evaluate not implemented for spline\
196  order " << SplineOrder);
197  return 0.0; // This is to avoid compiler warning about missing
198  // return statement. It should never be evaluated.
199  }
200 
201 };
202 
203 
204 } // end namespace itk
205 
206 #endif


Generated on 21-03-2014 for elastix by doxygen 1.8.1.2 elastix logo