ITK  6.0.0
Insight Toolkit
itkBSplineDerivativeKernelFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkBSplineDerivativeKernelFunction_h
19 #define itkBSplineDerivativeKernelFunction_h
20 
22 #include "itkMath.h"
23 
24 namespace itk
25 {
42 template <unsigned int VSplineOrder = 3, typename TRealValueType = double>
43 class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctionBase<TRealValueType>
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(BSplineDerivativeKernelFunction);
47 
52 
53  using typename Superclass::RealType;
55  itkNewMacro(Self);
56 
58  itkOverrideGetNameOfClassMacro(BSplineDerivativeKernelFunction);
59 
61  static constexpr unsigned int SplineOrder = VSplineOrder;
62 
65  static TRealValueType
66  FastEvaluate(const TRealValueType u)
67  {
68  return Self::Evaluate(Dispatch<VSplineOrder>(), u);
69  }
70 
72  TRealValueType
73  Evaluate(const TRealValueType & u) const override
74  {
75  return Self::FastEvaluate(u);
76  }
77 
78 protected:
80  ~BSplineDerivativeKernelFunction() override = default;
81 
82  void
83  PrintSelf(std::ostream & os, Indent indent) const override
84  {
85  Superclass::PrintSelf(os, indent);
86  os << indent << "Spline Order: " << SplineOrder << std::endl;
87  }
88 
89 private:
91  struct DispatchBase
92  {};
93  template <unsigned int>
94  struct Dispatch : public DispatchBase
95  {};
96 
98  inline static TRealValueType
99  Evaluate(const Dispatch<0> &, const TRealValueType & itkNotUsed(u))
100  {
101  return TRealValueType{ 0.0 };
102  }
103 
105  inline static TRealValueType
106  Evaluate(const Dispatch<1> &, const TRealValueType & u)
107  {
108  if (Math::ExactlyEquals(u, TRealValueType{ -1.0 }))
109  {
110  return TRealValueType{ 0.5 };
111  }
112  else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
113  {
114  return TRealValueType{ 1.0 };
115  }
116  else if (Math::ExactlyEquals(u, TRealValueType{ 0.0 }))
117  {
118  return TRealValueType{ 0.0 };
119  }
120  else if ((u > TRealValueType{ 0.0 }) && (u < TRealValueType{ 1.0 }))
121  {
122  return TRealValueType{ -1.0 };
123  }
124  else if (Math::ExactlyEquals(u, TRealValueType{ 1.0 }))
125  {
126  return TRealValueType{ -0.5 };
127  }
128  else
129  {
130  return TRealValueType{ 0.0 };
131  }
132  }
136  inline static TRealValueType
137  Evaluate(const Dispatch<2> &, const TRealValueType & u)
138  {
139  if ((u > TRealValueType{ -0.5 }) && (u < TRealValueType{ 0.5 }))
140  {
141  return (TRealValueType{ -2.0 } * u);
142  }
143  else if ((u >= TRealValueType{ 0.5 }) && (u < TRealValueType{ 1.5 }))
144  {
145  return (TRealValueType{ -1.5 } + u);
146  }
147  else if ((u > TRealValueType{ -1.5 }) && (u <= TRealValueType{ -0.5 }))
148  {
149  return (TRealValueType{ 1.5 } + u);
150  }
151  else
152  {
153  return TRealValueType{ 0.0 };
154  }
155  }
159  inline static TRealValueType
160  Evaluate(const Dispatch<3> &, const TRealValueType & u)
161  {
162  if ((u >= TRealValueType{ 0.0 }) && (u < TRealValueType{ 1.0 }))
163  {
164  return (TRealValueType{ -2.0 } * u + TRealValueType{ 1.5 } * u * u);
165  }
166  else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
167  {
168  return (TRealValueType{ -2.0 } * u - TRealValueType{ 1.5 } * u * u);
169  }
170  else if ((u >= TRealValueType{ 1.0 }) && (u < TRealValueType{ 2.0 }))
171  {
172  return (TRealValueType{ -2.0 } + TRealValueType{ 2.0 } * u - TRealValueType{ 0.5 } * u * u);
173  }
174  else if ((u > TRealValueType{ -2.0 }) && (u <= TRealValueType{ -1.0 }))
175  {
176  return (TRealValueType{ 2.0 } + TRealValueType{ 2.0 } * u + TRealValueType{ 0.5 } * u * u);
177  }
178  else
179  {
180  return TRealValueType{ 0.0 };
181  }
182  }
186  inline static TRealValueType
187  Evaluate(const DispatchBase &, const TRealValueType &)
188  {
189  itkGenericExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
190  }
191 };
192 } // end namespace itk
195 #endif
itk::BSplineDerivativeKernelFunction::FastEvaluate
static TRealValueType FastEvaluate(const TRealValueType u)
Definition: itkBSplineDerivativeKernelFunction.h:66
itk::KernelFunctionBase::RealType
TRealValueType RealType
Definition: itkKernelFunctionBase.h:52
itk::BSplineDerivativeKernelFunction::Evaluate
static TRealValueType Evaluate(const Dispatch< 3 > &, const TRealValueType &u)
Definition: itkBSplineDerivativeKernelFunction.h:160
itk::BSplineDerivativeKernelFunction::Evaluate
static TRealValueType Evaluate(const DispatchBase &, const TRealValueType &)
Definition: itkBSplineDerivativeKernelFunction.h:187
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const TRealValueType &u) const override
Definition: itkBSplineDerivativeKernelFunction.h:73
itk::BSplineDerivativeKernelFunction::Evaluate
static TRealValueType Evaluate(const Dispatch< 0 > &, const TRealValueType &)
Definition: itkBSplineDerivativeKernelFunction.h:99
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:722
itk::KernelFunctionBase
Kernel used for density estimation and nonparametric regression.
Definition: itkKernelFunctionBase.h:43
itk::BSplineDerivativeKernelFunction::Dispatch
Definition: itkBSplineDerivativeKernelFunction.h:94
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BSplineDerivativeKernelFunction::Evaluate
static TRealValueType Evaluate(const Dispatch< 1 > &, const TRealValueType &u)
Definition: itkBSplineDerivativeKernelFunction.h:106
itk::BSplineDerivativeKernelFunction::Evaluate
static TRealValueType Evaluate(const Dispatch< 2 > &, const TRealValueType &u)
Definition: itkBSplineDerivativeKernelFunction.h:137
itk::BSplineDerivativeKernelFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkBSplineDerivativeKernelFunction.h:83
itk::BSplineDerivativeKernelFunction::DispatchBase
Definition: itkBSplineDerivativeKernelFunction.h:91
itkBSplineKernelFunction.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::BSplineDerivativeKernelFunction
Derivative of a BSpline kernel used for density estimation and nonparametric regression.
Definition: itkBSplineDerivativeKernelFunction.h:43
itkMath.h