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
38#include "vnl/vnl_math.h"
39
40namespace itk
41{
42
58template< unsigned int VSplineOrder = 3 >
59class ITK_EXPORT BSplineKernelFunction2 : public KernelFunctionBase2< double >
60{
61public:
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 override
83 {
84 return this->Evaluate( Dispatch< VSplineOrder >(), u );
85 }
86
87
91 inline void Evaluate( const double & u, double * weights ) const override
92 {
93 this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
94 }
95
96
97protected:
98
101
102 void PrintSelf( std::ostream & os, Indent indent ) const override
103 {
104 Superclass::PrintSelf( os, indent );
105 os << indent << "Spline Order: " << SplineOrder << std::endl;
106 }
107
108
109private:
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 const double absValue = std::abs( u );
127
128 if( absValue < 0.5 ) { return NumericTraits< double >::OneValue(); }
129 else if( absValue == 0.5 ) { return 0.5; }
130 else { return NumericTraits< double >::ZeroValue(); }
131 }
132
133
135 inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
136 {
137 const double absValue = std::abs( u );
138
139 if( absValue < 1.0 ) { return NumericTraits< double >::OneValue() - absValue; }
140 else { return NumericTraits< double >::ZeroValue(); }
141 }
142
143
145 inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
146 {
147 const double absValue = std::abs( u );
148
149 if( absValue < 0.5 )
150 {
151 return 0.75 - absValue * absValue;
152 }
153 else if( absValue < 1.5 )
154 {
155 return ( 9.0 - 12.0 * absValue + 4.0 * absValue * absValue ) / 8.0;
156 }
157 else { return NumericTraits< double >::ZeroValue(); }
158 }
159
160
162 inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
163 {
164 const double absValue = std::abs( u );
165 const double sqrValue = u * 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 NumericTraits< double >::ZeroValue(); }
176 }
177
178
180 inline double Evaluate( const DispatchBase &, const double & ) const
181 {
182 itkExceptionMacro( << "Evaluate not implemented for spline order " << SplineOrder );
183 return 0.0;
184 }
185
186
192 inline void Evaluate( const Dispatch< 0 > &, const double & u,
193 double * weights ) const
194 {
195 const double absValue = std::abs( u );
196
197 if( absValue < 0.5 ) { weights[ 0 ] = NumericTraits< double >::OneValue(); }
198 else if( absValue == 0.5 ) { weights[ 0 ] = 0.5; }
199 else { weights[ 0 ] = NumericTraits< double >::ZeroValue(); }
200 }
201
202
204 inline void Evaluate( const Dispatch< 1 > &, const double & u,
205 double * weights ) const
206 {
207 const double absValue = std::abs( u );
208
209 weights[ 0 ] = NumericTraits< double >::OneValue() - absValue;
210 weights[ 1 ] = absValue;
211 }
212
213
215 inline void Evaluate( const Dispatch< 2 > &, const double & u,
216 double * weights ) const
217 {
218 const double absValue = std::abs( u );
219 const double sqrValue = u * u;
220
221 weights[ 0 ] = ( 9.0 - 12.0 * absValue + 4.0 * sqrValue ) / 8.0;
222 weights[ 1 ] = -0.25 + 2.0 * absValue - sqrValue;
223 weights[ 2 ] = ( 1.0 - 4.0 * absValue + 4.0 * sqrValue ) / 8.0;
224 }
225
226
228 inline void Evaluate( const Dispatch< 3 > &, const double & u,
229 double * weights ) const
230 {
231 const double absValue = std::abs( u );
232 const double sqrValue = u * u;
233 const double uuu = sqrValue * absValue;
234
235 // Use (numerically) slightly less accurate multiplication with 1/6
236 // instead of division by 6 to substantially improve speed.
237 static const double onesixth = 1.0 / 6.0;
238 weights[ 0 ] = ( 8.0 - 12.0 * absValue + 6.0 * sqrValue - uuu ) * onesixth;
239 weights[ 1 ] = ( -5.0 + 21.0 * absValue - 15.0 * sqrValue + 3.0 * uuu ) * onesixth;
240 weights[ 2 ] = ( 4.0 - 12.0 * absValue + 12.0 * sqrValue - 3.0 * uuu ) * onesixth;
241 weights[ 3 ] = ( -1.0 + 3.0 * absValue - 3.0 * sqrValue + uuu ) * onesixth;
242 }
243
244
246 inline double Evaluate( const DispatchBase &, const double &, double * ) const
247 {
248 itkExceptionMacro( << "Evaluate not implemented for spline order " << SplineOrder );
249 return 0.0;
250 }
251
252
253};
254
255} // end namespace itk
256
257#endif
B-spline kernel used for density estimation and nonparameteric regression.
void Evaluate(const double &u, double *weights) const override
void Evaluate(const Dispatch< 3 > &, const double &u, double *weights) const
void operator=(const Self &)
void PrintSelf(std::ostream &os, Indent indent) const override
double Evaluate(const DispatchBase &, const double &) const
void Evaluate(const Dispatch< 0 > &, const double &u, double *weights) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
FixedArray< double, itkGetStaticConstMacro(SplineOrder)+1 > WeightArrayType
void Evaluate(const Dispatch< 2 > &, const double &u, double *weights) const
KernelFunctionBase2< double > Superclass
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const DispatchBase &, const double &, double *) const
double Evaluate(const Dispatch< 0 > &, const double &u) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
void Evaluate(const Dispatch< 1 > &, const double &u, double *weights) const
BSplineKernelFunction2(const Self &)
double Evaluate(const double &u) const override
Kernel used for density estimation and nonparameteric regression.


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo