]> Creatis software - clitk.git/blob - itk/clitkVectorBSplineInterpolateImageFunctionWithLUT.h
Initial revision
[clitk.git] / itk / clitkVectorBSplineInterpolateImageFunctionWithLUT.h
1 #ifndef __clitkVectorBSplineInterpolateImageFunctionWithLUT_h
2 #define __clitkVectorBSplineInterpolateImageFunctionWithLUT_h
3
4 /* =========================================================================
5                                                                                 
6   @file   clitVectorkBSplineInterpolateImageFunctionWithLUT.h
7   @author jefvdmb@gmail.com
8
9   Copyright (c) 
10   * CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). 
11     All rights reserved. See Doc/License.txt or
12     http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13   * Léon Bérard cancer center, 28 rue Laënnec, 69373 Lyon cedex 08, France
14   * http://www.creatis.insa-lyon.fr/rio
15                                                                                 
16   This software is distributed WITHOUT ANY WARRANTY; without even the
17   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18   PURPOSE.  See the above copyright notices for more information.
19                                                                              
20 ========================================================================= */
21
22 #include "itkBSplineWeightsCalculator.h"
23 //#include "clitkTimer.h"
24 #include "clitkVectorBSplineInterpolateImageFunction.h"
25
26 namespace clitk {
27   
28   template <
29     class TImageType, 
30     class TCoordRep = double,
31     class TCoefficientType = double >
32   class ITK_EXPORT VectorBSplineInterpolateImageFunctionWithLUT : 
33     public VectorBSplineInterpolateImageFunction<TImageType,TCoordRep,TCoefficientType> {
34     
35   public: 
36     /** Class typedefs */
37     typedef VectorBSplineInterpolateImageFunctionWithLUT<TImageType,TCoordRep, TCoefficientType> Self;
38     typedef VectorBSplineInterpolateImageFunction<TImageType,TCoordRep, TCoefficientType>  Superclass;
39     typedef itk::SmartPointer<Self> Pointer;
40     typedef itk::SmartPointer<const Self> ConstPointer;
41     typedef typename Superclass::OutputType OutputType;
42     typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
43     typedef typename TImageType::IndexType           IndexType;
44     typedef typename TImageType::IndexValueType      IndexValueType;
45     typedef typename TImageType::SizeType            SizeType;
46     typedef typename TImageType::SpacingType         SpacingType;
47
48     typedef TCoefficientType CoefficientDataType;
49     typedef typename Superclass::CoefficientImagePixelType CoefficientImagePixelType;
50     typedef typename Superclass::CoefficientImageType CoefficientImageType;
51
52     /** New macro for creation of through a Smart Pointer */
53     itkNewMacro(Self);
54     
55     /** Setting LUT sampling (one parameters by dimension or a single
56         one for all dim); Default is 10 (for each dim) **/
57     void SetLUTSamplingFactor(const int& s);
58     void SetLUTSamplingFactors(const SizeType& s);
59
60     /** Get/Sets the Spline Order, supports 0th - 5th order
61      *  splines. The default is a 3rd order spline. */
62     void SetSplineOrder(const unsigned int & SplineOrder);
63
64     //JV this is added to support different degrees over each dimension
65     void SetSplineOrders(const  SizeType & SplineOrders);
66
67     /** Set the input image.  This must be set by the user. */
68     virtual void SetInputImage(const TImageType * inputData);
69     //void SetOutputSpacing(const SpacingType & s);
70     //void SetInputImageIsCoefficient(bool inputIsCoef) { mInputIsCoef = inputIsCoef; }
71
72     /** Evaluate the function at a ContinuousIndex position.
73         Overwritten for taking LUT into account */  
74     virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index ) const;
75     void EvaluateWeightsAtContinuousIndex(const ContinuousIndexType &  x,  const TCoefficientType ** pweights, IndexType & evaluateIndex) const;
76
77     /** Static convenient functions to compute BSpline weights for
78         various order, dimension, sampling ... **/
79     static void ComputeBlendingWeights(int dim, int order, int sampling, TCoefficientType * weights);
80
81     /** Timer giving computation time for coefficients computation **/    
82     // const clitk::Timer & GetCoefTimer() const { return mCoefficientTimer; }    
83
84     /** Get estimated error **/
85
86     double GetIntrinsicError() const { return *mIntrinsecError; }
87     long   GetNumberOfError() const { return *mNumberOfError; }
88     double GetIntrinsicErrorMax() const { return *mIntrinsecErrorMax; }
89
90   protected:
91     VectorBSplineInterpolateImageFunctionWithLUT();
92     ~VectorBSplineInterpolateImageFunctionWithLUT(){;}
93
94     SizeType               mSupport;            // nb of coef values used for interpolation (order+1) in 1 dimension
95     SizeType               mHalfSupport;        // half size of the previous
96     unsigned int           mSupportSize;        // Total support size for all dimension
97     std::vector<int>       mSupportOffset;      // Memory pointer offset for going from one coef position to the other (inside the whole support)
98     std::vector<IndexType> mSupportIndex;       // nD Index of all support values
99     IndexType              mInputMemoryOffset;  // Memory dimension offsets for input image
100
101     /** Sampling factors for LUT weights **/
102     SizeType               mSamplingFactors;
103     bool                   mWeightsAreUpToDate;
104     //SpacingType            mOutputSpacing;
105
106     double                 * mIntrinsecError;
107     double                 * mIntrinsecErrorMax;
108     long                   * mNumberOfError;
109
110     //JV add iscoeff, and splineorders
111     // bool     mInputIsCoef;
112     SizeType mSplineOrders;
113
114     // Filter to compute weights
115     itk::BSplineWeightsCalculator<TCoefficientType,TImageType::ImageDimension> mWeightsCalculator;
116
117     // Convenient functions
118     void UpdatePrecomputedWeights();
119     void UpdateWeightsProperties();
120     IndexType GetSampleIndexOfPixelPosition(const ContinuousIndexType & x, IndexType & EvaluateIndex) const;
121
122     // Timing options
123     // clitk::Timer mCoefficientTimer;
124     // clitk::Timer mLUTTimer;
125     bool  mTimerEnabled;
126
127     //JV threadsafety: everything on the stack
128     //std::vector<int> mCorrectedSupportOffset;
129     //std::vector<IndexType> mCorrectedSupportIndex;
130     TCoefficientType * coef;
131
132   }; // end class clitkVectorBSplineInterpolateImageFunctionWithLUT
133 } // end namespace
134
135 #ifndef ITK_MANUAL_INSTANTIATION
136 #include "clitkVectorBSplineInterpolateImageFunctionWithLUT.txx"
137 #endif
138
139 #endif /* end #define CLITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H */