]> Creatis software - clitk.git/blob - itk/itkBSplineInterpolateImageFunctionWithLUT.h
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / itk / itkBSplineInterpolateImageFunctionWithLUT.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://www.centreleonberard.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 ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H
19 #define ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H
20
21 #include "itkBSplineWeightsCalculator.h"
22 #include <itkBSplineInterpolateImageFunction.h>
23
24 namespace itk {
25   
26   template <
27     class TImageType, 
28     class TCoordRep = double,
29     class TCoefficientType = double >
30   class ITK_EXPORT BSplineInterpolateImageFunctionWithLUT : 
31     public itk::BSplineInterpolateImageFunction<TImageType,TCoordRep,TCoefficientType> {
32     
33   public: 
34     /** Class typedefs */
35     typedef BSplineInterpolateImageFunctionWithLUT<TImageType,TCoordRep, TCoefficientType> Self;
36     typedef BSplineInterpolateImageFunction<TImageType,TCoordRep, TCoefficientType>  Superclass;
37     typedef SmartPointer<Self> Pointer;
38     typedef SmartPointer<const Self> ConstPointer;
39     typedef typename Superclass::OutputType OutputType;
40     typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
41     typedef typename TImageType::IndexType           IndexType;
42     typedef typename TImageType::IndexValueType      IndexValueType;
43     typedef typename TImageType::SizeType            SizeType;
44     typedef typename TImageType::SpacingType         SpacingType;
45
46     /** New macro for creation of through a Smart Pointer */
47     itkNewMacro(Self);
48     
49     /** Setting LUT sampling (one parameters by dimension or a single
50         one for all dim); Default is 20 (for each dim) **/
51     void SetLUTSamplingFactor(const int& s);
52     void SetLUTSamplingFactors(const SizeType& s);
53
54     /** Get/Sets the Spline Order, supports 0th - 5th order
55      *  splines. The default is a 3rd order spline. */
56     void SetSplineOrder(const unsigned int & SplineOrder);
57
58     //JV this is added to support different degrees over each dimension
59     void SetSplineOrders(const  SizeType & SplineOrders);
60
61     /** Set the input image.  This must be set by the user. */
62     virtual void SetInputImage(const TImageType * inputData);
63     
64     /** Evaluate the function at a ContinuousIndex position.
65   Overwritten for taking LUT into account (RP: multi-threading-compatible version, 
66   the threadID is actually ignored) */  
67     virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index, unsigned int /* threadID */ ) const
68     {
69       return this->EvaluateAtContinuousIndex( index );
70     }
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     
76     /** Static convenient functions to compute BSpline weights for
77         various order, dimension, sampling ... **/
78     static void ComputeBlendingWeights(int dim, int order, int sampling, TCoefficientType * weights);
79
80   protected:
81     BSplineInterpolateImageFunctionWithLUT();
82     ~BSplineInterpolateImageFunctionWithLUT(){;}
83
84     SizeType               mSupport;            // nb of coef values used for interpolation (order+1) in 1 dimension
85     SizeType               mHalfSupport;        // half size of the previous
86     unsigned int           mSupportSize;        // Total support size for all dimension
87     std::vector<int>       mSupportOffset;      // Memory pointer offset for going from one coef position to the other (inside the whole support)
88     std::vector<IndexType> mSupportIndex;       // nD Index of all support values
89     IndexType              mInputMemoryOffset;  // Memory dimension offsets for input image
90
91     /** Sampling factors for LUT weights **/
92     SizeType               mSamplingFactors;
93     bool                   mWeightsAreUpToDate;
94     SizeType mSplineOrders;
95
96     // Filter to compute weights
97     itk::BSplineWeightsCalculator<TCoefficientType,TImageType::ImageDimension> mWeightsCalculator;
98
99     // Convenient functions
100     void UpdatePrecomputedWeights();
101     void UpdateWeightsProperties();
102     IndexType GetSampleIndexOfPixelPosition(const ContinuousIndexType & x, IndexType & EvaluateIndex) const;
103
104
105   }; // end class itkBSplineInterpolateImageFunctionWithLUT
106 } // end namespace
107
108 #ifndef ITK_MANUAL_INSTANTIATION
109 #include "itkBSplineInterpolateImageFunctionWithLUT.txx"
110 #endif
111
112 #endif /* end #define ITKBSPLINEINTERPOLATEIMAGEFUNCTIONWITHLUT_H */