1 /* =========================================================================
3 @file itkBSplineWeightsCalculator.h
4 @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
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
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.
17 ========================================================================= */
19 #ifndef ITKBSPLINEWEIGHTSCALCULATOR_H
20 #define ITKBSPLINEWEIGHTSCALCULATOR_H
24 #include <itkContinuousIndex.h>
28 //====================================================================
29 template<int VDimension>
30 typename Index<VDimension>::IndexValueType Index2Offset(const Index<VDimension> & index,
31 const Index<VDimension> & offsetTable);
33 //====================================================================
34 template<class TCoefficientType, int VDimension>
35 class BSplineWeightsCalculator {
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;
47 BSplineWeightsCalculator();
49 // Set order of the spline (could be different in each dimension)
50 void SetSplineOrder(int splineOrder);
51 void SetSplineOrders(const SizeType & splineOrder);
53 // Set the sampling factor (could be different in each dimension)
54 void SetSamplingFactor(int sampling);
55 void SetSamplingFactors(const SizeType & sampling);
57 // Main function : compute the tensor product at sampling positions
58 void ComputeTensorProducts();
60 // Must be used only after ComputeTensorProducts !
61 const TCoefficientType * GetFirstTensorProduct(const IndexType & index) const;
64 SizeType mSplineOrders;
65 SizeType mSplineSupport;
66 SizeType mSamplingFactors;
68 // Number of points in the BSpline support
71 // nD Index of all points in the BSpline support
72 std::vector<IndexType> mSupportIndex;
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
79 std::map<int, InitialWeightsType> mBasisFunctionCoefficientsMatrix;
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;
87 // mTensorProducts : 2D array with :
88 // X = sampling position 1D index
89 // Y = support position 1D index
90 std::vector<std::vector<TCoefficientType> > mTensorProducts;
93 IndexType mTensorProductMemoryOffset;
95 bool mWeightsAreUpToDate;
96 std::map<int, bool> mBasisFunctionCoefficientsMatrixAreUpToDate;
97 bool mTensorProductsAreUpToDate;
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);
106 }; // end class itkBSplineWeightsCalculator
108 #include "itkBSplineWeightsCalculator.txx"
112 #endif /* end #define ITKBSPLINEWEIGHTSCALCULATOR_H */