ITK  4.9.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:
50 
51  typedef typename Superclass::RealType RealType;
53  itkNewMacro(Self);
54 
57 
59  itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
60 
62  inline TRealValueType Evaluate( const TRealValueType & u ) const ITK_OVERRIDE
63  {
64  return this->Evaluate( Dispatch< VSplineOrder >(), u );
65  }
66 
67 protected:
70 
71  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
72  {
73  Superclass::PrintSelf(os, indent);
74  os << indent << "Spline Order: " << SplineOrder << std::endl;
75  }
76 
77 private:
78  BSplineDerivativeKernelFunction(const Self &) ITK_DELETE_FUNCTION;
79  void operator=(const Self &) ITK_DELETE_FUNCTION;
80 
82  struct DispatchBase {};
83  template< unsigned int >
84  struct Dispatch: public DispatchBase {};
85 
87  inline TRealValueType Evaluate( const Dispatch<0>&, const TRealValueType & itkNotUsed( u ) )
88  const
89  {
91  }
92 
94  inline TRealValueType Evaluate( const Dispatch<1>&, const TRealValueType& u ) const
95  {
97  {
98  return static_cast< TRealValueType >(0.5);
99  }
100  else if( ( u > -NumericTraits< TRealValueType >::OneValue() ) && ( u < NumericTraits< TRealValueType >::ZeroValue() ) )
101  {
103  }
105  {
107  }
109  {
111  }
113  {
114  return static_cast< TRealValueType >(-0.5);
115  }
116  else
117  {
119  }
120  }
122 
124  inline TRealValueType Evaluate( const Dispatch<2>&, const TRealValueType& u) const
125  {
126  if( ( u > static_cast< TRealValueType >(-0.5) ) && ( u < static_cast< TRealValueType >(0.5) ) )
127  {
128  return ( static_cast< TRealValueType >(-2.0) * u );
129  }
130  else if( ( u >= static_cast< TRealValueType >(0.5) ) && ( u < static_cast< TRealValueType >(1.5) ) )
131  {
132  return ( static_cast< TRealValueType >(-1.5) + u );
133  }
134  else if( ( u > static_cast< TRealValueType >(-1.5) ) && ( u <= static_cast< TRealValueType >(-0.5) ) )
135  {
136  return ( static_cast< TRealValueType >(1.5) + u );
137  }
138  else
139  {
141  }
142  }
144 
146  inline TRealValueType Evaluate( const Dispatch<3>&, const TRealValueType& u ) const
147  {
149  {
150  return ( static_cast< TRealValueType >(-2.0)* u + static_cast< TRealValueType >(1.5) * u * u );
151  }
153  {
154  return ( static_cast< TRealValueType >(-2.0) * u - static_cast< TRealValueType >(1.5) * u * u );
155  }
156  else if( ( u >= NumericTraits< TRealValueType >::OneValue() ) && ( u < static_cast< TRealValueType >(2.0) ) )
157  {
158  return ( static_cast< TRealValueType >(-2.0) + static_cast< TRealValueType >(2.0) * u - static_cast< TRealValueType >(0.5) * u * u );
159  }
160  else if( ( u > static_cast< TRealValueType >(-2.0) ) && ( u <= -NumericTraits< TRealValueType >::OneValue() ) )
161  {
162  return ( static_cast< TRealValueType >(2.0) + static_cast< TRealValueType >(2.0) * u + static_cast< TRealValueType >(0.5) * u * u );
163  }
164  else
165  {
167  }
168  }
170 
172  inline TRealValueType Evaluate( const DispatchBase&, const TRealValueType& ) const
173  {
174  itkExceptionMacro( "Evaluate not implemented for spline order " << SplineOrder );
175  return NumericTraits< TRealValueType >::ZeroValue(); // This is to avoid compiler warning about missing
176  // return statement. It should never be evaluated.
177  }
178 };
179 } // end namespace itk
181 
182 #endif
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:665
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
KernelFunctionBase< TRealValueType > Superclass
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
Define additional traits for native types such as int or float.