ITK  5.2.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  * 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 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>
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(BSplineDerivativeKernelFunction);
47 
52 
53  using RealType = typename Superclass::RealType;
55  itkNewMacro(Self);
56 
59 
61  static constexpr unsigned int SplineOrder = VSplineOrder;
62 
64  TRealValueType
65  Evaluate(const TRealValueType & u) const override
66  {
67  return this->Evaluate(Dispatch<VSplineOrder>(), u);
68  }
69 
70 protected:
72  ~BSplineDerivativeKernelFunction() override = default;
73 
74  void
75  PrintSelf(std::ostream & os, Indent indent) const override
76  {
77  Superclass::PrintSelf(os, indent);
78  os << indent << "Spline Order: " << SplineOrder << std::endl;
79  }
80 
81 private:
83  struct DispatchBase
84  {};
85  template <unsigned int>
86  struct Dispatch : public DispatchBase
87  {};
88 
90  inline TRealValueType
91  Evaluate(const Dispatch<0> &, const TRealValueType & itkNotUsed(u)) const
92  {
94  }
95 
97  inline TRealValueType
98  Evaluate(const Dispatch<1> &, const TRealValueType & u) const
99  {
101  {
102  return static_cast<TRealValueType>(0.5);
103  }
105  {
107  }
109  {
111  }
113  {
115  }
117  {
118  return static_cast<TRealValueType>(-0.5);
119  }
120  else
121  {
123  }
124  }
126 
128  inline TRealValueType
129  Evaluate(const Dispatch<2> &, const TRealValueType & u) const
130  {
131  if ((u > static_cast<TRealValueType>(-0.5)) && (u < static_cast<TRealValueType>(0.5)))
132  {
133  return (static_cast<TRealValueType>(-2.0) * u);
134  }
135  else if ((u >= static_cast<TRealValueType>(0.5)) && (u < static_cast<TRealValueType>(1.5)))
136  {
137  return (static_cast<TRealValueType>(-1.5) + u);
138  }
139  else if ((u > static_cast<TRealValueType>(-1.5)) && (u <= static_cast<TRealValueType>(-0.5)))
140  {
141  return (static_cast<TRealValueType>(1.5) + u);
142  }
143  else
144  {
146  }
147  }
149 
151  inline TRealValueType
152  Evaluate(const Dispatch<3> &, const TRealValueType & u) const
153  {
155  {
156  return (static_cast<TRealValueType>(-2.0) * u + static_cast<TRealValueType>(1.5) * u * u);
157  }
159  {
160  return (static_cast<TRealValueType>(-2.0) * u - static_cast<TRealValueType>(1.5) * u * u);
161  }
162  else if ((u >= NumericTraits<TRealValueType>::OneValue()) && (u < static_cast<TRealValueType>(2.0)))
163  {
164  return (static_cast<TRealValueType>(-2.0) + static_cast<TRealValueType>(2.0) * u -
165  static_cast<TRealValueType>(0.5) * u * u);
166  }
167  else if ((u > static_cast<TRealValueType>(-2.0)) && (u <= -NumericTraits<TRealValueType>::OneValue()))
168  {
169  return (static_cast<TRealValueType>(2.0) + static_cast<TRealValueType>(2.0) * u +
170  static_cast<TRealValueType>(0.5) * u * u);
171  }
172  else
173  {
175  }
176  }
178 
180  inline TRealValueType
181  Evaluate(const DispatchBase &, const TRealValueType &) const
182  {
183  itkExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
184  }
185 };
186 } // end namespace itk
188 
189 #endif
itk::KernelFunctionBase::RealType
TRealValueType RealType
Definition: itkKernelFunctionBase.h:52
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const TRealValueType &u) const override
Definition: itkBSplineDerivativeKernelFunction.h:65
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:723
itk::KernelFunctionBase
Kernel used for density estimation and nonparametric regression.
Definition: itkKernelFunctionBase.h:43
itk::BSplineDerivativeKernelFunction::Dispatch
Definition: itkBSplineDerivativeKernelFunction.h:86
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BSplineDerivativeKernelFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkBSplineDerivativeKernelFunction.h:75
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const Dispatch< 3 > &, const TRealValueType &u) const
Definition: itkBSplineDerivativeKernelFunction.h:152
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const Dispatch< 0 > &, const TRealValueType &) const
Definition: itkBSplineDerivativeKernelFunction.h:91
itk::BSplineDerivativeKernelFunction::~BSplineDerivativeKernelFunction
~BSplineDerivativeKernelFunction() override=default
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:156
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const Dispatch< 2 > &, const TRealValueType &u) const
Definition: itkBSplineDerivativeKernelFunction.h:129
itk::BSplineDerivativeKernelFunction::DispatchBase
Definition: itkBSplineDerivativeKernelFunction.h:83
itk::BSplineDerivativeKernelFunction::BSplineDerivativeKernelFunction
BSplineDerivativeKernelFunction()=default
itk::KernelFunctionBase::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkKernelFunctionBase.h:71
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itkBSplineKernelFunction.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::BSplineDerivativeKernelFunction
Derivative of a BSpline kernel used for density estimation and nonparametric regression.
Definition: itkBSplineDerivativeKernelFunction.h:43
itk::BSplineDerivativeKernelFunction::SplineOrder
static constexpr unsigned int SplineOrder
Definition: itkBSplineDerivativeKernelFunction.h:61
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const Dispatch< 1 > &, const TRealValueType &u) const
Definition: itkBSplineDerivativeKernelFunction.h:98
itk::BSplineDerivativeKernelFunction::Evaluate
TRealValueType Evaluate(const DispatchBase &, const TRealValueType &) const
Definition: itkBSplineDerivativeKernelFunction.h:181
itkMath.h
itk::BSplineDerivativeKernelFunction::RealType
typename Superclass::RealType RealType
Definition: itkBSplineDerivativeKernelFunction.h:53