go home Home | Main Page | Topics | 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
137
139 static double
140 Evaluate(const Dispatch<0> &, const double u)
141 {
142 const double absValue = std::abs(u);
143
144 if (absValue < 0.5)
145 {
146 return 1.0;
147 }
148 else if (absValue == 0.5)
149 {
150 return 0.5;
151 }
152 else
153 {
154 return 0.0;
155 }
156 }
157
158
160 static double
161 Evaluate(const Dispatch<1> &, const double u)
162 {
163 const double absValue = std::abs(u);
164
165 if (absValue < 1.0)
166 {
167 return 1.0 - absValue;
168 }
169 else
170 {
171 return 0.0;
172 }
173 }
174
175
177 static double
178 Evaluate(const Dispatch<2> &, const double u)
179 {
180 const double absValue = std::abs(u);
181
182 if (absValue < 0.5)
183 {
184 return 0.75 - absValue * absValue;
185 }
186 else if (absValue < 1.5)
187 {
188 return (9.0 - 12.0 * absValue + 4.0 * absValue * absValue) / 8.0;
189 }
190 else
191 {
192 return 0.0;
193 }
194 }
195
196
198 static double
199 Evaluate(const Dispatch<3> &, const double u)
200 {
201 const double absValue = std::abs(u);
202 const double sqrValue = u * u;
203
204 if (absValue < 1.0)
205 {
206 return (4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue) / 6.0;
207 }
208 else if (absValue < 2.0)
209 {
210 return (8.0 - 12.0 * absValue + 6.0 * sqrValue - sqrValue * absValue) / 6.0;
211 }
212 else
213 {
214 return 0.0;
215 }
216 }
217
218
222
224 static void
225 Evaluate(const Dispatch<0> &, const double u, double * weights)
226 {
227 const double absValue = std::abs(u);
228
229 if (absValue < 0.5)
230 {
231 weights[0] = 1.0;
232 }
233 else if (absValue == 0.5)
234 {
235 weights[0] = 0.5;
236 }
237 else
238 {
239 weights[0] = 0.0;
240 }
241 }
242
243
245 static void
246 Evaluate(const Dispatch<1> &, const double u, double * weights)
247 {
248 const double absValue = std::abs(u);
249
250 weights[0] = 1.0 - absValue;
251 weights[1] = absValue;
252 }
253
254
256 static void
257 Evaluate(const Dispatch<2> &, const double u, double * weights)
258 {
259 const double absValue = std::abs(u);
260 const double sqrValue = u * u;
261
262 weights[0] = (9.0 - 12.0 * absValue + 4.0 * sqrValue) / 8.0;
263 weights[1] = -0.25 + 2.0 * absValue - sqrValue;
264 weights[2] = (1.0 - 4.0 * absValue + 4.0 * sqrValue) / 8.0;
265 }
266
267
269 static void
270 Evaluate(const Dispatch<3> &, const double u, double * weights)
271 {
272 const double absValue = std::abs(u);
273 const double sqrValue = u * u;
274 const double uuu = sqrValue * absValue;
275
276 // Use (numerically) slightly less accurate multiplication with 1/6
277 // instead of division by 6 to substantially improve speed.
278 static const double onesixth = 1.0 / 6.0;
279 weights[0] = (8.0 - 12.0 * absValue + 6.0 * sqrValue - uuu) * onesixth;
280 weights[1] = (-5.0 + 21.0 * absValue - 15.0 * sqrValue + 3.0 * uuu) * onesixth;
281 weights[2] = (4.0 - 12.0 * absValue + 12.0 * sqrValue - 3.0 * uuu) * onesixth;
282 weights[3] = (-1.0 + 3.0 * absValue - 3.0 * sqrValue + uuu) * onesixth;
283 }
284};
285
286} // end namespace itk
287
288#endif
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
itkOverrideGetNameOfClassMacro(BSplineKernelFunction2)


Generated on 26-02-2026 for elastix by doxygen 1.16.1 (669aeeefca743c148e2d935b3d3c69535c7491e6) elastix logo