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  * 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: itkBSplineKernelFunction.h,v $
22  Language: C++
23  Date: $Date: 2006-03-18 20:13:35 $
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 __itkBSplineKernelFunction2_h
35 #define __itkBSplineKernelFunction2_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 BSplineKernelFunction2 : public KernelFunctionBase< double >
60 {
61 public:
62 
67 
69  itkNewMacro( Self );
70 
73 
75  itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
76 
78  typedef FixedArray< double,
79  itkGetStaticConstMacro( SplineOrder ) + 1 > WeightArrayType;
80 
82  inline double Evaluate( const double & u ) const
83  {
84  return this->Evaluate( Dispatch< VSplineOrder >(), u );
85  }
86 
87 
91  inline void Evaluate( const double & u, WeightArrayType & weights ) const
92  {
93  this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
94  }
95 
96 
97 protected:
98 
101 
102  void PrintSelf( std::ostream & os, Indent indent ) const
103  {
104  Superclass::PrintSelf( os, indent );
105  os << indent << "Spline Order: " << SplineOrder << std::endl;
106  }
107 
108 
109 private:
110 
111  BSplineKernelFunction2( const Self & ); //purposely not implemented
112  void operator=( const Self & ); //purposely not implemented
113 
115  struct DispatchBase {};
116  template< unsigned int >
117  struct Dispatch : DispatchBase {};
118 
124  inline double Evaluate( const Dispatch< 0 > &, const double & u ) const
125  {
126  double absValue = vnl_math_abs( u );
127 
128  if( absValue < 0.5 ) { return 1.0; }
129  else if( absValue == 0.5 ) { return 0.5; }
130  else { return 0.0; }
131  }
132 
133 
135  inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
136  {
137  double absValue = vnl_math_abs( u );
138 
139  if( absValue < 1.0 ) { return 1.0 - absValue; }
140  else { return 0.0; }
141  }
142 
143 
145  inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
146  {
147  double absValue = vnl_math_abs( u );
148 
149  if( absValue < 0.5 )
150  {
151  return 0.75 - vnl_math_sqr( absValue );
152  }
153  else if( absValue < 1.5 )
154  {
155  return ( 9.0 - 12.0 * absValue + 4.0 * vnl_math_sqr( absValue ) ) / 8.0;
156  }
157  else { return 0.0; }
158  }
159 
160 
162  inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
163  {
164  double absValue = vnl_math_abs( u );
165  double sqrValue = vnl_math_sqr( u );
166 
167  if( absValue < 1.0 )
168  {
169  return ( 4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue ) / 6.0;
170  }
171  else if( absValue < 2.0 )
172  {
173  return ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue ) / 6.0;
174  }
175  else { return 0.0; }
176  }
177 
178 
180  inline double Evaluate( const DispatchBase &, const double & ) const
181  {
182  itkExceptionMacro( << "Evaluate not implemented for spline order "
183  << SplineOrder );
184  return 0.0;
185  }
186 
187 
193  inline void Evaluate( const Dispatch< 0 > &, const double & u,
194  WeightArrayType & weights ) const
195  {
196  if( u < 0.5 ) { weights[ 0 ] = 1.0; }
197  else { weights[ 0 ] = 0.5; }
198  }
199 
200 
202  inline void Evaluate( const Dispatch< 1 > &, const double & u,
203  WeightArrayType & weights ) const
204  {
205  weights[ 0 ] = 1.0 - u;
206  weights[ 1 ] = u;
207  }
208 
209 
211  inline void Evaluate( const Dispatch< 2 > &, const double & u,
212  WeightArrayType & weights ) const
213  {
214  const double uu = vnl_math_sqr( u );
215 
216  weights[ 0 ] = ( 9.0 - 12.0 * u + 4.0 * uu ) / 8.0;
217  weights[ 1 ] = -0.25 + 2.0 * u - uu;
218  weights[ 2 ] = ( 1.0 - 4.0 * u + 4.0 * uu ) / 8.0;
219  }
220 
221 
223  inline void Evaluate( const Dispatch< 3 > &, const double & u,
224  WeightArrayType & weights ) const
225  {
226  const double uu = vnl_math_sqr( u );
227  const double uuu = uu * u;
228 
229  weights[ 0 ] = ( 8.0 - 12 * u + 6.0 * uu - uuu ) / 6.0;
230  weights[ 1 ] = ( -5.0 + 21.0 * u - 15.0 * uu + 3.0 * uuu ) / 6.0;
231  weights[ 2 ] = ( 4.0 - 12.0 * u + 12.0 * uu - 3.0 * uuu ) / 6.0;
232  weights[ 3 ] = ( -1.0 + 3.0 * u - 3.0 * uu + uuu ) / 6.0;
233  }
234 
235 
237  inline double Evaluate( const DispatchBase &, const double &,
238  WeightArrayType & ) const
239  {
240  itkExceptionMacro( << "Evaluate not implemented for spline order "
241  << SplineOrder );
242  return 0.0;
243  }
244 
245 
246 };
247 
248 } // end namespace itk
249 
250 #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 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo