1 // Created on: 1993-03-09
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //Passage en classe persistante - 23/01/91
18 //Modif suite a la deuxieme revue de projet toolkit Geometry -23/01/91
19 // pmn : 21/10/95 ; Correction de la methode segment (PRO5853)
20 // pmn : 31-Dec-96; Bonne gestion des poids (bug PRO4622)
21 // xab : 07-Jul-97; le cache est instable en degree 21
22 // a partir du degree 15 on ne l'utilise plus
23 // RBD : 15/10/98 ; Le cache est desormais defini sur [-1,1] (pro15537).
24 // pmn : 10/12/98 ; Update de la methode segment (suite a la modif de cache).
26 #define No_Standard_OutOfRange
27 #define No_Standard_DimensionError
30 #include <BSplCLib.hxx>
31 #include <Geom_BezierCurve.hxx>
32 #include <Geom_BezierSurface.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_Geometry.hxx>
37 #include <gp_Trsf.hxx>
41 #include <Precision.hxx>
42 #include <Standard_ConstructionError.hxx>
43 #include <Standard_DimensionError.hxx>
44 #include <Standard_OutOfRange.hxx>
45 #include <Standard_RangeError.hxx>
46 #include <Standard_Type.hxx>
47 #include <TColStd_Array1OfInteger.hxx>
49 //=======================================================================
51 //purpose : check rationality of an array of weights
52 //=======================================================================
53 static void Rational(const TColStd_Array2OfReal& Weights,
54 Standard_Boolean& Urational,
55 Standard_Boolean& Vrational)
58 J = Weights.LowerCol ();
59 Vrational = Standard_False;
60 while (!Vrational && J <= Weights.UpperCol()) {
61 I = Weights.LowerRow();
62 while (!Vrational && I <= Weights.UpperRow() - 1) {
63 Vrational = (Abs(Weights (I, J) - Weights (I+1, J))
64 > Epsilon (Abs(Weights (I, J))));
70 I = Weights.LowerRow ();
71 Urational = Standard_False;
72 while (!Urational && I <= Weights.UpperRow()) {
73 J = Weights.LowerCol();
74 while (!Urational && J <= Weights.UpperCol() - 1) {
75 Urational = (Abs(Weights (I, J) - Weights (I, J+1))
76 > Epsilon (Abs(Weights (I, J))));
83 //=======================================================================
84 //function : AddPoleCol
85 //purpose : Internal use only.
86 //=======================================================================
88 static void AddPoleCol
89 (const TColgp_Array2OfPnt& Poles,
90 const TColgp_Array1OfPnt& PoleCol,
91 const Standard_Integer AfterIndex,
92 TColgp_Array2OfPnt& NewPoles)
94 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
95 Standard_Integer Offset = NewPoles.LowerRow() - PoleCol.Lower();
96 Standard_Integer ColIndex = NewPoles.LowerCol();
97 Standard_Integer RowIndex;
98 while (ColIndex < InsertIndex) {
99 RowIndex = NewPoles.LowerRow();
100 while (RowIndex <= NewPoles.UpperRow()){
101 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
106 RowIndex = NewPoles.LowerRow();
107 while (RowIndex <= NewPoles.UpperRow()){
108 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - Offset);
112 while (ColIndex <= NewPoles.UpperCol()) {
113 RowIndex = NewPoles.LowerRow();
114 while (RowIndex <= NewPoles.UpperRow()){
115 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
122 //=======================================================================
123 //function : AddRatPoleCol
124 //purpose : Internal use only.
125 //=======================================================================
127 static void AddRatPoleCol
128 (const TColgp_Array2OfPnt& Poles,
129 const TColStd_Array2OfReal& Weights,
130 const TColgp_Array1OfPnt& PoleCol,
131 const TColStd_Array1OfReal& PoleWeightCol,
132 const Standard_Integer AfterIndex,
133 TColgp_Array2OfPnt& NewPoles,
134 TColStd_Array2OfReal& NewWeights)
136 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
137 Standard_Integer OffsetPol = NewPoles.LowerRow() - PoleCol.Lower();
138 Standard_Integer OffsetW = NewWeights.LowerRow() - PoleWeightCol.Lower();
140 Standard_Integer ColIndex = NewPoles.LowerCol();
141 Standard_Integer RowIndex;
142 while (ColIndex < InsertIndex) {
143 RowIndex = NewPoles.LowerRow();
144 while (RowIndex <= NewPoles.UpperRow()){
145 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
146 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
151 RowIndex = NewPoles.LowerRow();
152 while (RowIndex <= NewPoles.UpperRow()){
153 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - OffsetPol);
154 NewWeights (RowIndex, ColIndex) = PoleWeightCol (RowIndex - OffsetW);
158 while (ColIndex <= NewPoles.UpperCol()) {
159 RowIndex = NewPoles.LowerRow();
160 while (RowIndex <= NewPoles.UpperRow()){
161 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
163 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex - 1);
169 //=======================================================================
170 //function : AddPoleRow
171 //purpose : Internal use only.
172 //=======================================================================
174 static void AddPoleRow
175 (const TColgp_Array2OfPnt& Poles,
176 const TColgp_Array1OfPnt& PoleRow,
177 const Standard_Integer AfterIndex,
178 TColgp_Array2OfPnt& NewPoles)
180 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
181 Standard_Integer Offset = NewPoles.LowerCol() - PoleRow.Lower();
182 Standard_Integer RowIndex = NewPoles.LowerRow();
183 Standard_Integer ColIndex;
184 while (RowIndex < InsertIndex) {
185 ColIndex = NewPoles.LowerCol();
186 while (ColIndex <= NewPoles.UpperCol()){
187 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
192 ColIndex = NewPoles.LowerCol();
193 while (ColIndex <= NewPoles.UpperCol()){
194 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - Offset);
198 while (RowIndex <= NewPoles.UpperRow()) {
199 ColIndex = NewPoles.LowerCol();
200 while (ColIndex <= NewPoles.UpperCol()){
201 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
208 //=======================================================================
209 //function : AddRatPoleRow
211 //=======================================================================
213 static void AddRatPoleRow
214 (const TColgp_Array2OfPnt& Poles,
215 const TColStd_Array2OfReal& Weights,
216 const TColgp_Array1OfPnt& PoleRow,
217 const TColStd_Array1OfReal& PoleWeightRow,
218 const Standard_Integer AfterIndex,
219 TColgp_Array2OfPnt& NewPoles,
220 TColStd_Array2OfReal& NewWeights)
222 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
223 Standard_Integer OffsetPol = NewPoles.LowerCol() - PoleRow.Lower();
224 Standard_Integer OffsetW = NewWeights.LowerCol() - PoleWeightRow.Lower();
226 Standard_Integer ColIndex;
227 Standard_Integer RowIndex = NewPoles.LowerRow();
228 while (RowIndex < InsertIndex) {
229 ColIndex = NewPoles.LowerCol();
230 while (ColIndex <= NewPoles.UpperCol()){
231 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
232 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
237 ColIndex = NewPoles.LowerCol();
238 while (ColIndex <= NewPoles.UpperCol()){
239 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - OffsetPol);
240 NewWeights (RowIndex, ColIndex) = PoleWeightRow (ColIndex - OffsetW);
244 while (RowIndex <= NewPoles.UpperRow()) {
245 ColIndex = NewPoles.LowerCol();
246 while (ColIndex <= NewPoles.UpperCol()){
247 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
248 NewWeights (RowIndex, ColIndex) = Weights (RowIndex - 1, ColIndex);
255 //=======================================================================
256 //function : DeletePoleCol
258 //=======================================================================
260 static void DeletePoleCol
261 (const TColgp_Array2OfPnt& Poles,
262 const Standard_Integer Index,
263 TColgp_Array2OfPnt& NewPoles)
265 Standard_Integer Offset = 0;
266 Standard_Integer RowIndex;
267 Standard_Integer ColIndex = NewPoles.LowerCol();
268 while (ColIndex <= NewPoles.UpperCol()) {
269 RowIndex = NewPoles.LowerRow();
270 if (ColIndex == Index) Offset = 1;
271 while (RowIndex <= NewPoles.UpperRow()){
272 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
279 //=======================================================================
280 //function : DeleteRatPoleCol
282 //=======================================================================
284 static void DeleteRatPoleCol
285 (const TColgp_Array2OfPnt& Poles,
286 const TColStd_Array2OfReal& Weights,
287 const Standard_Integer Index,
288 TColgp_Array2OfPnt& NewPoles,
289 TColStd_Array2OfReal& NewWeights)
291 Standard_Integer Offset = 0;
292 Standard_Integer RowIndex;
293 Standard_Integer ColIndex = NewPoles.LowerCol();
294 while (ColIndex <= NewPoles.UpperCol()) {
295 RowIndex = NewPoles.LowerRow();
296 if (ColIndex == Index) Offset = 1;
297 while (RowIndex <= NewPoles.UpperRow()){
298 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
299 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex+Offset);
306 //=======================================================================
307 //function : DeletePoleRow
309 //=======================================================================
311 static void DeletePoleRow
312 (const TColgp_Array2OfPnt& Poles,
313 const Standard_Integer Index,
314 TColgp_Array2OfPnt& NewPoles)
316 Standard_Integer Offset = 0;
317 Standard_Integer ColIndex;
318 Standard_Integer RowIndex = NewPoles.LowerRow();
319 while (RowIndex <= NewPoles.UpperRow()) {
320 ColIndex = NewPoles.LowerCol();
321 if (RowIndex == Index) Offset = 1;
322 while (ColIndex <= NewPoles.UpperCol()){
323 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
330 //=======================================================================
331 //function : DeleteRatPoleRow
333 //=======================================================================
335 static void DeleteRatPoleRow
336 (const TColgp_Array2OfPnt& Poles,
337 const TColStd_Array2OfReal& Weights,
338 const Standard_Integer Index,
339 TColgp_Array2OfPnt& NewPoles,
340 TColStd_Array2OfReal& NewWeights)
342 Standard_Integer Offset = 0;
343 Standard_Integer ColIndex;
344 Standard_Integer RowIndex = NewPoles.LowerRow();
345 while (RowIndex <= NewPoles.UpperRow()) {
346 ColIndex = NewPoles.LowerCol();
347 if (RowIndex == Index) Offset = 1;
348 while (ColIndex <= NewPoles.UpperCol()){
349 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
350 NewWeights (RowIndex, ColIndex) = Weights (RowIndex+Offset, ColIndex);
357 //=======================================================================
358 //function : Geom_BezierSurface
360 //=======================================================================
362 Geom_BezierSurface::Geom_BezierSurface
363 (const TColgp_Array2OfPnt& SurfacePoles):
364 maxderivinvok(Standard_False)
366 Standard_Integer NbUPoles = SurfacePoles.ColLength();
367 Standard_Integer NbVPoles = SurfacePoles.RowLength();
368 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
369 NbVPoles < 2 || NbVPoles > MaxDegree()+1) {
370 Standard_ConstructionError::Raise();
373 Handle(TColgp_HArray2OfPnt) npoles =
374 new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
379 npoles->ChangeArray2() = SurfacePoles;
383 Handle(TColStd_HArray2OfReal)());
386 //=======================================================================
387 //function : Geom_BezierSurface
389 //=======================================================================
391 Geom_BezierSurface::Geom_BezierSurface
392 (const TColgp_Array2OfPnt& SurfacePoles,
393 const TColStd_Array2OfReal& PoleWeights ):
394 maxderivinvok(Standard_False)
396 Standard_Integer NbUPoles = SurfacePoles.ColLength();
397 Standard_Integer NbVPoles = SurfacePoles.RowLength();
398 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
399 NbVPoles < 2 || NbVPoles > MaxDegree()+1 ||
400 NbVPoles != PoleWeights.RowLength() ||
401 NbUPoles != PoleWeights.ColLength() ) {
402 Standard_ConstructionError::Raise();
405 Standard_Integer Row = PoleWeights.LowerRow();
406 Standard_Integer Col = PoleWeights.LowerCol();
407 while (Col <= PoleWeights.UpperCol()) {
408 Row = PoleWeights.LowerRow();
409 while (Row <= PoleWeights.UpperRow()) {
410 if (PoleWeights(Row, Col) <= gp::Resolution()) {
411 Standard_ConstructionError::Raise();
418 Handle(TColgp_HArray2OfPnt)
419 npoles = new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
420 npoles->ChangeArray2() = SurfacePoles;
422 Standard_Integer I, J;
423 urational = Standard_False;
424 vrational = Standard_False;
425 J = PoleWeights.LowerCol ();
426 while (!vrational && J <= PoleWeights.UpperCol()) {
427 I = PoleWeights.LowerRow();
428 while (!vrational && I <= PoleWeights.UpperRow() - 1) {
429 vrational = (Abs(PoleWeights (I, J) - PoleWeights (I+1, J))
430 > Epsilon (Abs(PoleWeights (I, J))));
435 I = PoleWeights.LowerRow ();
436 while (!urational && I <= PoleWeights.UpperRow()) {
437 J = PoleWeights.LowerCol();
438 while (!urational && J <= PoleWeights.UpperCol() - 1) {
439 urational = (Abs(PoleWeights (I, J) - PoleWeights (I, J+1))
440 > Epsilon (Abs(PoleWeights (I, J))));
447 Handle(TColStd_HArray2OfReal) nweights;
448 if (urational || vrational) {
449 nweights = new TColStd_HArray2OfReal (1, NbUPoles, 1, NbVPoles);
450 nweights->ChangeArray2() = PoleWeights;
454 Init(npoles,nweights);
457 //=======================================================================
458 //function : Geom_BezierSurface
460 //=======================================================================
462 Geom_BezierSurface::Geom_BezierSurface
463 (const Handle(TColgp_HArray2OfPnt)& SurfacePoles,
464 const Handle(TColStd_HArray2OfReal)& PoleWeights,
465 const Standard_Boolean IsURational,
466 const Standard_Boolean IsVRational)
467 :maxderivinvok(Standard_False)
469 urational = IsURational;
470 vrational = IsVRational;
471 Standard_Integer NbUPoles = SurfacePoles->ColLength();
472 Standard_Integer NbVPoles = SurfacePoles->RowLength();
474 poles = new TColgp_HArray2OfPnt (1,NbUPoles,
476 poles->ChangeArray2() = SurfacePoles->Array2();
478 if ( urational || vrational) {
479 weights = new TColStd_HArray2OfReal (1,NbUPoles,1,NbVPoles);
480 weights->ChangeArray2() = PoleWeights->Array2();
484 //=======================================================================
485 //function : MaxDegree
487 //=======================================================================
489 Standard_Integer Geom_BezierSurface::MaxDegree ()
491 return BSplCLib::MaxDegree();
494 //=======================================================================
495 //function : ExchangeUV
497 //=======================================================================
499 void Geom_BezierSurface::ExchangeUV ()
501 Standard_Integer LC = poles->LowerCol();
502 Standard_Integer UC = poles->UpperCol();
503 Standard_Integer LR = poles->LowerRow();
504 Standard_Integer UR = poles->UpperRow();
506 Handle(TColgp_HArray2OfPnt) npoles =
507 new TColgp_HArray2OfPnt (LC, UC, LR, UR);
508 Handle(TColStd_HArray2OfReal) nweights =
509 new TColStd_HArray2OfReal (LC, UC, LR, UR);
511 const TColgp_Array2OfPnt & spoles = poles->Array2();
512 const TColStd_Array2OfReal & sweights = weights->Array2();
514 TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2();
515 TColStd_Array2OfReal& snweights = nweights->ChangeArray2();
517 Standard_Integer i, j;
518 for (i = LC; i <= UC; i++) {
519 for (j = LR; j <= UR; j++) {
520 snpoles (i,j) = spoles (j,i);
521 snweights (i,j) = sweights (j,i);
528 Standard_Boolean temp = urational;
529 urational = vrational;
533 //=======================================================================
534 //function : Increase
536 //=======================================================================
538 void Geom_BezierSurface::Increase (const Standard_Integer UDeg,
539 const Standard_Integer VDeg)
541 if (UDeg < UDegree() || UDeg > Geom_BezierSurface::MaxDegree() ||
542 VDeg < VDegree() || VDeg > Geom_BezierSurface::MaxDegree() ) {
543 Standard_ConstructionError::Raise();
546 Standard_Integer oldUDeg = UDegree();
547 Standard_Integer oldVDeg = VDegree();
548 Standard_Integer IncUDeg = UDeg - oldUDeg;
549 Standard_Integer IncVDeg = VDeg - oldVDeg;
550 if (IncUDeg == 0 && IncVDeg == 0) return;
552 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
553 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
554 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
555 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
556 Handle(TColgp_HArray2OfPnt) npoles;
557 Handle(TColStd_HArray2OfReal) nweights;
560 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, oldVDeg + 1);
562 if ( urational || vrational) {
563 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDegree() + 1);
565 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
568 biduknots, bidumults,
569 npoles->ChangeArray2(),
570 &nweights->ChangeArray2(),
571 biduknots, bidumults);
575 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
577 BSplSLib::NoWeights(),
578 biduknots, bidumults,
579 npoles->ChangeArray2(),
580 BSplSLib::NoWeights(),
581 biduknots, bidumults);
586 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, VDeg + 1);
588 if ( urational || vrational) {
589 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDeg + 1);
591 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
594 bidvknots, bidvmults,
595 npoles->ChangeArray2(),
596 &nweights->ChangeArray2(),
597 bidvknots, bidvmults);
601 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
603 BSplSLib::NoWeights(),
604 bidvknots, bidvmults,
605 npoles->ChangeArray2(),
606 BSplSLib::NoWeights(),
607 bidvknots, bidvmults);
612 Init(npoles,nweights);
615 //=======================================================================
616 //function : InsertPoleColAfter
618 //=======================================================================
620 void Geom_BezierSurface::InsertPoleColAfter
621 (const Standard_Integer VIndex,
622 const TColgp_Array1OfPnt& CPoles)
624 const TColgp_Array2OfPnt & Poles = poles->Array2();
625 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
626 if (CPoles.Length() != Poles.ColLength()) {
627 Standard_ConstructionError::Raise();
630 Handle(TColgp_HArray2OfPnt) npoles =
631 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
633 Handle(TColStd_HArray2OfReal) nweights;
635 if (urational || vrational) {
637 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
639 TColStd_Array1OfReal CWeights(nweights->LowerRow(),nweights->UpperRow());
642 AddRatPoleCol (poles->Array2(), weights->Array2(),
643 CPoles, CWeights, VIndex,
644 npoles->ChangeArray2(), nweights->ChangeArray2());
647 AddPoleCol (poles->Array2(),
649 npoles->ChangeArray2());
655 //=======================================================================
656 //function : InsertPoleColAfter
658 //=======================================================================
660 void Geom_BezierSurface::InsertPoleColAfter
661 (const Standard_Integer VIndex,
662 const TColgp_Array1OfPnt& CPoles,
663 const TColStd_Array1OfReal& CPoleWeights)
665 const TColgp_Array2OfPnt & Poles = poles->Array2();
666 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
667 if (CPoles.Length() != Poles.ColLength() ||
668 CPoleWeights.Length() != CPoles.Length()) {
669 Standard_ConstructionError::Raise();
671 Standard_Integer Index = CPoleWeights.Lower();
672 while (Index <= CPoleWeights.Upper()) {
673 if (CPoleWeights (Index) <= gp::Resolution()) {
674 Standard_ConstructionError::Raise();
679 Handle(TColgp_HArray2OfPnt) npoles =
680 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
682 Handle(TColStd_HArray2OfReal) nweights =
683 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
685 AddRatPoleCol (poles->Array2(), weights->Array2(),
686 CPoles, CPoleWeights, VIndex,
687 npoles->ChangeArray2(), nweights->ChangeArray2());
692 Rational(weights->Array2(), urational, vrational);
695 //=======================================================================
696 //function : InsertPoleColBefore
698 //=======================================================================
700 void Geom_BezierSurface::InsertPoleColBefore (const Standard_Integer VIndex,
701 const TColgp_Array1OfPnt& CPoles)
703 InsertPoleColAfter(VIndex - 1, CPoles);
706 //=======================================================================
707 //function : InsertPoleColBefore
709 //=======================================================================
711 void Geom_BezierSurface::InsertPoleColBefore
712 (const Standard_Integer VIndex,
713 const TColgp_Array1OfPnt& CPoles,
714 const TColStd_Array1OfReal& CPoleWeights)
716 InsertPoleColAfter( VIndex - 1, CPoles, CPoleWeights);
719 //=======================================================================
720 //function : InsertPoleRowAfter
722 //=======================================================================
724 void Geom_BezierSurface::InsertPoleRowAfter (const Standard_Integer UIndex,
725 const TColgp_Array1OfPnt& CPoles)
727 const TColgp_Array2OfPnt & Poles = poles->Array2();
728 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
729 if (CPoles.Length() != Poles.RowLength()) {
730 Standard_ConstructionError::Raise();
733 Handle(TColgp_HArray2OfPnt) npoles =
734 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
736 Handle(TColStd_HArray2OfReal) nweights;
738 if (urational || vrational) {
740 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
742 // TColStd_Array1OfReal CWeights(nweights->LowerCol(),nweights->UpperCol(),
744 TColStd_Array1OfReal CWeights(1.0,
745 nweights->LowerCol(),nweights->UpperCol());
747 AddRatPoleRow (poles->Array2(), weights->Array2(),
748 CPoles, CWeights, UIndex,
749 npoles->ChangeArray2(), nweights->ChangeArray2());
752 AddPoleRow (poles->Array2(),
754 npoles->ChangeArray2());
760 //=======================================================================
761 //function : InsertPoleRowAfter
763 //=======================================================================
765 void Geom_BezierSurface::InsertPoleRowAfter
766 (const Standard_Integer UIndex,
767 const TColgp_Array1OfPnt& CPoles,
768 const TColStd_Array1OfReal& CPoleWeights)
770 const TColgp_Array2OfPnt & Poles = poles->Array2();
771 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
772 if (CPoles.Length() != Poles.RowLength() ||
773 CPoleWeights.Length() != CPoles.Length()) {
774 Standard_ConstructionError::Raise();
776 Standard_Integer Index = CPoleWeights.Lower();
777 while (Index <= CPoleWeights.Upper()) {
778 if (CPoleWeights(Index) <= gp::Resolution()) {
779 Standard_ConstructionError::Raise();
784 Handle(TColgp_HArray2OfPnt) npoles =
785 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
787 Handle(TColStd_HArray2OfReal) nweights =
788 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
790 AddRatPoleCol (poles->Array2(), weights->Array2(),
791 CPoles, CPoleWeights, UIndex,
792 npoles->ChangeArray2(), nweights->ChangeArray2());
797 Rational(weights->Array2(), urational, vrational);
800 //=======================================================================
801 //function : InsertPoleRowBefore
803 //=======================================================================
805 void Geom_BezierSurface::InsertPoleRowBefore (const Standard_Integer UIndex,
806 const TColgp_Array1OfPnt& CPoles)
808 InsertPoleRowAfter( UIndex - 1, CPoles);
811 //=======================================================================
812 //function : InsertPoleRowBefore
814 //=======================================================================
816 void Geom_BezierSurface::InsertPoleRowBefore
817 (const Standard_Integer UIndex,
818 const TColgp_Array1OfPnt& CPoles,
819 const TColStd_Array1OfReal& CPoleWeights)
821 InsertPoleRowAfter( UIndex - 1, CPoles, CPoleWeights);
824 //=======================================================================
825 //function : RemovePoleCol
827 //=======================================================================
829 void Geom_BezierSurface::RemovePoleCol (const Standard_Integer VIndex)
831 const TColgp_Array2OfPnt & Poles = poles->Array2();
832 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
833 if (Poles.RowLength() <= 2) Standard_ConstructionError::Raise();
835 Handle(TColgp_HArray2OfPnt) npoles =
836 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()-1);
838 Handle(TColStd_HArray2OfReal) nweights;
840 if (urational || vrational) {
842 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()-1);
844 DeleteRatPoleCol (poles->Array2(), weights->Array2(),
846 npoles->ChangeArray2(), nweights->ChangeArray2());
847 // Mise a jour de la rationalite
848 Rational(nweights->Array2(), urational, vrational);
851 DeletePoleCol (poles->Array2(),
853 npoles->ChangeArray2());
859 //=======================================================================
860 //function : RemovePoleRow
862 //=======================================================================
864 void Geom_BezierSurface::RemovePoleRow (const Standard_Integer UIndex)
866 const TColgp_Array2OfPnt & Poles = poles->Array2();
867 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
868 if (Poles.ColLength() <= 2) Standard_ConstructionError::Raise();
870 Handle(TColgp_HArray2OfPnt) npoles =
871 new TColgp_HArray2OfPnt(1,poles->ColLength()-1,1,poles->RowLength());
873 Handle(TColStd_HArray2OfReal) nweights;
875 if (urational || vrational) {
877 new TColStd_HArray2OfReal(1,poles->ColLength()-1,1,poles->RowLength());
879 DeleteRatPoleRow (poles->Array2(), weights->Array2(),
881 npoles->ChangeArray2(), nweights->ChangeArray2());
883 // Mise a jour de la rationalite
884 Rational(nweights->Array2(), urational, vrational);
887 DeletePoleRow (poles->Array2(),
889 npoles->ChangeArray2());
895 //=======================================================================
898 //=======================================================================
900 void Geom_BezierSurface::Segment
901 (const Standard_Real U1,
902 const Standard_Real U2,
903 const Standard_Real V1,
904 const Standard_Real V2)
906 Standard_Boolean rat = (urational || vrational);
907 Handle(TColgp_HArray2OfPnt) Coefs;
908 Handle(TColStd_HArray2OfReal) WCoefs;
910 Standard_Integer aMinDegree = UDegree() <= VDegree() ? UDegree() : VDegree();
911 Standard_Integer aMaxDegree = UDegree() > VDegree() ? UDegree() : VDegree();
912 Coefs = new TColgp_HArray2OfPnt(1, aMaxDegree + 1, 1, aMinDegree + 1);
914 WCoefs = new TColStd_HArray2OfReal(1, aMaxDegree + 1, 1, aMinDegree + 1);
916 TColStd_Array1OfReal biduflatknots(BSplCLib::FlatBezierKnots(UDegree()), 1, 2 * (UDegree() + 1));
917 TColStd_Array1OfReal bidvflatknots(BSplCLib::FlatBezierKnots(VDegree()), 1, 2 * (VDegree() + 1));
919 Standard_Real uparameter_11 = 0.5;
920 Standard_Real uspanlenght_11 = 0.5;
921 Standard_Real vparameter_11 = 0.5;
922 Standard_Real vspanlenght_11 = 0.5;
924 if (urational || vrational) {
925 BSplSLib::BuildCache(uparameter_11, vparameter_11,
926 uspanlenght_11, vspanlenght_11, 0, 0,
927 UDegree(), VDegree(), 0, 0,
928 biduflatknots, bidvflatknots,
931 Coefs->ChangeArray2(),
932 &WCoefs->ChangeArray2());
935 BSplSLib::BuildCache(uparameter_11, vparameter_11,
936 uspanlenght_11, vspanlenght_11, 0, 0,
937 UDegree(), VDegree(), 0, 0,
938 biduflatknots, bidvflatknots,
940 BSplSLib::NoWeights(),
941 Coefs->ChangeArray2(),
942 BSplSLib::NoWeights());
945 // Attention si udeg <= vdeg u et v sont intervertis
946 // dans les coeffs, il faut donc tout transposer.
947 if(UDegree() <= VDegree()) {
948 Handle(TColgp_HArray2OfPnt) coeffs = Coefs;
949 Handle(TColStd_HArray2OfReal) wcoeffs = WCoefs;
950 Standard_Integer ii, jj;
951 Coefs = new (TColgp_HArray2OfPnt)(1,UDegree()+1,1,VDegree()+1);
953 WCoefs = new (TColStd_HArray2OfReal)(1,UDegree()+1,1,VDegree()+1);
955 for (ii=1; ii<=UDegree()+1; ii++)
956 for (jj=1; jj<=VDegree()+1; jj++) {
957 Coefs->SetValue(ii, jj, coeffs->Value(jj,ii));
958 if (rat) WCoefs->SetValue(ii, jj, wcoeffs->Value(jj,ii));
962 // Trim dans la base cannonique et Update des Poles et Coeffs
964 // PMN : tranfo sur les parametres
965 Standard_Real ufirst = 2*(U1 - 0.5),
966 ulast = 2*(U2 - 0.5),
967 vfirst = 2*(V1 - 0.5),
968 vlast = 2*(V2 - 0.5);
970 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
971 &WCoefs->ChangeArray2());
972 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
973 &WCoefs->ChangeArray2());
974 PLib::CoefficientsPoles(Coefs->Array2(),
976 poles->ChangeArray2(),
977 &weights->ChangeArray2());
980 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(), PLib::NoWeights2());
981 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(), PLib::NoWeights2());
982 PLib::CoefficientsPoles (Coefs->Array2(), PLib::NoWeights2(),
983 poles->ChangeArray2(), PLib::NoWeights2());
987 //=======================================================================
990 //=======================================================================
992 void Geom_BezierSurface::SetPole
993 (const Standard_Integer UIndex,
994 const Standard_Integer VIndex,
997 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
999 UIndex > Poles.ColLength() ||
1001 VIndex > Poles.RowLength() ) Standard_OutOfRange::Raise();
1003 Poles (UIndex, VIndex) = P;
1006 //=======================================================================
1007 //function : SetPole
1009 //=======================================================================
1011 void Geom_BezierSurface::SetPole
1012 (const Standard_Integer UIndex,
1013 const Standard_Integer VIndex,
1015 const Standard_Real Weight)
1018 if (Weight <= gp::Resolution())
1019 Standard_ConstructionError::Raise("Geom_BezierSurface::SetPole");
1021 UIndex > poles->ColLength() ||
1023 VIndex > poles->RowLength())
1024 Standard_OutOfRange::Raise("Geom_BezierSurface::SetPole");
1026 poles->SetValue(UIndex, VIndex, P);
1028 SetWeight(UIndex, VIndex, Weight); //L'update des coeff est fait la dedans
1031 //=======================================================================
1032 //function : SetPoleCol
1034 //=======================================================================
1036 void Geom_BezierSurface::SetPoleCol
1037 (const Standard_Integer VIndex,
1038 const TColgp_Array1OfPnt& CPoles,
1039 const TColStd_Array1OfReal& CPoleWeights)
1041 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1042 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
1044 if (CPoles.Lower() < 1 ||
1045 CPoles.Lower() > Poles.ColLength() ||
1046 CPoles.Upper() < 1 ||
1047 CPoles.Upper() > Poles.ColLength() ||
1048 CPoleWeights.Lower() != CPoles.Lower() ||
1049 CPoleWeights.Upper() != CPoles.Upper()) {
1050 Standard_ConstructionError::Raise();
1054 for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1055 Poles (I, VIndex) = CPoles (I);
1057 SetWeightCol(VIndex, CPoleWeights); //Avec l'update
1060 //=======================================================================
1061 //function : SetPoleCol
1063 //=======================================================================
1065 void Geom_BezierSurface::SetPoleCol (const Standard_Integer VIndex,
1066 const TColgp_Array1OfPnt& CPoles)
1068 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1069 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
1071 if (CPoles.Lower() < 1 ||
1072 CPoles.Lower() > Poles.ColLength() ||
1073 CPoles.Upper() < 1 ||
1074 CPoles.Upper() > Poles.ColLength()) {
1075 Standard_ConstructionError::Raise();
1077 for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1078 Poles (I, VIndex) = CPoles (I);
1082 //=======================================================================
1083 //function : SetPoleRow
1085 //=======================================================================
1087 void Geom_BezierSurface::SetPoleRow (const Standard_Integer UIndex,
1088 const TColgp_Array1OfPnt& CPoles)
1090 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1091 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
1093 if (CPoles.Lower() < 1 ||
1094 CPoles.Lower() > Poles.RowLength() ||
1095 CPoles.Upper() < 1 ||
1096 CPoles.Upper() > Poles.RowLength()) Standard_ConstructionError::Raise();
1098 for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1099 Poles (UIndex, I) = CPoles (I);
1103 //=======================================================================
1104 //function : SetPoleRow
1106 //=======================================================================
1108 void Geom_BezierSurface::SetPoleRow
1109 (const Standard_Integer UIndex,
1110 const TColgp_Array1OfPnt& CPoles,
1111 const TColStd_Array1OfReal& CPoleWeights)
1113 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1114 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
1116 if (CPoles.Lower() < 1 ||
1117 CPoles.Lower() > Poles.RowLength() ||
1118 CPoles.Upper() < 1 ||
1119 CPoles.Upper() > Poles.RowLength() ||
1120 CPoleWeights.Lower() != CPoles.Lower() ||
1121 CPoleWeights.Upper() != CPoles.Upper()) {
1122 Standard_ConstructionError::Raise();
1127 for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1128 Poles (UIndex, I) = CPoles (I);
1131 SetWeightRow(UIndex, CPoleWeights); //Avec l'update
1134 //=======================================================================
1135 //function : SetWeight
1137 //=======================================================================
1139 void Geom_BezierSurface::SetWeight (const Standard_Integer UIndex,
1140 const Standard_Integer VIndex,
1141 const Standard_Real Weight)
1143 // compute new rationality
1144 Standard_Boolean wasrat = (urational||vrational);
1146 // a weight of 1. does not turn to rational
1147 if (Abs(Weight - 1.) <= gp::Resolution())
1150 // set weights of 1.
1151 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1152 1, poles->RowLength(), 1.);
1155 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1156 if (Weight <= gp::Resolution())
1157 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeight");
1160 UIndex > Weights.ColLength() ||
1162 VIndex > Weights.RowLength()) Standard_OutOfRange::Raise();
1164 if (Abs (Weight - Weights (UIndex, VIndex)) > gp::Resolution()) {
1165 Weights (UIndex, VIndex) = Weight;
1166 Rational(Weights, urational, vrational);
1169 // is it turning into non rational
1170 if (wasrat && !(urational || vrational))
1174 //=======================================================================
1175 //function : SetWeightCol
1177 //=======================================================================
1179 void Geom_BezierSurface::SetWeightCol
1180 (const Standard_Integer VIndex,
1181 const TColStd_Array1OfReal& CPoleWeights)
1184 // compute new rationality
1185 Standard_Boolean wasrat = (urational||vrational);
1187 // set weights of 1.
1188 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1189 1, poles->RowLength(), 1.);
1192 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1193 if (VIndex < 1 || VIndex > Weights.RowLength()) Standard_OutOfRange::Raise();
1195 if (CPoleWeights.Length() != Weights.ColLength()) {
1196 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightCol");
1199 I = CPoleWeights.Lower();
1200 while (I <= CPoleWeights.Upper()) {
1201 if (CPoleWeights(I) <= gp::Resolution()) {
1202 Standard_ConstructionError::Raise();
1204 Weights (I, VIndex) = CPoleWeights (I);
1208 Rational(Weights, urational, vrational);
1210 // is it turning into non rational
1211 if (wasrat && !(urational || vrational))
1215 //=======================================================================
1216 //function : SetWeightRow
1218 //=======================================================================
1220 void Geom_BezierSurface::SetWeightRow
1221 (const Standard_Integer UIndex,
1222 const TColStd_Array1OfReal& CPoleWeights)
1225 // compute new rationality
1226 Standard_Boolean wasrat = (urational||vrational);
1228 // set weights of 1.
1229 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1230 1, poles->RowLength(), 1.);
1233 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1234 if (UIndex < 1 || UIndex > Weights.ColLength())
1235 Standard_OutOfRange::Raise("Geom_BezierSurface::SetWeightRow");
1236 if (CPoleWeights.Lower() < 1 ||
1237 CPoleWeights.Lower() > Weights.RowLength() ||
1238 CPoleWeights.Upper() < 1 ||
1239 CPoleWeights.Upper() > Weights.RowLength() ) {
1240 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightRow");
1243 I = CPoleWeights.Lower();
1244 while (I <= CPoleWeights.Upper()) {
1245 if (CPoleWeights(I) <= gp::Resolution()) {
1246 Standard_ConstructionError::Raise();
1248 Weights (UIndex, I) = CPoleWeights (I);
1252 Rational(Weights, urational, vrational);
1254 // is it turning into non rational
1255 if (wasrat && !(urational || vrational))
1259 //=======================================================================
1260 //function : UReverse
1262 //=======================================================================
1264 void Geom_BezierSurface::UReverse ()
1267 Standard_Integer Row,Col;
1268 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1269 if (urational || vrational) {
1270 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1272 for (Col = 1; Col <= Poles.RowLength(); Col++) {
1273 for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) {
1274 W = Weights (Row, Col);
1275 Weights (Row, Col) = Weights (Poles.ColLength()- Row + 1, Col);
1276 Weights (Poles.ColLength() - Row + 1, Col) = W;
1277 Pol = Poles (Row, Col);
1278 Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col);
1279 Poles (Poles.ColLength() - Row + 1, Col) = Pol;
1284 for (Col = 1; Col <= Poles.RowLength(); Col++) {
1285 for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) {
1286 Pol = Poles (Row, Col);
1287 Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col);
1288 Poles (Poles.ColLength() - Row + 1, Col) = Pol;
1294 //=======================================================================
1295 //function : UReversedParameter
1297 //=======================================================================
1299 Standard_Real Geom_BezierSurface::UReversedParameter
1300 ( const Standard_Real U) const
1305 //=======================================================================
1306 //function : VReverse
1308 //=======================================================================
1310 void Geom_BezierSurface::VReverse ()
1313 Standard_Integer Row,Col;
1314 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1315 if (urational || vrational) {
1316 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1318 for (Row = 1; Row <= Poles.ColLength(); Row++) {
1319 for (Col = 1; Col <= IntegerPart (Poles.RowLength()/2); Col++) {
1320 W = Weights (Row, Col);
1321 Weights (Row, Col) = Weights (Row, Poles.RowLength() - Col + 1);
1322 Weights (Row, Poles.RowLength() - Col + 1) = W;
1323 Pol = Poles (Row, Col);
1324 Poles (Row, Col) = Poles (Row, Poles.RowLength() - Col + 1);
1325 Poles (Row, Poles.RowLength() - Col + 1) = Pol;
1330 for (Row = 1; Row <= Poles.ColLength(); Row++) {
1331 for (Col = 1; Col <= IntegerPart(Poles.RowLength()/2); Col++) {
1332 Pol = Poles (Row, Col);
1333 Poles (Row, Col)= Poles (Row, Poles.RowLength() - Col + 1);
1334 Poles (Row, Poles.RowLength() - Col + 1) = Pol;
1340 //=======================================================================
1341 //function : VReversedParameter
1343 //=======================================================================
1345 Standard_Real Geom_BezierSurface::VReversedParameter
1346 ( const Standard_Real V) const
1351 //=======================================================================
1354 //=======================================================================
1356 void Geom_BezierSurface::Bounds (Standard_Real& U1,
1359 Standard_Real& V2) const
1367 //=======================================================================
1368 //function : Continuity
1370 //=======================================================================
1372 GeomAbs_Shape Geom_BezierSurface::Continuity () const
1377 //=======================================================================
1380 //=======================================================================
1382 void Geom_BezierSurface::D0 (const Standard_Real U,
1383 const Standard_Real V,
1386 Standard_Real array_u[2];
1387 Standard_Real array_v[2];
1388 Standard_Integer mult_u[2];
1389 Standard_Integer mult_v[2];
1390 TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
1391 TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
1392 TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1393 TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
1394 if (urational || vrational) {
1395 BSplSLib::D0(U, V, 1, 1, poles->Array2(),
1397 biduknots, bidvknots, &bidumults, &bidvmults,
1398 UDegree(), VDegree(),
1399 urational, vrational, Standard_False, Standard_False,
1404 BSplSLib::D0(U, V, 1, 1, poles->Array2(),
1405 BSplSLib::NoWeights(),
1406 biduknots, bidvknots, &bidumults, &bidvmults,
1407 UDegree(), VDegree(),
1408 urational, vrational, Standard_False, Standard_False,
1413 //=======================================================================
1416 //=======================================================================
1418 void Geom_BezierSurface::D1
1419 (const Standard_Real U,
1420 const Standard_Real V,
1425 Standard_Real array_u[2];
1426 Standard_Real array_v[2];
1427 Standard_Integer mult_u[2];
1428 Standard_Integer mult_v[2];
1429 TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
1430 TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
1431 TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1432 TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
1433 if (urational || vrational) {
1434 BSplSLib::D1(U, V, 1, 1, poles->Array2(),
1436 biduknots, bidvknots, &bidumults, &bidvmults,
1437 UDegree(), VDegree(),
1438 urational, vrational, Standard_False, Standard_False,
1442 BSplSLib::D1(U, V, 1, 1, poles->Array2(),
1443 BSplSLib::NoWeights(),
1444 biduknots, bidvknots, &bidumults, &bidvmults,
1445 UDegree(), VDegree(),
1446 urational, vrational, Standard_False, Standard_False,
1451 //=======================================================================
1454 //=======================================================================
1456 void Geom_BezierSurface::D2
1457 (const Standard_Real U,
1458 const Standard_Real V,
1460 gp_Vec& D1U, gp_Vec& D1V,
1461 gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV ) const
1463 Standard_Real array_u[2];
1464 Standard_Real array_v[2];
1465 Standard_Integer mult_u[2];
1466 Standard_Integer mult_v[2];
1467 TColStd_Array1OfReal biduknots(array_u[0], 1, 2); biduknots(1) = 0.; biduknots(2) = 1.;
1468 TColStd_Array1OfInteger bidumults(mult_u[0], 1, 2); bidumults.Init(UDegree() + 1);
1469 TColStd_Array1OfReal bidvknots(array_v[0], 1, 2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1470 TColStd_Array1OfInteger bidvmults(mult_v[0], 1, 2); bidvmults.Init(VDegree() + 1);
1471 if (urational || vrational) {
1472 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1473 BSplSLib::D2(U, V, 1, 1, poles->Array2(),
1475 biduknots, bidvknots, &bidumults, &bidvmults,
1476 UDegree(), VDegree(),
1477 urational, vrational, Standard_False, Standard_False,
1478 P, D1U, D1V, D2U, D2V, D2UV);
1481 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1482 BSplSLib::D2(U, V, 1, 1, poles->Array2(),
1483 BSplSLib::NoWeights(),
1484 biduknots, bidvknots, &bidumults, &bidvmults,
1485 UDegree(), VDegree(),
1486 urational, vrational, Standard_False, Standard_False,
1487 P, D1U, D1V, D2U, D2V, D2UV);
1491 //=======================================================================
1494 //=======================================================================
1496 void Geom_BezierSurface::D3
1497 (const Standard_Real U, const Standard_Real V,
1499 gp_Vec& D1U, gp_Vec& D1V,
1500 gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV,
1501 gp_Vec& D3U, gp_Vec& D3V, gp_Vec& D3UUV, gp_Vec& D3UVV) const
1503 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1504 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1505 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1506 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1507 if (urational || vrational) {
1508 BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
1510 biduknots, bidvknots, &bidumults, &bidvmults,
1511 UDegree(), VDegree(), urational, vrational, 0, 0,
1515 D3U, D3V, D3UUV, D3UVV);
1518 BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
1519 BSplSLib::NoWeights(),
1520 biduknots, bidvknots, &bidumults, &bidvmults,
1521 UDegree(), VDegree(), urational, vrational, 0, 0,
1525 D3U, D3V, D3UUV, D3UVV);
1529 //=======================================================================
1532 //=======================================================================
1534 gp_Vec Geom_BezierSurface::DN
1535 (const Standard_Real U,
1536 const Standard_Real V,
1537 const Standard_Integer Nu,
1538 const Standard_Integer Nv) const
1540 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nv < 0 || Nu <0, " ");
1542 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1543 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1544 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1545 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1546 if (urational || vrational) {
1547 BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
1549 biduknots, bidvknots, &bidumults, &bidvmults,
1550 UDegree(), VDegree(), urational, vrational, 0, 0,
1554 BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
1555 BSplSLib::NoWeights(),
1556 biduknots, bidvknots, &bidumults, &bidvmults,
1557 UDegree(), VDegree(), urational, vrational, 0, 0,
1563 //=======================================================================
1564 //function : NbUPoles
1566 //=======================================================================
1568 Standard_Integer Geom_BezierSurface::NbUPoles () const
1570 return poles->ColLength();
1573 //=======================================================================
1574 //function : NbVPoles
1576 //=======================================================================
1578 Standard_Integer Geom_BezierSurface::NbVPoles () const
1580 return poles->RowLength();
1583 //=======================================================================
1586 //=======================================================================
1588 gp_Pnt Geom_BezierSurface::Pole (const Standard_Integer UIndex,
1589 const Standard_Integer VIndex) const
1591 Standard_OutOfRange_Raise_if
1592 (UIndex < 1 || UIndex > poles->ColLength() ||
1593 VIndex < 1 || VIndex > poles->RowLength(), " ");
1594 return poles->Value (UIndex + poles->LowerRow() - 1,
1595 VIndex + poles->LowerCol() - 1);
1598 //=======================================================================
1601 //=======================================================================
1603 void Geom_BezierSurface::Poles (TColgp_Array2OfPnt& P) const
1605 Standard_DimensionError_Raise_if
1606 (P.RowLength() != poles->RowLength() ||
1607 P.ColLength() != poles->ColLength(), " ");
1608 P = poles->Array2();
1611 //=======================================================================
1612 //function : UDegree
1614 //=======================================================================
1616 Standard_Integer Geom_BezierSurface::UDegree () const
1618 return poles->ColLength() - 1;
1621 //=======================================================================
1624 //=======================================================================
1626 Handle(Geom_Curve) Geom_BezierSurface::UIso (const Standard_Real U) const
1628 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1629 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1631 Handle(Geom_BezierCurve) UIsoCurve;
1632 const TColgp_Array2OfPnt & Poles = poles->Array2();
1633 TColgp_Array1OfPnt VCurvePoles (Poles.LowerCol() , Poles.UpperCol());
1634 if (urational || vrational) {
1635 const TColStd_Array2OfReal & Weights = weights->Array2();
1636 TColStd_Array1OfReal VCurveWeights
1637 (Weights.LowerCol() , Weights.UpperCol());
1638 BSplSLib::Iso (U, 1, Poles,
1640 biduknots, &bidumults,
1641 UDegree(), 0, VCurvePoles, &VCurveWeights);
1643 UIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
1645 UIsoCurve = new Geom_BezierCurve (VCurvePoles);
1648 BSplSLib::Iso (U, 1, Poles,
1649 BSplSLib::NoWeights(),
1650 biduknots, &bidumults,
1651 UDegree(), 0, VCurvePoles, PLib::NoWeights());
1652 UIsoCurve = new Geom_BezierCurve (VCurvePoles);
1657 //=======================================================================
1658 //function : VDegree
1660 //=======================================================================
1662 Standard_Integer Geom_BezierSurface::VDegree () const
1664 return poles->RowLength() - 1;
1667 //=======================================================================
1670 //=======================================================================
1672 Handle(Geom_Curve) Geom_BezierSurface::VIso (const Standard_Real V) const
1674 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1675 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1677 Handle(Geom_BezierCurve) VIsoCurve;
1678 const TColgp_Array2OfPnt & Poles = poles->Array2();
1679 TColgp_Array1OfPnt VCurvePoles (Poles.LowerRow() , Poles.UpperRow());
1680 if (vrational || urational) {
1681 const TColStd_Array2OfReal & Weights = weights->Array2();
1682 TColStd_Array1OfReal VCurveWeights
1683 (Weights.LowerRow() , Weights.UpperRow());
1684 BSplSLib::Iso (V, 0, Poles,
1686 bidvknots, &bidvmults,
1687 VDegree(), 0, VCurvePoles, &VCurveWeights);
1689 VIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
1691 VIsoCurve = new Geom_BezierCurve (VCurvePoles);
1694 BSplSLib::Iso (V, 0, Poles,
1695 BSplSLib::NoWeights(),
1696 bidvknots, &bidvmults,
1697 VDegree(), 0, VCurvePoles, PLib::NoWeights());
1698 VIsoCurve = new Geom_BezierCurve (VCurvePoles);
1703 //=======================================================================
1706 //=======================================================================
1708 Standard_Real Geom_BezierSurface::Weight (const Standard_Integer UIndex,
1709 const Standard_Integer VIndex) const
1711 Standard_OutOfRange_Raise_if (
1712 UIndex < 1 || UIndex > weights->ColLength() ||
1713 VIndex < 1 || VIndex > weights->RowLength(), " ");
1715 if (urational || vrational)
1716 return weights->Value (UIndex, VIndex);
1721 //=======================================================================
1722 //function : Weights
1724 //=======================================================================
1726 void Geom_BezierSurface::Weights (TColStd_Array2OfReal& W ) const
1728 Standard_DimensionError_Raise_if (
1729 W.RowLength() != weights->RowLength() ||
1730 W.ColLength() != weights->ColLength(), " " );
1731 if (urational || vrational)
1732 W = weights->Array2();
1737 //=======================================================================
1740 //=======================================================================
1742 Standard_Boolean Geom_BezierSurface::IsCNu (const Standard_Integer ) const
1744 return Standard_True;
1747 //=======================================================================
1750 //=======================================================================
1752 Standard_Boolean Geom_BezierSurface::IsCNv (const Standard_Integer ) const
1754 return Standard_True;
1757 //=======================================================================
1758 //function : IsURational
1760 //=======================================================================
1762 Standard_Boolean Geom_BezierSurface::IsURational () const
1767 //=======================================================================
1768 //function : IsVRational
1770 //=======================================================================
1772 Standard_Boolean Geom_BezierSurface::IsVRational () const
1777 //=======================================================================
1778 //function : Transform
1780 //=======================================================================
1782 void Geom_BezierSurface::Transform (const gp_Trsf& T)
1784 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1786 for (Standard_Integer I = 1; I <= Poles.ColLength(); I++) {
1788 for (Standard_Integer J = 1; J <= Poles.RowLength(); J++) {
1789 Poles (I, J).Transform (T);
1794 //=======================================================================
1795 //function : IsUClosed
1797 //=======================================================================
1799 Standard_Boolean Geom_BezierSurface::IsUClosed () const
1801 const TColgp_Array2OfPnt & Poles = poles->Array2();
1802 Standard_Boolean Closed = Standard_True;
1803 Standard_Integer Lower = Poles.LowerRow();
1804 Standard_Integer Upper = Poles.UpperRow();
1805 Standard_Integer Length = Poles.RowLength();
1806 Standard_Integer j = Poles.LowerCol();
1808 while (Closed && j <= Length) {
1809 Closed = (Poles (Lower,j).Distance (Poles (Upper,j)) <= Precision::Confusion());
1815 //=======================================================================
1816 //function : IsVClosed
1818 //=======================================================================
1820 Standard_Boolean Geom_BezierSurface::IsVClosed () const
1822 const TColgp_Array2OfPnt & Poles = poles->Array2();
1823 Standard_Boolean Closed = Standard_True;
1824 Standard_Integer Lower = Poles.LowerCol();
1825 Standard_Integer Upper = Poles.UpperCol();
1826 Standard_Integer Length = Poles.ColLength();
1827 Standard_Integer i = Poles.LowerRow();
1828 while (Closed && i <= Length) {
1829 Closed = (Poles (i,Lower).Distance (Poles (i,Upper)) <= Precision::Confusion());
1835 //=======================================================================
1836 //function : IsUPeriodic
1838 //=======================================================================
1840 Standard_Boolean Geom_BezierSurface::IsUPeriodic () const
1842 return Standard_False;
1845 //=======================================================================
1846 //function : IsVPeriodic
1848 //=======================================================================
1850 Standard_Boolean Geom_BezierSurface::IsVPeriodic () const
1852 return Standard_False;
1855 //=======================================================================
1856 //function : Resolution
1858 //=======================================================================
1860 void Geom_BezierSurface::Resolution(const Standard_Real Tolerance3D,
1861 Standard_Real& UTolerance,
1862 Standard_Real& VTolerance)
1865 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1866 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1867 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1868 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1869 if(urational || vrational){
1870 BSplSLib::Resolution(poles->Array2(),
1887 BSplSLib::Resolution(poles->Array2(),
1888 BSplSLib::NoWeights(),
1905 UTolerance = Tolerance3D * umaxderivinv;
1906 VTolerance = Tolerance3D * vmaxderivinv;
1909 //=======================================================================
1912 //=======================================================================
1914 Handle(Geom_Geometry) Geom_BezierSurface::Copy() const
1916 Handle(Geom_BezierSurface) S = new Geom_BezierSurface
1917 (poles, weights, urational, vrational);
1921 //=======================================================================
1924 //=======================================================================
1926 void Geom_BezierSurface::Init
1927 (const Handle(TColgp_HArray2OfPnt)& Poles,
1928 const Handle(TColStd_HArray2OfReal)& Weights)
1932 if (urational || vrational)