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