1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 /* =========================================================================
20 @file itkBSplineWeightsCalculator.h
21 @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
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
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.
34 ========================================================================= */
36 #ifndef ITKBSPLINEWEIGHTSCALCULATOR_H
37 #define ITKBSPLINEWEIGHTSCALCULATOR_H
41 #include <itkContinuousIndex.h>
45 //====================================================================
46 template<int VDimension>
47 typename Index<VDimension>::IndexValueType Index2Offset(const Index<VDimension> & index,
48 const Index<VDimension> & offsetTable);
50 //====================================================================
51 template<class TCoefficientType, int VDimension>
52 class BSplineWeightsCalculator {
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;
64 BSplineWeightsCalculator();
66 // Set order of the spline (could be different in each dimension)
67 void SetSplineOrder(int splineOrder);
68 void SetSplineOrders(const SizeType & splineOrder);
70 // Set the sampling factor (could be different in each dimension)
71 void SetSamplingFactor(int sampling);
72 void SetSamplingFactors(const SizeType & sampling);
74 // Main function : compute the tensor product at sampling positions
75 void ComputeTensorProducts();
77 // Must be used only after ComputeTensorProducts !
78 const TCoefficientType * GetFirstTensorProduct(const IndexType & index) const;
81 SizeType mSplineOrders;
82 SizeType mSplineSupport;
83 SizeType mSamplingFactors;
85 // Number of points in the BSpline support
88 // nD Index of all points in the BSpline support
89 std::vector<IndexType> mSupportIndex;
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
96 std::map<int, InitialWeightsType> mBasisFunctionCoefficientsMatrix;
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;
104 // mTensorProducts : 2D array with :
105 // X = sampling position 1D index
106 // Y = support position 1D index
107 std::vector<std::vector<TCoefficientType> > mTensorProducts;
110 IndexType mTensorProductMemoryOffset;
112 bool mWeightsAreUpToDate;
113 std::map<int, bool> mBasisFunctionCoefficientsMatrixAreUpToDate;
114 bool mTensorProductsAreUpToDate;
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);
123 }; // end class itkBSplineWeightsCalculator
125 #include "itkBSplineWeightsCalculator.txx"
129 #endif /* end #define ITKBSPLINEWEIGHTSCALCULATOR_H */