b311480e |
1 | // Created on: 1993-03-25 |
2 | // Created by: JCV |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | // Passage en classe persistante - 23/01/91 |
18 | // Modif suite a la deuxieme revue de projet toolkit Geometry -23/01/91 |
19 | // Infos : |
20 | // Actuellement pour les champs de la courbe le tableau des poles est |
21 | // declare de 1 a NbPoles et le tableau des poids est declare de 1 a NbPoles |
22 | |
23 | |
24 | // Revised RLE Aug 19 1993 |
25 | // Suppressed Swaps, added Init, removed typedefs |
26 | |
27 | #define No_Standard_OutOfRange |
28 | #define No_Standard_DimensionError |
29 | |
42cf5bc1 |
30 | |
42cf5bc1 |
31 | #include <Geom2d_BezierCurve.hxx> |
32 | #include <Geom2d_Geometry.hxx> |
7fd59977 |
33 | #include <gp.hxx> |
42cf5bc1 |
34 | #include <gp_Pnt2d.hxx> |
35 | #include <gp_Trsf2d.hxx> |
36 | #include <gp_Vec2d.hxx> |
7fd59977 |
37 | #include <gp_XY.hxx> |
42cf5bc1 |
38 | #include <PLib.hxx> |
7fd59977 |
39 | #include <Standard_ConstructionError.hxx> |
40 | #include <Standard_DimensionError.hxx> |
41 | #include <Standard_OutOfRange.hxx> |
42 | #include <Standard_RangeError.hxx> |
42cf5bc1 |
43 | #include <Standard_Type.hxx> |
7fd59977 |
44 | #include <TColStd_Array1OfInteger.hxx> |
42cf5bc1 |
45 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
46 | |
92efcf78 |
47 | IMPLEMENT_STANDARD_RTTIEXT(Geom2d_BezierCurve,Geom2d_BoundedCurve) |
48 | |
7fd59977 |
49 | //======================================================================= |
50 | //function : Rational |
51 | //purpose : check rationality of an array of weights |
52 | //======================================================================= |
7fd59977 |
53 | static Standard_Boolean Rational(const TColStd_Array1OfReal& W) |
54 | { |
55 | Standard_Integer i, n = W.Length(); |
56 | Standard_Boolean rat = Standard_False; |
57 | for (i = 1; i < n; i++) { |
58 | rat = Abs(W(i) - W(i+1)) > gp::Resolution(); |
59 | if (rat) break; |
60 | } |
61 | return rat; |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : Geom2d_BezierCurve |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Geom2d_BezierCurve::Geom2d_BezierCurve |
c8b5b3d8 |
71 | (const TColgp_Array1OfPnt2d& Poles) |
7fd59977 |
72 | { |
73 | // copy the poles |
74 | |
75 | Handle(TColgp_HArray1OfPnt2d) npoles = |
76 | new TColgp_HArray1OfPnt2d(1,Poles.Length()); |
77 | |
78 | npoles->ChangeArray1() = Poles; |
79 | |
80 | // Init non rational |
81 | Init(npoles, |
82 | Handle(TColStd_HArray1OfReal)()); |
83 | } |
84 | |
85 | |
86 | //======================================================================= |
87 | //function : Geom2d_BezierCurve |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | Geom2d_BezierCurve::Geom2d_BezierCurve |
c8b5b3d8 |
92 | (const TColgp_Array1OfPnt2d& Poles, |
93 | const TColStd_Array1OfReal& Weights) |
7fd59977 |
94 | |
95 | { |
96 | // copy the poles |
97 | |
98 | Handle(TColgp_HArray1OfPnt2d) npoles = |
99 | new TColgp_HArray1OfPnt2d(1,Poles.Length()); |
100 | |
101 | npoles->ChangeArray1() = Poles; |
102 | |
103 | |
104 | // check the weights |
105 | |
106 | Standard_Integer nbpoles = Poles.Length(); |
107 | |
108 | if (Weights.Length() != nbpoles) |
9775fa61 |
109 | throw Standard_ConstructionError(); |
7fd59977 |
110 | |
111 | Standard_Integer i; |
112 | for (i = 1; i <= nbpoles; i++) { |
113 | if (Weights(i) <= gp::Resolution()) { |
9775fa61 |
114 | throw Standard_ConstructionError(); |
7fd59977 |
115 | } |
116 | } |
117 | |
118 | // check really rational |
119 | Standard_Boolean rat = Rational(Weights); |
120 | |
121 | // copy the weights |
122 | Handle(TColStd_HArray1OfReal) nweights; |
123 | if (rat) { |
124 | nweights = new TColStd_HArray1OfReal(1,nbpoles); |
125 | nweights->ChangeArray1() = Weights; |
126 | } |
127 | |
128 | // Init |
129 | Init(npoles,nweights); |
130 | } |
131 | |
132 | |
133 | //======================================================================= |
134 | //function : Increase |
135 | //purpose : increase degree |
136 | //======================================================================= |
137 | |
138 | void Geom2d_BezierCurve::Increase (const Standard_Integer Deg) |
139 | { |
140 | if (Deg == Degree()) return; |
141 | |
142 | Standard_ConstructionError_Raise_if |
143 | (Deg < Degree() || |
144 | Deg > Geom2d_BezierCurve::MaxDegree(), "Geom2d_BezierCurve::Increase"); |
145 | |
146 | Handle(TColgp_HArray1OfPnt2d) npoles = |
147 | new TColgp_HArray1OfPnt2d(1,Deg+1); |
148 | |
149 | Handle(TColStd_HArray1OfReal) nweights; |
150 | |
151 | TColStd_Array1OfReal bidknots(1,2); bidknots(1) = 0.; bidknots(2) = 1.; |
152 | TColStd_Array1OfInteger bidmults(1,2); bidmults.Init(Degree() + 1); |
153 | |
154 | if (IsRational()) { |
155 | nweights = new TColStd_HArray1OfReal(1,Deg+1); |
156 | BSplCLib::IncreaseDegree(Degree(), Deg, 0, |
0e14656b |
157 | poles->Array1(),&weights->Array1(), |
7fd59977 |
158 | bidknots, bidmults, |
0e14656b |
159 | npoles->ChangeArray1(),&nweights->ChangeArray1(), |
7fd59977 |
160 | bidknots, bidmults); |
161 | } |
162 | else { |
163 | BSplCLib::IncreaseDegree(Degree(), Deg, 0, |
164 | poles->Array1(), |
0e14656b |
165 | BSplCLib::NoWeights(), |
7fd59977 |
166 | bidknots, bidmults, |
167 | npoles->ChangeArray1(), |
0e14656b |
168 | BSplCLib::NoWeights(), |
7fd59977 |
169 | bidknots, bidmults); |
170 | } |
171 | |
172 | Init(npoles,nweights); |
173 | } |
174 | |
175 | |
176 | //======================================================================= |
177 | //function : MaxDegree |
178 | //purpose : |
179 | //======================================================================= |
180 | |
181 | Standard_Integer Geom2d_BezierCurve::MaxDegree () |
182 | { |
183 | return BSplCLib::MaxDegree(); |
184 | } |
185 | |
186 | |
187 | //======================================================================= |
188 | //function : InsertPoleAfter |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | void Geom2d_BezierCurve::InsertPoleAfter |
193 | (const Standard_Integer Index, |
194 | const gp_Pnt2d& P, |
195 | const Standard_Real Weight) |
196 | { |
197 | Standard_Integer nbpoles = NbPoles(); |
198 | |
199 | Standard_ConstructionError_Raise_if |
200 | (nbpoles >= Geom2d_BezierCurve::MaxDegree() || |
201 | Weight <= gp::Resolution(), |
202 | "Geom2d_BezierCurve::InsertPoleAfter" ); |
203 | |
204 | Standard_OutOfRange_Raise_if |
205 | (Index < 0 || Index > nbpoles, |
206 | "Geom2d_BezierCurve::InsertPoleAfter"); |
207 | |
208 | Standard_Integer i; |
209 | |
210 | // Insert the pole |
211 | Handle(TColgp_HArray1OfPnt2d) npoles = |
212 | new TColgp_HArray1OfPnt2d(1,nbpoles+1); |
213 | |
214 | TColgp_Array1OfPnt2d& newpoles = npoles->ChangeArray1(); |
215 | const TColgp_Array1OfPnt2d& oldpoles = poles->Array1(); |
216 | |
217 | for (i = 1; i <= Index; i++) |
218 | newpoles(i) = oldpoles(i); |
219 | |
220 | newpoles(Index+1) = P; |
221 | |
222 | for (i = Index+1; i <= nbpoles; i++) |
223 | newpoles(i+1) = oldpoles(i); |
224 | |
225 | |
226 | // Insert the weight |
227 | Handle(TColStd_HArray1OfReal) nweights; |
228 | Standard_Boolean rat = IsRational() || Abs(Weight-1.) > gp::Resolution(); |
229 | |
230 | if (rat) { |
231 | nweights = new TColStd_HArray1OfReal(1,nbpoles+1); |
232 | TColStd_Array1OfReal& newweights = nweights->ChangeArray1(); |
233 | |
234 | for (i = 1; i <= Index; i++) |
235 | if (IsRational()) |
236 | newweights(i) = weights->Value(i); |
237 | else |
238 | newweights(i) = 1.; |
239 | |
240 | newweights(Index+1) = Weight; |
241 | |
242 | for (i = Index+1; i <= nbpoles; i++) |
243 | if (IsRational()) |
244 | newweights(i+1) = weights->Value(i); |
245 | else |
246 | newweights(i+1) = 1.; |
247 | } |
248 | |
249 | |
250 | Init(npoles,nweights); |
251 | } |
252 | |
253 | |
254 | //======================================================================= |
255 | //function : InsertPoleBefore |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | void Geom2d_BezierCurve::InsertPoleBefore |
260 | (const Standard_Integer Index, |
261 | const gp_Pnt2d& P, |
262 | const Standard_Real Weight) |
263 | { |
264 | InsertPoleAfter(Index-1,P,Weight); |
265 | } |
266 | |
267 | |
268 | //======================================================================= |
269 | //function : RemovePole |
270 | //purpose : |
271 | //======================================================================= |
272 | |
273 | void Geom2d_BezierCurve::RemovePole |
274 | (const Standard_Integer Index) |
275 | { |
276 | Standard_Integer nbpoles = NbPoles(); |
277 | |
278 | Standard_ConstructionError_Raise_if |
279 | (nbpoles <= 2 , "Geom2d_BezierCurve::RemovePole" ); |
280 | |
281 | Standard_OutOfRange_Raise_if |
282 | (Index < 1 || Index > nbpoles, |
283 | "Geom2d_BezierCurve::RemovePole"); |
284 | |
285 | Standard_Integer i; |
286 | |
287 | // Remove the pole |
288 | Handle(TColgp_HArray1OfPnt2d) npoles = |
289 | new TColgp_HArray1OfPnt2d(1,nbpoles-1); |
290 | |
291 | TColgp_Array1OfPnt2d& newpoles = npoles->ChangeArray1(); |
292 | const TColgp_Array1OfPnt2d& oldpoles = poles->Array1(); |
293 | |
294 | for (i = 1; i < Index; i++) |
295 | newpoles(i) = oldpoles(i); |
296 | |
297 | for (i = Index+1; i <= nbpoles; i++) |
298 | newpoles(i-1) = oldpoles(i); |
299 | |
300 | |
301 | // Remove the weight |
302 | Handle(TColStd_HArray1OfReal) nweights; |
303 | |
304 | if (IsRational()) { |
305 | nweights = new TColStd_HArray1OfReal(1,nbpoles-1); |
306 | TColStd_Array1OfReal& newweights = nweights->ChangeArray1(); |
307 | const TColStd_Array1OfReal& oldweights = weights->Array1(); |
308 | |
309 | for (i = 1; i < Index; i++) |
310 | newweights(i) = oldweights(i); |
311 | |
312 | for (i = Index+1; i <= nbpoles; i++) |
313 | newweights(i-1) = oldweights(i); |
314 | } |
315 | |
316 | Init(npoles,nweights); |
317 | } |
318 | |
319 | |
320 | //======================================================================= |
321 | //function : Reverse |
322 | //purpose : |
323 | //======================================================================= |
324 | |
325 | void Geom2d_BezierCurve::Reverse () |
326 | { |
327 | gp_Pnt2d P; |
328 | Standard_Integer i, nbpoles = NbPoles(); |
329 | TColgp_Array1OfPnt2d & cpoles = poles->ChangeArray1(); |
330 | |
331 | // reverse poles |
332 | for (i = 1; i <= nbpoles / 2; i++) { |
333 | P = cpoles(i); |
334 | cpoles(i) = cpoles(nbpoles-i+1); |
335 | cpoles(nbpoles-i+1) = P; |
336 | } |
337 | |
338 | // reverse weights |
339 | if (IsRational()) { |
340 | TColStd_Array1OfReal & cweights = weights->ChangeArray1(); |
341 | Standard_Real w; |
342 | for (i = 1; i <= nbpoles / 2; i++) { |
343 | w = cweights(i); |
344 | cweights(i) = cweights(nbpoles-i+1); |
345 | cweights(nbpoles-i+1) = w; |
346 | } |
347 | } |
7fd59977 |
348 | } |
349 | |
350 | |
351 | //======================================================================= |
352 | //function : ReversedParameter |
353 | //purpose : |
354 | //======================================================================= |
355 | |
356 | Standard_Real Geom2d_BezierCurve::ReversedParameter |
357 | ( const Standard_Real U) const |
358 | { |
359 | return ( 1. - U); |
360 | } |
361 | |
362 | |
363 | //======================================================================= |
364 | //function : Segment |
365 | //purpose : |
366 | //======================================================================= |
367 | |
368 | void Geom2d_BezierCurve::Segment |
369 | (const Standard_Real U1, const Standard_Real U2) |
370 | { |
371 | closed = (Abs(Value(U1).Distance (Value(U2))) <= gp::Resolution()); |
372 | // |
373 | // WARNING : when calling trimming be carefull that the cache |
374 | // is computed regarding 0.0e0 and not 1.0e0 |
375 | // |
c8b5b3d8 |
376 | TColStd_Array1OfReal bidflatknots(BSplCLib::FlatBezierKnots(Degree()), 1, 2 * (Degree() + 1)); |
377 | TColgp_Array1OfPnt2d coeffs(1, poles->Size()); |
7fd59977 |
378 | if (IsRational()) { |
c8b5b3d8 |
379 | TColStd_Array1OfReal wcoeffs(1, poles->Size()); |
380 | BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots, |
381 | poles->Array1(), &weights->Array1(), coeffs, &wcoeffs); |
382 | PLib::Trimming(U1, U2, coeffs, &wcoeffs); |
383 | PLib::CoefficientsPoles(coeffs, &wcoeffs, poles->ChangeArray1(), &weights->ChangeArray1()); |
7fd59977 |
384 | } |
385 | else { |
c8b5b3d8 |
386 | BSplCLib::BuildCache(0.0, 1.0, 0, Degree(), bidflatknots, |
387 | poles->Array1(), BSplCLib::NoWeights(), coeffs, BSplCLib::NoWeights()); |
388 | PLib::Trimming(U1, U2, coeffs, PLib::NoWeights()); |
389 | PLib::CoefficientsPoles(coeffs, PLib::NoWeights(), poles->ChangeArray1(), PLib::NoWeights()); |
7fd59977 |
390 | } |
7fd59977 |
391 | } |
392 | |
393 | |
394 | //======================================================================= |
395 | //function : SetPole |
396 | //purpose : |
397 | //======================================================================= |
398 | |
399 | void Geom2d_BezierCurve::SetPole |
400 | (const Standard_Integer Index, |
401 | const gp_Pnt2d& P) |
402 | { |
403 | Standard_OutOfRange_Raise_if (Index < 1 || Index > NbPoles(), |
404 | "Geom2d_BezierCurve::SetPole"); |
405 | |
406 | TColgp_Array1OfPnt2d& cpoles = poles->ChangeArray1(); |
407 | cpoles(Index) = P; |
408 | |
409 | if (Index == 1 || Index == cpoles.Length()) { |
410 | closed = (cpoles(1).Distance(cpoles(NbPoles())) <= gp::Resolution()); |
411 | } |
7fd59977 |
412 | } |
413 | |
414 | |
415 | //======================================================================= |
416 | //function : SetPole |
417 | //purpose : |
418 | //======================================================================= |
419 | |
420 | void Geom2d_BezierCurve::SetPole |
421 | (const Standard_Integer Index, |
422 | const gp_Pnt2d& P, |
423 | const Standard_Real Weight) |
424 | { |
425 | SetPole(Index,P); |
426 | SetWeight(Index,Weight); |
427 | } |
428 | |
429 | |
430 | //======================================================================= |
431 | //function : SetWeight |
432 | //purpose : |
433 | //======================================================================= |
434 | |
435 | void Geom2d_BezierCurve::SetWeight |
436 | (const Standard_Integer Index, |
437 | const Standard_Real Weight) |
438 | { |
439 | Standard_Integer nbpoles = NbPoles(); |
440 | |
441 | Standard_OutOfRange_Raise_if |
442 | (Index < 1 || Index > nbpoles, |
443 | "Geom2d_BezierCurve::SetWeight"); |
444 | Standard_ConstructionError_Raise_if |
445 | (Weight <= gp::Resolution (), |
446 | "Geom2d_BezierCurve::SetWeight"); |
447 | |
448 | |
449 | // compute new rationality |
450 | Standard_Boolean wasrat = IsRational(); |
451 | if (!wasrat) { |
452 | // a weight of 1. does not turn to rational |
453 | if (Abs(Weight - 1.) <= gp::Resolution()) return; |
454 | |
455 | // set weights of 1. |
456 | weights = new TColStd_HArray1OfReal(1,nbpoles); |
7fd59977 |
457 | weights->Init(1.); |
458 | } |
459 | |
460 | TColStd_Array1OfReal & cweights = weights->ChangeArray1(); |
461 | cweights(Index) = Weight; |
462 | |
463 | // is it turning into non rational |
c8b5b3d8 |
464 | if (wasrat && !Rational(cweights)) |
465 | weights.Nullify(); |
7fd59977 |
466 | } |
467 | |
468 | |
469 | //======================================================================= |
470 | //function : IsClosed |
471 | //purpose : |
472 | //======================================================================= |
473 | |
474 | Standard_Boolean Geom2d_BezierCurve::IsClosed () const |
475 | { |
476 | return closed; |
477 | } |
478 | |
479 | |
480 | //======================================================================= |
481 | //function : IsCN |
482 | //purpose : |
483 | //======================================================================= |
484 | |
485 | Standard_Boolean Geom2d_BezierCurve::IsCN (const Standard_Integer ) const |
486 | { |
487 | return Standard_True; |
488 | } |
489 | |
490 | |
491 | //======================================================================= |
492 | //function : IsPeriodic |
493 | //purpose : |
494 | //======================================================================= |
495 | |
496 | Standard_Boolean Geom2d_BezierCurve::IsPeriodic () const |
497 | { |
498 | return Standard_False; |
499 | } |
500 | |
501 | |
502 | //======================================================================= |
503 | //function : IsRational |
504 | //purpose : |
505 | //======================================================================= |
506 | |
507 | Standard_Boolean Geom2d_BezierCurve::IsRational () const |
508 | { |
509 | return !weights.IsNull(); |
510 | } |
511 | |
512 | |
513 | //======================================================================= |
514 | //function : Continuity |
515 | //purpose : |
516 | //======================================================================= |
517 | |
518 | GeomAbs_Shape Geom2d_BezierCurve::Continuity () const |
519 | { |
520 | return GeomAbs_CN; |
521 | } |
522 | |
523 | |
524 | //======================================================================= |
525 | //function : Degree |
526 | //purpose : |
527 | //======================================================================= |
528 | |
529 | Standard_Integer Geom2d_BezierCurve::Degree () const |
530 | { |
531 | return poles->Length()-1; |
532 | } |
533 | |
534 | |
535 | //======================================================================= |
536 | //function : D0 |
537 | //purpose : |
538 | //======================================================================= |
539 | |
540 | void Geom2d_BezierCurve::D0 (const Standard_Real U, gp_Pnt2d& P ) const |
541 | { |
c8b5b3d8 |
542 | BSplCLib::D0(U, Poles(), Weights(), P); |
7fd59977 |
543 | } |
544 | |
545 | //======================================================================= |
546 | //function : D1 |
547 | //purpose : |
548 | //======================================================================= |
549 | |
550 | void Geom2d_BezierCurve::D1(const Standard_Real U, |
551 | gp_Pnt2d& P, |
552 | gp_Vec2d& V1) const |
553 | { |
c8b5b3d8 |
554 | BSplCLib::D1(U, Poles(), Weights(), P, V1); |
7fd59977 |
555 | } |
556 | |
557 | //======================================================================= |
558 | //function : D2 |
559 | //purpose : |
560 | //======================================================================= |
561 | |
562 | void Geom2d_BezierCurve::D2 (const Standard_Real U, |
563 | gp_Pnt2d& P, |
564 | gp_Vec2d& V1, |
565 | gp_Vec2d& V2) const |
566 | { |
c8b5b3d8 |
567 | BSplCLib::D2(U, Poles(), Weights(), P, V1, V2); |
7fd59977 |
568 | } |
569 | |
570 | //======================================================================= |
571 | //function : D3 |
572 | //purpose : |
573 | //======================================================================= |
574 | |
575 | void Geom2d_BezierCurve::D3 (const Standard_Real U, |
576 | gp_Pnt2d& P, |
577 | gp_Vec2d& V1, |
578 | gp_Vec2d& V2, |
579 | gp_Vec2d& V3) const |
580 | { |
c8b5b3d8 |
581 | BSplCLib::D3(U, Poles(), Weights(), P, V1, V2, V3); |
7fd59977 |
582 | } |
583 | |
584 | //======================================================================= |
585 | //function : DN |
586 | //purpose : |
587 | //======================================================================= |
588 | |
589 | gp_Vec2d Geom2d_BezierCurve::DN (const Standard_Real U, |
590 | const Standard_Integer N) const |
591 | { |
592 | Standard_RangeError_Raise_if (N < 1, "Geom2d_BezierCurve::DN"); |
593 | gp_Vec2d V; |
594 | |
595 | TColStd_Array1OfReal bidknots(1,2); bidknots(1) = 0.; bidknots(2) = 1.; |
596 | TColStd_Array1OfInteger bidmults(1,2); bidmults.Init(Degree() + 1); |
597 | |
598 | if (IsRational()) |
599 | BSplCLib::DN(U,N,0,Degree(),Standard_False, |
0e14656b |
600 | poles->Array1(),&weights->Array1(), |
601 | bidknots,&bidmults,V); |
7fd59977 |
602 | else |
603 | BSplCLib::DN(U,N,0,Degree(),Standard_False, |
604 | poles->Array1(), |
0e14656b |
605 | BSplCLib::NoWeights(), |
606 | bidknots,&bidmults,V); |
7fd59977 |
607 | return V; |
608 | } |
609 | |
610 | //======================================================================= |
611 | //function : EndPoint |
612 | //purpose : |
613 | //======================================================================= |
614 | |
615 | gp_Pnt2d Geom2d_BezierCurve::EndPoint () const |
616 | { |
617 | return poles->Value (poles->Upper()); |
618 | } |
619 | |
620 | |
621 | //======================================================================= |
622 | //function : FirstParameter |
623 | //purpose : |
624 | //======================================================================= |
625 | |
626 | Standard_Real Geom2d_BezierCurve::FirstParameter () const |
627 | { |
628 | return 0.0; |
629 | } |
630 | |
631 | |
632 | //======================================================================= |
633 | //function : LastParameter |
634 | //purpose : |
635 | //======================================================================= |
636 | |
637 | Standard_Real Geom2d_BezierCurve::LastParameter () const |
638 | { |
639 | return 1.0; |
640 | } |
641 | |
642 | |
643 | //======================================================================= |
644 | //function : NbPoles |
645 | //purpose : |
646 | //======================================================================= |
647 | |
648 | Standard_Integer Geom2d_BezierCurve::NbPoles () const |
649 | { |
650 | return poles->Length(); |
651 | } |
652 | |
653 | |
654 | //======================================================================= |
655 | //function : Pole |
656 | //purpose : |
657 | //======================================================================= |
658 | |
81093856 |
659 | const gp_Pnt2d& Geom2d_BezierCurve::Pole (const Standard_Integer Index) const |
7fd59977 |
660 | { |
661 | Standard_OutOfRange_Raise_if (Index < 1 || Index > poles->Length(), |
662 | "Geom2d_BezierCurve::Pole"); |
663 | return poles->Value(Index); |
664 | } |
665 | |
666 | |
667 | //======================================================================= |
668 | //function : Poles |
669 | //purpose : |
670 | //======================================================================= |
671 | |
672 | void Geom2d_BezierCurve::Poles (TColgp_Array1OfPnt2d& P) const |
673 | { |
674 | Standard_DimensionError_Raise_if (P.Length() != poles->Length(), |
675 | "Geom2d_BezierCurve::Poles"); |
676 | P = poles->Array1(); |
677 | } |
678 | |
679 | |
680 | //======================================================================= |
681 | //function : StartPoint |
682 | //purpose : |
683 | //======================================================================= |
684 | |
685 | gp_Pnt2d Geom2d_BezierCurve::StartPoint () const |
686 | { |
687 | return poles->Value(1); |
688 | } |
689 | |
690 | |
691 | //======================================================================= |
692 | //function : Weight |
693 | //purpose : |
694 | //======================================================================= |
695 | |
696 | Standard_Real Geom2d_BezierCurve::Weight |
697 | (const Standard_Integer Index) const |
698 | { |
699 | Standard_OutOfRange_Raise_if (Index < 1 || Index > weights->Length(), |
700 | "Geom2d_BezierCurve::Weight"); |
701 | if (IsRational()) |
702 | return weights->Value(Index); |
703 | else |
704 | return 1.; |
705 | } |
706 | |
707 | |
708 | //======================================================================= |
709 | //function : Weights |
710 | //purpose : |
711 | //======================================================================= |
712 | |
713 | void Geom2d_BezierCurve::Weights |
714 | (TColStd_Array1OfReal& W) const |
715 | { |
716 | |
717 | Standard_Integer nbpoles = NbPoles(); |
718 | Standard_DimensionError_Raise_if (W.Length() != nbpoles, |
719 | "Geom2d_BezierCurve::Weights"); |
720 | if (IsRational()) |
721 | W = weights->Array1(); |
722 | else { |
723 | Standard_Integer i; |
724 | for (i = 1; i <= nbpoles; i++) |
725 | W(i) = 1.; |
726 | } |
727 | } |
728 | |
729 | |
730 | //======================================================================= |
731 | //function : Transform |
732 | //purpose : |
733 | //======================================================================= |
734 | |
735 | void Geom2d_BezierCurve::Transform (const gp_Trsf2d& T) |
736 | { |
737 | Standard_Integer nbpoles = NbPoles(); |
738 | TColgp_Array1OfPnt2d & cpoles = poles->ChangeArray1(); |
739 | |
740 | for (Standard_Integer i = 1; i <= nbpoles; i++) |
741 | cpoles (i).Transform(T); |
7fd59977 |
742 | } |
743 | |
744 | |
745 | //======================================================================= |
746 | //function : Resolution |
747 | //purpose : |
748 | //======================================================================= |
749 | |
750 | void Geom2d_BezierCurve::Resolution(const Standard_Real ToleranceUV, |
751 | Standard_Real & UTolerance) |
752 | { |
753 | if(!maxderivinvok){ |
754 | TColStd_Array1OfReal bidflatknots(1, 2*(Degree()+1)); |
755 | for(Standard_Integer i = 1; i <= Degree()+1; i++){ |
756 | bidflatknots(i) = 0.; |
757 | bidflatknots(i + Degree() +1) = 1.; |
758 | } |
759 | |
760 | if (IsRational()) { |
761 | BSplCLib::Resolution(poles->Array1(), |
0e14656b |
762 | &weights->Array1(), |
7fd59977 |
763 | poles->Length(), |
764 | bidflatknots, |
765 | Degree(), |
766 | 1., |
767 | maxderivinv) ; |
768 | } |
769 | else { |
770 | BSplCLib::Resolution(poles->Array1(), |
0e14656b |
771 | BSplCLib::NoWeights(), |
7fd59977 |
772 | poles->Length(), |
773 | bidflatknots, |
774 | Degree(), |
775 | 1., |
776 | maxderivinv) ; |
777 | } |
778 | maxderivinvok = 1; |
779 | } |
780 | UTolerance = ToleranceUV * maxderivinv; |
781 | } |
782 | |
783 | |
784 | //======================================================================= |
785 | //function : Copy |
786 | //purpose : |
787 | //======================================================================= |
788 | |
789 | Handle(Geom2d_Geometry) Geom2d_BezierCurve::Copy() const { |
790 | |
791 | Handle(Geom2d_BezierCurve) C; |
792 | if (IsRational()) |
793 | C = new Geom2d_BezierCurve (poles->Array1(),weights->Array1()); |
794 | else |
795 | C = new Geom2d_BezierCurve (poles->Array1()); |
796 | return C; |
797 | } |
798 | |
799 | |
800 | //======================================================================= |
801 | //function : Init |
802 | //purpose : |
803 | //======================================================================= |
804 | |
805 | void Geom2d_BezierCurve::Init |
806 | (const Handle(TColgp_HArray1OfPnt2d)& Poles, |
807 | const Handle(TColStd_HArray1OfReal)& Weights) |
808 | { |
809 | Standard_Integer nbpoles = Poles->Length(); |
810 | // closed ? |
811 | const TColgp_Array1OfPnt2d& cpoles = Poles->Array1(); |
812 | closed = cpoles(1).Distance(cpoles(nbpoles)) <= gp::Resolution(); |
813 | |
814 | // rational |
815 | rational = !Weights.IsNull(); |
816 | |
817 | // set fields |
c8b5b3d8 |
818 | poles = Poles; |
819 | if (rational) |
7fd59977 |
820 | weights = Weights; |
7fd59977 |
821 | else |
c8b5b3d8 |
822 | weights.Nullify(); |
7fd59977 |
823 | } |
824 | |