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