ITK  4.13.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  TRealValueType Evaluate( const TRealValueType & u ) const ITK_OVERRIDE
63  {
64  return this->Evaluate( Dispatch< VSplineOrder >(), u );
65  }
66 
67 protected:
69  virtual ~BSplineDerivativeKernelFunction() ITK_OVERRIDE {}
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  ITK_DISALLOW_COPY_AND_ASSIGN(BSplineDerivativeKernelFunction);
79 
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  return NumericTraits< TRealValueType >::ZeroValue(); // This is to avoid compiler warning about missing
175  // return statement. It should never be evaluated.
176  }
177 };
178 } // end namespace itk
180 
181 #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:710
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.