go home Home | Main Page | Topics | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
Loading...
Searching...
No Matches
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
129 // Derivative not defined.
130
132 static double
133 Evaluate(const Dispatch<1> &, const double u)
134 {
135 const double absValue = std::abs(u);
136
137 if (absValue < 1.0)
138 {
139 return -vnl_math::sgn(u);
140 }
141 else if (absValue == 1.0)
142 {
143 return -vnl_math::sgn(u) / 2.0;
144 }
145 else
146 {
147 return 0.0;
148 }
149 }
150
151
152 static void
153 Evaluate(const Dispatch<1> &, const double u, double * weights)
154 {
155 // MS \todo: check
156 const double absValue = std::abs(u);
157
158 if (absValue < 1.0 && absValue > 0.0)
159 {
160 weights[0] = -1.0;
161 weights[1] = 1.0;
162 }
163 else if (absValue == 1)
164 {
165 weights[0] = -0.5;
166 weights[1] = 0.0;
167 }
168 else
169 {
170 weights[0] = 0.0;
171 weights[1] = 0.5;
172 }
173 }
174
175
177 static double
178 Evaluate(const Dispatch<2> &, const double u)
179 {
180 double absValue = std::abs(u);
181
182 if (absValue < 0.5)
183 {
184 return -2.0 * u;
185 }
186 else if (absValue < 1.5)
187 {
188 return u - 1.5 * vnl_math::sgn(u);
189 }
190 else
191 {
192 return 0.0;
193 }
194 }
195
196
197 static void
198 Evaluate(const Dispatch<2> &, const double u, double * weights)
199 {
200 // MS \todo: check
201 weights[0] = u - 1.5;
202 weights[1] = -2.0 * u + 2.0;
203 weights[2] = u - 0.5;
204 }
205
206
208 static double
209 Evaluate(const Dispatch<3> &, const double u)
210 {
211 const double absValue = std::abs(u);
212 const double sqrValue = u * u;
213
214 if (absValue < 1.0)
215 {
216 if (u > 0.0)
217 {
218 const double dummy = std::abs(u + 0.5);
219 return (6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
220 }
221 else
222 {
223 const double dummy = std::abs(u - 0.5);
224 return -(6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0) / 4.0;
225 }
226 }
227 else if (absValue < 2.0)
228 {
229 if (u > 0.0)
230 {
231 const double dummy = std::abs(u - 0.5);
232 return (u - sqrValue + 3.0 * dummy - 2.5) / 2.0;
233 }
234 else
235 {
236 const double dummy = std::abs(u + 0.5);
237 return (u + sqrValue - 3.0 * dummy + 2.5) / 2.0;
238 }
239 }
240 else
241 {
242 return 0.0;
243 }
244 }
245
246
247 static void
248 Evaluate(const Dispatch<3> &, const double u, double * weights)
249 {
250 const double absValue = std::abs(u);
251 const double sqrValue = u * u;
252
253 weights[0] = 0.5 * sqrValue - 2.0 * absValue + 2.0;
254 weights[1] = -1.5 * sqrValue + 5.0 * absValue - 3.5;
255 weights[2] = 1.5 * sqrValue - 4.0 * absValue + 2.0;
256 weights[3] = -0.5 * sqrValue + absValue - 0.5;
257 }
258};
259
260} // end namespace itk
261
262#endif
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)
itkOverrideGetNameOfClassMacro(BSplineDerivativeKernelFunction2)
ITK_DISALLOW_COPY_AND_MOVE(BSplineDerivativeKernelFunction2)
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)


Generated on 1774142652 for elastix by doxygen 1.15.0 elastix logo