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