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 class Standard_ConstructionError;
33 class Standard_DimensionError;
34 class Standard_RangeError;
35 class Standard_OutOfRange;
39 class Geom2d_Geometry;
42 class Geom2d_BezierCurve;
43 DEFINE_STANDARD_HANDLE(Geom2d_BezierCurve, Geom2d_BoundedCurve)
45 //! Describes a rational or non-rational Bezier curve
46 //! - a non-rational Bezier curve is defined by a table
47 //! of 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_Pnt2d 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 //! which joins the first pole to the second pole is the
58 //! tangent to the curve at its start point, and the
59 //! segment which joins the last pole to the
60 //! second-from-last pole is the tangent to the curve
62 //! It is more difficult to give a geometric signification
63 //! to the weights but they are useful for providing
64 //! exact representations of the arcs of a circle or
65 //! ellipse. Moreover, if the weights of all the poles are
66 //! equal, the curve is polynomial; it is therefore a
67 //! non-rational curve. The non-rational curve is a
68 //! special and frequently used case. The weights are
69 //! defined and used only in case of a rational curve.
70 //! The degree of a Bezier curve is equal to the
71 //! number of poles, minus 1. It must be greater than or
72 //! equal to 1. However, the degree of a
73 //! Geom2d_BezierCurve curve is limited to a value
74 //! (25) which is defined and controlled by the system.
75 //! 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
78 //! curve are the same point then the curve is closed.
79 //! For example, to create a closed Bezier curve with
80 //! four control points, you have to give a 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
84 //! negative weights. We consider that a weight value
85 //! is zero if it is less than or equal to
86 //! gp::Resolution(). We also consider that
87 //! two weight values W1 and W2 are equal if:
88 //! |W2 - W1| <= gp::Resolution().
90 //! - When considering the continuity of a closed
91 //! Bezier curve at the junction point, remember that
92 //! a curve of this type is never periodic. This means
93 //! that the derivatives for the parameter u = 0
94 //! have no reason to be the same as the
95 //! derivatives for the parameter u = 1 even if the curve is closed.
96 //! - The length of a Bezier curve can be null.
97 class Geom2d_BezierCurve : public Geom2d_BoundedCurve
104 //! Creates a non rational Bezier curve with a set of poles :
105 //! CurvePoles. The weights are defaulted to all being 1.
106 //! Raises ConstructionError if the number of poles is greater than MaxDegree + 1
108 Standard_EXPORT Geom2d_BezierCurve(const TColgp_Array1OfPnt2d& CurvePoles);
111 //! Creates a rational Bezier curve with the set of poles
112 //! CurvePoles and the set of weights PoleWeights .
113 //! If all the weights are identical the curve is considered
114 //! as non rational. Raises ConstructionError if
115 //! the number of poles is greater than MaxDegree + 1 or lower
116 //! than 2 or CurvePoles and CurveWeights have not the same length
117 //! or one weight value is lower or equal to Resolution from
119 Standard_EXPORT Geom2d_BezierCurve(const TColgp_Array1OfPnt2d& CurvePoles, const TColStd_Array1OfReal& PoleWeights);
122 //! Increases the degree of a bezier curve. Degree is the new
124 //! raises ConstructionError if Degree is greater than MaxDegree or lower than 2
125 //! or lower than the initial degree of <me>.
126 Standard_EXPORT void Increase (const Standard_Integer Degree);
129 //! Inserts a pole with its weight in the set of poles after the
130 //! pole of range Index. If the curve was non rational it can
131 //! become rational if all the weights are not identical.
132 //! Raised if Index is not in the range [0, NbPoles]
134 //! Raised if the resulting number of poles is greater than
136 Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
139 //! Inserts a pole with its weight in the set of poles after
140 //! the pole of range Index. If the curve was non rational it
141 //! can become rational if all the weights are not identical.
142 //! Raised if Index is not in the range [1, NbPoles+1]
144 //! Raised if the resulting number of poles is greater than
146 Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
148 //! Removes the pole of range Index.
149 //! If the curve was rational it can become non rational.
150 //! Raised if Index is not in the range [1, NbPoles]
151 Standard_EXPORT void RemovePole (const Standard_Integer Index);
154 //! Reverses the direction of parametrization of <me>
155 //! Value (NewU) = Value (1 - OldU)
156 Standard_EXPORT void Reverse() Standard_OVERRIDE;
158 //! Returns the parameter on the reversed curve for
159 //! the point of parameter U on <me>.
162 Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
165 //! Segments the curve between U1 and U2 which can be out
166 //! of the bounds of the curve. The curve is oriented from U1
168 //! The control points are modified, the first and the last point
169 //! are not the same but the parametrization range is [0, 1]
170 //! else it could not be a Bezier curve.
172 //! Even if <me> is not closed it can become closed after the
173 //! segmentation for example if U1 or U2 are out of the bounds
174 //! of the curve <me> or if the curve makes loop.
175 //! After the segmentation the length of a curve can be null.
176 Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2);
179 //! Substitutes the pole of range index with P.
180 //! If the curve <me> is rational the weight of range Index
182 //! raiseD if Index is not in the range [1, NbPoles]
183 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P);
186 //! Substitutes the pole and the weights of range Index.
187 //! If the curve <me> is not rational it can become rational
188 //! if all the weights are not identical.
189 //! If the curve was rational it can become non rational if
190 //! all the weights are identical.
191 //! Raised if Index is not in the range [1, NbPoles]
192 //! Raised if Weight <= Resolution from package gp
193 Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight);
196 //! Changes the weight of the pole of range Index.
197 //! If the curve <me> is not rational it can become rational
198 //! if all the weights are not identical.
199 //! If the curve was rational it can become non rational if
200 //! all the weights are identical.
201 //! Raised if Index is not in the range [1, NbPoles]
202 //! Raised if Weight <= Resolution from package gp
203 Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight);
206 //! Returns True if the distance between the first point
207 //! and the last point of the curve is lower or equal to
208 //! the Resolution from package gp.
209 Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
211 //! Continuity of the curve, returns True.
212 Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
215 //! Returns False. A BezierCurve cannot be periodic in this
217 Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
220 //! Returns false if all the weights are identical. The tolerance
221 //! criterion is Resolution from package gp.
222 Standard_EXPORT Standard_Boolean IsRational() const;
224 //! Returns GeomAbs_CN, which is the continuity of any Bezier curve.
225 Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
228 //! Returns the polynomial degree of the curve. It is the number
229 //! of poles less one. In this package the Degree of a Bezier
230 //! curve cannot be greater than "MaxDegree".
231 Standard_EXPORT Standard_Integer Degree() const;
233 Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt2d& P) const Standard_OVERRIDE;
235 Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1) const Standard_OVERRIDE;
237 Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const Standard_OVERRIDE;
239 Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const Standard_OVERRIDE;
241 //! For this Bezier curve, computes
242 //! - the point P of parameter U, or
243 //! - the point P and one or more of the following values:
244 //! - V1, the first derivative vector,
245 //! - V2, the second derivative vector,
246 //! - V3, the third derivative vector.
247 //! Note: the parameter U can be outside the bounds of the curve.
248 //! Raises RangeError if N < 1.
249 Standard_EXPORT gp_Vec2d DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
251 //! Returns the end point or start point of this Bezier curve.
252 Standard_EXPORT gp_Pnt2d EndPoint() const Standard_OVERRIDE;
254 //! Returns the value of the first parameter of this
255 //! Bezier curve. This is 0.0, which gives the start point of this Bezier curve.
256 Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
258 //! Returns the value of the last parameter of this
259 //! Bezier curve. This is 1.0, which gives the end point of this Bezier curve.
260 Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
262 //! Returns the number of poles for this Bezier curve.
263 Standard_EXPORT Standard_Integer NbPoles() const;
265 //! Returns the pole of range Index.
266 //! Raised if Index is not in the range [1, NbPoles]
267 Standard_EXPORT gp_Pnt2d Pole (const Standard_Integer Index) const;
269 //! Returns all the poles of the curve.
271 //! Raised if the length of P is not equal to the number of poles.
272 Standard_EXPORT void Poles (TColgp_Array1OfPnt2d& P) const;
275 //! Returns Value (U=1), it is the first control point
277 Standard_EXPORT gp_Pnt2d StartPoint() const Standard_OVERRIDE;
279 //! Returns the weight of range Index.
280 //! Raised if Index is not in the range [1, NbPoles]
281 Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const;
283 //! Returns all the weights of the curve.
285 //! Raised if the length of W is not equal to the number of poles.
286 Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const;
288 //! Applies the transformation T to this Bezier curve.
289 Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
292 //! Returns the value of the maximum polynomial degree of a
293 //! BezierCurve. This value is 25.
294 Standard_EXPORT static Standard_Integer MaxDegree();
296 //! Computes for this Bezier curve the parametric
297 //! tolerance UTolerance for a given tolerance
298 //! Tolerance3D (relative to dimensions in the plane).
299 //! If f(t) is the equation of this Bezier curve,
300 //! UTolerance ensures that
301 //! | t1 - t0| < Utolerance ===>
302 //! |f(t1) - f(t0)| < ToleranceUV
303 Standard_EXPORT void Resolution (const Standard_Real ToleranceUV, Standard_Real& UTolerance);
305 //! Creates a new object which is a copy of this Bezier curve.
306 Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
311 DEFINE_STANDARD_RTTI(Geom2d_BezierCurve,Geom2d_BoundedCurve)
321 //! Set poles to Poles, weights to Weights (not
322 //! copied). If Weights is null the curve is non
323 //! rational. Create the arrays of coefficients. Poles
324 //! and Weights are assumed to have the first
327 //! Update rational and closed.
329 //! if nbpoles < 2 or nbboles > MaDegree + 1
330 Standard_EXPORT void Init (const Handle(TColgp_HArray1OfPnt2d)& Poles, const Handle(TColStd_HArray1OfReal)& Weights);
332 //! returns true if the coefficients have been
333 //! computed with the right value of cacheparameter
334 //! for the given U value.
335 Standard_EXPORT Standard_Boolean CoefficientsOK (const Standard_Real U) const;
337 //! Recompute the coeficients.
338 Standard_EXPORT void UpdateCoefficients (const Standard_Real U = 0.0);
340 Standard_Boolean rational;
341 Standard_Boolean closed;
342 Handle(TColgp_HArray1OfPnt2d) poles;
343 Handle(TColStd_HArray1OfReal) weights;
344 Handle(TColgp_HArray1OfPnt2d) coeffs;
345 Handle(TColStd_HArray1OfReal) wcoeffs;
346 Standard_Integer validcache;
347 Standard_Real parametercache;
348 Standard_Real spanlenghtcache;
349 Standard_Real maxderivinv;
350 Standard_Boolean maxderivinvok;
361 #endif // _Geom2d_BezierCurve_HeaderFile