ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkBSplineDerivativeKernelFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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_ASSIGN(BSplineDerivativeKernelFunction);
47 
52 
53  using RealType = typename Superclass::RealType;
55  itkNewMacro(Self);
56 
59 
61  static constexpr unsigned int SplineOrder = VSplineOrder;
62 
64  TRealValueType Evaluate( const TRealValueType & u ) const override
65  {
66  return this->Evaluate( Dispatch< VSplineOrder >(), u );
67  }
68 
69 protected:
71  ~BSplineDerivativeKernelFunction() override = default;
72 
73  void PrintSelf(std::ostream & os, Indent indent) const override
74  {
75  Superclass::PrintSelf(os, indent);
76  os << indent << "Spline Order: " << SplineOrder << std::endl;
77  }
78 
79 private:
81  struct DispatchBase {};
82  template< unsigned int >
83  struct Dispatch: public DispatchBase {};
84 
86  inline TRealValueType Evaluate( const Dispatch<0>&, const TRealValueType & itkNotUsed( u ) )
87  const
88  {
90  }
91 
93  inline TRealValueType Evaluate( const Dispatch<1>&, const TRealValueType& u ) const
94  {
96  {
97  return static_cast< TRealValueType >(0.5);
98  }
99  else if( ( u > -NumericTraits< TRealValueType >::OneValue() ) && ( u < NumericTraits< TRealValueType >::ZeroValue() ) )
100  {
102  }
104  {
106  }
108  {
110  }
112  {
113  return static_cast< TRealValueType >(-0.5);
114  }
115  else
116  {
118  }
119  }
121 
123  inline TRealValueType Evaluate( const Dispatch<2>&, const TRealValueType& u) const
124  {
125  if( ( u > static_cast< TRealValueType >(-0.5) ) && ( u < static_cast< TRealValueType >(0.5) ) )
126  {
127  return ( static_cast< TRealValueType >(-2.0) * u );
128  }
129  else if( ( u >= static_cast< TRealValueType >(0.5) ) && ( u < static_cast< TRealValueType >(1.5) ) )
130  {
131  return ( static_cast< TRealValueType >(-1.5) + u );
132  }
133  else if( ( u > static_cast< TRealValueType >(-1.5) ) && ( u <= static_cast< TRealValueType >(-0.5) ) )
134  {
135  return ( static_cast< TRealValueType >(1.5) + u );
136  }
137  else
138  {
140  }
141  }
143 
145  inline TRealValueType Evaluate( const Dispatch<3>&, const TRealValueType& u ) const
146  {
148  {
149  return ( static_cast< TRealValueType >(-2.0)* u + static_cast< TRealValueType >(1.5) * u * u );
150  }
152  {
153  return ( static_cast< TRealValueType >(-2.0) * u - static_cast< TRealValueType >(1.5) * u * u );
154  }
155  else if( ( u >= NumericTraits< TRealValueType >::OneValue() ) && ( u < static_cast< TRealValueType >(2.0) ) )
156  {
157  return ( static_cast< TRealValueType >(-2.0) + static_cast< TRealValueType >(2.0) * u - static_cast< TRealValueType >(0.5) * u * u );
158  }
159  else if( ( u > static_cast< TRealValueType >(-2.0) ) && ( u <= -NumericTraits< TRealValueType >::OneValue() ) )
160  {
161  return ( static_cast< TRealValueType >(2.0) + static_cast< TRealValueType >(2.0) * u + static_cast< TRealValueType >(0.5) * u * u );
162  }
163  else
164  {
166  }
167  }
169 
171  inline TRealValueType Evaluate( const DispatchBase&, const TRealValueType& ) const
172  {
173  itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
174  }
175 };
176 } // end namespace itk
178 
179 #endif
Define numeric traits for std::vector.
void PrintSelf(std::ostream &os, Indent indent) const override
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:707
TRealValueType Evaluate(const DispatchBase &, const TRealValueType &) const
Kernel used for density estimation and nonparameteric regression.
Derivative of a BSpline kernel used for density estimation and nonparameteric regression.
void PrintSelf(std::ostream &os, Indent indent) const override
TRealValueType Evaluate(const Dispatch< 2 > &, const TRealValueType &u) const
TRealValueType Evaluate(const Dispatch< 0 > &, const TRealValueType &) const
TRealValueType Evaluate(const Dispatch< 3 > &, const TRealValueType &u) const
TRealValueType Evaluate(const TRealValueType &u) const override
TRealValueType Evaluate(const Dispatch< 1 > &, const TRealValueType &u) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
~BSplineDerivativeKernelFunction() override=default