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  * 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 /*=========================================================================
19 
20  Program: Insight Segmentation & Registration Toolkit
21  Module: $RCSfile: itkBSplineDerivativeKernelFunction2.h,v $
22  Language: C++
23  Date: $Date: 2008-06-25 11:00:19 $
24  Version: $Revision: 1.7 $
25 
26  Copyright (c) Insight Software Consortium. All rights reserved.
27  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
28 
29  This software is distributed WITHOUT ANY WARRANTY; without even
30  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31  PURPOSE. See the above copyright notices for more information.
32 
33 =========================================================================*/
34 #ifndef __itkBSplineDerivativeKernelFunction2_h
35 #define __itkBSplineDerivativeKernelFunction2_h
36 
37 #include "itkKernelFunctionBase.h"
38 #include "vnl/vnl_math.h"
39 
40 namespace itk
41 {
42 
58 template< unsigned int VSplineOrder = 3 >
59 class ITK_EXPORT BSplineDerivativeKernelFunction2 : public KernelFunctionBase< double >
60 {
61 public:
62 
67 
69  itkNewMacro( Self );
70 
73 
75  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
76 
78  inline double Evaluate( const double & u ) const
79  {
80  return this->Evaluate( Dispatch< VSplineOrder >(), u );
81  }
82 
83 
84 protected:
85 
88 
89  void PrintSelf( std::ostream & os, Indent indent ) const
90  {
91  Superclass::PrintSelf( os, indent );
92  os << indent << "Spline Order: " << SplineOrder << std::endl;
93  }
94 
95 
96 private:
97 
98  BSplineDerivativeKernelFunction2( const Self & ); //purposely not implemented
99  void operator=( const Self & ); //purposely not implemented
100 
102  struct DispatchBase {};
103  template< unsigned int >
104  struct Dispatch : DispatchBase {};
105 
128  inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
129  {
130 
131  double absValue = vnl_math_abs( u );
132 
133  if( absValue < 1.0 )
134  {
135  return -vnl_math_sgn( u );
136  }
137  else if( absValue == 1.0 )
138  {
139  return -vnl_math_sgn( u ) / 2.0;
140  }
141  else
142  {
143  return 0.0;
144  }
145 
146  }
147 
148 
150  inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
151  {
152  double absValue = vnl_math_abs( u );
153 
154  if( absValue < 0.5 )
155  {
156  return -2.0 * u;
157  }
158  else if( absValue < 1.5 )
159  {
160  return u - 1.5 * vnl_math_sgn( u );
161  }
162  else
163  {
164  return 0.0;
165  }
166 
167  }
168 
169 
171  inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
172  {
173  const double absValue = vnl_math_abs( u );
174  const double sqrValue = vnl_math_sqr( u );
175 
176  if( absValue < 1.0 )
177  {
178  if( u > 0.0 )
179  {
180  const double dummy = vnl_math_abs( u + 0.5 );
181  return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
182  }
183  else
184  {
185  const double dummy = vnl_math_abs( u - 0.5 );
186  return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
187  }
188  }
189  else if( absValue < 2.0 )
190  {
191  if( u > 0.0 )
192  {
193  const double dummy = vnl_math_abs( u - 0.5 );
194  return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
195  }
196  else
197  {
198  const double dummy = vnl_math_abs( u + 0.5 );
199  return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
200  }
201  }
202  else
203  {
204  return 0.0;
205  }
206 
207  }
208 
209 
211  inline double Evaluate( const DispatchBase &, const double & ) const
212  {
213  itkExceptionMacro( "Evaluate not implemented for spline\
214  order " << SplineOrder );
215  return 0.0; // This is to avoid compiler warning about missing
216  // return statement. It should never be evaluated.
217  }
218 
219 
220 };
221 
222 } // end namespace itk
223 
224 #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 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo