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
29 #include <Geom_BezierSurface.ixx>
30 #include <Geom_BezierCurve.hxx>
35 #include <BSplCLib.hxx>
36 #include <BSplSLib.hxx>
37 #include <Precision.hxx>
39 #include <Standard_OutOfRange.hxx>
40 #include <Standard_RangeError.hxx>
41 #include <Standard_DimensionError.hxx>
42 #include <Standard_ConstructionError.hxx>
43 #include <TColStd_Array1OfInteger.hxx>
45 //=======================================================================
47 //purpose : check rationality of an array of weights
48 //=======================================================================
50 static void Rational(const TColStd_Array2OfReal& Weights,
51 Standard_Boolean& Urational,
52 Standard_Boolean& Vrational)
55 J = Weights.LowerCol ();
56 Vrational = Standard_False;
57 while (!Vrational && J <= Weights.UpperCol()) {
58 I = Weights.LowerRow();
59 while (!Vrational && I <= Weights.UpperRow() - 1) {
60 Vrational = (Abs(Weights (I, J) - Weights (I+1, J))
61 > Epsilon (Abs(Weights (I, J))));
67 I = Weights.LowerRow ();
68 Urational = Standard_False;
69 while (!Urational && I <= Weights.UpperRow()) {
70 J = Weights.LowerCol();
71 while (!Urational && J <= Weights.UpperCol() - 1) {
72 Urational = (Abs(Weights (I, J) - Weights (I, J+1))
73 > Epsilon (Abs(Weights (I, J))));
80 //=======================================================================
81 //function : AddPoleCol
82 //purpose : Internal use only.
83 //=======================================================================
85 static void AddPoleCol
86 (const TColgp_Array2OfPnt& Poles,
87 const TColgp_Array1OfPnt& PoleCol,
88 const Standard_Integer AfterIndex,
89 TColgp_Array2OfPnt& NewPoles)
91 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
92 Standard_Integer Offset = NewPoles.LowerRow() - PoleCol.Lower();
93 Standard_Integer ColIndex = NewPoles.LowerCol();
94 Standard_Integer RowIndex;
95 while (ColIndex < InsertIndex) {
96 RowIndex = NewPoles.LowerRow();
97 while (RowIndex <= NewPoles.UpperRow()){
98 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
103 RowIndex = NewPoles.LowerRow();
104 while (RowIndex <= NewPoles.UpperRow()){
105 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - Offset);
109 while (ColIndex <= NewPoles.UpperCol()) {
110 RowIndex = NewPoles.LowerRow();
111 while (RowIndex <= NewPoles.UpperRow()){
112 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
119 //=======================================================================
120 //function : AddRatPoleCol
121 //purpose : Internal use only.
122 //=======================================================================
124 static void AddRatPoleCol
125 (const TColgp_Array2OfPnt& Poles,
126 const TColStd_Array2OfReal& Weights,
127 const TColgp_Array1OfPnt& PoleCol,
128 const TColStd_Array1OfReal& PoleWeightCol,
129 const Standard_Integer AfterIndex,
130 TColgp_Array2OfPnt& NewPoles,
131 TColStd_Array2OfReal& NewWeights)
133 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerCol();
134 Standard_Integer OffsetPol = NewPoles.LowerRow() - PoleCol.Lower();
135 Standard_Integer OffsetW = NewWeights.LowerRow() - PoleWeightCol.Lower();
137 Standard_Integer ColIndex = NewPoles.LowerCol();
138 Standard_Integer RowIndex;
139 while (ColIndex < InsertIndex) {
140 RowIndex = NewPoles.LowerRow();
141 while (RowIndex <= NewPoles.UpperRow()){
142 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
143 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
148 RowIndex = NewPoles.LowerRow();
149 while (RowIndex <= NewPoles.UpperRow()){
150 NewPoles (RowIndex, ColIndex) = PoleCol (RowIndex - OffsetPol);
151 NewWeights (RowIndex, ColIndex) = PoleWeightCol (RowIndex - OffsetW);
155 while (ColIndex <= NewPoles.UpperCol()) {
156 RowIndex = NewPoles.LowerRow();
157 while (RowIndex <= NewPoles.UpperRow()){
158 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex - 1);
160 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex - 1);
166 //=======================================================================
167 //function : AddPoleRow
168 //purpose : Internal use only.
169 //=======================================================================
171 static void AddPoleRow
172 (const TColgp_Array2OfPnt& Poles,
173 const TColgp_Array1OfPnt& PoleRow,
174 const Standard_Integer AfterIndex,
175 TColgp_Array2OfPnt& NewPoles)
177 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
178 Standard_Integer Offset = NewPoles.LowerCol() - PoleRow.Lower();
179 Standard_Integer RowIndex = NewPoles.LowerRow();
180 Standard_Integer ColIndex;
181 while (RowIndex < InsertIndex) {
182 ColIndex = NewPoles.LowerCol();
183 while (ColIndex <= NewPoles.UpperCol()){
184 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
189 ColIndex = NewPoles.LowerCol();
190 while (ColIndex <= NewPoles.UpperCol()){
191 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - Offset);
195 while (RowIndex <= NewPoles.UpperRow()) {
196 ColIndex = NewPoles.LowerCol();
197 while (ColIndex <= NewPoles.UpperCol()){
198 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
205 //=======================================================================
206 //function : AddRatPoleRow
208 //=======================================================================
210 static void AddRatPoleRow
211 (const TColgp_Array2OfPnt& Poles,
212 const TColStd_Array2OfReal& Weights,
213 const TColgp_Array1OfPnt& PoleRow,
214 const TColStd_Array1OfReal& PoleWeightRow,
215 const Standard_Integer AfterIndex,
216 TColgp_Array2OfPnt& NewPoles,
217 TColStd_Array2OfReal& NewWeights)
219 Standard_Integer InsertIndex = AfterIndex + NewPoles.LowerRow();
220 Standard_Integer OffsetPol = NewPoles.LowerCol() - PoleRow.Lower();
221 Standard_Integer OffsetW = NewWeights.LowerCol() - PoleWeightRow.Lower();
223 Standard_Integer ColIndex;
224 Standard_Integer RowIndex = NewPoles.LowerRow();
225 while (RowIndex < InsertIndex) {
226 ColIndex = NewPoles.LowerCol();
227 while (ColIndex <= NewPoles.UpperCol()){
228 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex);
229 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex);
234 ColIndex = NewPoles.LowerCol();
235 while (ColIndex <= NewPoles.UpperCol()){
236 NewPoles (RowIndex, ColIndex) = PoleRow (ColIndex - OffsetPol);
237 NewWeights (RowIndex, ColIndex) = PoleWeightRow (ColIndex - OffsetW);
241 while (RowIndex <= NewPoles.UpperRow()) {
242 ColIndex = NewPoles.LowerCol();
243 while (ColIndex <= NewPoles.UpperCol()){
244 NewPoles (RowIndex, ColIndex) = Poles (RowIndex - 1, ColIndex);
245 NewWeights (RowIndex, ColIndex) = Weights (RowIndex - 1, ColIndex);
252 //=======================================================================
253 //function : DeletePoleCol
255 //=======================================================================
257 static void DeletePoleCol
258 (const TColgp_Array2OfPnt& Poles,
259 const Standard_Integer Index,
260 TColgp_Array2OfPnt& NewPoles)
262 Standard_Integer Offset = 0;
263 Standard_Integer RowIndex;
264 Standard_Integer ColIndex = NewPoles.LowerCol();
265 while (ColIndex <= NewPoles.UpperCol()) {
266 RowIndex = NewPoles.LowerRow();
267 if (ColIndex == Index) Offset = 1;
268 while (RowIndex <= NewPoles.UpperRow()){
269 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
276 //=======================================================================
277 //function : DeleteRatPoleCol
279 //=======================================================================
281 static void DeleteRatPoleCol
282 (const TColgp_Array2OfPnt& Poles,
283 const TColStd_Array2OfReal& Weights,
284 const Standard_Integer Index,
285 TColgp_Array2OfPnt& NewPoles,
286 TColStd_Array2OfReal& NewWeights)
288 Standard_Integer Offset = 0;
289 Standard_Integer RowIndex;
290 Standard_Integer ColIndex = NewPoles.LowerCol();
291 while (ColIndex <= NewPoles.UpperCol()) {
292 RowIndex = NewPoles.LowerRow();
293 if (ColIndex == Index) Offset = 1;
294 while (RowIndex <= NewPoles.UpperRow()){
295 NewPoles (RowIndex, ColIndex) = Poles (RowIndex, ColIndex + Offset);
296 NewWeights (RowIndex, ColIndex) = Weights (RowIndex, ColIndex+Offset);
303 //=======================================================================
304 //function : DeletePoleRow
306 //=======================================================================
308 static void DeletePoleRow
309 (const TColgp_Array2OfPnt& Poles,
310 const Standard_Integer Index,
311 TColgp_Array2OfPnt& NewPoles)
313 Standard_Integer Offset = 0;
314 Standard_Integer ColIndex;
315 Standard_Integer RowIndex = NewPoles.LowerRow();
316 while (RowIndex <= NewPoles.UpperRow()) {
317 ColIndex = NewPoles.LowerCol();
318 if (RowIndex == Index) Offset = 1;
319 while (ColIndex <= NewPoles.UpperCol()){
320 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
327 //=======================================================================
328 //function : DeleteRatPoleRow
330 //=======================================================================
332 static void DeleteRatPoleRow
333 (const TColgp_Array2OfPnt& Poles,
334 const TColStd_Array2OfReal& Weights,
335 const Standard_Integer Index,
336 TColgp_Array2OfPnt& NewPoles,
337 TColStd_Array2OfReal& NewWeights)
339 Standard_Integer Offset = 0;
340 Standard_Integer ColIndex;
341 Standard_Integer RowIndex = NewPoles.LowerRow();
342 while (RowIndex <= NewPoles.UpperRow()) {
343 ColIndex = NewPoles.LowerCol();
344 if (RowIndex == Index) Offset = 1;
345 while (ColIndex <= NewPoles.UpperCol()){
346 NewPoles (RowIndex, ColIndex) = Poles (RowIndex + Offset, ColIndex);
347 NewWeights (RowIndex, ColIndex) = Weights (RowIndex+Offset, ColIndex);
354 //=======================================================================
355 //function : Geom_BezierSurface
357 //=======================================================================
359 Geom_BezierSurface::Geom_BezierSurface
360 (const TColgp_Array2OfPnt& SurfacePoles):
363 ucachespanlenght(1.),
364 vcachespanlenght(1.),
366 maxderivinvok(Standard_False)
368 Standard_Integer NbUPoles = SurfacePoles.ColLength();
369 Standard_Integer NbVPoles = SurfacePoles.RowLength();
370 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
371 NbVPoles < 2 || NbVPoles > MaxDegree()+1) {
372 Standard_ConstructionError::Raise();
375 Handle(TColgp_HArray2OfPnt) npoles =
376 new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
381 npoles->ChangeArray2() = SurfacePoles;
385 Handle(TColStd_HArray2OfReal)());
388 //=======================================================================
389 //function : Geom_BezierSurface
391 //=======================================================================
393 Geom_BezierSurface::Geom_BezierSurface
394 (const TColgp_Array2OfPnt& SurfacePoles,
395 const TColStd_Array2OfReal& PoleWeights ):
398 ucachespanlenght(1.),
399 vcachespanlenght(1.),
401 maxderivinvok(Standard_False)
403 Standard_Integer NbUPoles = SurfacePoles.ColLength();
404 Standard_Integer NbVPoles = SurfacePoles.RowLength();
405 if (NbUPoles < 2 || NbUPoles > MaxDegree()+1 ||
406 NbVPoles < 2 || NbVPoles > MaxDegree()+1 ||
407 NbVPoles != PoleWeights.RowLength() ||
408 NbUPoles != PoleWeights.ColLength() ) {
409 Standard_ConstructionError::Raise();
412 Standard_Integer Row = PoleWeights.LowerRow();
413 Standard_Integer Col = PoleWeights.LowerCol();
414 while (Col <= PoleWeights.UpperCol()) {
415 Row = PoleWeights.LowerRow();
416 while (Row <= PoleWeights.UpperRow()) {
417 if (PoleWeights(Row, Col) <= gp::Resolution()) {
418 Standard_ConstructionError::Raise();
425 Handle(TColgp_HArray2OfPnt)
426 npoles = new TColgp_HArray2OfPnt (1, NbUPoles, 1, NbVPoles);
427 npoles->ChangeArray2() = SurfacePoles;
429 Standard_Integer I, J;
430 urational = Standard_False;
431 vrational = Standard_False;
432 J = PoleWeights.LowerCol ();
433 while (!vrational && J <= PoleWeights.UpperCol()) {
434 I = PoleWeights.LowerRow();
435 while (!vrational && I <= PoleWeights.UpperRow() - 1) {
436 vrational = (Abs(PoleWeights (I, J) - PoleWeights (I+1, J))
437 > Epsilon (Abs(PoleWeights (I, J))));
442 I = PoleWeights.LowerRow ();
443 while (!urational && I <= PoleWeights.UpperRow()) {
444 J = PoleWeights.LowerCol();
445 while (!urational && J <= PoleWeights.UpperCol() - 1) {
446 urational = (Abs(PoleWeights (I, J) - PoleWeights (I, J+1))
447 > Epsilon (Abs(PoleWeights (I, J))));
454 Handle(TColStd_HArray2OfReal) nweights;
455 if (urational || vrational) {
456 nweights = new TColStd_HArray2OfReal (1, NbUPoles, 1, NbVPoles);
457 nweights->ChangeArray2() = PoleWeights;
461 Init(npoles,nweights);
464 //=======================================================================
465 //function : Geom_BezierSurface
467 //=======================================================================
469 Geom_BezierSurface::Geom_BezierSurface
470 (const Handle(TColgp_HArray2OfPnt)& SurfacePoles,
471 const Handle(TColgp_HArray2OfPnt)& SurfaceCoefs,
472 const Handle(TColStd_HArray2OfReal)& PoleWeights,
473 const Handle(TColStd_HArray2OfReal)& CoefWeights,
474 const Standard_Boolean IsURational,
475 const Standard_Boolean IsVRational)
476 :maxderivinvok(Standard_False)
478 urational = IsURational;
479 vrational = IsVRational;
480 ucachespanlenght = 1.;
481 vcachespanlenght = 1.;
484 vcacheparameter = 0.;
485 Standard_Integer NbUPoles = SurfacePoles->ColLength();
486 Standard_Integer NbVPoles = SurfacePoles->RowLength();
488 poles = new TColgp_HArray2OfPnt (1,NbUPoles,
490 poles->ChangeArray2() = SurfacePoles->Array2();
492 coeffs = new TColgp_HArray2OfPnt (1,SurfaceCoefs->ColLength(),
493 1,SurfaceCoefs->RowLength()) ;
494 coeffs->ChangeArray2() = SurfaceCoefs->Array2();
496 if ( urational || vrational) {
497 weights = new TColStd_HArray2OfReal (1,NbUPoles,1,NbVPoles);
498 weights->ChangeArray2() = PoleWeights->Array2();
500 wcoeffs = new TColStd_HArray2OfReal (1,SurfaceCoefs->ColLength(),
501 1,SurfaceCoefs->RowLength()) ;
502 wcoeffs->ChangeArray2() = CoefWeights->Array2();
506 //=======================================================================
507 //function : MaxDegree
509 //=======================================================================
511 Standard_Integer Geom_BezierSurface::MaxDegree ()
513 return BSplCLib::MaxDegree();
516 //=======================================================================
517 //function : ExchangeUV
519 //=======================================================================
521 void Geom_BezierSurface::ExchangeUV ()
523 Standard_Integer LC = poles->LowerCol();
524 Standard_Integer UC = poles->UpperCol();
525 Standard_Integer LR = poles->LowerRow();
526 Standard_Integer UR = poles->UpperRow();
528 Handle(TColgp_HArray2OfPnt) npoles =
529 new TColgp_HArray2OfPnt (LC, UC, LR, UR);
530 Handle(TColStd_HArray2OfReal) nweights =
531 new TColStd_HArray2OfReal (LC, UC, LR, UR);
533 const TColgp_Array2OfPnt & spoles = poles->Array2();
534 const TColStd_Array2OfReal & sweights = weights->Array2();
536 TColgp_Array2OfPnt& snpoles = npoles->ChangeArray2();
537 TColStd_Array2OfReal& snweights = nweights->ChangeArray2();
539 Standard_Integer i, j;
540 for (i = LC; i <= UC; i++) {
541 for (j = LR; j <= UR; j++) {
542 snpoles (i,j) = spoles (j,i);
543 snweights (i,j) = sweights (j,i);
550 Standard_Boolean temp = urational;
551 urational = vrational;
553 coeffs = new TColgp_HArray2OfPnt (LC, UC, LR, UR);
554 wcoeffs = new TColStd_HArray2OfReal (LC, UC, LR, UR);
556 UpdateCoefficients();
559 //=======================================================================
560 //function : Increase
562 //=======================================================================
564 void Geom_BezierSurface::Increase (const Standard_Integer UDeg,
565 const Standard_Integer VDeg)
567 if (UDeg < UDegree() || UDeg > Geom_BezierSurface::MaxDegree() ||
568 VDeg < VDegree() || VDeg > Geom_BezierSurface::MaxDegree() ) {
569 Standard_ConstructionError::Raise();
572 Standard_Integer oldUDeg = UDegree();
573 Standard_Integer oldVDeg = VDegree();
574 Standard_Integer IncUDeg = UDeg - oldUDeg;
575 Standard_Integer IncVDeg = VDeg - oldVDeg;
576 if (IncUDeg == 0 && IncVDeg == 0) return;
578 TColStd_Array1OfReal biduknots(1,2); biduknots(1) = 0.; biduknots(2) = 1.;
579 TColStd_Array1OfInteger bidumults(1,2); bidumults.Init(UDegree() + 1);
580 TColStd_Array1OfReal bidvknots(1,2); bidvknots(1) = 0.; bidvknots(2) = 1.;
581 TColStd_Array1OfInteger bidvmults(1,2); bidvmults.Init(VDegree() + 1);
582 Handle(TColgp_HArray2OfPnt) npoles;
583 Handle(TColStd_HArray2OfReal) nweights;
586 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, oldVDeg + 1);
588 if ( urational || vrational) {
589 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDegree() + 1);
591 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
594 biduknots, bidumults,
595 npoles->ChangeArray2(),
596 nweights->ChangeArray2(),
597 biduknots, bidumults);
601 BSplSLib::IncreaseDegree(1, oldUDeg, UDeg, 0,
603 *((TColStd_Array2OfReal*) NULL),
604 biduknots, bidumults,
605 npoles->ChangeArray2(),
606 *((TColStd_Array2OfReal*) NULL),
607 biduknots, bidumults);
612 npoles = new TColgp_HArray2OfPnt( 1, UDeg + 1, 1, VDeg + 1);
614 if ( urational || vrational) {
615 nweights = new TColStd_HArray2OfReal( 1, UDeg + 1, 1, VDeg + 1);
617 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
620 bidvknots, bidvmults,
621 npoles->ChangeArray2(),
622 nweights->ChangeArray2(),
623 bidvknots, bidvmults);
627 BSplSLib::IncreaseDegree(0, oldVDeg, VDeg, 0,
629 *((TColStd_Array2OfReal*) NULL),
630 bidvknots, bidvmults,
631 npoles->ChangeArray2(),
632 *((TColStd_Array2OfReal*) NULL),
633 bidvknots, bidvmults);
638 Init(npoles,nweights);
641 //=======================================================================
642 //function : InsertPoleColAfter
644 //=======================================================================
646 void Geom_BezierSurface::InsertPoleColAfter
647 (const Standard_Integer VIndex,
648 const TColgp_Array1OfPnt& CPoles)
650 const TColgp_Array2OfPnt & Poles = poles->Array2();
651 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
652 if (CPoles.Length() != Poles.ColLength()) {
653 Standard_ConstructionError::Raise();
656 Handle(TColgp_HArray2OfPnt) npoles =
657 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
659 Handle(TColStd_HArray2OfReal) nweights;
661 if (urational || vrational) {
663 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
665 TColStd_Array1OfReal CWeights(nweights->LowerRow(),nweights->UpperRow());
668 AddRatPoleCol (poles->Array2(), weights->Array2(),
669 CPoles, CWeights, VIndex,
670 npoles->ChangeArray2(), nweights->ChangeArray2());
673 AddPoleCol (poles->Array2(),
675 npoles->ChangeArray2());
679 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
680 1,poles->RowLength());
681 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
682 1,poles->RowLength());
683 UpdateCoefficients();
686 //=======================================================================
687 //function : InsertPoleColAfter
689 //=======================================================================
691 void Geom_BezierSurface::InsertPoleColAfter
692 (const Standard_Integer VIndex,
693 const TColgp_Array1OfPnt& CPoles,
694 const TColStd_Array1OfReal& CPoleWeights)
696 const TColgp_Array2OfPnt & Poles = poles->Array2();
697 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
698 if (CPoles.Length() != Poles.ColLength() ||
699 CPoleWeights.Length() != CPoles.Length()) {
700 Standard_ConstructionError::Raise();
702 Standard_Integer Index = CPoleWeights.Lower();
703 while (Index <= CPoleWeights.Upper()) {
704 if (CPoleWeights (Index) <= gp::Resolution()) {
705 Standard_ConstructionError::Raise();
710 Handle(TColgp_HArray2OfPnt) npoles =
711 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()+1);
713 Handle(TColStd_HArray2OfReal) nweights =
714 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()+1);
716 AddRatPoleCol (poles->Array2(), weights->Array2(),
717 CPoles, CPoleWeights, VIndex,
718 npoles->ChangeArray2(), nweights->ChangeArray2());
722 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
723 1,poles->RowLength());
724 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
725 1,poles->RowLength());
727 Rational(weights->Array2(), urational, vrational);
729 UpdateCoefficients();
732 //=======================================================================
733 //function : InsertPoleColBefore
735 //=======================================================================
737 void Geom_BezierSurface::InsertPoleColBefore (const Standard_Integer VIndex,
738 const TColgp_Array1OfPnt& CPoles)
740 InsertPoleColAfter(VIndex - 1, CPoles);
743 //=======================================================================
744 //function : InsertPoleColBefore
746 //=======================================================================
748 void Geom_BezierSurface::InsertPoleColBefore
749 (const Standard_Integer VIndex,
750 const TColgp_Array1OfPnt& CPoles,
751 const TColStd_Array1OfReal& CPoleWeights)
753 InsertPoleColAfter( VIndex - 1, CPoles, CPoleWeights);
756 //=======================================================================
757 //function : InsertPoleRowAfter
759 //=======================================================================
761 void Geom_BezierSurface::InsertPoleRowAfter (const Standard_Integer UIndex,
762 const TColgp_Array1OfPnt& CPoles)
764 const TColgp_Array2OfPnt & Poles = poles->Array2();
765 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
766 if (CPoles.Length() != Poles.RowLength()) {
767 Standard_ConstructionError::Raise();
770 Handle(TColgp_HArray2OfPnt) npoles =
771 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
773 Handle(TColStd_HArray2OfReal) nweights;
775 if (urational || vrational) {
777 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
779 // TColStd_Array1OfReal CWeights(nweights->LowerCol(),nweights->UpperCol(),
781 TColStd_Array1OfReal CWeights(1.0,
782 nweights->LowerCol(),nweights->UpperCol());
784 AddRatPoleRow (poles->Array2(), weights->Array2(),
785 CPoles, CWeights, UIndex,
786 npoles->ChangeArray2(), nweights->ChangeArray2());
789 AddPoleRow (poles->Array2(),
791 npoles->ChangeArray2());
795 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
796 1,poles->RowLength());
797 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
798 1,poles->RowLength());
800 UpdateCoefficients();
803 //=======================================================================
804 //function : InsertPoleRowAfter
806 //=======================================================================
808 void Geom_BezierSurface::InsertPoleRowAfter
809 (const Standard_Integer UIndex,
810 const TColgp_Array1OfPnt& CPoles,
811 const TColStd_Array1OfReal& CPoleWeights)
813 const TColgp_Array2OfPnt & Poles = poles->Array2();
814 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
815 if (CPoles.Length() != Poles.RowLength() ||
816 CPoleWeights.Length() != CPoles.Length()) {
817 Standard_ConstructionError::Raise();
819 Standard_Integer Index = CPoleWeights.Lower();
820 while (Index <= CPoleWeights.Upper()) {
821 if (CPoleWeights(Index) <= gp::Resolution()) {
822 Standard_ConstructionError::Raise();
827 Handle(TColgp_HArray2OfPnt) npoles =
828 new TColgp_HArray2OfPnt(1,poles->ColLength()+1,1,poles->RowLength());
830 Handle(TColStd_HArray2OfReal) nweights =
831 new TColStd_HArray2OfReal(1,poles->ColLength()+1,1,poles->RowLength());
833 AddRatPoleCol (poles->Array2(), weights->Array2(),
834 CPoles, CPoleWeights, UIndex,
835 npoles->ChangeArray2(), nweights->ChangeArray2());
839 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
840 1,poles->RowLength());
841 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
842 1,poles->RowLength());
844 Rational(weights->Array2(), urational, vrational);
846 UpdateCoefficients();
849 //=======================================================================
850 //function : InsertPoleRowBefore
852 //=======================================================================
854 void Geom_BezierSurface::InsertPoleRowBefore (const Standard_Integer UIndex,
855 const TColgp_Array1OfPnt& CPoles)
857 InsertPoleRowAfter( UIndex - 1, CPoles);
860 //=======================================================================
861 //function : InsertPoleRowBefore
863 //=======================================================================
865 void Geom_BezierSurface::InsertPoleRowBefore
866 (const Standard_Integer UIndex,
867 const TColgp_Array1OfPnt& CPoles,
868 const TColStd_Array1OfReal& CPoleWeights)
870 InsertPoleRowAfter( UIndex - 1, CPoles, CPoleWeights);
873 //=======================================================================
874 //function : RemovePoleCol
876 //=======================================================================
878 void Geom_BezierSurface::RemovePoleCol (const Standard_Integer VIndex)
880 const TColgp_Array2OfPnt & Poles = poles->Array2();
881 if (VIndex < 1 || VIndex > Poles.RowLength()) Standard_OutOfRange::Raise();
882 if (Poles.RowLength() <= 2) Standard_ConstructionError::Raise();
884 Handle(TColgp_HArray2OfPnt) npoles =
885 new TColgp_HArray2OfPnt(1,poles->ColLength(),1,poles->RowLength()-1);
887 Handle(TColStd_HArray2OfReal) nweights;
889 if (urational || vrational) {
891 new TColStd_HArray2OfReal(1,poles->ColLength(),1,poles->RowLength()-1);
893 DeleteRatPoleCol (poles->Array2(), weights->Array2(),
895 npoles->ChangeArray2(), nweights->ChangeArray2());
896 // Mise a jour de la rationalite
897 Rational(nweights->Array2(), urational, vrational);
900 DeletePoleCol (poles->Array2(),
902 npoles->ChangeArray2());
906 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
907 1,poles->RowLength());
908 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
909 1,poles->RowLength());
910 UpdateCoefficients();
913 //=======================================================================
914 //function : RemovePoleRow
916 //=======================================================================
918 void Geom_BezierSurface::RemovePoleRow (const Standard_Integer UIndex)
920 const TColgp_Array2OfPnt & Poles = poles->Array2();
921 if (UIndex < 1 || UIndex > Poles.ColLength()) Standard_OutOfRange::Raise();
922 if (Poles.ColLength() <= 2) Standard_ConstructionError::Raise();
924 Handle(TColgp_HArray2OfPnt) npoles =
925 new TColgp_HArray2OfPnt(1,poles->ColLength()-1,1,poles->RowLength());
927 Handle(TColStd_HArray2OfReal) nweights;
929 if (urational || vrational) {
931 new TColStd_HArray2OfReal(1,poles->ColLength()-1,1,poles->RowLength());
933 DeleteRatPoleRow (poles->Array2(), weights->Array2(),
935 npoles->ChangeArray2(), nweights->ChangeArray2());
937 // Mise a jour de la rationalite
938 Rational(nweights->Array2(), urational, vrational);
941 DeletePoleRow (poles->Array2(),
943 npoles->ChangeArray2());
947 coeffs = new TColgp_HArray2OfPnt(1,poles->ColLength(),
948 1,poles->RowLength());
949 wcoeffs = new TColStd_HArray2OfReal(1,poles->ColLength(),
950 1,poles->RowLength());
951 UpdateCoefficients();
954 //=======================================================================
957 //=======================================================================
959 void Geom_BezierSurface::Segment
960 (const Standard_Real U1,
961 const Standard_Real U2,
962 const Standard_Real V1,
963 const Standard_Real V2)
965 Standard_Boolean rat = (urational || vrational);
966 Handle(TColgp_HArray2OfPnt) Coefs;
967 Handle(TColStd_HArray2OfReal) WCoefs;
969 if (validcache == 0) UpdateCoefficients(0., 0.);
971 // Attention si udeg <= vdeg u et v sont intervertis
972 // dans les coeffs, il faut donc tout transposer.
973 if(UDegree() <= VDegree()) {
974 Standard_Integer ii, jj;
975 Coefs = new (TColgp_HArray2OfPnt)(1,UDegree()+1,1,VDegree()+1);
977 WCoefs = new (TColStd_HArray2OfReal)(1,UDegree()+1,1,VDegree()+1);
979 for (ii=1; ii<=UDegree()+1; ii++)
980 for (jj=1; jj<=VDegree()+1; jj++) {
981 Coefs->SetValue(ii, jj, coeffs->Value(jj,ii));
982 if (rat) WCoefs->SetValue(ii, jj, wcoeffs->Value(jj,ii));
987 if (rat) {WCoefs = wcoeffs;}
990 // Trim dans la base cannonique et Update des Poles et Coeffs
992 // PMN : tranfo sur les parametres
993 Standard_Real ufirst = 2*(U1 - 0.5),
994 ulast = 2*(U2 - 0.5),
995 vfirst = 2*(V1 - 0.5),
996 vlast = 2*(V2 - 0.5);
998 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
999 WCoefs->ChangeArray2());
1000 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
1001 WCoefs->ChangeArray2());
1002 PLib::CoefficientsPoles(Coefs->Array2(),
1004 poles->ChangeArray2(),
1005 weights->ChangeArray2());
1008 PLib::UTrimming (ufirst, ulast, Coefs->ChangeArray2(),
1009 *((TColStd_Array2OfReal*) NULL));
1010 PLib::VTrimming (vfirst, vlast, Coefs->ChangeArray2(),
1011 *((TColStd_Array2OfReal*) NULL));
1012 PLib::CoefficientsPoles (Coefs->Array2(),
1013 *((TColStd_Array2OfReal*) NULL),
1014 poles->ChangeArray2(),
1015 *((TColStd_Array2OfReal*) NULL));
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
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 *((TColStd_Array2OfReal*) NULL),
2149 coeffs->ChangeArray2(),
2150 *((TColStd_Array2OfReal*) NULL));