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 <BSplSLib.hxx>
32 #include <Geom_BezierCurve.hxx>
33 #include <Geom_BezierSurface.hxx>
34 #include <Geom_Curve.hxx>
35 #include <Geom_Geometry.hxx>
38 #include <gp_Trsf.hxx>
42 #include <Precision.hxx>
43 #include <Standard_ConstructionError.hxx>
44 #include <Standard_DimensionError.hxx>
45 #include <Standard_OutOfRange.hxx>
46 #include <Standard_RangeError.hxx>
47 #include <Standard_Type.hxx>
48 #include <TColStd_Array1OfInteger.hxx>
50 //=======================================================================
52 //purpose : check rationality of an array of weights
53 //=======================================================================
54 static void Rational(const TColStd_Array2OfReal& Weights,
55 Standard_Boolean& Urational,
56 Standard_Boolean& Vrational)
59 J = Weights.LowerCol ();
60 Vrational = Standard_False;
61 while (!Vrational && J <= Weights.UpperCol()) {
62 I = Weights.LowerRow();
63 while (!Vrational && I <= Weights.UpperRow() - 1) {
64 Vrational = (Abs(Weights (I, J) - Weights (I+1, J))
65 > Epsilon (Abs(Weights (I, J))));
71 I = Weights.LowerRow ();
72 Urational = Standard_False;
73 while (!Urational && I <= Weights.UpperRow()) {
74 J = Weights.LowerCol();
75 while (!Urational && J <= Weights.UpperCol() - 1) {
76 Urational = (Abs(Weights (I, J) - Weights (I, J+1))
77 > Epsilon (Abs(Weights (I, J))));
84 //=======================================================================
85 //function : AddPoleCol
86 //purpose : Internal use only.
87 //=======================================================================
89 static void AddPoleCol
90 (const TColgp_Array2OfPnt& Poles,
91 const TColgp_Array1OfPnt& PoleCol,
92 const Standard_Integer AfterIndex,
93 TColgp_Array2OfPnt& NewPoles)
95 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
96 Standard_Integer Offset = NewPoles.LowerRow() - PoleCol.Lower();
97 Standard_Integer ColIndex = NewPoles.LowerCol();
98 Standard_Integer RowIndex;
99 while (ColIndex < InsertIndex) {
100 RowIndex = NewPoles.LowerRow();
101 while (RowIndex <= NewPoles.UpperRow()){
102 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
107 RowIndex = NewPoles.LowerRow();
108 while (RowIndex <= NewPoles.UpperRow()){
109 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - Offset);
113 while (ColIndex <= NewPoles.UpperCol()) {
114 RowIndex = NewPoles.LowerRow();
115 while (RowIndex <= NewPoles.UpperRow()){
116 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
123 //=======================================================================
124 //function : AddRatPoleCol
125 //purpose : Internal use only.
126 //=======================================================================
128 static void AddRatPoleCol
129 (const TColgp_Array2OfPnt& Poles,
130 const TColStd_Array2OfReal& Weights,
131 const TColgp_Array1OfPnt& PoleCol,
132 const TColStd_Array1OfReal& PoleWeightCol,
133 const Standard_Integer AfterIndex,
134 TColgp_Array2OfPnt& NewPoles,
135 TColStd_Array2OfReal& NewWeights)
137 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
138 Standard_Integer OffsetPol = NewPoles.LowerRow() - PoleCol.Lower();
139 Standard_Integer OffsetW = NewWeights.LowerRow() - PoleWeightCol.Lower();
141 Standard_Integer ColIndex = NewPoles.LowerCol();
142 Standard_Integer RowIndex;
143 while (ColIndex < InsertIndex) {
144 RowIndex = NewPoles.LowerRow();
145 while (RowIndex <= NewPoles.UpperRow()){
146 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
147 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
152 RowIndex = NewPoles.LowerRow();
153 while (RowIndex <= NewPoles.UpperRow()){
154 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - OffsetPol);
155 NewWeights (RowIndex, ColIndex) = PoleWeightCol (RowIndex - OffsetW);
159 while (ColIndex <= NewPoles.UpperCol()) {
160 RowIndex = NewPoles.LowerRow();
161 while (RowIndex <= NewPoles.UpperRow()){
162 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
164 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex - 1);
170 //=======================================================================
171 //function : AddPoleRow
172 //purpose : Internal use only.
173 //=======================================================================
175 static void AddPoleRow
176 (const TColgp_Array2OfPnt& Poles,
177 const TColgp_Array1OfPnt& PoleRow,
178 const Standard_Integer AfterIndex,
179 TColgp_Array2OfPnt& NewPoles)
181 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
182 Standard_Integer Offset = NewPoles.LowerCol() - PoleRow.Lower();
183 Standard_Integer RowIndex = NewPoles.LowerRow();
184 Standard_Integer ColIndex;
185 while (RowIndex < InsertIndex) {
186 ColIndex = NewPoles.LowerCol();
187 while (ColIndex <= NewPoles.UpperCol()){
188 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
193 ColIndex = NewPoles.LowerCol();
194 while (ColIndex <= NewPoles.UpperCol()){
195 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - Offset);
199 while (RowIndex <= NewPoles.UpperRow()) {
200 ColIndex = NewPoles.LowerCol();
201 while (ColIndex <= NewPoles.UpperCol()){
202 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
209 //=======================================================================
210 //function : AddRatPoleRow
212 //=======================================================================
214 static void AddRatPoleRow
215 (const TColgp_Array2OfPnt& Poles,
216 const TColStd_Array2OfReal& Weights,
217 const TColgp_Array1OfPnt& PoleRow,
218 const TColStd_Array1OfReal& PoleWeightRow,
219 const Standard_Integer AfterIndex,
220 TColgp_Array2OfPnt& NewPoles,
221 TColStd_Array2OfReal& NewWeights)
223 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
224 Standard_Integer OffsetPol = NewPoles.LowerCol() - PoleRow.Lower();
225 Standard_Integer OffsetW = NewWeights.LowerCol() - PoleWeightRow.Lower();
227 Standard_Integer ColIndex;
228 Standard_Integer RowIndex = NewPoles.LowerRow();
229 while (RowIndex < InsertIndex) {
230 ColIndex = NewPoles.LowerCol();
231 while (ColIndex <= NewPoles.UpperCol()){
232 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
233 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
238 ColIndex = NewPoles.LowerCol();
239 while (ColIndex <= NewPoles.UpperCol()){
240 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - OffsetPol);
241 NewWeights (RowIndex, ColIndex) = PoleWeightRow (ColIndex - OffsetW);
245 while (RowIndex <= NewPoles.UpperRow()) {
246 ColIndex = NewPoles.LowerCol();
247 while (ColIndex <= NewPoles.UpperCol()){
248 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
249 NewWeights (RowIndex, ColIndex) = Weights (RowIndex - 1, ColIndex);
256 //=======================================================================
257 //function : DeletePoleCol
259 //=======================================================================
261 static void DeletePoleCol
262 (const TColgp_Array2OfPnt& Poles,
263 const Standard_Integer Index,
264 TColgp_Array2OfPnt& NewPoles)
266 Standard_Integer Offset = 0;
267 Standard_Integer RowIndex;
268 Standard_Integer ColIndex = NewPoles.LowerCol();
269 while (ColIndex <= NewPoles.UpperCol()) {
270 RowIndex = NewPoles.LowerRow();
271 if (ColIndex == Index) Offset = 1;
272 while (RowIndex <= NewPoles.UpperRow()){
273 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
280 //=======================================================================
281 //function : DeleteRatPoleCol
283 //=======================================================================
285 static void DeleteRatPoleCol
286 (const TColgp_Array2OfPnt& Poles,
287 const TColStd_Array2OfReal& Weights,
288 const Standard_Integer Index,
289 TColgp_Array2OfPnt& NewPoles,
290 TColStd_Array2OfReal& NewWeights)
292 Standard_Integer Offset = 0;
293 Standard_Integer RowIndex;
294 Standard_Integer ColIndex = NewPoles.LowerCol();
295 while (ColIndex <= NewPoles.UpperCol()) {
296 RowIndex = NewPoles.LowerRow();
297 if (ColIndex == Index) Offset = 1;
298 while (RowIndex <= NewPoles.UpperRow()){
299 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
300 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex+Offset);
307 //=======================================================================
308 //function : DeletePoleRow
310 //=======================================================================
312 static void DeletePoleRow
313 (const TColgp_Array2OfPnt& Poles,
314 const Standard_Integer Index,
315 TColgp_Array2OfPnt& NewPoles)
317 Standard_Integer Offset = 0;
318 Standard_Integer ColIndex;
319 Standard_Integer RowIndex = NewPoles.LowerRow();
320 while (RowIndex <= NewPoles.UpperRow()) {
321 ColIndex = NewPoles.LowerCol();
322 if (RowIndex == Index) Offset = 1;
323 while (ColIndex <= NewPoles.UpperCol()){
324 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
331 //=======================================================================
332 //function : DeleteRatPoleRow
334 //=======================================================================
336 static void DeleteRatPoleRow
337 (const TColgp_Array2OfPnt& Poles,
338 const TColStd_Array2OfReal& Weights,
339 const Standard_Integer Index,
340 TColgp_Array2OfPnt& NewPoles,
341 TColStd_Array2OfReal& NewWeights)
343 Standard_Integer Offset = 0;
344 Standard_Integer ColIndex;
345 Standard_Integer RowIndex = NewPoles.LowerRow();
346 while (RowIndex <= NewPoles.UpperRow()) {
347 ColIndex = NewPoles.LowerCol();
348 if (RowIndex == Index) Offset = 1;
349 while (ColIndex <= NewPoles.UpperCol()){
350 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
351 NewWeights (RowIndex, ColIndex) = Weights (RowIndex+Offset, ColIndex);
358 //=======================================================================
359 //function : Geom_BezierSurface
361 //=======================================================================
363 Geom_BezierSurface::Geom_BezierSurface
364 (const TColgp_Array2OfPnt& SurfacePoles):
367 ucachespanlenght(1.),
368 vcachespanlenght(1.),
370 maxderivinvok(Standard_False)
372 Standard_Integer NbUPoles = SurfacePoles.ColLength();
373 Standard_Integer NbVPoles = SurfacePoles.RowLength();
374 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
375 NbVPoles < 2 || NbVPoles > MaxDegree()+1) {
376 Standard_ConstructionError::Raise();
379 Handle(TColgp_HArray2OfPnt) npoles =
380 new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
385 npoles->ChangeArray2() = SurfacePoles;
389 Handle(TColStd_HArray2OfReal)());
392 //=======================================================================
393 //function : Geom_BezierSurface
395 //=======================================================================
397 Geom_BezierSurface::Geom_BezierSurface
398 (const TColgp_Array2OfPnt& SurfacePoles,
399 const TColStd_Array2OfReal& PoleWeights ):
402 ucachespanlenght(1.),
403 vcachespanlenght(1.),
405 maxderivinvok(Standard_False)
407 Standard_Integer NbUPoles = SurfacePoles.ColLength();
408 Standard_Integer NbVPoles = SurfacePoles.RowLength();
409 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
410 NbVPoles < 2 || NbVPoles > MaxDegree()+1 ||
411 NbVPoles != PoleWeights.RowLength() ||
412 NbUPoles != PoleWeights.ColLength() ) {
413 Standard_ConstructionError::Raise();
416 Standard_Integer Row = PoleWeights.LowerRow();
417 Standard_Integer Col = PoleWeights.LowerCol();
418 while (Col <= PoleWeights.UpperCol()) {
419 Row = PoleWeights.LowerRow();
420 while (Row <= PoleWeights.UpperRow()) {
421 if (PoleWeights(Row, Col) <= gp::Resolution()) {
422 Standard_ConstructionError::Raise();
429 Handle(TColgp_HArray2OfPnt)
430 npoles = new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
431 npoles->ChangeArray2() = SurfacePoles;
433 Standard_Integer I, J;
434 urational = Standard_False;
435 vrational = Standard_False;
436 J = PoleWeights.LowerCol ();
437 while (!vrational && J <= PoleWeights.UpperCol()) {
438 I = PoleWeights.LowerRow();
439 while (!vrational && I <= PoleWeights.UpperRow() - 1) {
440 vrational = (Abs(PoleWeights (I, J) - PoleWeights (I+1, J))
441 > Epsilon (Abs(PoleWeights (I, J))));
446 I = PoleWeights.LowerRow ();
447 while (!urational && I <= PoleWeights.UpperRow()) {
448 J = PoleWeights.LowerCol();
449 while (!urational && J <= PoleWeights.UpperCol() - 1) {
450 urational = (Abs(PoleWeights (I, J) - PoleWeights (I, J+1))
451 > Epsilon (Abs(PoleWeights (I, J))));
458 Handle(TColStd_HArray2OfReal) nweights;
459 if (urational || vrational) {
460 nweights = new TColStd_HArray2OfReal (1, NbUPoles, 1, NbVPoles);
461 nweights->ChangeArray2() = PoleWeights;
465 Init(npoles,nweights);
468 //=======================================================================
469 //function : Geom_BezierSurface
471 //=======================================================================
473 Geom_BezierSurface::Geom_BezierSurface
474 (const Handle(TColgp_HArray2OfPnt)& SurfacePoles,
475 const Handle(TColgp_HArray2OfPnt)& SurfaceCoefs,
476 const Handle(TColStd_HArray2OfReal)& PoleWeights,
477 const Handle(TColStd_HArray2OfReal)& CoefWeights,
478 const Standard_Boolean IsURational,
479 const Standard_Boolean IsVRational)
480 :maxderivinvok(Standard_False)
482 urational = IsURational;
483 vrational = IsVRational;
484 ucachespanlenght = 1.;
485 vcachespanlenght = 1.;
488 vcacheparameter = 0.;
489 Standard_Integer NbUPoles = SurfacePoles->ColLength();
490 Standard_Integer NbVPoles = SurfacePoles->RowLength();
492 poles = new TColgp_HArray2OfPnt (1,NbUPoles,
494 poles->ChangeArray2() = SurfacePoles->Array2();
496 coeffs = new TColgp_HArray2OfPnt (1,SurfaceCoefs->ColLength(),
497 1,SurfaceCoefs->RowLength()) ;
498 coeffs->ChangeArray2() = SurfaceCoefs->Array2();
500 if ( urational || vrational) {
501 weights = new TColStd_HArray2OfReal (1,NbUPoles,1,NbVPoles);
502 weights->ChangeArray2() = PoleWeights->Array2();
504 wcoeffs = new TColStd_HArray2OfReal (1,SurfaceCoefs->ColLength(),
505 1,SurfaceCoefs->RowLength()) ;
506 wcoeffs->ChangeArray2() = CoefWeights->Array2();
510 //=======================================================================
511 //function : MaxDegree
513 //=======================================================================
515 Standard_Integer Geom_BezierSurface::MaxDegree ()
517 return BSplCLib::MaxDegree();
520 //=======================================================================
521 //function : ExchangeUV
523 //=======================================================================
525 void Geom_BezierSurface::ExchangeUV ()
527 Standard_Integer LC = poles->LowerCol();
528 Standard_Integer UC = poles->UpperCol();
529 Standard_Integer LR = poles->LowerRow();
530 Standard_Integer UR = poles->UpperRow();
532 Handle(TColgp_HArray2OfPnt) npoles =
533 new TColgp_HArray2OfPnt (LC, UC, LR, UR);
534 Handle(TColStd_HArray2OfReal) nweights =
535 new TColStd_HArray2OfReal (LC, UC, LR, UR);
537 const TColgp_Array2OfPnt & spoles = poles->Array2();
538 const TColStd_Array2OfReal & sweights = weights->Array2();
540 TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2();
541 TColStd_Array2OfReal& snweights = nweights->ChangeArray2();
543 Standard_Integer i, j;
544 for (i = LC; i <= UC; i++) {
545 for (j = LR; j <= UR; j++) {
546 snpoles (i,j) = spoles (j,i);
547 snweights (i,j) = sweights (j,i);
554 Standard_Boolean temp = urational;
555 urational = vrational;
557 coeffs = new TColgp_HArray2OfPnt (LC, UC, LR, UR);
558 wcoeffs = new TColStd_HArray2OfReal (LC, UC, LR, UR);
560 UpdateCoefficients();
563 //=======================================================================
564 //function : Increase
566 //=======================================================================
568 void Geom_BezierSurface::Increase (const Standard_Integer UDeg,
569 const Standard_Integer VDeg)
571 if (UDeg < UDegree() || UDeg > Geom_BezierSurface::MaxDegree() ||
572 VDeg < VDegree() || VDeg > Geom_BezierSurface::MaxDegree() ) {
573 Standard_ConstructionError::Raise();
576 Standard_Integer oldUDeg = UDegree();
577 Standard_Integer oldVDeg = VDegree();
578 Standard_Integer IncUDeg = UDeg - oldUDeg;
579 Standard_Integer IncVDeg = VDeg - oldVDeg;
580 if (IncUDeg == 0 && IncVDeg == 0) return;
582 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
583 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
584 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
585 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
586 Handle(TColgp_HArray2OfPnt) npoles;
587 Handle(TColStd_HArray2OfReal) nweights;
590 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, oldVDeg + 1);
592 if ( urational || vrational) {
593 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDegree() + 1);
595 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
598 biduknots, bidumults,
599 npoles->ChangeArray2(),
600 &nweights->ChangeArray2(),
601 biduknots, bidumults);
605 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
607 BSplSLib::NoWeights(),
608 biduknots, bidumults,
609 npoles->ChangeArray2(),
610 BSplSLib::NoWeights(),
611 biduknots, bidumults);
616 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, VDeg + 1);
618 if ( urational || vrational) {
619 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDeg + 1);
621 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
624 bidvknots, bidvmults,
625 npoles->ChangeArray2(),
626 &nweights->ChangeArray2(),
627 bidvknots, bidvmults);
631 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
633 BSplSLib::NoWeights(),
634 bidvknots, bidvmults,
635 npoles->ChangeArray2(),
636 BSplSLib::NoWeights(),
637 bidvknots, bidvmults);
642 Init(npoles,nweights);
645 //=======================================================================
646 //function : InsertPoleColAfter
648 //=======================================================================
650 void Geom_BezierSurface::InsertPoleColAfter
651 (const Standard_Integer VIndex,
652 const TColgp_Array1OfPnt& CPoles)
654 const TColgp_Array2OfPnt & Poles = poles->Array2();
655 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
656 if (CPoles.Length() != Poles.ColLength()) {
657 Standard_ConstructionError::Raise();
660 Handle(TColgp_HArray2OfPnt) npoles =
661 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
663 Handle(TColStd_HArray2OfReal) nweights;
665 if (urational || vrational) {
667 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
669 TColStd_Array1OfReal CWeights(nweights->LowerRow(),nweights->UpperRow());
672 AddRatPoleCol (poles->Array2(), weights->Array2(),
673 CPoles, CWeights, VIndex,
674 npoles->ChangeArray2(), nweights->ChangeArray2());
677 AddPoleCol (poles->Array2(),
679 npoles->ChangeArray2());
683 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
684 1,poles->RowLength());
685 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
686 1,poles->RowLength());
687 UpdateCoefficients();
690 //=======================================================================
691 //function : InsertPoleColAfter
693 //=======================================================================
695 void Geom_BezierSurface::InsertPoleColAfter
696 (const Standard_Integer VIndex,
697 const TColgp_Array1OfPnt& CPoles,
698 const TColStd_Array1OfReal& CPoleWeights)
700 const TColgp_Array2OfPnt & Poles = poles->Array2();
701 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
702 if (CPoles.Length() != Poles.ColLength() ||
703 CPoleWeights.Length() != CPoles.Length()) {
704 Standard_ConstructionError::Raise();
706 Standard_Integer Index = CPoleWeights.Lower();
707 while (Index <= CPoleWeights.Upper()) {
708 if (CPoleWeights (Index) <= gp::Resolution()) {
709 Standard_ConstructionError::Raise();
714 Handle(TColgp_HArray2OfPnt) npoles =
715 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
717 Handle(TColStd_HArray2OfReal) nweights =
718 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
720 AddRatPoleCol (poles->Array2(), weights->Array2(),
721 CPoles, CPoleWeights, VIndex,
722 npoles->ChangeArray2(), nweights->ChangeArray2());
726 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
727 1,poles->RowLength());
728 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
729 1,poles->RowLength());
731 Rational(weights->Array2(), urational, vrational);
733 UpdateCoefficients();
736 //=======================================================================
737 //function : InsertPoleColBefore
739 //=======================================================================
741 void Geom_BezierSurface::InsertPoleColBefore (const Standard_Integer VIndex,
742 const TColgp_Array1OfPnt& CPoles)
744 InsertPoleColAfter(VIndex - 1, CPoles);
747 //=======================================================================
748 //function : InsertPoleColBefore
750 //=======================================================================
752 void Geom_BezierSurface::InsertPoleColBefore
753 (const Standard_Integer VIndex,
754 const TColgp_Array1OfPnt& CPoles,
755 const TColStd_Array1OfReal& CPoleWeights)
757 InsertPoleColAfter( VIndex - 1, CPoles, CPoleWeights);
760 //=======================================================================
761 //function : InsertPoleRowAfter
763 //=======================================================================
765 void Geom_BezierSurface::InsertPoleRowAfter (const Standard_Integer UIndex,
766 const TColgp_Array1OfPnt& CPoles)
768 const TColgp_Array2OfPnt & Poles = poles->Array2();
769 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
770 if (CPoles.Length() != Poles.RowLength()) {
771 Standard_ConstructionError::Raise();
774 Handle(TColgp_HArray2OfPnt) npoles =
775 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
777 Handle(TColStd_HArray2OfReal) nweights;
779 if (urational || vrational) {
781 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
783 // TColStd_Array1OfReal CWeights(nweights->LowerCol(),nweights->UpperCol(),
785 TColStd_Array1OfReal CWeights(1.0,
786 nweights->LowerCol(),nweights->UpperCol());
788 AddRatPoleRow (poles->Array2(), weights->Array2(),
789 CPoles, CWeights, UIndex,
790 npoles->ChangeArray2(), nweights->ChangeArray2());
793 AddPoleRow (poles->Array2(),
795 npoles->ChangeArray2());
799 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
800 1,poles->RowLength());
801 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
802 1,poles->RowLength());
804 UpdateCoefficients();
807 //=======================================================================
808 //function : InsertPoleRowAfter
810 //=======================================================================
812 void Geom_BezierSurface::InsertPoleRowAfter
813 (const Standard_Integer UIndex,
814 const TColgp_Array1OfPnt& CPoles,
815 const TColStd_Array1OfReal& CPoleWeights)
817 const TColgp_Array2OfPnt & Poles = poles->Array2();
818 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
819 if (CPoles.Length() != Poles.RowLength() ||
820 CPoleWeights.Length() != CPoles.Length()) {
821 Standard_ConstructionError::Raise();
823 Standard_Integer Index = CPoleWeights.Lower();
824 while (Index <= CPoleWeights.Upper()) {
825 if (CPoleWeights(Index) <= gp::Resolution()) {
826 Standard_ConstructionError::Raise();
831 Handle(TColgp_HArray2OfPnt) npoles =
832 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
834 Handle(TColStd_HArray2OfReal) nweights =
835 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
837 AddRatPoleCol (poles->Array2(), weights->Array2(),
838 CPoles, CPoleWeights, UIndex,
839 npoles->ChangeArray2(), nweights->ChangeArray2());
843 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
844 1,poles->RowLength());
845 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
846 1,poles->RowLength());
848 Rational(weights->Array2(), urational, vrational);
850 UpdateCoefficients();
853 //=======================================================================
854 //function : InsertPoleRowBefore
856 //=======================================================================
858 void Geom_BezierSurface::InsertPoleRowBefore (const Standard_Integer UIndex,
859 const TColgp_Array1OfPnt& CPoles)
861 InsertPoleRowAfter( UIndex - 1, CPoles);
864 //=======================================================================
865 //function : InsertPoleRowBefore
867 //=======================================================================
869 void Geom_BezierSurface::InsertPoleRowBefore
870 (const Standard_Integer UIndex,
871 const TColgp_Array1OfPnt& CPoles,
872 const TColStd_Array1OfReal& CPoleWeights)
874 InsertPoleRowAfter( UIndex - 1, CPoles, CPoleWeights);
877 //=======================================================================
878 //function : RemovePoleCol
880 //=======================================================================
882 void Geom_BezierSurface::RemovePoleCol (const Standard_Integer VIndex)
884 const TColgp_Array2OfPnt & Poles = poles->Array2();
885 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
886 if (Poles.RowLength() <= 2) Standard_ConstructionError::Raise();
888 Handle(TColgp_HArray2OfPnt) npoles =
889 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()-1);
891 Handle(TColStd_HArray2OfReal) nweights;
893 if (urational || vrational) {
895 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()-1);
897 DeleteRatPoleCol (poles->Array2(), weights->Array2(),
899 npoles->ChangeArray2(), nweights->ChangeArray2());
900 // Mise a jour de la rationalite
901 Rational(nweights->Array2(), urational, vrational);
904 DeletePoleCol (poles->Array2(),
906 npoles->ChangeArray2());
910 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
911 1,poles->RowLength());
912 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
913 1,poles->RowLength());
914 UpdateCoefficients();
917 //=======================================================================
918 //function : RemovePoleRow
920 //=======================================================================
922 void Geom_BezierSurface::RemovePoleRow (const Standard_Integer UIndex)
924 const TColgp_Array2OfPnt & Poles = poles->Array2();
925 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
926 if (Poles.ColLength() <= 2) Standard_ConstructionError::Raise();
928 Handle(TColgp_HArray2OfPnt) npoles =
929 new TColgp_HArray2OfPnt(1,poles->ColLength()-1,1,poles->RowLength());
931 Handle(TColStd_HArray2OfReal) nweights;
933 if (urational || vrational) {
935 new TColStd_HArray2OfReal(1,poles->ColLength()-1,1,poles->RowLength());
937 DeleteRatPoleRow (poles->Array2(), weights->Array2(),
939 npoles->ChangeArray2(), nweights->ChangeArray2());
941 // Mise a jour de la rationalite
942 Rational(nweights->Array2(), urational, vrational);
945 DeletePoleRow (poles->Array2(),
947 npoles->ChangeArray2());
951 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
952 1,poles->RowLength());
953 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
954 1,poles->RowLength());
955 UpdateCoefficients();
958 //=======================================================================
961 //=======================================================================
963 void Geom_BezierSurface::Segment
964 (const Standard_Real U1,
965 const Standard_Real U2,
966 const Standard_Real V1,
967 const Standard_Real V2)
969 Standard_Boolean rat = (urational || vrational);
970 Handle(TColgp_HArray2OfPnt) Coefs;
971 Handle(TColStd_HArray2OfReal) WCoefs;
973 if (validcache == 0) UpdateCoefficients(0., 0.);
975 // Attention si udeg <= vdeg u et v sont intervertis
976 // dans les coeffs, il faut donc tout transposer.
977 if(UDegree() <= VDegree()) {
978 Standard_Integer ii, jj;
979 Coefs = new (TColgp_HArray2OfPnt)(1,UDegree()+1,1,VDegree()+1);
981 WCoefs = new (TColStd_HArray2OfReal)(1,UDegree()+1,1,VDegree()+1);
983 for (ii=1; ii<=UDegree()+1; ii++)
984 for (jj=1; jj<=VDegree()+1; jj++) {
985 Coefs->SetValue(ii, jj, coeffs->Value(jj,ii));
986 if (rat) WCoefs->SetValue(ii, jj, wcoeffs->Value(jj,ii));
991 if (rat) {WCoefs = wcoeffs;}
994 // Trim dans la base cannonique et Update des Poles et Coeffs
996 // PMN : tranfo sur les parametres
997 Standard_Real ufirst = 2*(U1 - 0.5),
998 ulast = 2*(U2 - 0.5),
999 vfirst = 2*(V1 - 0.5),
1000 vlast = 2*(V2 - 0.5);
1002 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
1003 &WCoefs->ChangeArray2());
1004 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
1005 &WCoefs->ChangeArray2());
1006 PLib::CoefficientsPoles(Coefs->Array2(),
1008 poles->ChangeArray2(),
1009 &weights->ChangeArray2());
1012 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(), PLib::NoWeights2());
1013 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(), PLib::NoWeights2());
1014 PLib::CoefficientsPoles (Coefs->Array2(), PLib::NoWeights2(),
1015 poles->ChangeArray2(), PLib::NoWeights2());
1017 UpdateCoefficients();
1020 //=======================================================================
1021 //function : SetPole
1023 //=======================================================================
1025 void Geom_BezierSurface::SetPole
1026 (const Standard_Integer UIndex,
1027 const Standard_Integer VIndex,
1030 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1032 UIndex > Poles.ColLength() ||
1034 VIndex > Poles.RowLength() ) Standard_OutOfRange::Raise();
1036 Poles (UIndex, VIndex) = P;
1037 UpdateCoefficients();
1040 //=======================================================================
1041 //function : SetPole
1043 //=======================================================================
1045 void Geom_BezierSurface::SetPole
1046 (const Standard_Integer UIndex,
1047 const Standard_Integer VIndex,
1049 const Standard_Real Weight)
1052 if (Weight <= gp::Resolution())
1053 Standard_ConstructionError::Raise("Geom_BezierSurface::SetPole");
1055 UIndex > poles->ColLength() ||
1057 VIndex > poles->RowLength())
1058 Standard_OutOfRange::Raise("Geom_BezierSurface::SetPole");
1060 poles->SetValue(UIndex, VIndex, P);
1062 SetWeight(UIndex, VIndex, Weight); //L'update des coeff est fait la dedans
1065 //=======================================================================
1066 //function : SetPoleCol
1068 //=======================================================================
1070 void Geom_BezierSurface::SetPoleCol
1071 (const Standard_Integer VIndex,
1072 const TColgp_Array1OfPnt& CPoles,
1073 const TColStd_Array1OfReal& CPoleWeights)
1075 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1076 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
1078 if (CPoles.Lower() < 1 ||
1079 CPoles.Lower() > Poles.ColLength() ||
1080 CPoles.Upper() < 1 ||
1081 CPoles.Upper() > Poles.ColLength() ||
1082 CPoleWeights.Lower() != CPoles.Lower() ||
1083 CPoleWeights.Upper() != CPoles.Upper()) {
1084 Standard_ConstructionError::Raise();
1088 for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1089 Poles (I, VIndex) = CPoles (I);
1091 SetWeightCol(VIndex, CPoleWeights); //Avec l'update
1094 //=======================================================================
1095 //function : SetPoleCol
1097 //=======================================================================
1099 void Geom_BezierSurface::SetPoleCol (const Standard_Integer VIndex,
1100 const TColgp_Array1OfPnt& CPoles)
1102 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1103 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
1105 if (CPoles.Lower() < 1 ||
1106 CPoles.Lower() > Poles.ColLength() ||
1107 CPoles.Upper() < 1 ||
1108 CPoles.Upper() > Poles.ColLength()) {
1109 Standard_ConstructionError::Raise();
1111 for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1112 Poles (I, VIndex) = CPoles (I);
1115 UpdateCoefficients();
1118 //=======================================================================
1119 //function : SetPoleRow
1121 //=======================================================================
1123 void Geom_BezierSurface::SetPoleRow (const Standard_Integer UIndex,
1124 const TColgp_Array1OfPnt& CPoles)
1126 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1127 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
1129 if (CPoles.Lower() < 1 ||
1130 CPoles.Lower() > Poles.RowLength() ||
1131 CPoles.Upper() < 1 ||
1132 CPoles.Upper() > Poles.RowLength()) Standard_ConstructionError::Raise();
1134 for (Standard_Integer I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1135 Poles (UIndex, I) = CPoles (I);
1137 UpdateCoefficients();
1140 //=======================================================================
1141 //function : SetPoleRow
1143 //=======================================================================
1145 void Geom_BezierSurface::SetPoleRow
1146 (const Standard_Integer UIndex,
1147 const TColgp_Array1OfPnt& CPoles,
1148 const TColStd_Array1OfReal& CPoleWeights)
1150 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1151 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
1153 if (CPoles.Lower() < 1 ||
1154 CPoles.Lower() > Poles.RowLength() ||
1155 CPoles.Upper() < 1 ||
1156 CPoles.Upper() > Poles.RowLength() ||
1157 CPoleWeights.Lower() != CPoles.Lower() ||
1158 CPoleWeights.Upper() != CPoles.Upper()) {
1159 Standard_ConstructionError::Raise();
1164 for (I = CPoles.Lower(); I <= CPoles.Upper(); I++) {
1165 Poles (UIndex, I) = CPoles (I);
1168 SetWeightRow(UIndex, CPoleWeights); //Avec l'update
1171 //=======================================================================
1172 //function : SetWeight
1174 //=======================================================================
1176 void Geom_BezierSurface::SetWeight (const Standard_Integer UIndex,
1177 const Standard_Integer VIndex,
1178 const Standard_Real Weight)
1180 // compute new rationality
1181 Standard_Boolean wasrat = (urational||vrational);
1183 // a weight of 1. does not turn to rational
1184 if (Abs(Weight - 1.) <= gp::Resolution()) {
1185 UpdateCoefficients(); //Pour l'appel via SetPole
1189 // set weights of 1.
1190 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1191 1, poles->RowLength(), 1.);
1192 wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
1193 1, poles->RowLength());
1196 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1197 if (Weight <= gp::Resolution())
1198 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeight");
1201 UIndex > Weights.ColLength() ||
1203 VIndex > Weights.RowLength()) Standard_OutOfRange::Raise();
1205 if (Abs (Weight - Weights (UIndex, VIndex)) > gp::Resolution()) {
1206 Weights (UIndex, VIndex) = Weight;
1207 Rational(Weights, urational, vrational);
1210 // is it turning into non rational
1212 if (!(urational || vrational)) {
1218 UpdateCoefficients(); //Dans tous cas :Attention a SetPoleCol !
1221 //=======================================================================
1222 //function : SetWeightCol
1224 //=======================================================================
1226 void Geom_BezierSurface::SetWeightCol
1227 (const Standard_Integer VIndex,
1228 const TColStd_Array1OfReal& CPoleWeights)
1231 // compute new rationality
1232 Standard_Boolean wasrat = (urational||vrational);
1234 // set weights of 1.
1235 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1236 1, poles->RowLength(), 1.);
1237 wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
1238 1, poles->RowLength());
1241 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1242 if (VIndex < 1 || VIndex > Weights.RowLength()) Standard_OutOfRange::Raise();
1244 if (CPoleWeights.Length() != Weights.ColLength()) {
1245 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightCol");
1248 I = CPoleWeights.Lower();
1249 while (I <= CPoleWeights.Upper()) {
1250 if (CPoleWeights(I) <= gp::Resolution()) {
1251 Standard_ConstructionError::Raise();
1253 Weights (I, VIndex) = CPoleWeights (I);
1257 Rational(Weights, urational, vrational);
1259 // is it turning into non rational
1261 if (!(urational || vrational)) {
1267 UpdateCoefficients();
1270 //=======================================================================
1271 //function : SetWeightRow
1273 //=======================================================================
1275 void Geom_BezierSurface::SetWeightRow
1276 (const Standard_Integer UIndex,
1277 const TColStd_Array1OfReal& CPoleWeights)
1280 // compute new rationality
1281 Standard_Boolean wasrat = (urational||vrational);
1283 // set weights of 1.
1284 weights = new TColStd_HArray2OfReal (1, poles->ColLength(),
1285 1, poles->RowLength(), 1.);
1286 wcoeffs = new TColStd_HArray2OfReal (1, poles->ColLength(),
1287 1, poles->RowLength());
1290 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1291 if (UIndex < 1 || UIndex > Weights.ColLength())
1292 Standard_OutOfRange::Raise("Geom_BezierSurface::SetWeightRow");
1293 if (CPoleWeights.Lower() < 1 ||
1294 CPoleWeights.Lower() > Weights.RowLength() ||
1295 CPoleWeights.Upper() < 1 ||
1296 CPoleWeights.Upper() > Weights.RowLength() ) {
1297 Standard_ConstructionError::Raise("Geom_BezierSurface::SetWeightRow");
1300 I = CPoleWeights.Lower();
1301 while (I <= CPoleWeights.Upper()) {
1302 if (CPoleWeights(I) <= gp::Resolution()) {
1303 Standard_ConstructionError::Raise();
1305 Weights (UIndex, I) = CPoleWeights (I);
1309 Rational(Weights, urational, vrational);
1311 // is it turning into non rational
1313 if (!(urational || vrational)) {
1319 UpdateCoefficients();
1322 //=======================================================================
1323 //function : UReverse
1325 //=======================================================================
1327 void Geom_BezierSurface::UReverse ()
1330 Standard_Integer Row,Col;
1331 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1332 if (urational || vrational) {
1333 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1335 for (Col = 1; Col <= Poles.RowLength(); Col++) {
1336 for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) {
1337 W = Weights (Row, Col);
1338 Weights (Row, Col) = Weights (Poles.ColLength()- Row + 1, Col);
1339 Weights (Poles.ColLength() - Row + 1, Col) = W;
1340 Pol = Poles (Row, Col);
1341 Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col);
1342 Poles (Poles.ColLength() - Row + 1, Col) = Pol;
1347 for (Col = 1; Col <= Poles.RowLength(); Col++) {
1348 for (Row = 1; Row <= IntegerPart (Poles.ColLength() / 2); Row++) {
1349 Pol = Poles (Row, Col);
1350 Poles (Row, Col) = Poles (Poles.ColLength() - Row + 1, Col);
1351 Poles (Poles.ColLength() - Row + 1, Col) = Pol;
1355 UpdateCoefficients();
1358 //=======================================================================
1359 //function : UReversedParameter
1361 //=======================================================================
1363 Standard_Real Geom_BezierSurface::UReversedParameter
1364 ( const Standard_Real U) const
1369 //=======================================================================
1370 //function : VReverse
1372 //=======================================================================
1374 void Geom_BezierSurface::VReverse ()
1377 Standard_Integer Row,Col;
1378 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1379 if (urational || vrational) {
1380 TColStd_Array2OfReal & Weights = weights->ChangeArray2();
1382 for (Row = 1; Row <= Poles.ColLength(); Row++) {
1383 for (Col = 1; Col <= IntegerPart (Poles.RowLength()/2); Col++) {
1384 W = Weights (Row, Col);
1385 Weights (Row, Col) = Weights (Row, Poles.RowLength() - Col + 1);
1386 Weights (Row, Poles.RowLength() - Col + 1) = W;
1387 Pol = Poles (Row, Col);
1388 Poles (Row, Col) = Poles (Row, Poles.RowLength() - Col + 1);
1389 Poles (Row, Poles.RowLength() - Col + 1) = Pol;
1394 for (Row = 1; Row <= Poles.ColLength(); Row++) {
1395 for (Col = 1; Col <= IntegerPart(Poles.RowLength()/2); Col++) {
1396 Pol = Poles (Row, Col);
1397 Poles (Row, Col)= Poles (Row, Poles.RowLength() - Col + 1);
1398 Poles (Row, Poles.RowLength() - Col + 1) = Pol;
1402 UpdateCoefficients();
1405 //=======================================================================
1406 //function : VReversedParameter
1408 //=======================================================================
1410 Standard_Real Geom_BezierSurface::VReversedParameter
1411 ( const Standard_Real V) const
1416 //=======================================================================
1419 //=======================================================================
1421 void Geom_BezierSurface::Bounds (Standard_Real& U1,
1424 Standard_Real& V2) const
1432 //=======================================================================
1433 //function : Continuity
1435 //=======================================================================
1437 GeomAbs_Shape Geom_BezierSurface::Continuity () const
1442 //=======================================================================
1445 //=======================================================================
1447 void Geom_BezierSurface::D0 (const Standard_Real U,
1448 const Standard_Real V,
1452 if (validcache == 1) {
1454 // XAB : cet algorithme devient instable pour les hauts degres
1455 // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
1458 Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
1459 uspanlenght_11 = ucachespanlenght/2,
1460 vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
1461 vspanlenght_11 = vcachespanlenght/2 ;
1462 if (urational || vrational) {
1463 BSplSLib::CacheD0(U, V, UDegree(), VDegree(),
1464 uparameter_11, vparameter_11,
1465 uspanlenght_11, vspanlenght_11,
1471 BSplSLib::CacheD0(U, V, UDegree(), VDegree(),
1472 uparameter_11, vparameter_11,
1473 uspanlenght_11, vspanlenght_11,
1475 BSplSLib::NoWeights(),
1480 Standard_Real array_u[2] ;
1481 Standard_Real array_v[2] ;
1482 Standard_Integer mult_u[2] ;
1483 Standard_Integer mult_v[2] ;
1484 TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1485 TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
1486 TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1487 TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
1488 if (urational || vrational) {
1489 BSplSLib::D0(U, V, 1,1,poles->Array2(),
1491 biduknots,bidvknots,&bidumults,&bidvmults,
1492 UDegree(),VDegree(),
1493 urational,vrational,Standard_False,Standard_False,
1498 BSplSLib::D0(U, V, 1,1,poles->Array2(),
1499 BSplSLib::NoWeights(),
1500 biduknots,bidvknots,&bidumults,&bidvmults,
1501 UDegree(),VDegree(),
1502 urational,vrational,Standard_False,Standard_False,
1508 //=======================================================================
1511 //=======================================================================
1513 void Geom_BezierSurface::D1
1514 (const Standard_Real U,
1515 const Standard_Real V,
1521 if (validcache == 1) {
1523 // XAB : cet algorithme devient instable pour les hauts degres
1524 // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
1527 Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
1528 uspanlenght_11 = ucachespanlenght/2,
1529 vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
1530 vspanlenght_11 = vcachespanlenght/2 ;
1531 if (urational || vrational) {
1532 BSplSLib::CacheD1(U, V, UDegree(), VDegree(),
1533 uparameter_11, vparameter_11,
1534 uspanlenght_11, vspanlenght_11,
1540 BSplSLib::CacheD1(U, V, UDegree(), VDegree(),
1541 uparameter_11, vparameter_11,
1542 uspanlenght_11, vspanlenght_11,
1544 BSplSLib::NoWeights(),
1549 Standard_Real array_u[2] ;
1550 Standard_Real array_v[2] ;
1551 Standard_Integer mult_u[2] ;
1552 Standard_Integer mult_v[2] ;
1553 TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1554 TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
1555 TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1556 TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
1557 if (urational || vrational) {
1558 BSplSLib::D1(U, V, 1,1,poles->Array2(),
1560 biduknots,bidvknots,&bidumults,&bidvmults,
1561 UDegree(),VDegree(),
1562 urational,vrational,Standard_False,Standard_False,
1566 BSplSLib::D1(U, V, 1,1,poles->Array2(),
1567 BSplSLib::NoWeights(),
1568 biduknots,bidvknots,&bidumults,&bidvmults,
1569 UDegree(),VDegree(),
1570 urational,vrational,Standard_False,Standard_False,
1576 //=======================================================================
1579 //=======================================================================
1581 void Geom_BezierSurface::D2
1582 (const Standard_Real U,
1583 const Standard_Real V,
1585 gp_Vec& D1U, gp_Vec& D1V,
1586 gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV ) const
1589 if (validcache == 1) {
1591 // XAB : cet algorithme devient instable pour les hauts degres
1592 // RBD : Beaucoup moins maintenant avec le calcul d'un nouveau cache
1595 Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
1596 uspanlenght_11 = ucachespanlenght/2,
1597 vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
1598 vspanlenght_11 = vcachespanlenght/2 ;
1599 if (urational || vrational) {
1600 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1601 BSplSLib::CacheD2(U, V, UDegree(), VDegree(),
1602 uparameter_11, vparameter_11,
1603 uspanlenght_11, vspanlenght_11,
1606 P, D1U, D1V, D2U, D2UV , D2V);
1609 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1610 BSplSLib::CacheD2(U, V, UDegree(), VDegree(),
1611 uparameter_11, vparameter_11,
1612 uspanlenght_11, vspanlenght_11,
1614 BSplSLib::NoWeights(),
1615 P, D1U, D1V, D2U, D2UV , D2V);
1619 Standard_Real array_u[2] ;
1620 Standard_Real array_v[2] ;
1621 Standard_Integer mult_u[2] ;
1622 Standard_Integer mult_v[2] ;
1623 TColStd_Array1OfReal biduknots(array_u[0],1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1624 TColStd_Array1OfInteger bidumults(mult_u[0],1,2); bidumults.Init(UDegree() + 1);
1625 TColStd_Array1OfReal bidvknots(array_v[0],1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1626 TColStd_Array1OfInteger bidvmults(mult_v[0],1,2); bidvmults.Init(VDegree() + 1);
1627 if (urational || vrational) {
1628 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1629 BSplSLib::D2(U, V, 1,1,poles->Array2(),
1631 biduknots,bidvknots,&bidumults,&bidvmults,
1632 UDegree(),VDegree(),
1633 urational,vrational,Standard_False,Standard_False,
1634 P,D1U, D1V, D2U, D2V , D2UV) ;
1637 //-- ATTENTION a l'ORDRE d'appel ds BSPLSLIB
1638 BSplSLib::D2(U, V, 1,1,poles->Array2(),
1639 BSplSLib::NoWeights(),
1640 biduknots,bidvknots,&bidumults,&bidvmults,
1641 UDegree(),VDegree(),
1642 urational,vrational,Standard_False,Standard_False,
1643 P,D1U, D1V, D2U, D2V, D2UV ) ;
1648 //=======================================================================
1651 //=======================================================================
1653 void Geom_BezierSurface::D3
1654 (const Standard_Real U, const Standard_Real V,
1656 gp_Vec& D1U, gp_Vec& D1V,
1657 gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV,
1658 gp_Vec& D3U, gp_Vec& D3V, gp_Vec& D3UUV, gp_Vec& D3UVV) const
1660 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1661 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1662 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1663 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1664 if (urational || vrational) {
1665 BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
1667 biduknots, bidvknots, &bidumults, &bidvmults,
1668 UDegree(), VDegree(), urational, vrational, 0, 0,
1672 D3U, D3V, D3UUV, D3UVV);
1675 BSplSLib::D3 (U, V, 0, 0, poles->Array2(),
1676 BSplSLib::NoWeights(),
1677 biduknots, bidvknots, &bidumults, &bidvmults,
1678 UDegree(), VDegree(), urational, vrational, 0, 0,
1682 D3U, D3V, D3UUV, D3UVV);
1686 //=======================================================================
1689 //=======================================================================
1691 gp_Vec Geom_BezierSurface::DN
1692 (const Standard_Real U,
1693 const Standard_Real V,
1694 const Standard_Integer Nu,
1695 const Standard_Integer Nv) const
1697 Standard_RangeError_Raise_if (Nu + Nv < 1 || Nv < 0 || Nu <0, " ");
1699 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1700 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1701 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1702 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1703 if (urational || vrational) {
1704 BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
1706 biduknots, bidvknots, &bidumults, &bidvmults,
1707 UDegree(), VDegree(), urational, vrational, 0, 0,
1711 BSplSLib::DN (U, V, Nu, Nv, 0, 0, poles->Array2(),
1712 BSplSLib::NoWeights(),
1713 biduknots, bidvknots, &bidumults, &bidvmults,
1714 UDegree(), VDegree(), urational, vrational, 0, 0,
1720 //=======================================================================
1721 //function : NbUPoles
1723 //=======================================================================
1725 Standard_Integer Geom_BezierSurface::NbUPoles () const
1727 return poles->ColLength();
1730 //=======================================================================
1731 //function : NbVPoles
1733 //=======================================================================
1735 Standard_Integer Geom_BezierSurface::NbVPoles () const
1737 return poles->RowLength();
1740 //=======================================================================
1743 //=======================================================================
1745 gp_Pnt Geom_BezierSurface::Pole (const Standard_Integer UIndex,
1746 const Standard_Integer VIndex) const
1748 Standard_OutOfRange_Raise_if
1749 (UIndex < 1 || UIndex > poles->ColLength() ||
1750 VIndex < 1 || VIndex > poles->RowLength(), " ");
1751 return poles->Value (UIndex + poles->LowerRow() - 1,
1752 VIndex + poles->LowerCol() - 1);
1755 //=======================================================================
1758 //=======================================================================
1760 void Geom_BezierSurface::Poles (TColgp_Array2OfPnt& P) const
1762 Standard_DimensionError_Raise_if
1763 (P.RowLength() != poles->RowLength() ||
1764 P.ColLength() != poles->ColLength(), " ");
1765 P = poles->Array2();
1768 //=======================================================================
1769 //function : UDegree
1771 //=======================================================================
1773 Standard_Integer Geom_BezierSurface::UDegree () const
1775 return poles->ColLength() - 1;
1778 //=======================================================================
1781 //=======================================================================
1783 Handle(Geom_Curve) Geom_BezierSurface::UIso (const Standard_Real U) const
1785 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
1786 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
1788 Handle(Geom_BezierCurve) UIsoCurve;
1789 const TColgp_Array2OfPnt & Poles = poles->Array2();
1790 TColgp_Array1OfPnt VCurvePoles (Poles.LowerCol() , Poles.UpperCol());
1791 if (urational || vrational) {
1792 const TColStd_Array2OfReal & Weights = weights->Array2();
1793 TColStd_Array1OfReal VCurveWeights
1794 (Weights.LowerCol() , Weights.UpperCol());
1795 BSplSLib::Iso (U, 1, Poles,
1797 biduknots, &bidumults,
1798 UDegree(), 0, VCurvePoles, &VCurveWeights);
1800 UIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
1802 UIsoCurve = new Geom_BezierCurve (VCurvePoles);
1805 BSplSLib::Iso (U, 1, Poles,
1806 BSplSLib::NoWeights(),
1807 biduknots, &bidumults,
1808 UDegree(), 0, VCurvePoles, PLib::NoWeights());
1809 UIsoCurve = new Geom_BezierCurve (VCurvePoles);
1814 //=======================================================================
1815 //function : VDegree
1817 //=======================================================================
1819 Standard_Integer Geom_BezierSurface::VDegree () const
1821 return poles->RowLength() - 1;
1824 //=======================================================================
1827 //=======================================================================
1829 Handle(Geom_Curve) Geom_BezierSurface::VIso (const Standard_Real V) const
1831 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
1832 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
1834 Handle(Geom_BezierCurve) VIsoCurve;
1835 const TColgp_Array2OfPnt & Poles = poles->Array2();
1836 TColgp_Array1OfPnt VCurvePoles (Poles.LowerRow() , Poles.UpperRow());
1837 if (vrational || urational) {
1838 const TColStd_Array2OfReal & Weights = weights->Array2();
1839 TColStd_Array1OfReal VCurveWeights
1840 (Weights.LowerRow() , Weights.UpperRow());
1841 BSplSLib::Iso (V, 0, Poles,
1843 bidvknots, &bidvmults,
1844 VDegree(), 0, VCurvePoles, &VCurveWeights);
1846 VIsoCurve = new Geom_BezierCurve (VCurvePoles, VCurveWeights);
1848 VIsoCurve = new Geom_BezierCurve (VCurvePoles);
1851 BSplSLib::Iso (V, 0, Poles,
1852 BSplSLib::NoWeights(),
1853 bidvknots, &bidvmults,
1854 VDegree(), 0, VCurvePoles, PLib::NoWeights());
1855 VIsoCurve = new Geom_BezierCurve (VCurvePoles);
1860 //=======================================================================
1863 //=======================================================================
1865 Standard_Real Geom_BezierSurface::Weight (const Standard_Integer UIndex,
1866 const Standard_Integer VIndex) const
1868 Standard_OutOfRange_Raise_if (
1869 UIndex < 1 || UIndex > weights->ColLength() ||
1870 VIndex < 1 || VIndex > weights->RowLength(), " ");
1872 if (urational || vrational)
1873 return weights->Value (UIndex, VIndex);
1878 //=======================================================================
1879 //function : Weights
1881 //=======================================================================
1883 void Geom_BezierSurface::Weights (TColStd_Array2OfReal& W ) const
1885 Standard_DimensionError_Raise_if (
1886 W.RowLength() != weights->RowLength() ||
1887 W.ColLength() != weights->ColLength(), " " );
1888 if (urational || vrational)
1889 W = weights->Array2();
1894 //=======================================================================
1897 //=======================================================================
1899 Standard_Boolean Geom_BezierSurface::IsCNu (const Standard_Integer ) const
1901 return Standard_True;
1904 //=======================================================================
1907 //=======================================================================
1909 Standard_Boolean Geom_BezierSurface::IsCNv (const Standard_Integer ) const
1911 return Standard_True;
1914 //=======================================================================
1915 //function : IsURational
1917 //=======================================================================
1919 Standard_Boolean Geom_BezierSurface::IsURational () const
1924 //=======================================================================
1925 //function : IsVRational
1927 //=======================================================================
1929 Standard_Boolean Geom_BezierSurface::IsVRational () const
1934 //=======================================================================
1935 //function : Transform
1937 //=======================================================================
1939 void Geom_BezierSurface::Transform (const gp_Trsf& T)
1941 TColgp_Array2OfPnt & Poles = poles->ChangeArray2();
1943 for (Standard_Integer I = 1; I <= Poles.ColLength(); I++) {
1945 for (Standard_Integer J = 1; J <= Poles.RowLength(); J++) {
1946 Poles (I, J).Transform (T);
1949 UpdateCoefficients();
1952 //=======================================================================
1953 //function : IsUClosed
1955 //=======================================================================
1957 Standard_Boolean Geom_BezierSurface::IsUClosed () const
1959 const TColgp_Array2OfPnt & Poles = poles->Array2();
1960 Standard_Boolean Closed = Standard_True;
1961 Standard_Integer Lower = Poles.LowerRow();
1962 Standard_Integer Upper = Poles.UpperRow();
1963 Standard_Integer Length = Poles.RowLength();
1964 Standard_Integer j = Poles.LowerCol();
1966 while (Closed && j <= Length) {
1967 Closed = (Poles (Lower,j).Distance (Poles (Upper,j)) <= Precision::Confusion());
1973 //=======================================================================
1974 //function : IsVClosed
1976 //=======================================================================
1978 Standard_Boolean Geom_BezierSurface::IsVClosed () const
1980 const TColgp_Array2OfPnt & Poles = poles->Array2();
1981 Standard_Boolean Closed = Standard_True;
1982 Standard_Integer Lower = Poles.LowerCol();
1983 Standard_Integer Upper = Poles.UpperCol();
1984 Standard_Integer Length = Poles.ColLength();
1985 Standard_Integer i = Poles.LowerRow();
1986 while (Closed && i <= Length) {
1987 Closed = (Poles (i,Lower).Distance (Poles (i,Upper)) <= Precision::Confusion());
1993 //=======================================================================
1994 //function : IsUPeriodic
1996 //=======================================================================
1998 Standard_Boolean Geom_BezierSurface::IsUPeriodic () const
2000 return Standard_False;
2003 //=======================================================================
2004 //function : IsVPeriodic
2006 //=======================================================================
2008 Standard_Boolean Geom_BezierSurface::IsVPeriodic () const
2010 return Standard_False;
2013 //=======================================================================
2014 //function : Resolution
2016 //=======================================================================
2018 void Geom_BezierSurface::Resolution(const Standard_Real Tolerance3D,
2019 Standard_Real& UTolerance,
2020 Standard_Real& VTolerance)
2023 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
2024 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
2025 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
2026 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
2027 if(urational || vrational){
2028 BSplSLib::Resolution(poles->Array2(),
2045 BSplSLib::Resolution(poles->Array2(),
2046 BSplSLib::NoWeights(),
2063 UTolerance = Tolerance3D * umaxderivinv;
2064 VTolerance = Tolerance3D * vmaxderivinv;
2067 //=======================================================================
2070 //=======================================================================
2072 Handle(Geom_Geometry) Geom_BezierSurface::Copy() const
2074 Handle(Geom_BezierSurface) S = new Geom_BezierSurface
2075 (poles, coeffs, weights, wcoeffs, urational, vrational);
2079 //=======================================================================
2082 //=======================================================================
2084 void Geom_BezierSurface::Init
2085 (const Handle(TColgp_HArray2OfPnt)& Poles,
2086 const Handle(TColStd_HArray2OfReal)& Weights)
2088 Standard_Integer NbUPoles = Poles->ColLength();
2089 Standard_Integer NbVPoles = Poles->RowLength();
2091 Standard_Integer maxcls = Max(NbUPoles, NbVPoles);
2092 Standard_Integer mincls = Min(NbUPoles, NbVPoles);
2096 coeffs = new TColgp_HArray2OfPnt (1,maxcls,1,mincls);
2098 if (urational || vrational) {
2100 wcoeffs = new TColStd_HArray2OfReal (1,maxcls,1,mincls);
2107 UpdateCoefficients();
2111 //=======================================================================
2112 //function : UpdateCoefficients
2114 //=======================================================================
2116 void Geom_BezierSurface::UpdateCoefficients(const Standard_Real ,
2117 const Standard_Real )
2119 maxderivinvok = Standard_False;
2120 ucacheparameter = 0.;
2121 TColStd_Array1OfReal biduflatknots(BSplCLib::FlatBezierKnots(UDegree()),
2122 1, 2*(UDegree()+1));
2123 vcacheparameter = 0.;
2124 TColStd_Array1OfReal bidvflatknots(BSplCLib::FlatBezierKnots(VDegree()),
2125 1, 2*(VDegree()+1));
2127 Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
2128 uspanlenght_11 = ucachespanlenght/2,
2129 vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
2130 vspanlenght_11 = vcachespanlenght/2 ;
2132 if ( urational || vrational ) {
2133 BSplSLib::BuildCache(uparameter_11,vparameter_11,
2134 uspanlenght_11,vspanlenght_11,0,0,
2135 UDegree(),VDegree(),0,0,
2136 biduflatknots,bidvflatknots,
2139 coeffs->ChangeArray2(),
2140 &wcoeffs->ChangeArray2());
2143 BSplSLib::BuildCache(uparameter_11,vparameter_11,
2144 uspanlenght_11,vspanlenght_11,0,0,
2145 UDegree(),VDegree(),0,0,
2146 biduflatknots,bidvflatknots,
2148 BSplSLib::NoWeights(),
2149 coeffs->ChangeArray2(),
2150 BSplSLib::NoWeights());