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 Date: $Date: 2008-06-25 11:00:19 $
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 itkBSplineDerivativeKernelFunction2_h
34#define itkBSplineDerivativeKernelFunction2_h
35
37#include <vnl/vnl_math.h>
38
39namespace itk
40{
41
57template <unsigned int VSplineOrder = 3>
58class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction2 : public KernelFunctionBase2<double>
59{
60public:
62
66 using Pointer = SmartPointer<Self>;
67
69 itkNewMacro(Self);
70
73
75 itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
76
79 static double
80 FastEvaluate(const double u)
81 {
82 return Self::Evaluate(Dispatch<VSplineOrder>(), u);
83 }
84
85
88 static void
89 FastEvaluate(const double u, double * const weights)
90 {
91 return Self::Evaluate(Dispatch<VSplineOrder>(), u, weights);
92 }
93
94
96 double
97 Evaluate(const double & u) const override
98 {
99 return Self::FastEvaluate(u);
100 }
101
102
104 void
105 Evaluate(const double & u, double * weights) const override
106 {
107 return Self::FastEvaluate(u, weights);
108 }
109
110
111protected:
114
115 void
116 PrintSelf(std::ostream & os, Indent indent) const override
117 {
118 Superclass::PrintSelf(os, indent);
119 os << indent << "Spline Order: " << SplineOrder << std::endl;
120 }
121
122
123private:
125 template <unsigned int>
126 struct ITK_TEMPLATE_EXPORT Dispatch
127 {};
128
130 // Derivative not defined.
131
133 static double
134 Evaluate(const Dispatch<1> &, const double u)
135 {
136 const double absValue = std::abs(u);
137
138 if (absValue < 1.0)
139 {
140 return -vnl_math::sgn(u);
141 }
142 else if (absValue == 1.0)
143 {
144 return -vnl_math::sgn(u) / 2.0;
145 }
146 else
147 {
148 return 0.0;
149 }
150 }
151
152
153 static void
154 Evaluate(const Dispatch<1> &, const double u, double * weights)
155 {
156 // MS \todo: check
157 const double absValue = std::abs(u);
158
159 if (absValue < 1.0 && absValue > 0.0)
160 {
161 weights[0] = -1.0;
162 weights[1] = 1.0;
163 }
164 else if (absValue == 1)
165 {
166 weights[0] = -0.5;
167 weights[1] = 0.0;
168 }
169 else
170 {
171 weights[0] = 0.0;
172 weights[1] = 0.5;
173 }
174 }
175
176
178 static double
179 Evaluate(const Dispatch<2> &, const double u)
180 {
181 double absValue = std::abs(u);
182
183 if (absValue < 0.5)
184 {
185 return -2.0 * u;
186 }
187 else if (absValue < 1.5)
188 {
189 return u - 1.5 * vnl_math::sgn(u);
190 }
191 else
192 {
193 return 0.0;
194 }
195 }
196
197
198 static void
199 Evaluate(const Dispatch<2> &, const double u, double * weights)
200 {
201 // MS \todo: check
202 weights[0] = u - 1.5;
203 weights[1] = -2.0 * u + 2.0;
204 weights[2] = u - 0.5;
205 }
206
207
209 static double
210 Evaluate(const Dispatch<3> &, const double u)
211 {
212 const double absValue = std::abs(u);
213 const double sqrValue = u * u;
214
215 if (absValue < 1.0)
216 {
217 if (u > 0.0)
218 {
219 const double dummy = std::abs(u + 0.5);
220 return (6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
221 }
222 else
223 {
224 const double dummy = std::abs(u - 0.5);
225 return -(6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
226 }
227 }
228 else if (absValue < 2.0)
229 {
230 if (u > 0.0)
231 {
232 const double dummy = std::abs(u - 0.5);
233 return (u - sqrValue + 3.0 * dummy - 2.5) / 2.0;
234 }
235 else
236 {
237 const double dummy = std::abs(u + 0.5);
238 return (u + sqrValue - 3.0 * dummy + 2.5) / 2.0;
239 }
240 }
241 else
242 {
243 return 0.0;
244 }
245 }
246
247
248 static void
249 Evaluate(const Dispatch<3> &, const double u, double * weights)
250 {
251 const double absValue = std::abs(u);
252 const double sqrValue = u * u;
253
254 weights[0] = 0.5 * sqrValue - 2.0 * absValue + 2.0;
255 weights[1] = -1.5 * sqrValue + 5.0 * absValue - 3.5;
256 weights[2] = 1.5 * sqrValue - 4.0 * absValue + 2.0;
257 weights[3] = -0.5 * sqrValue + absValue - 0.5;
258 }
259};
260
261} // end namespace itk
262
263#endif
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
void Evaluate(const double &u, double *weights) const override
static void Evaluate(const Dispatch< 2 > &, const double u, double *weights)
void PrintSelf(std::ostream &os, Indent indent) const override
static double Evaluate(const Dispatch< 3 > &, const double u)
~BSplineDerivativeKernelFunction2() override=default
static double Evaluate(const Dispatch< 2 > &, const double u)
static void Evaluate(const Dispatch< 1 > &, const double u, double *weights)
static double Evaluate(const Dispatch< 1 > &, const double u)
double Evaluate(const double &u) const override
static void FastEvaluate(const double u, double *const weights)
static void Evaluate(const Dispatch< 3 > &, const double u, double *weights)
ITK_DISALLOW_COPY_AND_MOVE(BSplineDerivativeKernelFunction2)
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
Kernel used for density estimation and nonparameteric regression.


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