42cf5bc1 |
1 | // Created on: 1993-03-09 |
2 | // Created by: Philippe DAUTRY |
3 | // Copyright (c) 1993-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 _Geom_BezierCurve_HeaderFile |
18 | #define _Geom_BezierCurve_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
22 | |
23 | #include <Standard_Boolean.hxx> |
24 | #include <TColgp_HArray1OfPnt.hxx> |
25 | #include <TColStd_HArray1OfReal.hxx> |
26 | #include <Standard_Integer.hxx> |
27 | #include <Standard_Real.hxx> |
28 | #include <Geom_BoundedCurve.hxx> |
29 | #include <TColgp_Array1OfPnt.hxx> |
30 | #include <TColStd_Array1OfReal.hxx> |
31 | #include <GeomAbs_Shape.hxx> |
32 | class Standard_ConstructionError; |
33 | class Standard_DimensionError; |
34 | class Standard_RangeError; |
35 | class Standard_OutOfRange; |
36 | class gp_Pnt; |
37 | class gp_Vec; |
38 | class gp_Trsf; |
39 | class Geom_Geometry; |
40 | |
41 | |
42 | class Geom_BezierCurve; |
43 | DEFINE_STANDARD_HANDLE(Geom_BezierCurve, Geom_BoundedCurve) |
44 | |
45 | //! Describes a rational or non-rational Bezier curve |
46 | //! - a non-rational Bezier curve is defined by a table of |
47 | //! poles (also called control points), |
48 | //! - a rational Bezier curve is defined by a table of |
49 | //! poles with varying weights. |
50 | //! These data are manipulated by two parallel arrays: |
51 | //! - the poles table, which is an array of gp_Pnt points, and |
52 | //! - the weights table, which is an array of reals. |
53 | //! The bounds of these arrays are 1 and "the number of "poles" of the curve. |
54 | //! The poles of the curve are "control points" used to deform the curve. |
55 | //! The first pole is the start point of the curve, and the |
56 | //! last pole is the end point of the curve. The segment |
57 | //! that joins the first pole to the second pole is the |
58 | //! tangent to the curve at its start point, and the |
59 | //! segment that joins the last pole to the |
60 | //! second-from-last pole is the tangent to the curve at its end point. |
61 | //! It is more difficult to give a geometric signification to |
62 | //! the weights but they are useful for providing the exact |
63 | //! representations of arcs of a circle or ellipse. |
64 | //! Moreover, if the weights of all poles are equal, the |
65 | //! curve is polynomial; it is therefore a non-rational |
66 | //! curve. The non-rational curve is a special and |
67 | //! frequently used case. The weights are defined and |
68 | //! used only in the case of a rational curve. |
69 | //! The degree of a Bezier curve is equal to the number |
70 | //! of poles, minus 1. It must be greater than or equal to |
71 | //! 1. However, the degree of a Geom_BezierCurve |
72 | //! curve is limited to a value (25) which is defined and |
73 | //! controlled by the system. This value is returned by the function MaxDegree. |
74 | //! The parameter range for a Bezier curve is [ 0, 1 ]. |
75 | //! If the first and last control points of the Bezier curve |
76 | //! are the same point then the curve is closed. For |
77 | //! example, to create a closed Bezier curve with four |
78 | //! control points, you have to give the set of control |
79 | //! points P1, P2, P3 and P1. |
80 | //! The continuity of a Bezier curve is infinite. |
81 | //! It is not possible to build a Bezier curve with negative |
82 | //! weights. We consider that a weight value is zero if it |
83 | //! is less than or equal to gp::Resolution(). We |
84 | //! also consider that two weight values W1 and W2 are equal if: |
85 | //! |W2 - W1| <= gp::Resolution(). |
86 | //! Warning |
87 | //! - When considering the continuity of a closed Bezier |
88 | //! curve at the junction point, remember that a curve |
89 | //! of this type is never periodic. This means that the |
90 | //! derivatives for the parameter u = 0 have no |
91 | //! reason to be the same as the derivatives for the |
92 | //! parameter u = 1 even if the curve is closed. |
93 | //! - The length of a Bezier curve can be null. |
94 | class Geom_BezierCurve : public Geom_BoundedCurve |
95 | { |
96 | |
97 | public: |
98 | |
99 | |
100 | //! Creates a non rational Bezier curve with a set of poles |
101 | //! CurvePoles. The weights are defaulted to all being 1. |
102 | //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1 |
103 | //! or lower than 2. |
104 | Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles); |
105 | |
106 | //! Creates a rational Bezier curve with the set of poles |
107 | //! CurvePoles and the set of weights PoleWeights . |
108 | //! If all the weights are identical the curve is considered |
109 | //! as non rational. Raises ConstructionError if |
110 | //! the number of poles is greater than MaxDegree + 1 or lower |
111 | //! than 2 or CurvePoles and CurveWeights have not the same length |
112 | //! or one weight value is lower or equal to Resolution from package gp. |
113 | Standard_EXPORT Geom_BezierCurve(const TColgp_Array1OfPnt& CurvePoles, const TColStd_Array1OfReal& PoleWeights); |
114 | |
115 | //! Increases the degree of a bezier curve. Degree is the new |
116 | //! degree of <me>. Raises ConstructionError |
117 | //! if Degree is greater than MaxDegree or lower than 2 |
118 | //! or lower than the initial degree of <me>. |
119 | Standard_EXPORT void Increase (const Standard_Integer Degree); |
120 | |
121 | //! Inserts a pole P after the pole of range Index. |
122 | //! If the curve <me> is rational the weight value for the new |
123 | //! pole of range Index is 1.0. |
124 | //! raised if Index is not in the range [1, NbPoles] |
125 | //! |
126 | //! raised if the resulting number of poles is greater than |
127 | //! MaxDegree + 1. |
128 | Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P); |
129 | |
130 | |
131 | //! Inserts a pole with its weight in the set of poles after the |
132 | //! pole of range Index. If the curve was non rational it can |
133 | //! become rational if all the weights are not identical. |
134 | //! Raised if Index is not in the range [1, NbPoles] |
135 | //! |
136 | //! Raised if the resulting number of poles is greater than |
137 | //! MaxDegree + 1. |
138 | //! Raised if Weight is lower or equal to Resolution from package gp. |
139 | Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); |
140 | |
141 | //! Inserts a pole P before the pole of range Index. |
142 | //! If the curve <me> is rational the weight value for the new |
143 | //! pole of range Index is 1.0. |
144 | //! Raised if Index is not in the range [1, NbPoles] |
145 | //! |
146 | //! Raised if the resulting number of poles is greater than |
147 | //! MaxDegree + 1. |
148 | Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P); |
149 | |
150 | |
151 | //! Inserts a pole with its weight in the set of poles after |
152 | //! the pole of range Index. If the curve was non rational it |
153 | //! can become rational if all the weights are not identical. |
154 | //! Raised if Index is not in the range [1, NbPoles] |
155 | //! |
156 | //! Raised if the resulting number of poles is greater than |
157 | //! MaxDegree + 1. |
158 | //! Raised if Weight is lower or equal to Resolution from |
159 | //! package gp. |
160 | Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); |
161 | |
162 | //! Removes the pole of range Index. |
163 | //! If the curve was rational it can become non rational. |
164 | //! Raised if Index is not in the range [1, NbPoles] |
165 | //! Raised if Degree is lower than 2. |
166 | Standard_EXPORT void RemovePole (const Standard_Integer Index); |
167 | |
168 | |
169 | //! Reverses the direction of parametrization of <me> |
170 | //! Value (NewU) = Value (1 - OldU) |
79104795 |
171 | Standard_EXPORT void Reverse() Standard_OVERRIDE; |
42cf5bc1 |
172 | |
173 | //! Returns the parameter on the reversed curve for |
174 | //! the point of parameter U on <me>. |
175 | //! |
176 | //! returns 1-U |
79104795 |
177 | Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE; |
42cf5bc1 |
178 | |
179 | |
180 | //! Segments the curve between U1 and U2 which can be out |
181 | //! of the bounds of the curve. The curve is oriented from U1 |
182 | //! to U2. |
183 | //! The control points are modified, the first and the last point |
184 | //! are not the same but the parametrization range is [0, 1] |
185 | //! else it could not be a Bezier curve. |
186 | //! Warnings : |
187 | //! Even if <me> is not closed it can become closed after the |
188 | //! segmentation for example if U1 or U2 are out of the bounds |
189 | //! of the curve <me> or if the curve makes loop. |
190 | //! After the segmentation the length of a curve can be null. |
191 | Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2); |
192 | |
193 | |
194 | //! Substitutes the pole of range index with P. |
195 | //! If the curve <me> is rational the weight of range Index |
196 | //! is not modified. |
197 | //! raiseD if Index is not in the range [1, NbPoles] |
198 | Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P); |
199 | |
200 | |
201 | //! Substitutes the pole and the weights of range Index. |
202 | //! If the curve <me> is not rational it can become rational |
203 | //! if all the weights are not identical. |
204 | //! If the curve was rational it can become non rational if |
205 | //! all the weights are identical. |
206 | //! Raised if Index is not in the range [1, NbPoles] |
207 | //! Raised if Weight <= Resolution from package gp |
208 | Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt& P, const Standard_Real Weight); |
209 | |
210 | |
211 | //! Changes the weight of the pole of range Index. |
212 | //! If the curve <me> is not rational it can become rational |
213 | //! if all the weights are not identical. |
214 | //! If the curve was rational it can become non rational if |
215 | //! all the weights are identical. |
216 | //! Raised if Index is not in the range [1, NbPoles] |
217 | //! Raised if Weight <= Resolution from package gp |
218 | Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight); |
219 | |
220 | |
221 | //! Returns True if the distance between the first point |
222 | //! and the last point of the curve is lower or equal to |
223 | //! the Resolution from package gp. |
79104795 |
224 | Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE; |
42cf5bc1 |
225 | |
226 | //! Continuity of the curve, returns True. |
79104795 |
227 | Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE; |
42cf5bc1 |
228 | |
229 | |
230 | //! Returns True if the parametrization of a curve is periodic. |
231 | //! (P(u) = P(u + T) T = constante) |
79104795 |
232 | Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE; |
42cf5bc1 |
233 | |
234 | |
235 | //! Returns false if all the weights are identical. The tolerance |
236 | //! criterion is Resolution from package gp. |
237 | Standard_EXPORT Standard_Boolean IsRational() const; |
238 | |
239 | //! a Bezier curve is CN |
79104795 |
240 | Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE; |
42cf5bc1 |
241 | |
242 | //! Returns the polynomial degree of the curve. |
243 | //! it is the number of poles - 1 |
244 | //! point P and derivatives (V1, V2, V3) computation |
245 | //! The Bezier Curve has a Polynomial representation so the |
246 | //! parameter U can be out of the bounds of the curve. |
247 | Standard_EXPORT Standard_Integer Degree() const; |
248 | |
79104795 |
249 | Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt& P) const Standard_OVERRIDE; |
42cf5bc1 |
250 | |
79104795 |
251 | Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1) const Standard_OVERRIDE; |
42cf5bc1 |
252 | |
79104795 |
253 | Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2) const Standard_OVERRIDE; |
42cf5bc1 |
254 | |
255 | //! For this Bezier curve, computes |
256 | //! - the point P of parameter U, or |
257 | //! - the point P and one or more of the following values: |
258 | //! - V1, the first derivative vector, |
259 | //! - V2, the second derivative vector, |
260 | //! - V3, the third derivative vector. |
261 | //! Note: the parameter U can be outside the bounds of the curve. |
79104795 |
262 | Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt& P, gp_Vec& V1, gp_Vec& V2, gp_Vec& V3) const Standard_OVERRIDE; |
42cf5bc1 |
263 | |
264 | //! For the point of parameter U of this Bezier curve, |
265 | //! computes the vector corresponding to the Nth derivative. |
266 | //! Note: the parameter U can be outside the bounds of the curve. |
267 | //! Exceptions Standard_RangeError if N is less than 1. |
79104795 |
268 | Standard_EXPORT gp_Vec DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE; |
42cf5bc1 |
269 | |
270 | //! Returns Value (U=0.), it is the first control point of the curve. |
79104795 |
271 | Standard_EXPORT gp_Pnt StartPoint() const Standard_OVERRIDE; |
42cf5bc1 |
272 | |
273 | //! Returns Value (U=1.), it is the last control point of the Bezier curve. |
79104795 |
274 | Standard_EXPORT gp_Pnt EndPoint() const Standard_OVERRIDE; |
42cf5bc1 |
275 | |
276 | //! Returns the value of the first parameter of this |
277 | //! Bezier curve. This is 0.0, which gives the start point of this Bezier curve |
79104795 |
278 | Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE; |
42cf5bc1 |
279 | |
280 | //! Returns the value of the last parameter of this |
281 | //! Bezier curve. This is 1.0, which gives the end point of this Bezier curve. |
79104795 |
282 | Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE; |
42cf5bc1 |
283 | |
284 | //! Returns the number of poles of this Bezier curve. |
285 | Standard_EXPORT Standard_Integer NbPoles() const; |
286 | |
287 | //! Returns the pole of range Index. |
288 | //! Raised if Index is not in the range [1, NbPoles] |
289 | Standard_EXPORT gp_Pnt Pole (const Standard_Integer Index) const; |
290 | |
291 | //! Returns all the poles of the curve. |
292 | //! |
293 | //! Raised if the length of P is not equal to the number of poles. |
294 | Standard_EXPORT void Poles (TColgp_Array1OfPnt& P) const; |
bcd19756 |
295 | |
296 | //! Returns all the poles of the curve. |
297 | Standard_EXPORT const TColgp_Array1OfPnt& Poles () const; |
42cf5bc1 |
298 | |
299 | //! Returns the weight of range Index. |
300 | //! Raised if Index is not in the range [1, NbPoles] |
301 | Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const; |
302 | |
303 | //! Returns all the weights of the curve. |
304 | //! |
305 | //! Raised if the length of W is not equal to the number of poles. |
306 | Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const; |
307 | |
308 | //! Applies the transformation T to this Bezier curve. |
79104795 |
309 | Standard_EXPORT void Transform (const gp_Trsf& T) Standard_OVERRIDE; |
42cf5bc1 |
310 | |
311 | |
312 | //! Returns the value of the maximum polynomial degree |
313 | //! of any Geom_BezierCurve curve. This value is 25. |
314 | Standard_EXPORT static Standard_Integer MaxDegree(); |
315 | |
316 | //! Computes for this Bezier curve the parametric |
317 | //! tolerance UTolerance for a given 3D tolerance Tolerance3D. |
318 | //! If f(t) is the equation of this Bezier curve, |
319 | //! UTolerance ensures that: |
320 | //! |t1-t0| < UTolerance ===> |f(t1)-f(t0)| < Tolerance3D |
321 | Standard_EXPORT void Resolution (const Standard_Real Tolerance3D, Standard_Real& UTolerance); |
322 | |
323 | //! Creates a new object which is a copy of this Bezier curve. |
79104795 |
324 | Standard_EXPORT Handle(Geom_Geometry) Copy() const Standard_OVERRIDE; |
42cf5bc1 |
325 | |
326 | |
327 | |
328 | |
329 | DEFINE_STANDARD_RTTI(Geom_BezierCurve,Geom_BoundedCurve) |
330 | |
331 | protected: |
332 | |
333 | |
334 | |
335 | |
336 | private: |
337 | |
338 | |
339 | //! Set poles to Poles, weights to Weights (not |
340 | //! copied). If Weights is null the curve is non |
341 | //! rational. Create the arrays of coefficients. Poles |
342 | //! and Weights are assumed to have the first |
343 | //! coefficient 1. |
344 | //! Update rational and closed. |
345 | //! |
346 | //! if nbpoles < 2 or nbboles > MaDegree + 1 |
347 | Standard_EXPORT void Init (const Handle(TColgp_HArray1OfPnt)& Poles, const Handle(TColStd_HArray1OfReal)& Weights); |
348 | |
349 | //! returns true if the coefficients have been |
350 | //! computed with the right value of cacheparameter |
351 | //! for the given U value. |
352 | Standard_EXPORT Standard_Boolean CoefficientsOK (const Standard_Real U) const; |
353 | |
354 | //! Recompute the coeficients. |
355 | Standard_EXPORT void UpdateCoefficients (const Standard_Real U = 0.0); |
356 | |
357 | Standard_Boolean rational; |
358 | Standard_Boolean closed; |
359 | Handle(TColgp_HArray1OfPnt) poles; |
360 | Handle(TColStd_HArray1OfReal) weights; |
361 | Handle(TColgp_HArray1OfPnt) coeffs; |
362 | Handle(TColStd_HArray1OfReal) wcoeffs; |
363 | Standard_Integer validcache; |
364 | Standard_Real parametercache; |
365 | Standard_Real spanlenghtcache; |
366 | Standard_Real maxderivinv; |
367 | Standard_Boolean maxderivinvok; |
368 | |
369 | |
370 | }; |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | #endif // _Geom_BezierCurve_HeaderFile |