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