]> Creatis software - clitk.git/blob - itk/itkBSplineWeightsCalculator.h
18402e8919d33df431442b0b27291b6989f14cc5
[clitk.git] / itk / itkBSplineWeightsCalculator.h
1 /* =========================================================================
2                                                                                 
3   @file   itkBSplineWeightsCalculator.h
4   @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
5
6   Copyright (c) 
7   * CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). 
8     All rights reserved. See Doc/License.txt or
9     http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
10   * Léon Bérard cancer center, 28 rue Laënnec, 69373 Lyon cedex 08, France
11   * http://www.creatis.insa-lyon.fr/rio
12                                                                                 
13   This software is distributed WITHOUT ANY WARRANTY; without even the
14   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15   PURPOSE.  See the above copyright notices for more information.
16                                                                              
17 ========================================================================= */
18
19 #ifndef ITKBSPLINEWEIGHTSCALCULATOR_H
20 #define ITKBSPLINEWEIGHTSCALCULATOR_H
21
22 #include <vector>
23 #include <itkIndex.h>
24 #include <itkContinuousIndex.h>
25
26 namespace itk {
27   
28   //====================================================================
29   template<int VDimension>
30   typename Index<VDimension>::IndexValueType Index2Offset(const Index<VDimension> & index, 
31                                                           const Index<VDimension> & offsetTable);
32
33   //====================================================================
34   template<class TCoefficientType, int VDimension>
35   class BSplineWeightsCalculator {
36     
37   public: 
38     // Some typedef
39     typedef Index<VDimension> IndexType;
40     typedef Size<VDimension>  SizeType;
41     typedef ContinuousIndex<double, VDimension>         ContinuousIndexType;
42     typedef typename IndexType::IndexValueType          IndexValueType;
43     typedef typename SizeType::SizeValueType            SizeValueType;
44     typedef std::vector<std::vector<TCoefficientType> > InitialWeightsType;
45
46     // Constructor
47     BSplineWeightsCalculator();
48
49     // Set order of the spline (could be different in each dimension)
50     void SetSplineOrder(int splineOrder);
51     void SetSplineOrders(const SizeType & splineOrder);
52
53     // Set the sampling factor (could be different in each dimension)
54     void SetSamplingFactor(int sampling);
55     void SetSamplingFactors(const SizeType & sampling);
56     
57     // Main function : compute the tensor product at sampling positions
58     void ComputeTensorProducts();
59
60     // Must be used only after ComputeTensorProducts !
61     const TCoefficientType * GetFirstTensorProduct(const IndexType & index) const;
62
63   protected:
64     SizeType      mSplineOrders;
65     SizeType      mSplineSupport;
66     SizeType      mSamplingFactors;
67
68     // Number of points in the BSpline support
69     int                    mSupportSize;
70
71     // nD Index of all points in the BSpline support
72     std::vector<IndexType> mSupportIndex;
73
74     // mBasisFunctionCoefficientsMatrix : map of 2D matrix for basic function of arbitrary order
75     // Could be computed once for all if needed.
76     //       index map = BSpline order 
77     //               X = support size
78     //               Y = support size
79     std::map<int, InitialWeightsType> mBasisFunctionCoefficientsMatrix;
80
81     // mWeights : 3D array with  :
82     //            X = dimension number
83     //            Y = support position 1D index
84     //            Z = sampling position 1D index
85     std::vector<std::vector<std::vector<TCoefficientType> > > mWeights;
86     
87     // mTensorProducts : 2D array with :
88     //            X = sampling position 1D index
89     //            Y = support position 1D index
90     std::vector<std::vector<TCoefficientType> > mTensorProducts;
91
92
93     IndexType mTensorProductMemoryOffset;
94     
95     bool                mWeightsAreUpToDate;
96     std::map<int, bool> mBasisFunctionCoefficientsMatrixAreUpToDate;
97     bool                mTensorProductsAreUpToDate;
98
99     void ComputeSampledWeights();
100     void ComputeSampledWeights1D(std::vector<std::vector<TCoefficientType> > & w, int order, int sampling);
101     TCoefficientType BSplineEvaluate(int order, int b, double e);
102     InitialWeightsType & GetInitialWeights(int order);
103     void ComputeBasisFunctionCoefficientsMatrix(int order);
104     double BinomialCoefficient(int i, int j);
105
106   }; // end class itkBSplineWeightsCalculator
107
108 #include "itkBSplineWeightsCalculator.txx"
109
110 } // end namespace
111
112 #endif /* end #define ITKBSPLINEWEIGHTSCALCULATOR_H */
113