go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkBSplineSecondOrderDerivativeKernelFunction2.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright UMC Utrecht and contributors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkBSplineSecondOrderDerivativeKernelFunction2_h
19 #define __itkBSplineSecondOrderDerivativeKernelFunction2_h
20 
21 #include "itkKernelFunctionBase.h"
22 #include "vnl/vnl_math.h"
23 #include <cmath> // For abs.
24 
25 namespace itk
26 {
27 
43 template< unsigned int VSplineOrder = 3 >
44 class BSplineSecondOrderDerivativeKernelFunction2 : public KernelFunctionBase< double >
45 {
46 public:
47 
50  typedef KernelFunctionBase< double > Superclass;
51  typedef SmartPointer< Self > Pointer;
52 
54  itkNewMacro( Self );
55 
57  itkTypeMacro( BSplineSecondOrderDerivativeKernelFunction2, KernelFunctionBase );
58 
60  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
61 
63  inline double Evaluate( const double & u ) const override
64  {
65  return this->Evaluate( Dispatch< VSplineOrder >(), u );
66  }
67 
68 
70  inline void Evaluate( const double & u, double * weights ) const
71  {
72  this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
73  }
74 
75 
76 protected:
77 
80 
81  void PrintSelf( std::ostream & os, Indent indent ) const override
82  {
83  Superclass::PrintSelf( os, indent );
84  os << indent << "Spline Order: " << SplineOrder << std::endl;
85  }
86 
87 
88 private:
89 
90  BSplineSecondOrderDerivativeKernelFunction2( const Self & ); // purposely not implemented
91  void operator=( const Self & ); // purposely not implemented
92 
94  struct DispatchBase {};
95  template< unsigned int >
96  struct Dispatch : DispatchBase {};
97 
99  // Second order derivative not defined.
100 
102  // Second order derivative not defined.
103 
105  inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
106  {
107  double absValue = std::abs( u );
108 
109  if( absValue < 0.5 )
110  {
111  return -2.0;
112  }
113  else if( absValue == 0.5 )
114  {
115  return -0.5;
116  }
117  else if( absValue < 1.5 )
118  {
119  return 1.0;
120  }
121  else if( absValue == 1.5 )
122  {
123  return 0.5;
124  }
125  else
126  {
127  return 0.0;
128  }
129  }
130 
131 
132  inline void Evaluate( const Dispatch< 2 > &, const double & u, double * weights ) const
133  {
134  weights[ 0 ] = 1.0;
135  weights[ 1 ] = -2.0;
136  weights[ 2 ] = 1.0;
137  }
138 
139 
141  inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
142  {
143  const double absValue = std::abs( u );
144 
145  if( absValue < 1.0 )
146  {
147  return vnl_math::sgn0( u ) * ( 3.0 * u ) - 2.0;
148  }
149  else if( absValue < 2.0 )
150  {
151  return -vnl_math::sgn( u ) * u + 2.0;
152  }
153  else
154  {
155  return 0.0;
156  }
157  }
158 
159 
160  inline void Evaluate( const Dispatch< 3 > &, const double & u, double * weights ) const
161  {
162  weights[ 0 ] = -u + 2.0;
163  weights[ 1 ] = 3.0 * u - 5.0;
164  weights[ 2 ] = -3.0 * u + 4.0;
165  weights[ 3 ] = u - 1.0;
166  }
167 
168 
170  inline double Evaluate( const DispatchBase &, const double & ) const
171  {
172  itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
173  }
174 
175 
176  inline void Evaluate( const DispatchBase &, const double &, double * ) const
177  {
178  itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
179  }
180 
181 
182 };
183 
184 } // end namespace itk
185 
186 #endif
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
void Evaluate(const DispatchBase &, const double &, double *) const
void PrintSelf(std::ostream &os, Indent indent) const override
void Evaluate(const Dispatch< 3 > &, const double &u, double *weights) const
void Evaluate(const Dispatch< 2 > &, const double &u, double *weights) const


Generated on 1667476801 for elastix by doxygen 1.9.1 elastix logo