]> Creatis software - clitk.git/blob - itk/clitkVectorBSplineInterpolateImageFunction.h
removed headers
[clitk.git] / itk / clitkVectorBSplineInterpolateImageFunction.h
1 #ifndef __clitkVectorBSplineInterpolateImageFunction_h
2 #define __clitkVectorBSplineInterpolateImageFunction_h
3 #include "clitkVectorBSplineDecompositionImageFilter.h"
4
5 // First make sure that the configuration is available.
6 // This line can be removed once the optimized versions
7 // gets integrated into the main directories.
8 #include "itkConfigure.h"
9
10 // #ifdef ITK_USE_OPTIMIZED_REGISTRATION_METHODS
11 // #include "itkOptBSplineInterpolateImageFunction.h"
12 // #else
13
14 #include <vector>
15
16 #include "itkImageLinearIteratorWithIndex.h"
17 #include "itkVectorInterpolateImageFunction.h"
18 #include "vnl/vnl_matrix.h"
19
20 #include "itkBSplineDecompositionImageFilter.h"
21 #include "itkConceptChecking.h"
22 #include "itkCovariantVector.h"
23
24
25 namespace clitk
26 {
27
28 template <
29   class TImageType, 
30   class TCoordRep = double,
31   class TCoefficientType = double >
32 class ITK_EXPORT VectorBSplineInterpolateImageFunction : 
33     public itk::VectorInterpolateImageFunction<TImageType,TCoordRep> 
34 {
35 public:
36   /** Standard class typedefs. */
37   typedef VectorBSplineInterpolateImageFunction       Self;
38   typedef itk::VectorInterpolateImageFunction<TImageType,TCoordRep>  Superclass;
39   typedef itk::SmartPointer<Self>                    Pointer;
40   typedef itk::SmartPointer<const Self>              ConstPointer;
41
42   /** Run-time type information (and related methods). */
43   itkTypeMacro(VectorBSplineInterpolateImageFunction, InterpolateImageFunction);
44
45
46   /** New macro for creation of through a Smart Pointer */
47   itkNewMacro( Self );
48
49   /** OutputType typedef support. */
50   typedef typename Superclass::OutputType OutputType;
51
52   /** InputImageType typedef support. */
53   typedef typename Superclass::InputImageType InputImageType;
54
55   /** Dimension underlying input image. */
56   itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
57
58   /** Index typedef support. */
59   typedef typename Superclass::IndexType IndexType;
60
61   /** ContinuousIndex typedef support. */
62   typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
63
64   /** PointType typedef support */
65   typedef typename Superclass::PointType PointType;
66
67   //JV the vector dimension
68   itkStaticConstMacro(VectorDimension, unsigned int,Superclass::Dimension);
69
70
71   /** Iterator typedef support */
72   typedef itk::ImageLinearIteratorWithIndex<TImageType> Iterator;
73
74   /** Internal Coefficient typedef support */
75   typedef TCoefficientType CoefficientDataType;
76
77   //JV
78   typedef itk::Vector<CoefficientDataType, itkGetStaticConstMacro(VectorDimension)> CoefficientImagePixelType;
79   typedef  itk::Image<CoefficientImagePixelType , itkGetStaticConstMacro(ImageDimension) > CoefficientImageType;
80
81   /** Define filter for calculating the BSpline coefficients */
82   //JV make vectorial
83   typedef clitk::VectorBSplineDecompositionImageFilter<TImageType, CoefficientImageType> 
84   CoefficientFilter;
85   typedef typename CoefficientFilter::Pointer CoefficientFilterPointer;
86
87   /** Evaluate the function at a ContinuousIndex position.
88    *
89    * Returns the B-Spline interpolated image intensity at a 
90    * specified point position. No bounds checking is done.
91    * The point is assume to lie within the image buffer.
92    *
93    * ImageFunction::IsInsideBuffer() can be used to check bounds before
94    * calling the method. */
95   virtual OutputType EvaluateAtContinuousIndex( 
96     const ContinuousIndexType & index ) const; 
97
98   /** Derivative typedef support */
99   typedef itk::CovariantVector<OutputType,
100                           itkGetStaticConstMacro(ImageDimension)
101     > CovariantVectorType;
102
103   CovariantVectorType EvaluateDerivative( const PointType & point ) const
104   {    
105     ContinuousIndexType index;
106     this->GetInputImage()->TransformPhysicalPointToContinuousIndex( point, index );
107     return ( this->EvaluateDerivativeAtContinuousIndex( index ) );
108   } 
109
110   CovariantVectorType EvaluateDerivativeAtContinuousIndex( 
111     const ContinuousIndexType & x ) const;
112
113
114   /** Get/Sets the Spline Order, supports 0th - 5th order splines. The default
115    *  is a 3rd order spline. */
116   void SetSplineOrder(unsigned int SplineOrder);
117   itkGetMacro(SplineOrder, int);
118
119
120   /** Set the input image.  This must be set by the user. */
121   virtual void SetInputImage(const TImageType * inputData);
122
123
124   /** The UseImageDirection flag determines whether image derivatives are
125    * computed with respect to the image grid or with respect to the physical
126    * space. When this flag is ON the derivatives are computed with respect to
127    * the coodinate system of physical space. The difference is whether we take
128    * into account the image Direction or not. The flag ON will take into
129    * account the image direction and will result in an extra matrix
130    * multiplication compared to the amount of computation performed when the
131    * flag is OFF.  This flag is OFF by default.*/
132   itkSetMacro( UseImageDirection, bool );
133   itkGetMacro( UseImageDirection, bool );
134   itkBooleanMacro( UseImageDirection );
135
136
137 protected:
138   VectorBSplineInterpolateImageFunction();
139   virtual ~VectorBSplineInterpolateImageFunction() {};
140   void operator=( const Self& ); //purposely not implemented
141   void PrintSelf(std::ostream& os, itk::Indent indent) const;
142
143   // These are needed by the smoothing spline routine.
144   std::vector<CoefficientDataType>    m_Scratch;        // temp storage for processing of Coefficients
145   typename TImageType::SizeType       m_DataLength;  // Image size
146   unsigned int                        m_SplineOrder; // User specified spline order (3rd or cubic is the default)
147
148   typename CoefficientImageType::ConstPointer       m_Coefficients; // Spline coefficients  
149
150 private:
151   VectorBSplineInterpolateImageFunction( const Self& ); //purposely not implemented
152   /** Determines the weights for interpolation of the value x */
153   void SetInterpolationWeights( const ContinuousIndexType & x, 
154                                 const vnl_matrix<long> & EvaluateIndex, 
155                                 vnl_matrix<double> & weights, 
156                                 unsigned int splineOrder ) const;
157
158   /** Determines the weights for the derivative portion of the value x */
159   void SetDerivativeWeights( const ContinuousIndexType & x, 
160                              const vnl_matrix<long> & EvaluateIndex, 
161                              vnl_matrix<double> & weights, 
162                              unsigned int splineOrder ) const;
163
164   /** Precomputation for converting the 1D index of the interpolation neighborhood 
165     * to an N-dimensional index. */
166   void GeneratePointsToIndex(  );
167
168   /** Determines the indicies to use give the splines region of support */
169   void DetermineRegionOfSupport( vnl_matrix<long> & evaluateIndex, 
170                                  const ContinuousIndexType & x, 
171                                  unsigned int splineOrder ) const;
172
173   /** Set the indicies in evaluateIndex at the boundaries based on mirror 
174     * boundary conditions. */
175   void ApplyMirrorBoundaryConditions(vnl_matrix<long> & evaluateIndex, 
176                                      unsigned int splineOrder) const;
177
178
179   Iterator                  m_CIterator;    // Iterator for traversing spline coefficients.
180   unsigned long             m_MaxNumberInterpolationPoints; // number of neighborhood points used for interpolation
181   std::vector<IndexType>    m_PointsToIndex;  // Preallocation of interpolation neighborhood indicies
182
183   CoefficientFilterPointer     m_CoefficientFilter;
184   
185   // flag to take or not the image direction into account when computing the
186   // derivatives.
187   bool m_UseImageDirection;
188
189
190 };
191
192 } // namespace itk
193
194 #ifndef ITK_MANUAL_INSTANTIATION
195 #include "clitkVectorBSplineInterpolateImageFunction.txx"
196 #endif
197
198 #endif
199
200 //#endif