1 #ifndef __clitkVectorBSplineInterpolateImageFunction_h
2 #define __clitkVectorBSplineInterpolateImageFunction_h
3 #include "clitkVectorBSplineDecompositionImageFilter.h"
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"
10 // #ifdef ITK_USE_OPTIMIZED_REGISTRATION_METHODS
11 // #include "itkOptBSplineInterpolateImageFunction.h"
16 #include "itkImageLinearIteratorWithIndex.h"
17 #include "itkVectorInterpolateImageFunction.h"
18 #include "vnl/vnl_matrix.h"
20 #include "itkBSplineDecompositionImageFilter.h"
21 #include "itkConceptChecking.h"
22 #include "itkCovariantVector.h"
30 class TCoordRep = double,
31 class TCoefficientType = double >
32 class ITK_EXPORT VectorBSplineInterpolateImageFunction :
33 public itk::VectorInterpolateImageFunction<TImageType,TCoordRep>
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;
42 /** Run-time type information (and related methods). */
43 itkTypeMacro(VectorBSplineInterpolateImageFunction, InterpolateImageFunction);
46 /** New macro for creation of through a Smart Pointer */
49 /** OutputType typedef support. */
50 typedef typename Superclass::OutputType OutputType;
52 /** InputImageType typedef support. */
53 typedef typename Superclass::InputImageType InputImageType;
55 /** Dimension underlying input image. */
56 itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
58 /** Index typedef support. */
59 typedef typename Superclass::IndexType IndexType;
61 /** ContinuousIndex typedef support. */
62 typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
64 /** PointType typedef support */
65 typedef typename Superclass::PointType PointType;
67 //JV the vector dimension
68 itkStaticConstMacro(VectorDimension, unsigned int,Superclass::Dimension);
71 /** Iterator typedef support */
72 typedef itk::ImageLinearIteratorWithIndex<TImageType> Iterator;
74 /** Internal Coefficient typedef support */
75 typedef TCoefficientType CoefficientDataType;
78 typedef itk::Vector<CoefficientDataType, itkGetStaticConstMacro(VectorDimension)> CoefficientImagePixelType;
79 typedef itk::Image<CoefficientImagePixelType , itkGetStaticConstMacro(ImageDimension) > CoefficientImageType;
81 /** Define filter for calculating the BSpline coefficients */
83 typedef clitk::VectorBSplineDecompositionImageFilter<TImageType, CoefficientImageType>
85 typedef typename CoefficientFilter::Pointer CoefficientFilterPointer;
87 /** Evaluate the function at a ContinuousIndex position.
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.
93 * ImageFunction::IsInsideBuffer() can be used to check bounds before
94 * calling the method. */
95 virtual OutputType EvaluateAtContinuousIndex(
96 const ContinuousIndexType & index ) const;
98 /** Derivative typedef support */
99 typedef itk::CovariantVector<OutputType,
100 itkGetStaticConstMacro(ImageDimension)
101 > CovariantVectorType;
103 CovariantVectorType EvaluateDerivative( const PointType & point ) const
105 ContinuousIndexType index;
106 this->GetInputImage()->TransformPhysicalPointToContinuousIndex( point, index );
107 return ( this->EvaluateDerivativeAtContinuousIndex( index ) );
110 CovariantVectorType EvaluateDerivativeAtContinuousIndex(
111 const ContinuousIndexType & x ) const;
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);
120 /** Set the input image. This must be set by the user. */
121 virtual void SetInputImage(const TImageType * inputData);
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 );
138 VectorBSplineInterpolateImageFunction();
139 virtual ~VectorBSplineInterpolateImageFunction() {};
140 void operator=( const Self& ); //purposely not implemented
141 void PrintSelf(std::ostream& os, itk::Indent indent) const;
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)
148 typename CoefficientImageType::ConstPointer m_Coefficients; // Spline coefficients
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;
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;
164 /** Precomputation for converting the 1D index of the interpolation neighborhood
165 * to an N-dimensional index. */
166 void GeneratePointsToIndex( );
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;
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;
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
183 CoefficientFilterPointer m_CoefficientFilter;
185 // flag to take or not the image direction into account when computing the
187 bool m_UseImageDirection;
194 #ifndef ITK_MANUAL_INSTANTIATION
195 #include "clitkVectorBSplineInterpolateImageFunction.txx"