1 // Created on: 1993-03-24
3 // Copyright (c) 1993-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 _Geom2d_BezierCurve_HeaderFile
18 #define _Geom2d_BezierCurve_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <TColgp_HArray1OfPnt2d.hxx>
25 #include <TColStd_HArray1OfReal.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_Real.hxx>
28 #include <Geom2d_BoundedCurve.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <GeomAbs_Shape.hxx>
32 #include <BSplCLib.hxx>
34 class Standard_ConstructionError;
35 class Standard_DimensionError;
36 class Standard_RangeError;
37 class Standard_OutOfRange;
41 class Geom2d_Geometry;
44 class Geom2d_BezierCurve;
45 DEFINE_STANDARD_HANDLE(Geom2d_BezierCurve, Geom2d_BoundedCurve)
47 //! Describes a rational or non-rational Bezier curve
48 //! - a non-rational Bezier curve is defined by a table
49 //! of 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_Pnt2d 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 //! which joins the first pole to the second pole is the
60 //! tangent to the curve at its start point, and the
61 //! segment which joins the last pole to the
62 //! second-from-last pole is the tangent to the curve
64 //! It is more difficult to give a geometric signification
65 //! to the weights but they are useful for providing
66 //! exact representations of the arcs of a circle or
67 //! ellipse. Moreover, if the weights of all the poles are
68 //! equal, the curve is polynomial; it is therefore a
69 //! non-rational curve. The non-rational curve is a
70 //! special and frequently used case. The weights are
71 //! defined and used only in case of a rational curve.
72 //! The degree of a Bezier curve is equal to the
73 //! number of poles, minus 1. It must be greater than or
74 //! equal to 1. However, the degree of a
75 //! Geom2d_BezierCurve curve is limited to a value
76 //! (25) which is defined and controlled by the system.
77 //! This value is returned by the function MaxDegree.
78 //! The parameter range for a Bezier curve is [ 0, 1 ].
79 //! If the first and last control points of the Bezier
80 //! curve are the same point then the curve is closed.
81 //! For example, to create a closed Bezier curve with
82 //! four control points, you have to give a set of control
83 //! points P1, P2, P3 and P1.
84 //! The continuity of a Bezier curve is infinite.
85 //! It is not possible to build a Bezier curve with
86 //! negative weights. We consider that a weight value
87 //! is zero if it is less than or equal to
88 //! gp::Resolution(). We also consider that
89 //! two weight values W1 and W2 are equal if:
90 //! |W2 - W1| <= gp::Resolution().
92 //! - When considering the continuity of a closed
93 //! Bezier curve at the junction point, remember that
94 //! a curve of this type is never periodic. This means
95 //! that the derivatives for the parameter u = 0
96 //! have no reason to be the same as the
97 //! derivatives for the parameter u = 1 even if the curve is closed.
98 //! - The length of a Bezier curve can be null.
99 class Geom2d_BezierCurve : public Geom2d_BoundedCurve
106 //! Creates a non rational Bezier curve with a set of poles :
107 //! CurvePoles. The weights are defaulted to all being 1.
108 //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1
110 Standard_EXPORT Geom2d_BezierCurve(const TColgp_Array1OfPnt2d& CurvePoles);
113 //! Creates a rational Bezier curve with the set of poles
114 //! CurvePoles and the set of weights PoleWeights .
115 //! If all the weights are identical the curve is considered
116 //! as non rational. Raises ConstructionError if
117 //! the number of poles is greater than MaxDegree + 1 or lower
118 //! than 2 or CurvePoles and CurveWeights have not the same length
119 //! or one weight value is lower or equal to Resolution from
121 Standard_EXPORT Geom2d_BezierCurve(const TColgp_Array1OfPnt2d& CurvePoles, const TColStd_Array1OfReal& PoleWeights);
124 //! Increases the degree of a bezier curve. Degree is the new
126 //! raises ConstructionError if Degree is greater than MaxDegree or lower than 2
127 //! or lower than the initial degree of <me>.
128 Standard_EXPORT void Increase (const Standard_Integer Degree);
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 [0, NbPoles]
136 //! Raised if the resulting number of poles is greater than
138 Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
141 //! Inserts a pole with its weight in the set of poles after
142 //! the pole of range Index. If the curve was non rational it
143 //! can become rational if all the weights are not identical.
144 //! Raised if Index is not in the range [1, NbPoles+1]
146 //! Raised if the resulting number of poles is greater than
148 Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
150 //! Removes the pole of range Index.
151 //! If the curve was rational it can become non rational.
152 //! Raised if Index is not in the range [1, NbPoles]
153 Standard_EXPORT void RemovePole (const Standard_Integer Index);
156 //! Reverses the direction of parametrization of <me>
157 //! Value (NewU) = Value (1 - OldU)
158 Standard_EXPORT void Reverse() Standard_OVERRIDE;
160 //! Returns the parameter on the reversed curve for
161 //! the point of parameter U on <me>.
164 Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
167 //! Segments the curve between U1 and U2 which can be out
168 //! of the bounds of the curve. The curve is oriented from U1
170 //! The control points are modified, the first and the last point
171 //! are not the same but the parametrization range is [0, 1]
172 //! else it could not be a Bezier curve.
174 //! Even if <me> is not closed it can become closed after the
175 //! segmentation for example if U1 or U2 are out of the bounds
176 //! of the curve <me> or if the curve makes loop.
177 //! After the segmentation the length of a curve can be null.
178 Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2);
181 //! Substitutes the pole of range index with P.
182 //! If the curve <me> is rational the weight of range Index
184 //! raiseD if Index is not in the range [1, NbPoles]
185 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P);
188 //! Substitutes the pole and the weights of range Index.
189 //! If the curve <me> is not rational it can become rational
190 //! if all the weights are not identical.
191 //! If the curve was rational it can become non rational if
192 //! all the weights are identical.
193 //! Raised if Index is not in the range [1, NbPoles]
194 //! Raised if Weight <= Resolution from package gp
195 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight);
198 //! Changes the weight of the pole of range Index.
199 //! If the curve <me> is not rational it can become rational
200 //! if all the weights are not identical.
201 //! If the curve was rational it can become non rational if
202 //! all the weights are identical.
203 //! Raised if Index is not in the range [1, NbPoles]
204 //! Raised if Weight <= Resolution from package gp
205 Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight);
208 //! Returns True if the distance between the first point
209 //! and the last point of the curve is lower or equal to
210 //! the Resolution from package gp.
211 Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
213 //! Continuity of the curve, returns True.
214 Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
217 //! Returns False. A BezierCurve cannot be periodic in this
219 Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
222 //! Returns false if all the weights are identical. The tolerance
223 //! criterion is Resolution from package gp.
224 Standard_EXPORT Standard_Boolean IsRational() const;
226 //! Returns GeomAbs_CN, which is the continuity of any Bezier curve.
227 Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
230 //! Returns the polynomial degree of the curve. It is the number
231 //! of poles less one. In this package the Degree of a Bezier
232 //! curve cannot be greater than "MaxDegree".
233 Standard_EXPORT Standard_Integer Degree() const;
235 Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt2d& P) const Standard_OVERRIDE;
237 Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1) const Standard_OVERRIDE;
239 Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const Standard_OVERRIDE;
241 Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const Standard_OVERRIDE;
243 //! For this Bezier curve, computes
244 //! - the point P of parameter U, or
245 //! - the point P and one or more of the following values:
246 //! - V1, the first derivative vector,
247 //! - V2, the second derivative vector,
248 //! - V3, the third derivative vector.
249 //! Note: the parameter U can be outside the bounds of the curve.
250 //! Raises RangeError if N < 1.
251 Standard_EXPORT gp_Vec2d DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
253 //! Returns the end point or start point of this Bezier curve.
254 Standard_EXPORT gp_Pnt2d EndPoint() const Standard_OVERRIDE;
256 //! Returns the value of the first parameter of this
257 //! Bezier curve. This is 0.0, which gives the start point of this Bezier curve.
258 Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
260 //! Returns the value of the last parameter of this
261 //! Bezier curve. This is 1.0, which gives the end point of this Bezier curve.
262 Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
264 //! Returns the number of poles for this Bezier curve.
265 Standard_EXPORT Standard_Integer NbPoles() const;
267 //! Returns the pole of range Index.
268 //! Raised if Index is not in the range [1, NbPoles]
269 Standard_EXPORT gp_Pnt2d Pole (const Standard_Integer Index) const;
271 //! Returns all the poles of the curve.
273 //! Raised if the length of P is not equal to the number of poles.
274 Standard_EXPORT void Poles (TColgp_Array1OfPnt2d& P) const;
276 //! Returns all the poles of the curve.
277 const TColgp_Array1OfPnt2d& Poles() const
279 return poles->Array1();
282 //! Returns Value (U=1), it is the first control point
284 Standard_EXPORT gp_Pnt2d StartPoint() const Standard_OVERRIDE;
286 //! Returns the weight of range Index.
287 //! Raised if Index is not in the range [1, NbPoles]
288 Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const;
290 //! Returns all the weights of the curve.
292 //! Raised if the length of W is not equal to the number of poles.
293 Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const;
295 //! Returns all the weights of the curve.
296 const TColStd_Array1OfReal* Weights() const
298 if (!weights.IsNull())
299 return &weights->Array1();
300 return BSplCLib::NoWeights();
303 //! Applies the transformation T to this Bezier curve.
304 Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
307 //! Returns the value of the maximum polynomial degree of a
308 //! BezierCurve. This value is 25.
309 Standard_EXPORT static Standard_Integer MaxDegree();
311 //! Computes for this Bezier curve the parametric
312 //! tolerance UTolerance for a given tolerance
313 //! Tolerance3D (relative to dimensions in the plane).
314 //! If f(t) is the equation of this Bezier curve,
315 //! UTolerance ensures that
316 //! | t1 - t0| < Utolerance ===>
317 //! |f(t1) - f(t0)| < ToleranceUV
318 Standard_EXPORT void Resolution (const Standard_Real ToleranceUV, Standard_Real& UTolerance);
320 //! Creates a new object which is a copy of this Bezier curve.
321 Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
326 DEFINE_STANDARD_RTTIEXT(Geom2d_BezierCurve,Geom2d_BoundedCurve)
336 //! Set poles to Poles, weights to Weights (not
337 //! copied). If Weights is null the curve is non
338 //! rational. Create the arrays of coefficients. Poles
339 //! and Weights are assumed to have the first
342 //! Update rational and closed.
344 //! if nbpoles < 2 or nbboles > MaDegree + 1
345 void Init (const Handle(TColgp_HArray1OfPnt2d)& Poles, const Handle(TColStd_HArray1OfReal)& Weights);
348 Standard_Boolean rational;
349 Standard_Boolean closed;
350 Handle(TColgp_HArray1OfPnt2d) poles;
351 Handle(TColStd_HArray1OfReal) weights;
352 Standard_Real maxderivinv;
353 Standard_Boolean maxderivinvok;
364 #endif // _Geom2d_BezierCurve_HeaderFile