0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / PLib / PLib.hxx
CommitLineData
42cf5bc1 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
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _PLib_HeaderFile
18#define _PLib_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
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>
33class math_Matrix;
34class PLib_Base;
35class PLib_JacobiPolynomial;
36class PLib_HermitJacobi;
37class PLib_DoubleJacobiPolynomial;
38
39
40//! PLib means Polynomial functions library. This pk
41//! provides basic computation functions for
42//! polynomial functions.
43class PLib
44{
45public:
46
47 DEFINE_STANDARD_ALLOC
48
49
50 //! Used as argument for a non rational functions
51 static TColStd_Array1OfReal& NoWeights();
52
53 //! Used as argument for a non rational functions
54 static TColStd_Array2OfReal& NoWeights2();
55
56 //! Copy in FP the coordinates of the poles.
57 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal& FP);
58
59 //! Copy in FP the coordinates of the poles.
60 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt& Poles, const TColStd_Array1OfReal& Weights, TColStd_Array1OfReal& FP);
61
62 //! Get from FP the coordinates of the poles.
63 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt& Poles);
64
65 //! Get from FP the coordinates of the poles.
66 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal& Weights);
67
68 //! Copy in FP the coordinates of the poles.
69 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal& FP);
70
71 //! Copy in FP the coordinates of the poles.
72 Standard_EXPORT static void SetPoles (const TColgp_Array1OfPnt2d& Poles, const TColStd_Array1OfReal& Weights, TColStd_Array1OfReal& FP);
73
74 //! Get from FP the coordinates of the poles.
75 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt2d& Poles);
76
77 //! Get from FP the coordinates of the poles.
78 Standard_EXPORT static void GetPoles (const TColStd_Array1OfReal& FP, TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal& Weights);
79
80 //! Returns the Binomial Cnp. N should be <= BSplCLib::MaxDegree().
81 Standard_EXPORT static Standard_Real Bin (const Standard_Integer N, const Standard_Integer P);
82
83 //! Computes the derivatives of a ratio at order
84 //! <N> in dimension <Dimension>.
85 //!
86 //! <Ders> is an array containing the values of the
87 //! input derivatives from 0 to Min(<N>,<Degree>).
88 //! For orders higher than <Degree> the inputcd /s2d1/BMDL/
89 //! derivatives are assumed to be 0.
90 //!
91 //! Content of <Ders> :
92 //!
93 //! x(1),x(2),...,x(Dimension),w
94 //! x'(1),x'(2),...,x'(Dimension),w'
95 //! x''(1),x''(2),...,x''(Dimension),w''
96 //!
97 //! If <All> is false, only the derivative at order
98 //! <N> is computed. <RDers> is an array of length
99 //! Dimension which will contain the result :
100 //!
101 //! x(1)/w , x(2)/w , ... derivated <N> times
102 //!
103 //! If <All> is true all the derivatives up to order
104 //! <N> are computed. <RDers> is an array of length
105 //! Dimension * (N+1) which will contains :
106 //!
107 //! x(1)/w , x(2)/w , ...
108 //! x(1)/w , x(2)/w , ... derivated <1> times
109 //! x(1)/w , x(2)/w , ... derivated <2> times
110 //! ...
111 //! x(1)/w , x(2)/w , ... derivated <N> times
112 //!
113 //! Warning: <RDers> must be dimensionned properly.
114 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);
115
116 //! Computes DerivativesRequest derivatives of a ratio at
117 //! of a BSpline function of degree <Degree>
118 //! dimension <Dimension>.
119 //!
120 //! <PolesDerivatives> is an array containing the values
121 //! of the input derivatives from 0 to <DerivativeRequest>
122 //! For orders higher than <Degree> the input
123 //! derivatives are assumed to be 0.
124 //!
125 //! Content of <PoleasDerivatives> :
126 //!
127 //! x(1),x(2),...,x(Dimension)
128 //! x'(1),x'(2),...,x'(Dimension)
129 //! x''(1),x''(2),...,x''(Dimension)
130 //!
131 //! WeightsDerivatives is an array that contains derivatives
132 //! from 0 to <DerivativeRequest>
133 //! After returning from the routine the array
134 //! RationalDerivatives contains the following
135 //! x(1)/w , x(2)/w , ...
136 //! x(1)/w , x(2)/w , ... derivated once
137 //! x(1)/w , x(2)/w , ... twice
138 //! x(1)/w , x(2)/w , ... derivated <DerivativeRequest> times
139 //!
140 //! The array RationalDerivatives and PolesDerivatives
141 //! can be same since the overwrite is non destructive within
142 //! the algorithm
143 //!
144 //! Warning: <RationalDerivates> must be dimensionned properly.
145 Standard_EXPORT static void RationalDerivatives (const Standard_Integer DerivativesRequest, const Standard_Integer Dimension, Standard_Real& PolesDerivatives, Standard_Real& WeightsDerivatives, Standard_Real& RationalDerivates);
146
147 //! Performs Horner method with synthethic division
148 //! for derivatives
149 //! parameter <U>, with <Degree> and <Dimension>.
150 //! PolynomialCoeff are stored in the following fashion
151 //! c0(1) c0(2) .... c0(Dimension)
152 //! c1(1) c1(2) .... c1(Dimension)
153 //!
154 //! cDegree(1) cDegree(2) .... cDegree(Dimension)
155 //! where the polynomial is defined as :
156 //!
157 //! 2 Degree
158 //! c0 + c1 X + c2 X + .... cDegree X
159 //!
160 //! Results stores the result in the following format
161 //!
162 //! f(1) f(2) .... f(Dimension)
163 //! (1) (1) (1)
164 //! f (1) f (2) .... f (Dimension)
165 //!
166 //! (DerivativeRequest) (DerivativeRequest)
167 //! f (1) f (Dimension)
168 //!
169 //! this just evaluates the point at parameter U
170 //!
171 //! Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
172 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);
173
174 //! Same as above with DerivativeOrder = 0;
175 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);
176
177 //! Applies EvalPolynomial twice to evaluate the derivative
178 //! of orders UDerivativeOrder in U, VDerivativeOrder in V
179 //! at parameters U,V
180 //!
181 //! PolynomialCoeff are stored in the following fashion
182 //! c00(1) .... c00(Dimension)
183 //! c10(1) .... c10(Dimension)
184 //! ....
185 //! cm0(1) .... cm0(Dimension)
186 //! ....
187 //! c01(1) .... c01(Dimension)
188 //! c11(1) .... c11(Dimension)
189 //! ....
190 //! cm1(1) .... cm1(Dimension)
191 //! ....
192 //! c0n(1) .... c0n(Dimension)
193 //! c1n(1) .... c1n(Dimension)
194 //! ....
195 //! cmn(1) .... cmn(Dimension)
196 //!
197 //! where the polynomial is defined as :
198 //! 2 m
199 //! c00 + c10 U + c20 U + .... + cm0 U
200 //! 2 m
201 //! + c01 V + c11 UV + c21 U V + .... + cm1 U V
202 //! n m n
203 //! + .... + c0n V + .... + cmn U V
204 //!
205 //! with m = UDegree and n = VDegree
206 //!
207 //! Results stores the result in the following format
208 //!
209 //! f(1) f(2) .... f(Dimension)
210 //!
211 //! Warning: <Results> and <PolynomialCoeff> must be dimensioned properly
212 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);
213
214 //! Performs the Lagrange Interpolation of
215 //! given series of points with given parameters
216 //! with the requested derivative order
217 //! Results will store things in the following format
218 //! with d = DerivativeOrder
219 //!
220 //! [0], [Dimension-1] : value
221 //! [Dimension], [Dimension + Dimension-1] : first derivative
222 //!
223 //! [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
224 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);
225
226 //! Performs the Cubic Hermite Interpolation of
227 //! given series of points with given parameters
228 //! with the requested derivative order.
229 //! ValueArray stores the value at the first and
230 //! last parameter. It has the following format :
231 //! [0], [Dimension-1] : value at first param
232 //! [Dimension], [Dimension + Dimension-1] : value at last param
233 //! Derivative array stores the value of the derivatives
234 //! at the first parameter and at the last parameter
235 //! in the following format
236 //! [0], [Dimension-1] : derivative at
237 //! first param
238 //! [Dimension], [Dimension + Dimension-1] : derivative at
239 //! last param
240 //!
241 //! ParameterArray stores the first and last parameter
242 //! in the following format :
243 //! [0] : first parameter
244 //! [1] : last parameter
245 //!
246 //! Results will store things in the following format
247 //! with d = DerivativeOrder
248 //!
249 //! [0], [Dimension-1] : value
250 //! [Dimension], [Dimension + Dimension-1] : first derivative
251 //!
252 //! [d *Dimension], [d*Dimension + Dimension-1]: dth derivative
253 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);
254
255 //! This build the coefficient of Hermite's polynomes on
256 //! [FirstParameter, LastParameter]
257 //!
258 //! if j <= FirstOrder+1 then
259 //!
260 //! MatrixCoefs[i, j] = ith coefficient of the polynome H0,j-1
261 //!
262 //! else
263 //!
264 //! MatrixCoefs[i, j] = ith coefficient of the polynome H1,k
265 //! with k = j - FirstOrder - 2
266 //!
267 //! return false if
268 //! - |FirstParameter| > 100
269 //! - |LastParameter| > 100
270 //! - |FirstParameter| +|LastParameter| < 1/100
271 //! - |LastParameter - FirstParameter|
272 //! / (|FirstParameter| +|LastParameter|) < 1/100
273 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);
274
275 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array1OfPnt& Coefs, const TColStd_Array1OfReal& WCoefs, TColgp_Array1OfPnt& Poles, TColStd_Array1OfReal& WPoles);
276
277 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array1OfPnt2d& Coefs, const TColStd_Array1OfReal& WCoefs, TColgp_Array1OfPnt2d& Poles, TColStd_Array1OfReal& WPoles);
278
279 Standard_EXPORT static void CoefficientsPoles (const TColStd_Array1OfReal& Coefs, const TColStd_Array1OfReal& WCoefs, TColStd_Array1OfReal& Poles, TColStd_Array1OfReal& WPoles);
280
281 Standard_EXPORT static void CoefficientsPoles (const Standard_Integer dim, const TColStd_Array1OfReal& Coefs, const TColStd_Array1OfReal& WCoefs, TColStd_Array1OfReal& Poles, TColStd_Array1OfReal& WPoles);
282
283 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array1OfPnt& Coeffs, TColStd_Array1OfReal& WCoeffs);
284
285 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array1OfPnt2d& Coeffs, TColStd_Array1OfReal& WCoeffs);
286
287 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, TColStd_Array1OfReal& Coeffs, TColStd_Array1OfReal& WCoeffs);
288
289 Standard_EXPORT static void Trimming (const Standard_Real U1, const Standard_Real U2, const Standard_Integer dim, TColStd_Array1OfReal& Coeffs, TColStd_Array1OfReal& WCoeffs);
290
291 Standard_EXPORT static void CoefficientsPoles (const TColgp_Array2OfPnt& Coefs, const TColStd_Array2OfReal& WCoefs, TColgp_Array2OfPnt& Poles, TColStd_Array2OfReal& WPoles);
292
293 Standard_EXPORT static void UTrimming (const Standard_Real U1, const Standard_Real U2, TColgp_Array2OfPnt& Coeffs, TColStd_Array2OfReal& WCoeffs);
294
295 Standard_EXPORT static void VTrimming (const Standard_Real V1, const Standard_Real V2, TColgp_Array2OfPnt& Coeffs, TColStd_Array2OfReal& WCoeffs);
296
297 //! Compute the coefficients in the canonical base of the
298 //! polynomial satisfying the given constraints
299 //! at the given parameters
300 //! The array FirstContr(i,j) i=1,Dimension j=0,FirstOrder
301 //! contains the values of the constraint at parameter FirstParameter
302 //! idem for LastConstr
303 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);
304
305 //! Compute the number of points used for integral
306 //! computations (NbGaussPoints) and the degree of Jacobi
307 //! Polynomial (WorkDegree).
308 //! ConstraintOrder has to be GeomAbs_C0, GeomAbs_C1 or GeomAbs_C2
309 //! Code: Code d' init. des parametres de discretisation.
310 //! = -5
311 //! = -4
312 //! = -3
313 //! = -2
314 //! = -1
315 //! = 1 calcul rapide avec precision moyenne.
316 //! = 2 calcul rapide avec meilleure precision.
317 //! = 3 calcul un peu plus lent avec bonne precision.
318 //! = 4 calcul lent avec la meilleure precision possible.
319 Standard_EXPORT static void JacobiParameters (const GeomAbs_Shape ConstraintOrder, const Standard_Integer MaxDegree, const Standard_Integer Code, Standard_Integer& NbGaussPoints, Standard_Integer& WorkDegree);
320
321 //! translates from GeomAbs_Shape to Integer
322 Standard_EXPORT static Standard_Integer NivConstr (const GeomAbs_Shape ConstraintOrder);
323
324 //! translates from Integer to GeomAbs_Shape
325 Standard_EXPORT static GeomAbs_Shape ConstraintOrder (const Standard_Integer NivConstr);
326
327 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);
328
329 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);
330
331
332
333
334protected:
335
336
337
338
339
340private:
341
342
343
344
345friend class PLib_Base;
346friend class PLib_JacobiPolynomial;
347friend class PLib_HermitJacobi;
348friend class PLib_DoubleJacobiPolynomial;
349
350};
351
352
353#include <PLib.lxx>
354
355
356
357
358
359#endif // _PLib_HeaderFile