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