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 Language: C++
23 Date: $Date: 2008-06-25 11:00:19 $
24 Version: $Revision: 1.7 $
25
26 Copyright (c) Insight Software Consortium. All rights reserved.
27 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
28
29 This software is distributed WITHOUT ANY WARRANTY; without even
30 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31 PURPOSE. See the above copyright notices for more information.
32
33=========================================================================*/
34#ifndef __itkBSplineDerivativeKernelFunction2_h
35#define __itkBSplineDerivativeKernelFunction2_h
36
38#include "vnl/vnl_math.h"
39
40namespace itk
41{
42
58template< unsigned int VSplineOrder = 3 >
59class ITK_EXPORT BSplineDerivativeKernelFunction2 : public KernelFunctionBase2< double >
60{
61public:
62
67
69 itkNewMacro( Self );
70
73
75 itkStaticConstMacro( SplineOrder, unsigned int, VSplineOrder );
76
78 inline double Evaluate( const double & u ) const override
79 {
80 return this->Evaluate( Dispatch< VSplineOrder >(), u );
81 }
82
83
85 inline void Evaluate( const double & u, double * weights ) const override
86 {
87 return this->Evaluate( Dispatch< VSplineOrder >(), u, weights );
88 }
89
90
91protected:
92
95
96 void PrintSelf( std::ostream & os, Indent indent ) const override
97 {
98 Superclass::PrintSelf( os, indent );
99 os << indent << "Spline Order: " << SplineOrder << std::endl;
100 }
101
102
103private:
104
105 BSplineDerivativeKernelFunction2( const Self & ); // purposely not implemented
106 void operator=( const Self & ); // purposely not implemented
107
109 struct DispatchBase {};
110 template< unsigned int >
111 struct Dispatch : DispatchBase {};
112
114 // Derivative not defined.
115
117 inline double Evaluate( const Dispatch< 1 > &, const double & u ) const
118 {
119 const double absValue = std::abs( u );
120
121 if( absValue < NumericTraits< double >::OneValue() )
122 {
123 return -vnl_math::sgn( u );
124 }
125 else if( absValue == NumericTraits< double >::OneValue() )
126 {
127 return -vnl_math::sgn( u ) / 2.0;
128 }
129 else { return NumericTraits< double >::ZeroValue(); }
130 }
131
132
133 inline void Evaluate( const Dispatch< 1 > &, const double & u, double * weights ) const
134 {
135 // MS \todo: check
136 const double absValue = std::abs( u );
137
138 if( absValue < 1.0 && absValue > 0.0 )
139 {
140 weights[ 0 ] = -1.0;
141 weights[ 1 ] = 1.0;
142 }
143 else if( absValue == 1 )
144 {
145 weights[ 0 ] = -0.5;
146 weights[ 1 ] = 0.0;
147 }
148 else
149 {
150 weights[ 0 ] = 0.0;
151 weights[ 1 ] = 0.5;
152 }
153
154 }
155
156
158 inline double Evaluate( const Dispatch< 2 > &, const double & u ) const
159 {
160 double absValue = std::abs( u );
161
162 if( absValue < 0.5 )
163 {
164 return -2.0 * u;
165 }
166 else if( absValue < 1.5 )
167 {
168 return u - 1.5 * vnl_math::sgn( u );
169 }
170 else
171 {
172 return NumericTraits< double >::ZeroValue();
173 }
174 }
175
176
177 inline void Evaluate( const Dispatch< 2 > &, const double & u, double * weights ) const
178 {
179 // MS \todo: check
180 weights[ 0 ] = u - 1.5;
181 weights[ 1 ] = -2.0 * u + 2.0;
182 weights[ 2 ] = u - 0.5;
183 }
184
185
187 inline double Evaluate( const Dispatch< 3 > &, const double & u ) const
188 {
189 const double absValue = std::abs( u );
190 const double sqrValue = u * u;
191
192 if( absValue < 1.0 )
193 {
194 if( u > 0.0 )
195 {
196 const double dummy = std::abs( u + 0.5 );
197 return ( 6.0 * sqrValue - 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
198 }
199 else
200 {
201 const double dummy = std::abs( u - 0.5 );
202 return -( 6.0 * sqrValue + 2.0 * u - 6.0 * dummy + 3.0 ) / 4.0;
203 }
204 }
205 else if( absValue < 2.0 )
206 {
207 if( u > 0.0 )
208 {
209 const double dummy = std::abs( u - 0.5 );
210 return ( u - sqrValue + 3.0 * dummy - 2.5 ) / 2.0;
211 }
212 else
213 {
214 const double dummy = std::abs( u + 0.5 );
215 return ( u + sqrValue - 3.0 * dummy + 2.5 ) / 2.0;
216 }
217 }
218 else
219 {
220 return 0.0;
221 }
222 }
223
224
225 inline void Evaluate( const Dispatch< 3 > &, const double & u, double * weights ) const
226 {
227 const double absValue = std::abs( u );
228 const double sqrValue = u * u;
229
230 weights[ 0 ] = 0.5 * sqrValue - 2.0 * absValue + 2.0;
231 weights[ 1 ] = -1.5 * sqrValue + 5.0 * absValue - 3.5;
232 weights[ 2 ] = 1.5 * sqrValue - 4.0 * absValue + 2.0;
233 weights[ 3 ] = -0.5 * sqrValue + absValue - 0.5;
234 }
235
236
238 inline double Evaluate( const DispatchBase &, const double & ) const
239 {
240 itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
241 return 0.0; // This is to avoid compiler warning about missing
242 // return statement. It should never be evaluated.
243 }
244
245
247 inline void Evaluate( const DispatchBase &, const double &, double * ) const
248 {
249 itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
250 }
251
252
253};
254
255} // end namespace itk
256
257#endif
Derivative of a B-spline kernel used for density estimation and nonparametric regression.
void Evaluate(const double &u, double *weights) const override
void PrintSelf(std::ostream &os, Indent indent) const override
void Evaluate(const DispatchBase &, const double &, double *) const
double Evaluate(const Dispatch< 3 > &, const double &u) const
void Evaluate(const Dispatch< 2 > &, const double &u, double *weights) const
void Evaluate(const Dispatch< 3 > &, const double &u, double *weights) const
double Evaluate(const DispatchBase &, const double &) const
double Evaluate(const double &u) const override
void Evaluate(const Dispatch< 1 > &, const double &u, double *weights) const
double Evaluate(const Dispatch< 2 > &, const double &u) const
double Evaluate(const Dispatch< 1 > &, const double &u) const
itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder)
Kernel used for density estimation and nonparameteric regression.


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo