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 class BezierCurve from Geom2d inherits BoundedCurve from Geom2d
19 --- Purpose : Describes a rational or non-rational Bezier curve
20 -- - a non-rational Bezier curve is defined by a table
21 -- of poles (also called control points),
22 -- - a rational Bezier curve is defined by a table of
23 -- poles with varying weights.
24 -- These data are manipulated by two parallel arrays:
25 -- - the poles table, which is an array of gp_Pnt2d points, and
26 -- - the weights table, which is an array of reals.
27 -- The bounds of these arrays are 1 and "the number of poles" of the curve.
28 -- The poles of the curve are "control points" used to deform the curve.
29 -- The first pole is the start point of the curve, and the
30 -- last pole is the end point of the curve. The segment
31 -- which joins the first pole to the second pole is the
32 -- tangent to the curve at its start point, and the
33 -- segment which joins the last pole to the
34 -- second-from-last pole is the tangent to the curve
36 -- It is more difficult to give a geometric signification
37 -- to the weights but they are useful for providing
38 -- exact representations of the arcs of a circle or
39 -- ellipse. Moreover, if the weights of all the poles are
40 -- equal, the curve is polynomial; it is therefore a
41 -- non-rational curve. The non-rational curve is a
42 -- special and frequently used case. The weights are
43 -- defined and used only in case of a rational curve.
44 -- The degree of a Bezier curve is equal to the
45 -- number of poles, minus 1. It must be greater than or
46 -- equal to 1. However, the degree of a
47 -- Geom2d_BezierCurve curve is limited to a value
48 -- (25) which is defined and controlled by the system.
49 -- This value is returned by the function MaxDegree.
50 -- The parameter range for a Bezier curve is [ 0, 1 ].
51 -- If the first and last control points of the Bezier
52 -- curve are the same point then the curve is closed.
53 -- For example, to create a closed Bezier curve with
54 -- four control points, you have to give a set of control
55 -- points P1, P2, P3 and P1.
56 -- The continuity of a Bezier curve is infinite.
57 -- It is not possible to build a Bezier curve with
58 -- negative weights. We consider that a weight value
59 -- is zero if it is less than or equal to
60 -- gp::Resolution(). We also consider that
61 -- two weight values W1 and W2 are equal if:
62 -- |W2 - W1| <= gp::Resolution().
64 -- - When considering the continuity of a closed
65 -- Bezier curve at the junction point, remember that
66 -- a curve of this type is never periodic. This means
67 -- that the derivatives for the parameter u = 0
68 -- have no reason to be the same as the
69 -- derivatives for the parameter u = 1 even if the curve is closed.
70 -- - The length of a Bezier curve can be null.
73 uses Array1OfReal from TColStd,
74 HArray1OfReal from TColStd,
75 Array1OfPnt2d from TColgp,
78 HArray1OfPnt2d from TColgp,
85 raises ConstructionError from Standard,
86 DimensionError from Standard,
87 RangeError from Standard,
88 OutOfRange from Standard
96 Create (CurvePoles : Array1OfPnt2d from TColgp) returns BezierCurve
98 -- Creates a non rational Bezier curve with a set of poles :
99 -- CurvePoles. The weights are defaulted to all being 1.
100 -- Raises ConstructionError if the number of poles is greater than MaxDegree + 1
102 raises ConstructionError;
105 Create (CurvePoles : Array1OfPnt2d from TColgp;
106 PoleWeights : Array1OfReal from TColStd)
109 -- Creates a rational Bezier curve with the set of poles
110 -- CurvePoles and the set of weights PoleWeights .
111 -- If all the weights are identical the curve is considered
112 -- as non rational. Raises ConstructionError if
113 -- the number of poles is greater than MaxDegree + 1 or lower
114 -- than 2 or CurvePoles and CurveWeights have not the same length
115 -- or one weight value is lower or equal to Resolution from
117 raises ConstructionError;
120 Increase (me : mutable; Degree : Integer)
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>.
127 raises ConstructionError;
131 InsertPoleAfter (me : mutable; Index : Integer; P : Pnt2d;
134 -- Inserts a pole with its weight in the set of poles after the
135 -- pole of range Index. If the curve was non rational it can
136 -- become rational if all the weights are not identical.
138 --- Purpose : Raised if Index is not in the range [0, NbPoles]
141 -- Raised if the resulting number of poles is greater than
145 InsertPoleBefore (me : mutable; Index : Integer; P : Pnt2d;
148 -- Inserts a pole with its weight in the set of poles after
149 -- the pole of range Index. If the curve was non rational it
150 -- can become rational if all the weights are not identical.
152 --- Purpose : Raised if Index is not in the range [1, NbPoles+1]
155 -- Raised if the resulting number of poles is greater than
159 RemovePole (me : mutable; Index : Integer)
160 --- Purpose : Removes the pole of range Index.
161 -- If the curve was rational it can become non rational.
163 --- Purpose : Raised if Index is not in the range [1, NbPoles]
165 -- Purpose : Raised if Degree is lower than 2.
168 Reverse (me : mutable);
170 -- Reverses the direction of parametrization of <me>
171 -- Value (NewU) = Value (1 - OldU)
174 ReversedParameter(me; U : Real) returns Real;
175 ---Purpose: Returns the parameter on the reversed curve for
176 -- the point of parameter U on <me>.
181 Segment (me : mutable; U1, U2 : Real);
183 -- Segments the curve between U1 and U2 which can be out
184 -- of the bounds of the curve. The curve is oriented from U1
186 -- The control points are modified, the first and the last point
187 -- are not the same but the parametrization range is [0, 1]
188 -- else it could not be a Bezier curve.
190 -- Even if <me> is not closed it can become closed after the
191 -- segmentation for example if U1 or U2 are out of the bounds
192 -- of the curve <me> or if the curve makes loop.
193 -- After the segmentation the length of a curve can be null.
196 SetPole (me : mutable; Index : Integer; P : Pnt2d)
198 -- Substitutes the pole of range index with P.
199 -- If the curve <me> is rational the weight of range Index
202 --- Purpose : raiseD if Index is not in the range [1, NbPoles]
205 SetPole (me : mutable; Index : Integer; P : Pnt2d; Weight : Real)
207 -- Substitutes the pole and the weights of range Index.
208 -- If the curve <me> is not rational it can become rational
209 -- if all the weights are not identical.
210 -- If the curve was rational it can become non rational if
211 -- all the weights are identical.
213 --- Purpose : Raised if Index is not in the range [1, NbPoles]
215 --- Purpose : Raised if Weight <= Resolution from package gp
218 SetWeight (me : mutable; Index : Integer; Weight : Real)
220 -- Changes the weight of the pole of range Index.
221 -- If the curve <me> is not rational it can become rational
222 -- if all the weights are not identical.
223 -- If the curve was rational it can become non rational if
224 -- all the weights are identical.
226 --- Purpose : Raised if Index is not in the range [1, NbPoles]
228 --- Purpose : Raised if Weight <= Resolution from package gp
232 IsClosed (me) returns Boolean;
234 -- Returns True if the distance between the first point
235 -- and the last point of the curve is lower or equal to
236 -- the Resolution from package gp.
239 IsCN (me; N : Integer) returns Boolean;
240 --- Purpose : Continuity of the curve, returns True.
243 IsPeriodic (me) returns Boolean;
245 -- Returns False. A BezierCurve cannot be periodic in this
249 IsRational (me) returns Boolean;
251 -- Returns false if all the weights are identical. The tolerance
252 -- criterion is Resolution from package gp.
255 Continuity (me) returns Shape from GeomAbs;
256 --- Purpose : Returns GeomAbs_CN, which is the continuity of any Bezier curve.
259 Degree (me) returns Integer;
261 -- Returns the polynomial degree of the curve. It is the number
262 -- of poles less one. In this package the Degree of a Bezier
263 -- curve cannot be greater than "MaxDegree".
270 D0 (me; U : Real; P : out Pnt2d);
272 D1 (me; U : Real; P : out Pnt2d; V1 : out Vec2d);
274 D2 (me; U : Real; P : out Pnt2d; V1, V2 : out Vec2d);
276 D3 (me; U : Real; P : out Pnt2d; V1, V2, V3 : out Vec2d);
278 DN (me; U : Real; N : Integer) returns Vec2d
279 --- Purpose : For this Bezier curve, computes
280 -- - the point P of parameter U, or
281 -- - the point P and one or more of the following values:
282 -- - V1, the first derivative vector,
283 -- - V2, the second derivative vector,
284 -- - V3, the third derivative vector.
285 -- Note: the parameter U can be outside the bounds of the curve.
286 -- Raises RangeError if N < 1.
289 EndPoint (me) returns Pnt2d;
290 --- Purpose : Returns the end point or start point of this Bezier curve.
293 FirstParameter (me) returns Real;
294 --- Purpose : Returns the value of the first parameter of this
295 -- Bezier curve. This is 0.0, which gives the start point of this Bezier curve.
298 LastParameter (me) returns Real;
299 --- Purpose : Returns the value of the last parameter of this
300 -- Bezier curve. This is 1.0, which gives the end point of this Bezier curve.
303 NbPoles (me) returns Integer;
305 ---Purpose: Returns the number of poles for this Bezier curve.
307 Pole (me; Index : Integer) returns Pnt2d
308 --- Purpose : Returns the pole of range Index.
310 --- Purpose : Raised if Index is not in the range [1, NbPoles]
313 Poles (me; P : out Array1OfPnt2d from TColgp)
314 --- Purpose : Returns all the poles of the curve.
315 raises DimensionError;
317 -- Raised if the length of P is not equal to the number of poles.
320 StartPoint (me) returns Pnt2d;
322 -- Returns Value (U=1), it is the first control point
326 Weight (me; Index : Integer) returns Real
327 --- Purpose : Returns the weight of range Index.
329 --- Purpose : Raised if Index is not in the range [1, NbPoles]
332 Weights (me; W : out Array1OfReal from TColStd)
333 --- Purpose : Returns all the weights of the curve.
334 raises DimensionError;
336 -- Raised if the length of W is not equal to the number of poles.
341 Transform (me : mutable; T : Trsf2d);
343 ---Purpose: Applies the transformation T to this Bezier curve.
346 MaxDegree (myclass) returns Integer;
348 -- Returns the value of the maximum polynomial degree of a
349 -- BezierCurve. This value is 25.
353 Resolution(me : mutable;
355 UTolerance : out Real);
356 ---Purpose: Computes for this Bezier curve the parametric
357 -- tolerance UTolerance for a given tolerance
358 -- Tolerance3D (relative to dimensions in the plane).
359 -- If f(t) is the equation of this Bezier curve,
360 -- UTolerance ensures that
361 -- | t1 - t0| < Utolerance ===>
362 -- |f(t1) - f(t0)| < ToleranceUV
364 Copy (me) returns like me;
365 ---Purpose: Creates a new object which is a copy of this Bezier curve.
367 Init (me : mutable; Poles : HArray1OfPnt2d from TColgp;
368 Weights : HArray1OfReal from TColStd)
370 ---Purpose : Set poles to Poles, weights to Weights (not
371 -- copied). If Weights is null the curve is non
372 -- rational. Create the arrays of coefficients. Poles
373 -- and Weights are assumed to have the first
376 -- Update rational and closed.
378 raises ConstructionError -- if nbpoles < 2 or nbboles > MaDegree + 1
382 CoefficientsOK(me; U : Real) returns Boolean
384 ---Purpose : returns true if the coefficients have been
385 -- computed with the right value of cacheparameter
386 -- for the given U value.
390 UpdateCoefficients(me : mutable; U : Real from Standard = 0.0)
391 ---Purpose: Recompute the coeficients.
400 poles : HArray1OfPnt2d from TColgp;
401 weights : HArray1OfReal from TColStd;
403 coeffs : HArray1OfPnt2d from TColgp;
404 wcoeffs : HArray1OfReal from TColStd;
406 validcache : Integer;
407 -- = 1 the cache is valid
408 -- = 0 the cache is invalid
409 parametercache : Real;
410 -- Parameter at which the Taylor expension is stored in
411 -- the cache, often 0., sometimes 1..
412 spanlenghtcache : Real;
413 -- always 1. for the moment.
415 -- usefull to evaluate the parametric resolution
416 maxderivinv : Real from Standard;
417 maxderivinvok : Boolean from Standard;