ITK  4.3.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 
23 namespace itk
24 {
41 template< unsigned int VSplineOrder = 3, typename TRealValueType = double >
42 class ITK_EXPORT BSplineDerivativeKernelFunction:public KernelFunctionBase<TRealValueType>
43 {
44 public:
49 
50  typedef typename Superclass::RealType RealType;
52  itkNewMacro(Self);
53 
56 
58  itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
59 
61  inline TRealValueType Evaluate( const TRealValueType & u ) const
62  {
63  return this->Evaluate( Dispatch< VSplineOrder >(), u );
64  }
65 
66 protected:
69 
70  void PrintSelf(std::ostream & os, Indent indent) const
71  {
72  Superclass::PrintSelf(os, indent);
73  os << indent << "Spline Order: " << SplineOrder << std::endl;
74  }
75 
76 private:
77  BSplineDerivativeKernelFunction(const Self &); //purposely not implemented
78  void operator=(const Self &); //purposely not implemented
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 >::One ) && ( u < NumericTraits< TRealValueType >::Zero ) )
100  {
102  }
104  {
106  }
107  else if( ( u > NumericTraits< TRealValueType >::Zero ) && ( u < NumericTraits< TRealValueType >::One ) )
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 >::One ) && ( 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 >::One ) )
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 >::Zero; // 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
182