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 Date: $Date: 2006-03-18 20:13:35 $
23 Version: $Revision: 1.7 $
24
25 Copyright (c) Insight Software Consortium. All rights reserved.
26 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
27
28 This software is distributed WITHOUT ANY WARRANTY; without even
29 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
30 PURPOSE. See the above copyright notices for more information.
31
32=========================================================================*/
33#ifndef itkBSplineKernelFunction2_h
34#define itkBSplineKernelFunction2_h
35
37#include <vnl/vnl_math.h>
38
39namespace itk
40{
41
57template <unsigned int VSplineOrder = 3>
58class ITK_TEMPLATE_EXPORT BSplineKernelFunction2 : public KernelFunctionBase2<double>
59{
60public:
62
66 using Pointer = SmartPointer<Self>;
67
69 itkNewMacro(Self);
70
73
75 itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
76
78 using WeightArrayType = FixedArray<double, VSplineOrder + 1>;
79
82 static double
83 FastEvaluate(const double u)
84 {
85 return Self::Evaluate(Dispatch<VSplineOrder>(), u);
86 }
87
88
92 static void
93 FastEvaluate(const double u, double * const weights)
94 {
95 Self::Evaluate(Dispatch<VSplineOrder>(), u, weights);
96 }
97
98
100 double
101 Evaluate(const double & u) const override
102 {
103 return Self::FastEvaluate(u);
104 }
105
106
110 void
111 Evaluate(const double & u, double * weights) const override
112 {
113 Self::FastEvaluate(u, weights);
114 }
115
116
117protected:
119 ~BSplineKernelFunction2() override = default;
120
121 void
122 PrintSelf(std::ostream & os, Indent indent) const override
123 {
124 Superclass::PrintSelf(os, indent);
125 os << indent << "Spline Order: " << SplineOrder << std::endl;
126 }
127
128
129private:
131 template <unsigned int>
132 struct ITK_TEMPLATE_EXPORT Dispatch
133 {};
134
140 static double
141 Evaluate(const Dispatch<0> &, const double u)
142 {
143 const double absValue = std::abs(u);
144
145 if (absValue < 0.5)
146 {
147 return 1.0;
148 }
149 else if (absValue == 0.5)
150 {
151 return 0.5;
152 }
153 else
154 {
155 return 0.0;
156 }
157 }
158
159
161 static double
162 Evaluate(const Dispatch<1> &, const double u)
163 {
164 const double absValue = std::abs(u);
165
166 if (absValue < 1.0)
167 {
168 return 1.0 - absValue;
169 }
170 else
171 {
172 return 0.0;
173 }
174 }
175
176
178 static double
179 Evaluate(const Dispatch<2> &, const double u)
180 {
181 const double absValue = std::abs(u);
182
183 if (absValue < 0.5)
184 {
185 return 0.75 - absValue * absValue;
186 }
187 else if (absValue < 1.5)
188 {
189 return (9.0 - 12.0 * absValue + 4.0 * absValue * absValue) / 8.0;
190 }
191 else
192 {
193 return 0.0;
194 }
195 }
196
197
199 static double
200 Evaluate(const Dispatch<3> &, const double u)
201 {
202 const double absValue = std::abs(u);
203 const double sqrValue = u * u;
204
205 if (absValue < 1.0)
206 {
207 return (4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue) / 6.0;
208 }
209 else if (absValue < 2.0)
210 {
211 return (8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue) / 6.0;
212 }
213 else
214 {
215 return 0.0;
216 }
217 }
218
219
225 static void
226 Evaluate(const Dispatch<0> &, const double u, double * weights)
227 {
228 const double absValue = std::abs(u);
229
230 if (absValue < 0.5)
231 {
232 weights[0] = 1.0;
233 }
234 else if (absValue == 0.5)
235 {
236 weights[0] = 0.5;
237 }
238 else
239 {
240 weights[0] = 0.0;
241 }
242 }
243
244
246 static void
247 Evaluate(const Dispatch<1> &, const double u, double * weights)
248 {
249 const double absValue = std::abs(u);
250
251 weights[0] = 1.0 - absValue;
252 weights[1] = absValue;
253 }
254
255
257 static void
258 Evaluate(const Dispatch<2> &, const double u, double * weights)
259 {
260 const double absValue = std::abs(u);
261 const double sqrValue = u * u;
262
263 weights[0] = (9.0 - 12.0 * absValue + 4.0 * sqrValue) / 8.0;
264 weights[1] = -0.25 + 2.0 * absValue - sqrValue;
265 weights[2] = (1.0 - 4.0 * absValue + 4.0 * sqrValue) / 8.0;
266 }
267
268
270 static void
271 Evaluate(const Dispatch<3> &, const double u, double * weights)
272 {
273 const double absValue = std::abs(u);
274 const double sqrValue = u * u;
275 const double uuu = sqrValue * absValue;
276
277 // Use (numerically) slightly less accurate multiplication with 1/6
278 // instead of division by 6 to substantially improve speed.
279 static const double onesixth = 1.0 / 6.0;
280 weights[0] = (8.0 - 12.0 * absValue + 6.0 * sqrValue - uuu) * onesixth;
281 weights[1] = (-5.0 + 21.0 * absValue - 15.0 * sqrValue + 3.0 * uuu) * onesixth;
282 weights[2] = (4.0 - 12.0 * absValue + 12.0 * sqrValue - 3.0 * uuu) * onesixth;
283 weights[3] = (-1.0 + 3.0 * absValue - 3.0 * sqrValue + uuu) * onesixth;
284 }
285};
286
287} // end namespace itk
288
289#endif
B-spline kernel used for density estimation and nonparameteric regression.
FixedArray< double, VSplineOrder+1 > WeightArrayType
~BSplineKernelFunction2() override=default
static void Evaluate(const Dispatch< 2 > &, const double u, double *weights)
void Evaluate(const double &u, double *weights) const override
static void Evaluate(const Dispatch< 1 > &, const double u, double *weights)
void PrintSelf(std::ostream &os, Indent indent) const override
static double Evaluate(const Dispatch< 1 > &, const double u)
static void FastEvaluate(const double u, double *const weights)
static double Evaluate(const Dispatch< 0 > &, const double u)
static void Evaluate(const Dispatch< 3 > &, const double u, double *weights)
static void Evaluate(const Dispatch< 0 > &, const double u, double *weights)
static double Evaluate(const Dispatch< 3 > &, const double u)
ITK_DISALLOW_COPY_AND_MOVE(BSplineKernelFunction2)
static double Evaluate(const Dispatch< 2 > &, const double u)
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
static double FastEvaluate(const double u)
double Evaluate(const double &u) const override
Kernel used for density estimation and nonparameteric regression.


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo