1 // Created on: 1995-08-28
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _PLib_HeaderFile
18 #define _PLib_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <TColStd_Array1OfReal.hxx>
25 #include <TColStd_Array2OfReal.hxx>
26 #include <TColgp_Array1OfPnt.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
28 #include <Standard_Real.hxx>
29 #include <Standard_Integer.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <TColgp_Array2OfPnt.hxx>
32 #include <GeomAbs_Shape.hxx>
35 class PLib_JacobiPolynomial;
36 class PLib_HermitJacobi;
37 class PLib_DoubleJacobiPolynomial;
40 //! PLib means Polynomial functions library. This pk
41 //! provides basic computation functions for
42 //! polynomial functions.
43 //! Note: weight arrays can be passed by pointer for
44 //! some functions so that NULL pointer is valid.
45 //! That means no weights passed.
53 //! Used as argument for a non rational functions
54 inline static TColStd_Array1OfReal* NoWeights()
59 //! Used as argument for a non rational functions
60 inline static TColStd_Array2OfReal* NoWeights2()
65 //! Copy in FP the coordinates of the poles.
66 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal& FP);
68 //! Copy in FP the coordinates of the poles.
69 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt& Poles, const TColStd_Array1OfReal& Weights, TColStd_Array1OfReal& FP);
71 //! Get from FP the coordinates of the poles.
72 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt& Poles);
74 //! Get from FP the coordinates of the poles.
75 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal& Weights);
77 //! Copy in FP the coordinates of the poles.
78 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal& FP);
80 //! Copy in FP the coordinates of the poles.
81 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt2d& Poles, const TColStd_Array1OfReal& Weights, TColStd_Array1OfReal& FP);
83 //! Get from FP the coordinates of the poles.
84 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt2d& Poles);
86 //! Get from FP the coordinates of the poles.
87 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal& Weights);
89 //! Returns the Binomial Cnp. N should be <= BSplCLib::MaxDegree().
90 Standard_EXPORT static Standard_Real Bin (const Standard_Integer N, const Standard_Integer P);
92 //! Computes the derivatives of a ratio at order
93 //! <N> in dimension <Dimension>.
95 //! <Ders> is an array containing the values of the
96 //! input derivatives from 0 to Min(<N>,<Degree>).
97 //! For orders higher than <Degree> the inputcd /s2d1/BMDL/
98 //! derivatives are assumed to be 0.
100 //! Content of <Ders> :
102 //! x(1),x(2),...,x(Dimension),w
103 //! x'(1),x'(2),...,x'(Dimension),w'
104 //! x''(1),x''(2),...,x''(Dimension),w''
106 //! If <All> is false, only the derivative at order
107 //! <N> is computed. <RDers> is an array of length
108 //! Dimension which will contain the result :
110 //! x(1)/w , x(2)/w , ... derivated <N> times
112 //! If <All> is true all the derivatives up to order
113 //! <N> are computed. <RDers> is an array of length
114 //! Dimension * (N+1) which will contains :
116 //! x(1)/w , x(2)/w , ...
117 //! x(1)/w , x(2)/w , ... derivated <1> times
118 //! x(1)/w , x(2)/w , ... derivated <2> times
120 //! x(1)/w , x(2)/w , ... derivated <N> times
122 //! Warning: <RDers> must be dimensionned properly.
123 Standard_EXPORT static void RationalDerivative (const Standard_Integer Degree, const Standard_Integer N, const Standard_Integer Dimension, Standard_Real& Ders, Standard_Real& RDers, const Standard_Boolean All = Standard_True);
125 //! Computes DerivativesRequest derivatives of a ratio at
126 //! of a BSpline function of degree <Degree>
127 //! dimension <Dimension>.
129 //! <PolesDerivatives> is an array containing the values
130 //! of the input derivatives from 0 to <DerivativeRequest>
131 //! For orders higher than <Degree> the input
132 //! derivatives are assumed to be 0.
134 //! Content of <PoleasDerivatives> :
136 //! x(1),x(2),...,x(Dimension)
137 //! x'(1),x'(2),...,x'(Dimension)
138 //! x''(1),x''(2),...,x''(Dimension)
140 //! WeightsDerivatives is an array that contains derivatives
141 //! from 0 to <DerivativeRequest>
142 //! After returning from the routine the array
143 //! RationalDerivatives contains the following
144 //! x(1)/w , x(2)/w , ...
145 //! x(1)/w , x(2)/w , ... derivated once
146 //! x(1)/w , x(2)/w , ... twice
147 //! x(1)/w , x(2)/w , ... derivated <DerivativeRequest> times
149 //! The array RationalDerivatives and PolesDerivatives
150 //! can be same since the overwrite is non destructive within
153 //! Warning: <RationalDerivates> must be dimensionned properly.
154 Standard_EXPORT static void RationalDerivatives (const Standard_Integer DerivativesRequest, const Standard_Integer Dimension, Standard_Real& PolesDerivatives, Standard_Real& WeightsDerivatives, Standard_Real& RationalDerivates);
156 //! Performs Horner method with synthethic division
158 //! parameter <U>, with <Degree> and <Dimension>.
159 //! PolynomialCoeff are stored in the following fashion
160 //! c0(1) c0(2) .... c0(Dimension)
161 //! c1(1) c1(2) .... c1(Dimension)
163 //! cDegree(1) cDegree(2) .... cDegree(Dimension)
164 //! where the polynomial is defined as :
167 //! c0 + c1 X + c2 X + .... cDegree X
169 //! Results stores the result in the following format
171 //! f(1) f(2) .... f(Dimension)
173 //! f (1) f (2) .... f (Dimension)
175 //! (DerivativeRequest) (DerivativeRequest)
176 //! f (1) f (Dimension)
178 //! this just evaluates the point at parameter U
180 //! Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
181 Standard_EXPORT static void EvalPolynomial (const Standard_Real U, const Standard_Integer DerivativeOrder, const Standard_Integer Degree, const Standard_Integer Dimension, Standard_Real& PolynomialCoeff, Standard_Real& Results);
183 //! Same as above with DerivativeOrder = 0;
184 Standard_EXPORT static void NoDerivativeEvalPolynomial (const Standard_Real U, const Standard_Integer Degree, const Standard_Integer Dimension, const Standard_Integer DegreeDimension, Standard_Real& PolynomialCoeff, Standard_Real& Results);
186 //! Applies EvalPolynomial twice to evaluate the derivative
187 //! of orders UDerivativeOrder in U, VDerivativeOrder in V
188 //! at parameters U,V
190 //! PolynomialCoeff are stored in the following fashion
191 //! c00(1) .... c00(Dimension)
192 //! c10(1) .... c10(Dimension)
194 //! cm0(1) .... cm0(Dimension)
196 //! c01(1) .... c01(Dimension)
197 //! c11(1) .... c11(Dimension)
199 //! cm1(1) .... cm1(Dimension)
201 //! c0n(1) .... c0n(Dimension)
202 //! c1n(1) .... c1n(Dimension)
204 //! cmn(1) .... cmn(Dimension)
206 //! where the polynomial is defined as :
208 //! c00 + c10 U + c20 U + .... + cm0 U
210 //! + c01 V + c11 UV + c21 U V + .... + cm1 U V
212 //! + .... + c0n V + .... + cmn U V
214 //! with m = UDegree and n = VDegree
216 //! Results stores the result in the following format
218 //! f(1) f(2) .... f(Dimension)
220 //! Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
221 Standard_EXPORT static void EvalPoly2Var (const Standard_Real U, const Standard_Real V, const Standard_Integer UDerivativeOrder, const Standard_Integer VDerivativeOrder, const Standard_Integer UDegree, const Standard_Integer VDegree, const Standard_Integer Dimension, Standard_Real& PolynomialCoeff, Standard_Real& Results);
223 //! Performs the Lagrange Interpolation of
224 //! given series of points with given parameters
225 //! with the requested derivative order
226 //! Results will store things in the following format
227 //! with d = DerivativeOrder
229 //! [0], [Dimension-1] : value
230 //! [Dimension], [Dimension + Dimension-1] : first derivative
232 //! [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
233 Standard_EXPORT static Standard_Integer EvalLagrange (const Standard_Real U, const Standard_Integer DerivativeOrder, const Standard_Integer Degree, const Standard_Integer Dimension, Standard_Real& ValueArray, Standard_Real& ParameterArray, Standard_Real& Results);
235 //! Performs the Cubic Hermite Interpolation of
236 //! given series of points with given parameters
237 //! with the requested derivative order.
238 //! ValueArray stores the value at the first and
239 //! last parameter. It has the following format :
240 //! [0], [Dimension-1] : value at first param
241 //! [Dimension], [Dimension + Dimension-1] : value at last param
242 //! Derivative array stores the value of the derivatives
243 //! at the first parameter and at the last parameter
244 //! in the following format
245 //! [0], [Dimension-1] : derivative at
247 //! [Dimension], [Dimension + Dimension-1] : derivative at
250 //! ParameterArray stores the first and last parameter
251 //! in the following format :
252 //! [0] : first parameter
253 //! [1] : last parameter
255 //! Results will store things in the following format
256 //! with d = DerivativeOrder
258 //! [0], [Dimension-1] : value
259 //! [Dimension], [Dimension + Dimension-1] : first derivative
261 //! [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
262 Standard_EXPORT static Standard_Integer EvalCubicHermite (const Standard_Real U, const Standard_Integer DerivativeOrder, const Standard_Integer Dimension, Standard_Real& ValueArray, Standard_Real& DerivativeArray, Standard_Real& ParameterArray, Standard_Real& Results);
264 //! This build the coefficient of Hermite's polynomes on
265 //! [FirstParameter, LastParameter]
267 //! if j <= FirstOrder+1 then
269 //! MatrixCoefs[i, j] = ith coefficient of the polynome H0,j-1
273 //! MatrixCoefs[i, j] = ith coefficient of the polynome H1,k
274 //! with k = j - FirstOrder - 2
277 //! - |FirstParameter| > 100
278 //! - |LastParameter| > 100
279 //! - |FirstParameter| +|LastParameter| < 1/100
280 //! - |LastParameter - FirstParameter|
281 //! / (|FirstParameter| +|LastParameter|) < 1/100
282 Standard_EXPORT static Standard_Boolean HermiteCoefficients (const Standard_Real FirstParameter, const Standard_Real LastParameter, const Standard_Integer FirstOrder, const Standard_Integer LastOrder, math_Matrix& MatrixCoefs);
284 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array1OfPnt& Coefs, const TColStd_Array1OfReal* WCoefs, TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal* WPoles);
286 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array1OfPnt2d& Coefs, const TColStd_Array1OfReal* WCoefs, TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal* WPoles);
288 Standard_EXPORT static void CoefficientsPoles (const TColStd_Array1OfReal& Coefs, const TColStd_Array1OfReal* WCoefs, TColStd_Array1OfReal& Poles, TColStd_Array1OfReal* WPoles);
290 Standard_EXPORT static void CoefficientsPoles (const Standard_Integer dim, const TColStd_Array1OfReal& Coefs, const TColStd_Array1OfReal* WCoefs, TColStd_Array1OfReal& Poles, TColStd_Array1OfReal* WPoles);
292 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array1OfPnt& Coeffs, TColStd_Array1OfReal* WCoeffs);
294 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array1OfPnt2d& Coeffs, TColStd_Array1OfReal* WCoeffs);
296 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColStd_Array1OfReal& Coeffs, TColStd_Array1OfReal* WCoeffs);
298 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, const Standard_Integer dim, TColStd_Array1OfReal& Coeffs, TColStd_Array1OfReal* WCoeffs);
300 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array2OfPnt& Coefs, const TColStd_Array2OfReal* WCoefs, TColgp_Array2OfPnt& Poles, TColStd_Array2OfReal* WPoles);
302 Standard_EXPORT static void UTrimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array2OfPnt& Coeffs, TColStd_Array2OfReal* WCoeffs);
304 Standard_EXPORT static void VTrimming (const Standard_Real V1, const Standard_Real V2, TColgp_Array2OfPnt& Coeffs, TColStd_Array2OfReal* WCoeffs);
306 //! Compute the coefficients in the canonical base of the
307 //! polynomial satisfying the given constraints
308 //! at the given parameters
309 //! The array FirstContr(i,j) i=1,Dimension j=0,FirstOrder
310 //! contains the values of the constraint at parameter FirstParameter
311 //! idem for LastConstr
312 Standard_EXPORT static Standard_Boolean HermiteInterpolate (const Standard_Integer Dimension, const Standard_Real FirstParameter, const Standard_Real LastParameter, const Standard_Integer FirstOrder, const Standard_Integer LastOrder, const TColStd_Array2OfReal& FirstConstr, const TColStd_Array2OfReal& LastConstr, TColStd_Array1OfReal& Coefficients);
314 //! Compute the number of points used for integral
315 //! computations (NbGaussPoints) and the degree of Jacobi
316 //! Polynomial (WorkDegree).
317 //! ConstraintOrder has to be GeomAbs_C0, GeomAbs_C1 or GeomAbs_C2
318 //! Code: Code d' init. des parametres de discretisation.
324 //! = 1 calcul rapide avec precision moyenne.
325 //! = 2 calcul rapide avec meilleure precision.
326 //! = 3 calcul un peu plus lent avec bonne precision.
327 //! = 4 calcul lent avec la meilleure precision possible.
328 Standard_EXPORT static void JacobiParameters (const GeomAbs_Shape ConstraintOrder, const Standard_Integer MaxDegree, const Standard_Integer Code, Standard_Integer& NbGaussPoints, Standard_Integer& WorkDegree);
330 //! translates from GeomAbs_Shape to Integer
331 Standard_EXPORT static Standard_Integer NivConstr (const GeomAbs_Shape ConstraintOrder);
333 //! translates from Integer to GeomAbs_Shape
334 Standard_EXPORT static GeomAbs_Shape ConstraintOrder (const Standard_Integer NivConstr);
336 Standard_EXPORT static void EvalLength (const Standard_Integer Degree, const Standard_Integer Dimension, Standard_Real& PolynomialCoeff, const Standard_Real U1, const Standard_Real U2, Standard_Real& Length);
338 Standard_EXPORT static void EvalLength (const Standard_Integer Degree, const Standard_Integer Dimension, Standard_Real& PolynomialCoeff, const Standard_Real U1, const Standard_Real U2, const Standard_Real Tol, Standard_Real& Length, Standard_Real& Error);
354 friend class PLib_Base;
355 friend class PLib_JacobiPolynomial;
356 friend class PLib_HermitJacobi;
357 friend class PLib_DoubleJacobiPolynomial;
361 #endif // _PLib_HeaderFile