]> Creatis software - clitk.git/blob - itk/itkBSplineInterpolateImageFunctionWithLUT.h
85b3436c970e2f400021327484f9aa265e16fe02
[clitk.git] / itk / itkBSplineInterpolateImageFunctionWithLUT.h
1 #ifndef ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H
2 #define ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H
3
4 /* =========================================================================
5                                                                                 
6   @file   itkBSplineInterpolateImageFunctionWithLUT.h
7   @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
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 <itkBSplineInterpolateImageFunction.h>
25
26 namespace itk {
27   
28   template <
29     class TImageType, 
30     class TCoordRep = double,
31     class TCoefficientType = double >
32   class ITK_EXPORT BSplineInterpolateImageFunctionWithLUT : 
33     public itk::BSplineInterpolateImageFunction<TImageType,TCoordRep,TCoefficientType> {
34     
35   public: 
36     /** Class typedefs */
37     typedef BSplineInterpolateImageFunctionWithLUT<TImageType,TCoordRep, TCoefficientType> Self;
38     typedef BSplineInterpolateImageFunction<TImageType,TCoordRep, TCoefficientType>  Superclass;
39     typedef SmartPointer<Self> Pointer;
40     typedef 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     /** New macro for creation of through a Smart Pointer */
49     itkNewMacro(Self);
50     
51     /** Setting LUT sampling (one parameters by dimension or a single
52         one for all dim); Default is 10 (for each dim) **/
53     void SetLUTSamplingFactor(const int& s);
54     void SetLUTSamplingFactors(const SizeType& s);
55
56     /** Get/Sets the Spline Order, supports 0th - 5th order
57      *  splines. The default is a 3rd order spline. */
58     void SetSplineOrder(const unsigned int & SplineOrder);
59
60     //JV this is added to support different degrees over each dimension
61     void SetSplineOrders(const  SizeType & SplineOrders);
62
63     /** Set the input image.  This must be set by the user. */
64     virtual void SetInputImage(const TImageType * inputData);
65     //void SetOutputSpacing(const SpacingType & s);
66     //void SetInputImageIsCoefficient(bool inputIsCoef) { mInputIsCoef = inputIsCoef; }
67
68     /** Evaluate the function at a ContinuousIndex position.
69         Overwritten for taking LUT into account */  
70     virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index ) const;
71     
72     /** Static convenient functions to compute BSpline weights for
73         various order, dimension, sampling ... **/
74     static void ComputeBlendingWeights(int dim, int order, int sampling, TCoefficientType * weights);
75
76     /** Timer giving computation time for coefficients computation **/    
77     // const clitk::Timer & GetCoefTimer() const { return mCoefficientTimer; }    
78
79     /** Get estimated error **/
80
81     double GetIntrinsicError() const { return *mIntrinsecError; }
82     long   GetNumberOfError() const { return *mNumberOfError; }
83     double GetIntrinsicErrorMax() const { return *mIntrinsecErrorMax; }
84
85   protected:
86     BSplineInterpolateImageFunctionWithLUT();
87     ~BSplineInterpolateImageFunctionWithLUT(){;}
88
89     SizeType               mSupport;            // nb of coef values used for interpolation (order+1) in 1 dimension
90     SizeType               mHalfSupport;        // half size of the previous
91     unsigned int           mSupportSize;        // Total support size for all dimension
92     std::vector<int>       mSupportOffset;      // Memory pointer offset for going from one coef position to the other (inside the whole support)
93     std::vector<IndexType> mSupportIndex;       // nD Index of all support values
94     IndexType              mInputMemoryOffset;  // Memory dimension offsets for input image
95
96     /** Sampling factors for LUT weights **/
97     SizeType               mSamplingFactors;
98     bool                   mWeightsAreUpToDate;
99     //SpacingType            mOutputSpacing;
100
101     double                 * mIntrinsecError;
102     double                 * mIntrinsecErrorMax;
103     long                   * mNumberOfError;
104
105     //JV add iscoeff, and splineorders
106     // bool     mInputIsCoef;
107     SizeType mSplineOrders;
108
109     // Filter to compute weights
110     itk::BSplineWeightsCalculator<TCoefficientType,TImageType::ImageDimension> mWeightsCalculator;
111
112     // Convenient functions
113     void UpdatePrecomputedWeights();
114     void UpdateWeightsProperties();
115     IndexType GetSampleIndexOfPixelPosition(const ContinuousIndexType & x, IndexType & EvaluateIndex) const;
116
117     // Timing options
118     // clitk::Timer mCoefficientTimer;
119     // clitk::Timer mLUTTimer;
120     bool  mTimerEnabled;
121
122     //JV threadsafety: everything on the stack
123     //std::vector<int> mCorrectedSupportOffset;
124     //std::vector<IndexType> mCorrectedSupportIndex;
125     TCoefficientType * coef;
126
127   }; // end class itkBSplineInterpolateImageFunctionWithLUT
128 } // end namespace
129
130 #ifndef ITK_MANUAL_INSTANTIATION
131 #include "itkBSplineInterpolateImageFunctionWithLUT.txx"
132 #endif
133
134 #endif /* end #define ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H */