KWStyle - itkBSplineKernelFunction.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkBSplineKernelFunction.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkBSplineKernelFunction_h
18 DEF #define _itkBSplineKernelFunction_h
19
20 #include "itkKernelFunction.h"
21 #include "vnl/vnl_math.h"
22
23 namespace itk
24 {
25
26 /** \class BSplineKernelFunction
27  * \brief BSpline kernel used for density estimation and nonparameteric
28  *  regression.
29  *
30  * This class enscapsulates BSpline kernel for
31  * density estimation or nonparameteric regression.
32  * See documentation for KernelFunction for more details.
33  *
34  * This class is templated over the spline order.
35  * \warning Evaluate is only implemented for spline order 0 to 3
36  *
37  * \sa KernelFunction
38  *
39  * \ingroup Functions
40  */
41 template <unsigned int VSplineOrder = 3>
42 class ITK_EXPORT BSplineKernelFunction : public KernelFunction
43 {
44 public:
45   /** Standard class typedefs. */
46   typedef BSplineKernelFunction Self;
47 TDA   typedef KernelFunction Superclass;
48 TDA   typedef SmartPointer<Self>  Pointer;
49
50   /** Method for creation through the object factory. */
51   itkNewMacro(Self); 
52
53   /** Run-time type information (and related methods). */
54   itkTypeMacro(BSplineKernelFunction, KernelFunction); 
55
56   /** Enum of for spline order. */
57   itkStaticConstMacro(SplineOrder, unsigned int, VSplineOrder);
58
59   /** Evaluate the function. */
60   inline double Evaluate( const double & u ) const
61     {
62     return this->Evaluate( Dispatch<VSplineOrder>(), u );
63     }
64
65 protected:
66   BSplineKernelFunction(){};
67   ~BSplineKernelFunction(){};
68   void PrintSelf(std::ostream& os, Indent indent) const
69     { 
70     Superclass::PrintSelf( os, indent ); 
71     os << indent  << "Spline Order: " << SplineOrder << std::endl;
72     }  
73
74 private:
75   BSplineKernelFunction(const Self&); //purposely not implemented
76   void operator=(const Self&); //purposely not implemented
77
78   /** Structures to control overloaded versions of Evaluate */
79   struct DispatchBase {};
80   template<unsigned int>
81   struct Dispatch : DispatchBase {};
82
83   /** Zeroth order spline. */
84   inline double Evaluate (const Dispatch<0>&, const double & u) const
85     {
86
87     double absValue = vnl_math_abs( u );
88
89     if ( absValue  < 0.5 )
90       {
91       return 1.0;
92       }
93     else if ( absValue == 0.5 )
94       {
95       return 0.5;
96       }
97     else
98       {
99       return 0.0;
100       }
101
102     }
103
104   /** First order spline */
105   inline double Evaluate ( const Dispatch<1>&, const double& u) const
106     {
107
108     double absValue = vnl_math_abs( u );
109
110     if ( absValue  < 1.0 )
111       {
112       return 1.0 - absValue;
113       }
114     else
115       {
116       return 0.0;
117       }
118
119     }
120
121   /** Second order spline. */
122   inline double Evaluate ( const Dispatch<2>&, const double& u) const
123     {
124
125     double absValue = vnl_math_abs( u );
126
127     if ( absValue  < 0.5 )
128       {
129       return 0.75 - vnl_math_sqr( absValue );
130       }
131     else if ( absValue < 1.5 )
132       {
133       return ( 9.0 - 12.0 * absValue + 4.0 * vnl_math_sqr( absValue ) ) / 8.0; 
134       }
135     else
136       {
137       return 0.0;
138       }
139
140     }
141
142   /**  Third order spline. */
143   inline double Evaluate ( const Dispatch<3>&, const double& u) const
144     {
145
146     double absValue = vnl_math_abs( u );
147     double sqrValue = vnl_math_sqr( u );
148
149     if ( absValue  < 1.0 )
150       {
151       return ( 4.0 - 6.0 * sqrValue + 3.0 * sqrValue * absValue ) / 6.0;
152       }
153     else if ( absValue < 2.0 )
154       {
155 LEN       return ( 8.0 - 12 * absValue + 6.0 * sqrValue - sqrValue * absValue ) / 6.0;
156       }
157     else
158       {
159       return 0.0;
160       }
161
162     }
163
164   /** Unimplemented spline order */
165   inline double Evaluate ( const DispatchBase&, const double&) const
166     {
167 LEN     itkExceptionMacro("Evaluate not implemented for spline order " << SplineOrder);
168 LEN     return 0.0; //This is to avoid compiler warning about missing return statement.  It should never be evaluated.
169     }
170
171 };
172
173
174 EML
175 // namespace itk
176
177 #endif
178

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:01PM
© Kitware Inc.