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