0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Geom2d / Geom2d_BSplineCurve.hxx
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_BSplineCurve_HeaderFile
18 #define _Geom2d_BSplineCurve_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Precision.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <GeomAbs_BSplKnotDistribution.hxx>
26 #include <GeomAbs_Shape.hxx>
27 #include <Standard_Integer.hxx>
28 #include <TColgp_HArray1OfPnt2d.hxx>
29 #include <TColStd_HArray1OfReal.hxx>
30 #include <TColStd_HArray1OfInteger.hxx>
31 #include <Standard_Real.hxx>
32 #include <Geom2d_BoundedCurve.hxx>
33 #include <TColgp_Array1OfPnt2d.hxx>
34 #include <TColStd_Array1OfReal.hxx>
35 #include <TColStd_Array1OfInteger.hxx>
36 class Standard_ConstructionError;
37 class Standard_DimensionError;
38 class Standard_DomainError;
39 class Standard_OutOfRange;
40 class Standard_RangeError;
41 class Standard_NoSuchObject;
42 class Geom2d_UndefinedDerivative;
43 class gp_Pnt2d;
44 class gp_Vec2d;
45 class gp_Trsf2d;
46 class Geom2d_Geometry;
47
48
49 class Geom2d_BSplineCurve;
50 DEFINE_STANDARD_HANDLE(Geom2d_BSplineCurve, Geom2d_BoundedCurve)
51
52 //! Describes a BSpline curve.
53 //! A BSpline curve can be:
54 //! - uniform or non-uniform,
55 //! - rational or non-rational,
56 //! - periodic or non-periodic.
57 //! A BSpline curve is defined by:
58 //! - its degree; the degree for a
59 //! Geom2d_BSplineCurve is limited to a value (25)
60 //! which is defined and controlled by the system. This
61 //! value is returned by the function MaxDegree;
62 //! - its periodic or non-periodic nature;
63 //! - a table of poles (also called control points), with
64 //! their associated weights if the BSpline curve is
65 //! rational. The poles of the curve are "control points"
66 //! used to deform the curve. If the curve is
67 //! non-periodic, the first pole is the start point of the
68 //! curve, and the last pole is the end point of the
69 //! curve. The segment, which joins the first pole to the
70 //! second pole, is the tangent to the curve at its start
71 //! point, and the segment, which joins the last pole to
72 //! the second-from-last pole, is the tangent to the
73 //! curve at its end point. If the curve is periodic, these
74 //! geometric properties are not verified. It is more
75 //! difficult to give a geometric signification to the
76 //! weights but they are useful for providing exact
77 //! representations of the arcs of a circle or ellipse.
78 //! Moreover, if the weights of all the poles are equal,
79 //! the curve has a polynomial equation; it is
80 //! therefore a non-rational curve.
81 //! - a table of knots with their multiplicities. For a
82 //! Geom2d_BSplineCurve, the table of knots is an
83 //! increasing sequence of reals without repetition; the
84 //! multiplicities define the repetition of the knots. A
85 //! BSpline curve is a piecewise polynomial or rational
86 //! curve. The knots are the parameters of junction
87 //! points between two pieces. The multiplicity
88 //! Mult(i) of the knot Knot(i) of the BSpline
89 //! curve is related to the degree of continuity of the
90 //! curve at the knot Knot(i), which is equal to
91 //! Degree - Mult(i) where Degree is the
92 //! degree of the BSpline curve.
93 //! If the knots are regularly spaced (i.e. the difference
94 //! between two consecutive knots is a constant), three
95 //! specific and frequently used cases of knot distribution
96 //! can be identified:
97 //! - "uniform" if all multiplicities are equal to 1,
98 //! - "quasi-uniform" if all multiplicities are equal to 1,
99 //! except the first and the last knot which have a
100 //! multiplicity of Degree + 1, where Degree is
101 //! the degree of the BSpline curve,
102 //! - "Piecewise Bezier" if all multiplicities are equal to
103 //! Degree except the first and last knot which have
104 //! a multiplicity of Degree + 1, where Degree is
105 //! the degree of the BSpline curve. A curve of this
106 //! type is a concatenation of arcs of Bezier curves.
107 //! If the BSpline curve is not periodic:
108 //! - the bounds of the Poles and Weights tables are 1
109 //! and NbPoles, where NbPoles is the number of
110 //! poles of the BSpline curve,
111 //! - the bounds of the Knots and Multiplicities tables are
112 //! 1 and NbKnots, where NbKnots is the number
113 //! of knots of the BSpline curve.
114 //! If the BSpline curve is periodic, and if there are k
115 //! periodic knots and p periodic poles, the period is:
116 //! period = Knot(k + 1) - Knot(1)
117 //! and the poles and knots tables can be considered as
118 //! infinite tables, such that:
119 //! - Knot(i+k) = Knot(i) + period
120 //! - Pole(i+p) = Pole(i)
121 //! Note: data structures of a periodic BSpline curve are
122 //! more complex than those of a non-periodic one.
123 //! Warnings :
124 //! In this class we consider that a weight value is zero if
125 //! Weight <= Resolution from package gp.
126 //! For two parametric values (or two knot values) U1, U2 we
127 //! consider that U1 = U2 if Abs (U2 - U1) <= Epsilon (U1).
128 //! For two weights values W1, W2 we consider that W1 = W2 if
129 //! Abs (W2 - W1) <= Epsilon (W1).  The method Epsilon is
130 //! defined in the class Real from package Standard.
131 //!
132 //! References :
133 //! . A survey of curve and surface methods in CADG Wolfgang BOHM
134 //! CAGD 1 (1984)
135 //! . On de Boor-like algorithms and blossoming Wolfgang BOEHM
136 //! cagd 5 (1988)
137 //! . Blossoming and knot insertion algorithms for B-spline curves
138 //! Ronald N. GOLDMAN
139 //! . Modelisation des surfaces en CAO, Henri GIAUME Peugeot SA
140 //! . Curves and Surfaces for Computer Aided Geometric Design,
141 //! a practical guide Gerald Farin
142 class Geom2d_BSplineCurve : public Geom2d_BoundedCurve
143 {
144
145 public:
146
147   
148   //! Creates a  non-rational B_spline curve   on  the
149   //! basis <Knots, Multiplicities> of degree <Degree>.
150   //! The following conditions must be verified.
151   //! 0 < Degree <= MaxDegree.
152   //!
153   //! Knots.Length() == Mults.Length() >= 2
154   //!
155   //! Knots(i) < Knots(i+1) (Knots are increasing)
156   //!
157   //! 1 <= Mults(i) <= Degree
158   //!
159   //! On a non periodic curve the first and last multiplicities
160   //! may be Degree+1 (this is even recommanded if you want the
161   //! curve to start and finish on the first and last pole).
162   //!
163   //! On a periodic  curve the first  and  the last multicities
164   //! must be the same.
165   //!
166   //! on non-periodic curves
167   //!
168   //! Poles.Length() == Sum(Mults(i)) - Degree - 1 >= 2
169   //!
170   //! on periodic curves
171   //!
172   //! Poles.Length() == Sum(Mults(i)) except the first or last
173   Standard_EXPORT Geom2d_BSplineCurve(const TColgp_Array1OfPnt2d& Poles, const TColStd_Array1OfReal& Knots, const TColStd_Array1OfInteger& Multiplicities, const Standard_Integer Degree, const Standard_Boolean Periodic = Standard_False);
174   
175   //! Creates  a rational B_spline  curve  on the basis
176   //! <Knots, Multiplicities> of degree <Degree>.
177   //! The following conditions must be verified.
178   //! 0 < Degree <= MaxDegree.
179   //!
180   //! Knots.Length() == Mults.Length() >= 2
181   //!
182   //! Knots(i) < Knots(i+1) (Knots are increasing)
183   //!
184   //! 1 <= Mults(i) <= Degree
185   //!
186   //! On a non periodic curve the first and last multiplicities
187   //! may be Degree+1 (this is even recommanded if you want the
188   //! curve to start and finish on the first and last pole).
189   //!
190   //! On a periodic  curve the first  and  the last multicities
191   //! must be the same.
192   //!
193   //! on non-periodic curves
194   //!
195   //! Poles.Length() == Sum(Mults(i)) - Degree - 1 >= 2
196   //!
197   //! on periodic curves
198   //!
199   //! Poles.Length() == Sum(Mults(i)) except the first or last
200   Standard_EXPORT Geom2d_BSplineCurve(const TColgp_Array1OfPnt2d& Poles, const TColStd_Array1OfReal& Weights, const TColStd_Array1OfReal& Knots, const TColStd_Array1OfInteger& Multiplicities, const Standard_Integer Degree, const Standard_Boolean Periodic = Standard_False);
201   
202   //! Increases the degree of this BSpline curve to
203   //! Degree. As a result, the poles, weights and
204   //! multiplicities tables are modified; the knots table is
205   //! not changed. Nothing is done if Degree is less than
206   //! or equal to the current degree.
207   //! Exceptions
208   //! Standard_ConstructionError if Degree is greater than
209   //! Geom2d_BSplineCurve::MaxDegree().
210   Standard_EXPORT void IncreaseDegree (const Standard_Integer Degree);
211   
212   //! Increases the multiplicity  of the knot <Index> to
213   //! <M>.
214   //!
215   //! If   <M>   is   lower   or  equal   to  the current
216   //! multiplicity nothing is done. If <M> is higher than
217   //! the degree the degree is used.
218   //! If <Index> is not in [FirstUKnotIndex, LastUKnotIndex]
219   Standard_EXPORT void IncreaseMultiplicity (const Standard_Integer Index, const Standard_Integer M);
220   
221   //! Increases  the  multiplicities   of  the knots  in
222   //! [I1,I2] to <M>.
223   //!
224   //! For each knot if  <M>  is  lower  or equal  to  the
225   //! current multiplicity  nothing  is  done. If <M>  is
226   //! higher than the degree the degree is used.
227   //! As a result, the poles and weights tables of this curve are modified.
228   //! Warning
229   //! It is forbidden to modify the multiplicity of the first or
230   //! last knot of a non-periodic curve. Be careful as
231   //! Geom2d does not protect against this.
232   //! Exceptions
233   //! Standard_OutOfRange if either Index, I1 or I2 is
234   //! outside the bounds of the knots table.
235   Standard_EXPORT void IncreaseMultiplicity (const Standard_Integer I1, const Standard_Integer I2, const Standard_Integer M);
236   
237   //! Increases by M the multiplicity of the knots of indexes
238   //! I1 to I2 in the knots table of this BSpline curve. For
239   //! each knot, the resulting multiplicity is limited to the
240   //! degree of this curve. If M is negative, nothing is done.
241   //! As a result, the poles and weights tables of this
242   //! BSpline curve are modified.
243   //! Warning
244   //! It is forbidden to modify the multiplicity of the first or
245   //! last knot of a non-periodic curve. Be careful as
246   //! Geom2d does not protect against this.
247   //! Exceptions
248   //! Standard_OutOfRange if I1 or I2 is outside the
249   //! bounds of the knots table.
250   Standard_EXPORT void IncrementMultiplicity (const Standard_Integer I1, const Standard_Integer I2, const Standard_Integer M);
251   
252   //! Inserts a knot value in the sequence of knots.  If
253   //! <U>  is an  existing knot     the multiplicity  is
254   //! increased by <M>.
255   //!
256   //! If U  is  not  on the parameter  range  nothing is
257   //! done.
258   //!
259   //! If the multiplicity is negative or null nothing is
260   //! done. The  new   multiplicity  is limited  to  the
261   //! degree.
262   //!
263   //! The  tolerance criterion  for  knots  equality  is
264   //! the max of Epsilon(U) and ParametricTolerance.
265   //! Warning
266   //! - If U is less than the first parameter or greater than
267   //! the last parameter of this BSpline curve, nothing is done.
268   //! - If M is negative or null, nothing is done.
269   //! - The multiplicity of a knot is limited to the degree of
270   //! this BSpline curve.
271   Standard_EXPORT void InsertKnot (const Standard_Real U, const Standard_Integer M = 1, const Standard_Real ParametricTolerance = 0.0);
272   
273   //! Inserts the values of the array Knots, with the
274   //! respective multiplicities given by the array Mults, into
275   //! the knots table of this BSpline curve.
276   //! If a value of the array Knots is an existing knot, its multiplicity is:
277   //! - increased by M, if Add is true, or
278   //! - increased to M, if Add is false (default value).
279   //! The tolerance criterion used for knot equality is the
280   //! larger of the values ParametricTolerance (defaulted
281   //! to 0.) and Standard_Real::Epsilon(U),
282   //! where U is the current knot value.
283   //! Warning
284   //! - For a value of the array Knots which is less than
285   //! the first parameter or greater than the last
286   //! parameter of this BSpline curve, nothing is done.
287   //! - For a value of the array Mults which is negative or
288   //! null, nothing is done.
289   //! - The multiplicity of a knot is limited to the degree of
290   //! this BSpline curve.
291   Standard_EXPORT void InsertKnots (const TColStd_Array1OfReal& Knots, const TColStd_Array1OfInteger& Mults, const Standard_Real ParametricTolerance = 0.0, const Standard_Boolean Add = Standard_False);
292   
293   //! Reduces the multiplicity of the knot of index Index
294   //! to M. If M is equal to 0, the knot is removed.
295   //! With a modification of this type, the array of poles is also modified.
296   //! Two different algorithms are systematically used to
297   //! compute the new poles of the curve. If, for each
298   //! pole, the distance between the pole calculated
299   //! using the first algorithm and the same pole
300   //! calculated using the second algorithm, is less than
301   //! Tolerance, this ensures that the curve is not
302   //! modified by more than Tolerance. Under these
303   //! conditions, true is returned; otherwise, false is returned.
304   //! A low tolerance is used to prevent modification of
305   //! the curve. A high tolerance is used to "smooth" the curve.
306   //! Exceptions
307   //! Standard_OutOfRange if Index is outside the
308   //! bounds of the knots table.
309   Standard_EXPORT Standard_Boolean RemoveKnot (const Standard_Integer Index, const Standard_Integer M, const Standard_Real Tolerance);
310   
311
312   //! The new pole is inserted after the pole of range Index.
313   //! If the curve was non rational it can become rational.
314   //!
315   //! Raised if the B-spline is NonUniform or PiecewiseBezier or if
316   //! Weight <= 0.0
317   //! Raised if Index is not in the range [1, Number of Poles]
318   Standard_EXPORT void InsertPoleAfter (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
319   
320
321   //! The new pole is inserted before the pole of range Index.
322   //! If the curve was non rational it can become rational.
323   //!
324   //! Raised if the B-spline is NonUniform or PiecewiseBezier or if
325   //! Weight <= 0.0
326   //! Raised if Index is not in the range [1, Number of Poles]
327   Standard_EXPORT void InsertPoleBefore (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight = 1.0);
328   
329
330   //! Removes the pole of range Index
331   //! If the curve was rational it can become non rational.
332   //!
333   //! Raised if the B-spline is NonUniform or PiecewiseBezier.
334   //! Raised if the number of poles of the B-spline curve is lower or
335   //! equal to 2 before removing.
336   //! Raised if Index is not in the range [1, Number of Poles]
337   Standard_EXPORT void RemovePole (const Standard_Integer Index);
338   
339   //! Reverses the orientation of this BSpline curve. As a result
340   //! - the knots and poles tables are modified;
341   //! - the start point of the initial curve becomes the end
342   //! point of the reversed curve;
343   //! - the end point of the initial curve becomes the start
344   //! point of the reversed curve.
345   Standard_EXPORT void Reverse() Standard_OVERRIDE;
346   
347   //! Computes the parameter on the reversed curve for
348   //! the point of parameter U on this BSpline curve.
349   //! The returned value is: UFirst + ULast - U,
350   //! where UFirst and ULast are the values of the
351   //! first and last parameters of this BSpline curve.
352   Standard_EXPORT Standard_Real ReversedParameter (const Standard_Real U) const Standard_OVERRIDE;
353   
354   //! Modifies this BSpline curve by segmenting it
355   //! between U1 and U2. Either of these values can be
356   //! outside the bounds of the curve, but U2 must be greater than U1.
357   //! All data structure tables of this BSpline curve are
358   //! modified, but the knots located between U1 and U2
359   //! are retained. The degree of the curve is not modified.
360   //!
361   //! Parameter theTolerance defines the possible proximity of the segment
362   //! boundaries and B-spline knots to treat them as equal.
363   //!
364   //! Warnings :
365   //! Even if <me> is not closed it can become closed after the
366   //! segmentation for example if U1 or U2 are out of the bounds
367   //! of the curve <me> or if the curve makes loop.
368   //! After the segmentation the length of a curve can be null.
369   //! - The segmentation of a periodic curve over an
370   //! interval corresponding to its period generates a
371   //! non-periodic curve with equivalent geometry.
372   //! Exceptions
373   //! Standard_DomainError if U2 is less than U1.
374   //! raises if U2 < U1.
375   //! Standard_DomainError if U2 - U1 exceeds the period for periodic curves.
376   //! i.e. ((U2 - U1) - Period) > Precision::PConfusion().
377   Standard_EXPORT void Segment (const Standard_Real U1, const Standard_Real U2,
378                                 const Standard_Real theTolerance = Precision::PConfusion());
379   
380   //! Modifies this BSpline curve by assigning the value K
381   //! to the knot of index Index in the knots table. This is a
382   //! relatively local modification because K must be such that:
383   //! Knots(Index - 1) < K < Knots(Index + 1)
384   //! Exceptions
385   //! Standard_ConstructionError if:
386   //! - K is not such that:
387   //! Knots(Index - 1) < K < Knots(Index + 1)
388   //! - M is greater than the degree of this BSpline curve
389   //! or lower than the previous multiplicity of knot of
390   //! index Index in the knots table.
391   //! Standard_OutOfRange if Index is outside the bounds of the knots table.
392   Standard_EXPORT void SetKnot (const Standard_Integer Index, const Standard_Real K);
393   
394   //! Modifies this BSpline curve by assigning the array
395   //! K to its knots table. The multiplicity of the knots is not modified.
396   //! Exceptions
397   //! Standard_ConstructionError if the values in the
398   //! array K are not in ascending order.
399   //! Standard_OutOfRange if the bounds of the array
400   //! K are not respectively 1 and the number of knots of this BSpline curve.
401   Standard_EXPORT void SetKnots (const TColStd_Array1OfReal& K);
402   
403   //! Modifies this BSpline curve by assigning the value K
404   //! to the knot of index Index in the knots table. This is a
405   //! relatively local modification because K must be such that:
406   //! Knots(Index - 1) < K < Knots(Index + 1)
407   //! The second syntax allows you also to increase the
408   //! multiplicity of the knot to M (but it is not possible to
409   //! decrease the multiplicity of the knot with this function).
410   //! Exceptions
411   //! Standard_ConstructionError if:
412   //! - K is not such that:
413   //! Knots(Index - 1) < K < Knots(Index + 1)
414   //! - M is greater than the degree of this BSpline curve
415   //! or lower than the previous multiplicity of knot of
416   //! index Index in the knots table.
417   //! Standard_OutOfRange if Index is outside the bounds of the knots table.
418   Standard_EXPORT void SetKnot (const Standard_Integer Index, const Standard_Real K, const Standard_Integer M);
419   
420   //! Computes the parameter normalized within the
421   //! "first" period of this BSpline curve, if it is periodic:
422   //! the returned value is in the range Param1 and
423   //! Param1 + Period, where:
424   //! - Param1 is the "first parameter", and
425   //! - Period the period of this BSpline curve.
426   //! Note: If this curve is not periodic, U is not modified.
427   Standard_EXPORT void PeriodicNormalization (Standard_Real& U) const;
428   
429   //! Changes this BSpline curve into a periodic curve.
430   //! To become periodic, the curve must first be closed.
431   //! Next, the knot sequence must be periodic. For this,
432   //! FirstUKnotIndex and LastUKnotIndex are used to
433   //! compute I1 and I2, the indexes in the knots array
434   //! of the knots corresponding to the first and last
435   //! parameters of this BSpline curve.
436   //! The period is therefore Knot(I2) - Knot(I1).
437   //! Consequently, the knots and poles tables are modified.
438   //! Exceptions
439   //! Standard_ConstructionError if this BSpline curve is not closed.
440   Standard_EXPORT void SetPeriodic();
441   
442   //! Assigns the knot of index Index in the knots table as
443   //! the origin of this periodic BSpline curve. As a
444   //! consequence, the knots and poles tables are modified.
445   //! Exceptions
446   //! Standard_NoSuchObject if this curve is not periodic.
447   //! Standard_DomainError if Index is outside the
448   //! bounds of the knots table.
449   Standard_EXPORT void SetOrigin (const Standard_Integer Index);
450   
451   //! Changes this BSpline curve into a non-periodic
452   //! curve. If this curve is already non-periodic, it is not modified.
453   //! Note that the poles and knots tables are modified.
454   //! Warning
455   //! If this curve is periodic, as the multiplicity of the first
456   //! and last knots is not modified, and is not equal to
457   //! Degree + 1, where Degree is the degree of
458   //! this BSpline curve, the start and end points of the
459   //! curve are not its first and last poles.
460   Standard_EXPORT void SetNotPeriodic();
461   
462   //! Modifies this BSpline curve by assigning P to the
463   //! pole of index Index in the poles table.
464   //! Exceptions
465   //! Standard_OutOfRange if Index is outside the
466   //! bounds of the poles table.
467   //! Standard_ConstructionError if Weight is negative or null.
468   Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P);
469   
470   //! Modifies this BSpline curve by assigning P to the
471   //! pole of index Index in the poles table.
472   //! The second syntax also allows you to modify the
473   //! weight of the modified pole, which becomes Weight.
474   //! In this case, if this BSpline curve is non-rational, it
475   //! can become rational and vice versa.
476   //! Exceptions
477   //! Standard_OutOfRange if Index is outside the
478   //! bounds of the poles table.
479   //! Standard_ConstructionError if Weight is negative or null.
480   Standard_EXPORT void SetPole (const Standard_Integer Index, const gp_Pnt2d& P, const Standard_Real Weight);
481   
482   //! Assigns the weight Weight to the pole of index Index of the poles table.
483   //! If the curve was non rational it can become rational.
484   //! If the curve was rational it can become non rational.
485   //! Exceptions
486   //! Standard_OutOfRange if Index is outside the
487   //! bounds of the poles table.
488   //! Standard_ConstructionError if Weight is negative or null.
489   Standard_EXPORT void SetWeight (const Standard_Integer Index, const Standard_Real Weight);
490   
491   //! Moves the point of parameter U of this BSpline
492   //! curve to P. Index1 and Index2 are the indexes in the
493   //! table of poles of this BSpline curve of the first and
494   //! last poles designated to be moved.
495   //! FirstModifiedPole and LastModifiedPole are the
496   //! indexes of the first and last poles, which are
497   //! effectively modified.
498   //! In the event of incompatibility between Index1,
499   //! Index2 and the value U:
500   //! - no change is made to this BSpline curve, and
501   //! - the FirstModifiedPole and LastModifiedPole are returned null.
502   //! Exceptions
503   //! Standard_OutOfRange if:
504   //! - Index1 is greater than or equal to Index2, or
505   //! - Index1 or Index2 is less than 1 or greater than the
506   //! number of poles of this BSpline curve.
507   Standard_EXPORT void MovePoint (const Standard_Real U, const gp_Pnt2d& P, const Standard_Integer Index1, const Standard_Integer Index2, Standard_Integer& FirstModifiedPole, Standard_Integer& LastModifiedPole);
508   
509   //! Move a point with parameter U to P.
510   //! and makes it tangent at U be Tangent.
511   //! StartingCondition = -1 means first can move
512   //! EndingCondition   = -1 means last point can move
513   //! StartingCondition = 0 means the first point cannot move
514   //! EndingCondition   = 0 means the last point cannot move
515   //! StartingCondition = 1 means the first point and tangent cannot move
516   //! EndingCondition   = 1 means the last point and tangent cannot move
517   //! and so forth
518   //! ErrorStatus != 0 means that there are not enought degree of freedom
519   //! with the constrain to deform the curve accordingly
520   Standard_EXPORT void MovePointAndTangent (const Standard_Real U, const gp_Pnt2d& P, const gp_Vec2d& Tangent, const Standard_Real Tolerance, const Standard_Integer StartingCondition, const Standard_Integer EndingCondition, Standard_Integer& ErrorStatus);
521   
522   //! Returns true if the degree of continuity of this
523   //! BSpline curve is at least N. A BSpline curve is at least GeomAbs_C0.
524   //! Exceptions Standard_RangeError if N is negative.
525   Standard_EXPORT Standard_Boolean IsCN (const Standard_Integer N) const Standard_OVERRIDE;
526   
527
528   //! Check if curve has at least G1 continuity in interval [theTf, theTl]
529   //! Returns true if IsCN(1)
530   //! or
531   //! angle betweem "left" and "right" first derivatives at
532   //! knots with C0 continuity is less then theAngTol
533   //! only knots in interval [theTf, theTl] is checked
534   Standard_EXPORT Standard_Boolean IsG1 (const Standard_Real theTf, const Standard_Real theTl, const Standard_Real theAngTol) const;
535   
536
537   //! Returns true if the distance between the first point and the
538   //! last point of the curve is lower or equal to Resolution
539   //! from package gp.
540   //! Warnings :
541   //! The first and the last point can be different from the first
542   //! pole and the last pole of the curve.
543   Standard_EXPORT Standard_Boolean IsClosed() const Standard_OVERRIDE;
544   
545   //! Returns True if the curve is periodic.
546   Standard_EXPORT Standard_Boolean IsPeriodic() const Standard_OVERRIDE;
547   
548
549   //! Returns True if the weights are not identical.
550   //! The tolerance criterion is Epsilon of the class Real.
551   Standard_EXPORT Standard_Boolean IsRational() const;
552   
553
554   //! Returns the global continuity of the curve :
555   //! C0 : only geometric continuity,
556   //! C1 : continuity of the first derivative all along the Curve,
557   //! C2 : continuity of the second derivative all along the Curve,
558   //! C3 : continuity of the third derivative all along the Curve,
559   //! CN : the order of continuity is infinite.
560   //! For a B-spline curve of degree d if a knot Ui has a
561   //! multiplicity p the B-spline curve is only Cd-p continuous
562   //! at Ui. So the global continuity of the curve can't be greater
563   //! than Cd-p where p is the maximum multiplicity of the interior
564   //! Knots. In the interior of a knot span the curve is infinitely
565   //! continuously differentiable.
566   Standard_EXPORT GeomAbs_Shape Continuity() const Standard_OVERRIDE;
567   
568   //! Returns the degree of this BSpline curve.
569   //! In this class the degree of the basis normalized B-spline
570   //! functions cannot be greater than "MaxDegree"
571   //! Computation of value and derivatives
572   Standard_EXPORT Standard_Integer Degree() const;
573   
574   Standard_EXPORT void D0 (const Standard_Real U, gp_Pnt2d& P) const Standard_OVERRIDE;
575   
576   //! Raised if the continuity of the curve is not C1.
577   Standard_EXPORT void D1 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1) const Standard_OVERRIDE;
578   
579   //! Raised if the continuity of the curve is not C2.
580   Standard_EXPORT void D2 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const Standard_OVERRIDE;
581   
582   //! For this BSpline curve, computes
583   //! - the point P of parameter U, or
584   //! - the point P and one or more of the following values:
585   //! - V1, the first derivative vector,
586   //! - V2, the second derivative vector,
587   //! - V3, the third derivative vector.
588   //! Warning
589   //! On a point where the continuity of the curve is not the
590   //! one requested, these functions impact the part
591   //! defined by the parameter with a value greater than U,
592   //! i.e. the part of the curve to the "right" of the singularity.
593   //! Raises UndefinedDerivative if the continuity of the curve is not C3.
594   Standard_EXPORT void D3 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const Standard_OVERRIDE;
595   
596   //! For the point of parameter U of this BSpline curve,
597   //! computes the vector corresponding to the Nth derivative.
598   //! Warning
599   //! On a point where the continuity of the curve is not the
600   //! one requested, this function impacts the part defined
601   //! by the parameter with a value greater than U, i.e. the
602   //! part of the curve to the "right" of the singularity.
603   //! Raises  UndefinedDerivative if the continuity of the curve is not CN.
604   //! RangeError if N < 1.
605   //! The following functions computes the point of parameter U
606   //! and the derivatives at this point on the B-spline curve
607   //! arc defined between the knot FromK1 and the knot ToK2.
608   //! U can be out of bounds [Knot (FromK1),  Knot (ToK2)] but
609   //! for the computation we only use the definition of the curve
610   //! between these two knots. This method is useful to compute
611   //! local derivative, if the order of continuity of the whole
612   //! curve is not greater enough.    Inside the parametric
613   //! domain Knot (FromK1), Knot (ToK2) the evaluations are
614   //! the same as if we consider the whole definition of the
615   //! curve. Of course the evaluations are different outside
616   //! this parametric domain.
617   Standard_EXPORT gp_Vec2d DN (const Standard_Real U, const Standard_Integer N) const Standard_OVERRIDE;
618   
619   //! Raised if FromK1 = ToK2.
620   Standard_EXPORT gp_Pnt2d LocalValue (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2) const;
621   
622   //! Raised if FromK1 = ToK2.
623   Standard_EXPORT void LocalD0 (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2, gp_Pnt2d& P) const;
624   
625
626   //! Raised if the local continuity of the curve is not C1
627   //! between the knot K1 and the knot K2.
628   //! Raised if FromK1 = ToK2.
629   Standard_EXPORT void LocalD1 (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2, gp_Pnt2d& P, gp_Vec2d& V1) const;
630   
631
632   //! Raised if the local continuity of the curve is not C2
633   //! between the knot K1 and the knot K2.
634   //! Raised if FromK1 = ToK2.
635   Standard_EXPORT void LocalD2 (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const;
636   
637
638   //! Raised if the local continuity of the curve is not C3
639   //! between the knot K1 and the knot K2.
640   //! Raised if FromK1 = ToK2.
641   Standard_EXPORT void LocalD3 (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const;
642   
643
644   //! Raised if the local continuity of the curve is not CN
645   //! between the knot K1 and the knot K2.
646   //! Raised if FromK1 = ToK2.
647   //! Raised if N < 1.
648   Standard_EXPORT gp_Vec2d LocalDN (const Standard_Real U, const Standard_Integer FromK1, const Standard_Integer ToK2, const Standard_Integer N) const;
649   
650
651   //! Returns the last point of the curve.
652   //! Warnings :
653   //! The last point of the curve is different from the last
654   //! pole of the curve if the multiplicity of the last knot
655   //! is lower than Degree.
656   Standard_EXPORT gp_Pnt2d EndPoint() const Standard_OVERRIDE;
657   
658
659   //! For a B-spline curve the first parameter (which gives the start
660   //! point of the curve) is a knot value but if the multiplicity of
661   //! the first knot index is lower than Degree + 1 it is not the
662   //! first knot of the curve. This method computes the index of the
663   //! knot corresponding to the first parameter.
664   Standard_EXPORT Standard_Integer FirstUKnotIndex() const;
665   
666
667   //! Computes the parametric value of the start point of the curve.
668   //! It is a knot value.
669   Standard_EXPORT Standard_Real FirstParameter() const Standard_OVERRIDE;
670   
671
672   //! Returns the knot of range Index. When there is a knot
673   //! with a multiplicity greater than 1 the knot is not repeated.
674   //! The method Multiplicity can be used to get the multiplicity
675   //! of the Knot.
676   //! Raised if Index < 1 or Index > NbKnots
677   Standard_EXPORT Standard_Real Knot (const Standard_Integer Index) const;
678   
679   //! returns the knot values of the B-spline curve;
680   //!
681   //! Raised K.Lower() is less than number of first knot or
682   //! K.Upper() is more than number of last knot.
683   Standard_EXPORT void Knots (TColStd_Array1OfReal& K) const;
684   
685   //! returns the knot values of the B-spline curve;
686   Standard_EXPORT const TColStd_Array1OfReal& Knots() const;
687   
688   //! Returns the knots sequence.
689   //! In this sequence the knots with a multiplicity greater than 1
690   //! are repeated.
691   //! Example :
692   //! K = {k1, k1, k1, k2, k3, k3, k4, k4, k4}
693   //!
694   //! Raised if K.Lower() is less than number of first knot
695   //! in knot sequence with repetitions or K.Upper() is more
696   //! than number of last knot in knot sequence with repetitions.
697   Standard_EXPORT void KnotSequence (TColStd_Array1OfReal& K) const;
698   
699   //! Returns the knots sequence.
700   //! In this sequence the knots with a multiplicity greater than 1
701   //! are repeated.
702   //! Example :
703   //! K = {k1, k1, k1, k2, k3, k3, k4, k4, k4}
704   Standard_EXPORT const TColStd_Array1OfReal& KnotSequence() const;
705   
706
707   //! Returns NonUniform or Uniform or QuasiUniform or PiecewiseBezier.
708   //! If all the knots differ by a positive constant from the
709   //! preceding knot the BSpline Curve can be :
710   //! - Uniform if all the knots are of multiplicity 1,
711   //! - QuasiUniform if all the knots are of multiplicity 1 except for
712   //! the first and last knot which are of multiplicity Degree + 1,
713   //! - PiecewiseBezier if the first and last knots have multiplicity
714   //! Degree + 1 and if interior knots have multiplicity Degree
715   //! A piecewise Bezier with only two knots is a BezierCurve.
716   //! else the curve is non uniform.
717   //! The tolerance criterion is Epsilon from class Real.
718   Standard_EXPORT GeomAbs_BSplKnotDistribution KnotDistribution() const;
719   
720
721   //! For a BSpline curve the last parameter (which gives the
722   //! end point of the curve) is a knot value but if the
723   //! multiplicity of the last knot index is lower than
724   //! Degree + 1 it is not the last knot of the curve. This
725   //! method computes the index of the knot corresponding to
726   //! the last parameter.
727   Standard_EXPORT Standard_Integer LastUKnotIndex() const;
728   
729
730   //! Computes the parametric value of the end point of the curve.
731   //! It is a knot value.
732   Standard_EXPORT Standard_Real LastParameter() const Standard_OVERRIDE;
733   
734
735   //! Locates the parametric value U in the sequence of knots.
736   //! If "WithKnotRepetition" is True we consider the knot's
737   //! representation with repetition of multiple knot value,
738   //! otherwise  we consider the knot's representation with
739   //! no repetition of multiple knot values.
740   //! Knots (I1) <= U <= Knots (I2)
741   //! . if I1 = I2  U is a knot value (the tolerance criterion
742   //! ParametricTolerance is used).
743   //! . if I1 < 1  => U < Knots (1) - Abs(ParametricTolerance)
744   //! . if I2 > NbKnots => U > Knots (NbKnots) + Abs(ParametricTolerance)
745   Standard_EXPORT void LocateU (const Standard_Real U, const Standard_Real ParametricTolerance, Standard_Integer& I1, Standard_Integer& I2, const Standard_Boolean WithKnotRepetition = Standard_False) const;
746   
747
748   //! Returns the multiplicity of the knots of range Index.
749   //! Raised if Index < 1 or Index > NbKnots
750   Standard_EXPORT Standard_Integer Multiplicity (const Standard_Integer Index) const;
751   
752
753   //! Returns the multiplicity of the knots of the curve.
754   //!
755   //! Raised if the length of M is not equal to NbKnots.
756   Standard_EXPORT void Multiplicities (TColStd_Array1OfInteger& M) const;
757   
758   //! returns the multiplicity of the knots of the curve.
759   Standard_EXPORT const TColStd_Array1OfInteger& Multiplicities() const;
760   
761
762   //! Returns the number of knots. This method returns the number of
763   //! knot without repetition of multiple knots.
764   Standard_EXPORT Standard_Integer NbKnots() const;
765   
766   //! Returns the number of poles
767   Standard_EXPORT Standard_Integer NbPoles() const;
768   
769   //! Returns the pole of range Index.
770   //! Raised if Index < 1 or Index > NbPoles.
771   Standard_EXPORT const gp_Pnt2d& Pole (const Standard_Integer Index) const;
772   
773   //! Returns the poles of the B-spline curve;
774   //!
775   //! Raised if the length of P is not equal to the number of poles.
776   Standard_EXPORT void Poles (TColgp_Array1OfPnt2d& P) const;
777   
778   //! Returns the poles of the B-spline curve;
779   Standard_EXPORT const TColgp_Array1OfPnt2d& Poles() const;
780   
781
782   //! Returns the start point of the curve.
783   //! Warnings :
784   //! This point is different from the first pole of the curve if the
785   //! multiplicity of the first knot is lower than Degree.
786   Standard_EXPORT gp_Pnt2d StartPoint() const Standard_OVERRIDE;
787   
788   //! Returns the weight of the pole of range Index .
789   //! Raised if Index < 1 or Index > NbPoles.
790   Standard_EXPORT Standard_Real Weight (const Standard_Integer Index) const;
791   
792   //! Returns the weights of the B-spline curve;
793   //!
794   //! Raised if the length of W is not equal to NbPoles.
795   Standard_EXPORT void Weights (TColStd_Array1OfReal& W) const;
796   
797   //! Returns the weights of the B-spline curve;
798   Standard_EXPORT const TColStd_Array1OfReal* Weights() const;
799   
800   //! Applies the transformation T to this BSpline curve.
801   Standard_EXPORT void Transform (const gp_Trsf2d& T) Standard_OVERRIDE;
802   
803
804   //! Returns the value of the maximum degree of the normalized
805   //! B-spline basis functions in this package.
806   Standard_EXPORT static Standard_Integer MaxDegree();
807   
808   //! Computes for this BSpline curve the parametric
809   //! tolerance UTolerance for a given tolerance
810   //! Tolerance3D (relative to dimensions in the plane).
811   //! If f(t) is the equation of this BSpline curve,
812   //! UTolerance ensures that:
813   //! | t1 - t0| < Utolerance ===>
814   //! |f(t1) - f(t0)| < ToleranceUV
815   Standard_EXPORT void Resolution (const Standard_Real ToleranceUV, Standard_Real& UTolerance);
816   
817   //! Creates a new object which is a copy of this BSpline curve.
818   Standard_EXPORT Handle(Geom2d_Geometry) Copy() const Standard_OVERRIDE;
819
820   //! Dumps the content of me into the stream
821   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
822
823
824
825
826   DEFINE_STANDARD_RTTIEXT(Geom2d_BSplineCurve,Geom2d_BoundedCurve)
827
828 protected:
829
830
831
832
833 private:
834
835   
836   //! Recompute  the  flatknots,  the knotsdistribution, the continuity.
837   Standard_EXPORT void UpdateKnots();
838
839   Standard_Boolean rational;
840   Standard_Boolean periodic;
841   GeomAbs_BSplKnotDistribution knotSet;
842   GeomAbs_Shape smooth;
843   Standard_Integer deg;
844   Handle(TColgp_HArray1OfPnt2d) poles;
845   Handle(TColStd_HArray1OfReal) weights;
846   Handle(TColStd_HArray1OfReal) flatknots;
847   Handle(TColStd_HArray1OfReal) knots;
848   Handle(TColStd_HArray1OfInteger) mults;
849   Standard_Real maxderivinv;
850   Standard_Boolean maxderivinvok;
851
852
853 };
854
855
856
857
858
859
860
861 #endif // _Geom2d_BSplineCurve_HeaderFile