go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkBSplineSecondOrderDerivativeKernelFunction2.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#ifndef itkBSplineSecondOrderDerivativeKernelFunction2_h
19#define itkBSplineSecondOrderDerivativeKernelFunction2_h
20
21#include "itkKernelFunctionBase.h"
22#include <vnl/vnl_math.h>
23#include <cmath> // For abs.
24
25namespace itk
26{
27
43template <unsigned int VSplineOrder = 3>
44class ITK_TEMPLATE_EXPORT BSplineSecondOrderDerivativeKernelFunction2 : public KernelFunctionBase<double>
45{
46public:
48
51 using Superclass = KernelFunctionBase<double>;
52 using Pointer = SmartPointer<Self>;
53
55 itkNewMacro(Self);
56
58 itkTypeMacro(BSplineSecondOrderDerivativeKernelFunction2, KernelFunctionBase);
59
61 itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
62
65 static double
66 FastEvaluate(const double u)
67 {
68 return Self::Evaluate(Dispatch<VSplineOrder>(), u);
69 }
70
71
74 static void
75 FastEvaluate(const double u, double * const weights)
76 {
77 Self::Evaluate(Dispatch<VSplineOrder>(), u, weights);
78 }
79
80
82 double
83 Evaluate(const double & u) const override
84 {
85 return Self::FastEvaluate(u);
86 }
87
88
90 void
91 Evaluate(const double u, double * weights) const
92 {
93 Self::FastEvaluate(u, weights);
94 }
95
96
97protected:
100
101 void
102 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:
111 struct DispatchBase
112 {};
113 template <unsigned int>
114 struct ITK_TEMPLATE_EXPORT Dispatch : DispatchBase
115 {};
116
118 // Second order derivative not defined.
119
121 // Second order derivative not defined.
122
124 static double
125 Evaluate(const Dispatch<2> &, const double u)
126 {
127 double absValue = std::abs(u);
128
129 if (absValue < 0.5)
130 {
131 return -2.0;
132 }
133 else if (absValue == 0.5)
134 {
135 return -0.5;
136 }
137 else if (absValue < 1.5)
138 {
139 return 1.0;
140 }
141 else if (absValue == 1.5)
142 {
143 return 0.5;
144 }
145 else
146 {
147 return 0.0;
148 }
149 }
150
151
152 static void
153 Evaluate(const Dispatch<2> &, const double u, double * weights)
154 {
155 weights[0] = 1.0;
156 weights[1] = -2.0;
157 weights[2] = 1.0;
158 }
159
160
162 static double
163 Evaluate(const Dispatch<3> &, const double u)
164 {
165 const double absValue = std::abs(u);
166
167 if (absValue < 1.0)
168 {
169 return vnl_math::sgn0(u) * (3.0 * u) - 2.0;
170 }
171 else if (absValue < 2.0)
172 {
173 return -vnl_math::sgn(u) * u + 2.0;
174 }
175 else
176 {
177 return 0.0;
178 }
179 }
180
181
182 static void
183 Evaluate(const Dispatch<3> &, const double u, double * weights)
184 {
185 weights[0] = -u + 2.0;
186 weights[1] = 3.0 * u - 5.0;
187 weights[2] = -3.0 * u + 4.0;
188 weights[3] = u - 1.0;
189 }
190
191
193 static double
194 Evaluate(const DispatchBase &, const double)
195 {
196 itkGenericExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
197 }
198
199
200 static void
201 Evaluate(const DispatchBase &, const double, double *)
202 {
203 itkGenericExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
204 }
205};
206
207} // end namespace itk
208
209#endif
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
static void Evaluate(const Dispatch< 3 > &, const double u, double *weights)
static void Evaluate(const Dispatch< 2 > &, const double u, double *weights)
static void Evaluate(const DispatchBase &, const double, double *)
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
~BSplineSecondOrderDerivativeKernelFunction2() override=default
ITK_DISALLOW_COPY_AND_MOVE(BSplineSecondOrderDerivativeKernelFunction2)
void PrintSelf(std::ostream &os, Indent indent) const override


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo