1 // Created on: 1999-03-08
2 // Created by: Fabrice SERVANT
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <IntPolyh_Triangle.ixx>
24 #include <IntPolyh_Point.ixx>
25 #include <IntPolyh_Edge.ixx>
26 #include <IntPolyh_StartPoint.ixx>
27 #include <IntPolyh_Couple.ixx>
30 #define MyTolerance 10.0e-7
31 #define MyConfusionPrecision 10.0e-12
32 #define SquareMyConfusionPrecision 10.0e-24
35 void GetInfoTA(const Standard_Integer numP1,
36 const Standard_Integer numP2,
37 const Standard_Integer numTA,
38 const IntPolyh_ArrayOfTriangles & TTriangles,
39 Standard_Integer & numP3b,
40 Standard_Integer & P3bIndex,
41 Standard_Integer & Edge2b,
42 Standard_Integer & Edge3b);
44 void NewTriangle(const Standard_Integer P1,
45 const Standard_Integer P2,
46 const Standard_Integer P3,
47 IntPolyh_ArrayOfTriangles &TTriangles,
48 const Handle(Adaptor3d_HSurface)& MySurface,
49 IntPolyh_ArrayOfPoints &TPoints);
51 void NewEdge(const Standard_Integer P1,
52 const Standard_Integer P2,
53 const Standard_Integer T1,
54 const Standard_Integer T2,
55 IntPolyh_ArrayOfEdges & TEdges);
57 void OldEdge(const Standard_Integer EdgeN,
58 const Standard_Integer NumTri,
59 const Standard_Integer NewTriNum,
60 IntPolyh_ArrayOfEdges & TEdges) ;
62 //=======================================================================
63 //function : IntPolyh_Triangle
65 //=======================================================================
66 IntPolyh_Triangle::IntPolyh_Triangle()
69 e1(-1),oe1(0),e2(-1),oe2(0),e3(-1),oe3(0),
70 II(0),IP(1),Fleche(0.0)
73 //=======================================================================
74 //function : IntPolyh_Triangle
76 //=======================================================================
77 IntPolyh_Triangle::IntPolyh_Triangle(const Standard_Integer a,
78 const Standard_Integer b,
79 const Standard_Integer c)
82 e1(-1),oe1(0),e2(-1),oe2(0),e3(-1),oe3(0),
83 II(0),IP(1),Fleche(0.0)
86 //=======================================================================
87 //function : FirstPoint
89 //=======================================================================
90 Standard_Integer IntPolyh_Triangle::FirstPoint() const
94 //=======================================================================
95 //function : SecondPoint
97 //=======================================================================
98 Standard_Integer IntPolyh_Triangle::SecondPoint() const
102 //=======================================================================
103 //function : ThirdPoint
105 //=======================================================================
106 Standard_Integer IntPolyh_Triangle::ThirdPoint() const
110 //=======================================================================
111 //function : FirstEdge
113 //=======================================================================
114 Standard_Integer IntPolyh_Triangle::FirstEdge() const
118 //=======================================================================
119 //function : FirstEdgeOrientation
121 //=======================================================================
122 Standard_Integer IntPolyh_Triangle::FirstEdgeOrientation() const
126 //=======================================================================
127 //function : SecondEdge
129 //=======================================================================
130 Standard_Integer IntPolyh_Triangle::SecondEdge() const
134 //=======================================================================
135 //function : SecondEdgeOrientation
137 //=======================================================================
138 Standard_Integer IntPolyh_Triangle::SecondEdgeOrientation() const
142 //=======================================================================
143 //function : ThirdEdge
145 //=======================================================================
146 Standard_Integer IntPolyh_Triangle::ThirdEdge() const
150 //=======================================================================
151 //function : ThirdEdgeOrientation
153 //=======================================================================
154 Standard_Integer IntPolyh_Triangle::ThirdEdgeOrientation() const
158 //=======================================================================
159 //function : GetFleche
161 //=======================================================================
162 Standard_Real IntPolyh_Triangle::GetFleche() const
166 //=======================================================================
167 //function : IndiceIntersectionPossible
169 //=======================================================================
170 Standard_Integer IntPolyh_Triangle::IndiceIntersectionPossible() const
174 //=======================================================================
175 //function : IndiceIntersection
177 //=======================================================================
178 Standard_Integer IntPolyh_Triangle::IndiceIntersection() const
182 //=======================================================================
183 //function : SetFirstPoint
185 //=======================================================================
186 void IntPolyh_Triangle::SetFirstPoint(const Standard_Integer a)
190 //=======================================================================
191 //function : SetSecondPoint
193 //=======================================================================
194 void IntPolyh_Triangle::SetSecondPoint(const Standard_Integer b)
198 //=======================================================================
199 //function : SetThirdPoint
201 //=======================================================================
202 void IntPolyh_Triangle::SetThirdPoint(const Standard_Integer c)
206 //=======================================================================
207 //function : SetFirstEdge
209 //=======================================================================
210 void IntPolyh_Triangle::SetFirstEdge(const Standard_Integer e,
211 const Standard_Integer oe)
216 //=======================================================================
217 //function : SetSecondEdge
219 //=======================================================================
220 void IntPolyh_Triangle::SetSecondEdge(const Standard_Integer f,
221 const Standard_Integer of)
226 //=======================================================================
227 //function : SetThirdEdge
229 //=======================================================================
230 void IntPolyh_Triangle::SetThirdEdge(const Standard_Integer g,
231 const Standard_Integer og)
236 //=======================================================================
237 //function : SetFleche
239 //=======================================================================
240 void IntPolyh_Triangle::SetFleche(const Standard_Real A)
244 //=======================================================================
245 //function : SetIndiceIntersectionPossible
247 //=======================================================================
248 void IntPolyh_Triangle::SetIndiceIntersectionPossible(const Standard_Integer I)
252 //=======================================================================
253 //function : SetIndiceIntersection
255 //=======================================================================
256 void IntPolyh_Triangle::SetIndiceIntersection(const Standard_Integer I)
260 //=======================================================================
261 //function : GetEdgeNumber
263 //=======================================================================
265 IntPolyh_Triangle::GetEdgeNumber(const Standard_Integer EdgeIndex) const
276 //=======================================================================
279 //=======================================================================
280 void IntPolyh_Triangle::SetEdge(const Standard_Integer EdgeIndex,
281 const Standard_Integer EdgeNumber)
290 //=======================================================================
291 //function : GetEdgeOrientation
293 //=======================================================================
295 IntPolyh_Triangle::GetEdgeOrientation(const Standard_Integer EdgeIndex) const
307 //=======================================================================
308 //function : SetEdgeOrientation
310 //=======================================================================
311 void IntPolyh_Triangle::SetEdgeOrientation(const Standard_Integer EdgeIndex,
312 const Standard_Integer OrEd)
323 //=======================================================================
324 //function : TriangleDeflection
326 /*Calcul de la fleche pour un triangle**************
327 Distance entre le plan forme par le triangle et
328 le barycentre situe sur la surface calcule avec les coordonnees Gu,Gv
329 (coordonnees du barycentre du triangle dans l'espace UV)*/
330 //=======================================================================
331 void IntPolyh_Triangle::TriangleDeflection(const Handle(Adaptor3d_HSurface)& MySurface,
332 const IntPolyh_ArrayOfPoints& TPoints)
334 const IntPolyh_Point & P1 = TPoints[p1];
335 const IntPolyh_Point & P2 = TPoints[p2];
336 const IntPolyh_Point & P3 = TPoints[p3];
338 //modified by NIZNHY-PKV Fri Jan 20 14:25:11 2012f
340 Standard_Integer iDeg1, iDeg2, iDeg3, iDeg;
342 iDeg1=(P1.Degenerated()) ? 1 : 0;
343 iDeg2=(P2.Degenerated()) ? 1 : 0;
344 iDeg3=(P3.Degenerated()) ? 1 : 0;
345 iDeg=iDeg1+iDeg2+iDeg3;
351 //modified by NIZNHY-PKV Fri Jan 20 14:25:13 2012t
352 Standard_Real Gu, Gv, SqNorme;
355 Gu=(P1.U()+P2.U()+P3.U())/3.0;
356 Gv=(P1.V()+P2.V()+P3.V())/3.0;
358 PtXYZ = (MySurface)->Value( Gu, Gv);
359 IntPolyh_Point BarycentreReel(PtXYZ.X(), PtXYZ.Y(), PtXYZ.Z(), Gu, Gv);
360 IntPolyh_Point NormaleTri;
361 NormaleTri.Cross(P2-P1,P3-P1);
362 SqNorme=NormaleTri.SquareModulus();
364 if (SqNorme > SquareMyConfusionPrecision) {
365 NormaleTri=NormaleTri/sqrt(SqNorme);
366 Fleche=Abs(NormaleTri.Dot( BarycentreReel-P1));
369 // On calcule la fleche sur le plus grand des edges
370 // calcul des longueurs des cotes au carre
371 Standard_Real L12 = P1.SquareDistance(P2);
372 Standard_Real L23 = P2.SquareDistance(P3);
373 Standard_Real L31 = P3.SquareDistance(P1);
375 IntPolyh_Point Milieu; // milieu du plus grand des edges
377 if ((L12>L23) && (L12>L31))
378 Milieu.Middle( MySurface,P1, P2);
379 else if ((L23>L31) && (L23>L12))
380 Milieu.Middle( MySurface,P2, P3);
381 else if ((L31>L12) && (L31>L23))
382 Milieu.Middle( MySurface,P3, P1);
385 gp_Pnt PtXYZ = (MySurface)->Value( Milieu.U(), Milieu.V());
386 IntPolyh_Point MilieuReel(PtXYZ.X(), PtXYZ.Y(), PtXYZ.Z(), Milieu.U(), Milieu.V());
387 Fleche = sqrt(Milieu.SquareDistance(MilieuReel));
391 //=======================================================================
392 //function : CheckCommonEdge
394 //=======================================================================
396 IntPolyh_Triangle::CheckCommonEdge(const Standard_Integer PT1,
397 const Standard_Integer PT2,
398 const Standard_Integer PT3,
399 const Standard_Integer Index,
400 const IntPolyh_ArrayOfTriangles &TTriangles) const
402 Standard_Integer P1,P2,P3,res=-1;
403 P1=TTriangles[Index].FirstPoint();
404 P2=TTriangles[Index].SecondPoint();
405 P3=TTriangles[Index].ThirdPoint();
407 if ( (P1==PT1)||(P1==PT2) ) {
408 if ( ( (P2==PT1)||(P2==PT2) )&&(P3!=PT3) ) res = Index; //edge commun P1P2
409 else if ( ( (P3==PT1)||(P3==PT2) )&&(P2!=PT3) ) res = Index;//edge commun P1P3
411 else if ( (P2==PT1)||(P2==PT2) ) {
412 if ( ( (P3==PT1)||(P3==PT2) )&&(P1!=PT3) ) res = Index; //edge commun P2P3
417 //=======================================================================
418 //function : GetNextTriangle2
420 //=======================================================================
422 IntPolyh_Triangle::GetNextTriangle2(const Standard_Integer NumTri,
423 const Standard_Integer NumEdge,
424 const IntPolyh_ArrayOfEdges &TEdges) const
426 Standard_Integer NumNextTri=-1;
428 const IntPolyh_Edge & Edge1=TEdges[e1];
429 if(Edge1.FirstTriangle()==NumTri)
430 NumNextTri=Edge1.SecondTriangle();
432 NumNextTri=Edge1.FirstTriangle();
434 else if (NumEdge==2) {
435 const IntPolyh_Edge & Edge2=TEdges[e2];
436 if(Edge2.FirstTriangle()==NumTri)
437 NumNextTri=Edge2.SecondTriangle();
439 NumNextTri=Edge2.FirstTriangle();
441 else if (NumEdge==3) {
442 const IntPolyh_Edge & Edge3=TEdges[e3];
443 if(Edge3.FirstTriangle()==NumTri)
444 NumNextTri=Edge3.SecondTriangle();
446 NumNextTri=Edge3.FirstTriangle();
452 //=======================================================================
453 //function : LinkEdges2Triangle
455 //=======================================================================
456 void IntPolyh_Triangle::LinkEdges2Triangle(const IntPolyh_ArrayOfEdges & TEdges,
457 const Standard_Integer edge1,
458 const Standard_Integer edge2,
459 const Standard_Integer edge3) {
460 if( (edge1<0)||(edge2<0)||(edge3<0) ) {
468 if(TEdges[e1].FirstPoint()==p1) oe1=1;
470 if(TEdges[e2].FirstPoint()==p2) oe2=1;
472 if(TEdges[e3].FirstPoint()==p3) oe3=1;
477 //=======================================================================
478 //function : GetInfoTA
480 //=======================================================================
481 void GetInfoTA(const Standard_Integer numP1,
482 const Standard_Integer numP2,
483 const Standard_Integer numTA,
484 const IntPolyh_ArrayOfTriangles & TTriangles,
485 Standard_Integer & numP3b,
486 Standard_Integer & P3bIndex,
487 Standard_Integer & Edge2b,
488 Standard_Integer & Edge3b)
490 /// On veut savoir quel est le troisieme point du triangle
491 /// adjacent (TriAdj) et quel sont les edges partant de ce point
492 const IntPolyh_Triangle & TriAdj=TTriangles[numTA];
493 Standard_Integer P1b=TriAdj.FirstPoint();
494 Standard_Integer P2b=TriAdj.SecondPoint();
495 Standard_Integer P3b=TriAdj.ThirdPoint();
497 if ( (P1b!=numP1)&&(P1b!=numP2) ) {
501 ///P1bP2b==numP3bnumP1:Edge3b donc dans ce cas
502 Edge3b=TriAdj.FirstEdge();
503 /// Donc P1bP3b==numP3bnumP2:Edge2b
504 Edge2b=TriAdj.ThirdEdge();
507 Edge2b=TriAdj.FirstEdge();
508 Edge3b=TriAdj.ThirdEdge();
511 else if( (P2b!=numP1)&&(P2b!=numP2) ) {
515 ///P2bP1b==numP3bnumP1:Edge3b donc dans ce cas
516 Edge3b=TriAdj.FirstEdge();
517 /// Donc P2bP3b==numP3bnumP2:Edge2b
518 Edge2b=TriAdj.SecondEdge();
521 Edge2b=TriAdj.FirstEdge();
522 Edge3b=TriAdj.SecondEdge();
525 else if( (P3b!=numP1)&&(P3b!=numP2) ) {
529 ///P3bP2b==numP3bnumP1:Edge3b donc dans ce cas
530 Edge3b=TriAdj.SecondEdge();
531 /// Donc P3bP1b==numP3bnumP2:Edge2b
532 Edge2b=TriAdj.ThirdEdge();
535 Edge2b=TriAdj.SecondEdge();
536 Edge3b=TriAdj.ThirdEdge();
541 //=======================================================================
542 //function : NewTriangle
544 //=======================================================================
545 void NewTriangle(const Standard_Integer P1,
546 const Standard_Integer P2,
547 const Standard_Integer P3,
548 IntPolyh_ArrayOfTriangles &TTriangles,
549 const Handle(Adaptor3d_HSurface)& MySurface,
550 IntPolyh_ArrayOfPoints &TPoints) {
551 const Standard_Integer FinTT = TTriangles.NbItems();
552 TTriangles[FinTT].SetFirstPoint(P1);
553 TTriangles[FinTT].SetSecondPoint(P2);
554 TTriangles[FinTT].SetThirdPoint(P3);
555 TTriangles[FinTT].TriangleDeflection(MySurface, TPoints);
556 TTriangles.IncrementNbItems();
559 //=======================================================================
562 //=======================================================================
563 void NewEdge(const Standard_Integer P1,
564 const Standard_Integer P2,
565 const Standard_Integer T1,
566 const Standard_Integer T2,
567 IntPolyh_ArrayOfEdges & TEdges)
570 const Standard_Integer FinTE = TEdges.NbItems();
572 TEdges[FinTE].SetFirstPoint(P1);
573 TEdges[FinTE].SetSecondPoint(P2);
574 TEdges[FinTE].SetFirstTriangle(T1);
575 TEdges[FinTE].SetSecondTriangle(T2);
576 TEdges.IncrementNbItems();
579 //=======================================================================
582 //=======================================================================
583 void OldEdge(const Standard_Integer EdgeN,
584 const Standard_Integer NumTri,
585 const Standard_Integer NewTriNum,
586 IntPolyh_ArrayOfEdges & TEdges)
588 if(TEdges[EdgeN].FirstTriangle()==NumTri){
589 TEdges[EdgeN].SetFirstTriangle(NewTriNum);
592 TEdges[EdgeN].SetSecondTriangle(NewTriNum);
596 //=======================================================================
597 //function : MiddleRefinement
599 //=======================================================================
600 void IntPolyh_Triangle::MiddleRefinement(const Standard_Integer NumTri,
601 const Handle(Adaptor3d_HSurface)& MySurface,
602 IntPolyh_ArrayOfPoints &TPoints,
603 IntPolyh_ArrayOfTriangles &TTriangles,
604 IntPolyh_ArrayOfEdges & TEdges) {
606 Standard_Integer FinTE = TEdges.NbItems();
607 Standard_Integer FinTT = TTriangles.NbItems();
609 ///Raffinage de la maille et de ses voisines par le milieu du plus grand des cotes
611 Standard_Integer numP1 = FirstPoint();
612 Standard_Integer numP2 = SecondPoint();
613 Standard_Integer numP3 = ThirdPoint();
615 IntPolyh_Point P1 = TPoints[numP1];
616 IntPolyh_Point P2 = TPoints[numP2];
617 IntPolyh_Point P3 = TPoints[numP3];
620 ///calcul des longueurs des cotes au carre
622 Standard_Real L12 = P1.SquareDistance(P2);
623 Standard_Real L23 = P2.SquareDistance(P3);
624 Standard_Real L31 = P3.SquareDistance(P1);
626 if ((L12>L23) && (L12>L31)) {
627 const Standard_Integer FinTP = TPoints.NbItems();
628 (TPoints[FinTP]).Middle( MySurface,P1, P2);
630 ///les nouveaux triangles
631 Standard_Integer T1,T2,T3,T4;
634 NewTriangle(numP2,numP3,FinTP,TTriangles,MySurface,TPoints);
637 NewTriangle(numP3,numP1,FinTP,TTriangles,MySurface,TPoints);
640 ///***AFFINAGE DU TRIANGLE ADJACENT***
642 Standard_Integer numTA = GetNextTriangle2(NumTri,1,TEdges);
645 Standard_Integer numP3b = -1;
646 Standard_Integer P3bIndex = -1;
648 Standard_Integer Edge2b = -1;
649 Standard_Integer Edge3b = -1;
651 GetInfoTA(numP1,numP2,numTA,TTriangles,numP3b,P3bIndex,Edge2b,Edge3b);
654 NewTriangle(numP2,numP3b,FinTP,TTriangles,MySurface,TPoints);
657 NewTriangle(numP3b,numP1,FinTP,TTriangles,MySurface,TPoints);
659 ///On cree les nouveaux edges
660 Standard_Integer E1,E2,E3,E4;
663 NewEdge(numP1,FinTP,T2,T4,TEdges);
666 NewEdge(FinTP,numP2,T1,T3,TEdges);
669 NewEdge(FinTP,numP3,T1,T2,TEdges);
672 NewEdge(FinTP,numP3b,T3,T4,TEdges);
674 ///On met a jour les anciens edges
675 OldEdge(e2,NumTri,T1,TEdges);
676 OldEdge(e3,NumTri,T2,TEdges);
677 OldEdge(Edge2b,numTA,T3,TEdges);
678 OldEdge(Edge3b,numTA,T4,TEdges);
680 /// On remplit les nouveaux triangles avec les edges
681 TTriangles[T1].LinkEdges2Triangle(TEdges,e2,E3,E2);
682 TTriangles[T2].LinkEdges2Triangle(TEdges,e3,E1,E3);
683 TTriangles[T3].LinkEdges2Triangle(TEdges,Edge2b,E4,E2);
684 TTriangles[T4].LinkEdges2Triangle(TEdges,Edge3b,E1,E4);
686 ///On tue le triangle adjacent
687 TTriangles[numTA].Fleche=-1.0;
688 TTriangles[numTA].IP=0;
691 else { ///seulement deux nouveaux triangles
692 //on cree les nouveaux edges avec T1 et T2
693 Standard_Integer E1,E2,E3;
696 NewEdge(numP1,FinTP,T2,-1,TEdges);
699 NewEdge(FinTP,numP2,T1,-1,TEdges);
702 NewEdge(FinTP,numP3,T1,T2,TEdges);
704 ///On met a jour les anciens edges
705 OldEdge(e2,NumTri,T1,TEdges);
706 OldEdge(e3,NumTri,T2,TEdges);
708 /// On remplit les nouveaux triangles avec les edges
709 TTriangles[T1].LinkEdges2Triangle(TEdges,e2,E3,E2);
710 TTriangles[T2].LinkEdges2Triangle(TEdges,e3,E1,E3);
714 else if ((L23>L31) && (L23>L12)){
715 const Standard_Integer FinTP = TPoints.NbItems();
716 (TPoints[FinTP]).Middle(MySurface, P2,P3);
718 ///les nouveaux triangles
719 Standard_Integer T1,T2,T3,T4;
722 NewTriangle(numP1,numP2,FinTP,TTriangles,MySurface,TPoints);
725 NewTriangle(numP3,numP1,FinTP,TTriangles,MySurface,TPoints);
728 ///*RAFFINAGE DU TRIANGLE ADJACENT***
730 Standard_Integer numTA = GetNextTriangle2(NumTri,2,TEdges);
733 Standard_Integer numP1b=-1;
734 Standard_Integer P1bIndex = -1;
736 Standard_Integer Edge1b = -1;
737 Standard_Integer Edge3b = -1;
739 GetInfoTA(numP2,numP3,numTA,TTriangles,numP1b,P1bIndex,Edge3b,Edge1b);
742 NewTriangle(numP2,numP1b,FinTP,TTriangles,MySurface,TPoints);
745 NewTriangle(numP1b,numP3,FinTP,TTriangles,MySurface,TPoints);
748 Standard_Integer E1,E2,E3,E4;
751 NewEdge(numP2,FinTP,T1,T3,TEdges);
754 NewEdge(FinTP,numP3,T2,T4,TEdges);
757 NewEdge(FinTP,numP1,T1,T2,TEdges);
760 NewEdge(FinTP,numP1b,T3,T4,TEdges);
762 ///On met a jour les anciens edges
763 OldEdge(e1,NumTri,T1,TEdges);
764 OldEdge(e3,NumTri,T2,TEdges);
765 OldEdge(Edge1b,numTA,T3,TEdges);
766 OldEdge(Edge3b,numTA,T4,TEdges);
768 /// On remplit les nouveaux triangles avec les edges
769 TTriangles[T1].LinkEdges2Triangle(TEdges,e1,E1,E3);
770 TTriangles[T2].LinkEdges2Triangle(TEdges,e3,E3,E2);
771 TTriangles[T3].LinkEdges2Triangle(TEdges,Edge1b,E4,E1);
772 TTriangles[T4].LinkEdges2Triangle(TEdges,Edge3b,E2,E4);
774 ///On tue le triangle adjacent
775 TTriangles[numTA].Fleche=-1.0;
776 TTriangles[numTA].IP=0;
778 else { ///seulement deux nouveaux triangles
780 Standard_Integer E1,E2,E3;
783 NewEdge(numP2,FinTP,T1,-1,TEdges);
786 NewEdge(FinTP,numP3,T2,-1,TEdges);
789 NewEdge(FinTP,numP1,T1,T2,TEdges);
791 ///On met a jour les anciens edges
792 OldEdge(e1,NumTri,T1,TEdges);
793 OldEdge(e3,NumTri,T2,TEdges);
795 /// On remplit les nouveaux triangles avec les edges
796 TTriangles[T1].LinkEdges2Triangle(TEdges,e1,E1,E3);
797 TTriangles[T2].LinkEdges2Triangle(TEdges,e3,E3,E2);
801 const Standard_Integer FinTP = TPoints.NbItems();
802 (TPoints[FinTP]).Middle(MySurface, P3,P1);
804 Standard_Integer T1,T2,T3,T4;
807 NewTriangle(numP1,numP2,FinTP,TTriangles,MySurface,TPoints);
810 NewTriangle(numP2,numP3,FinTP,TTriangles,MySurface,TPoints);
813 ///*RAFFINAGE DU TRIANGLE ADJACENT***
815 Standard_Integer numTA = GetNextTriangle2(NumTri,3,TEdges);
819 Standard_Integer numP2b = -1;
820 Standard_Integer P2bIndex = -1;
822 Standard_Integer Edge1b = -1;
823 Standard_Integer Edge2b = -1;
825 GetInfoTA(numP3,numP1,numTA,TTriangles,numP2b,P2bIndex,Edge1b,Edge2b);
828 NewTriangle(numP1,numP2b,FinTP,TTriangles,MySurface,TPoints);
831 NewTriangle(numP2b,numP3,FinTP,TTriangles,MySurface,TPoints);
834 Standard_Integer E1,E2,E3,E4;
837 NewEdge(numP2,FinTP,T1,T2,TEdges);
840 NewEdge(FinTP,numP3,T2,T4,TEdges);
843 NewEdge(FinTP,numP2b,T4,T3,TEdges);
846 NewEdge(FinTP,numP1,T1,T3,TEdges);
848 ///On met a jour les anciens edges
849 OldEdge(e1,NumTri,T1,TEdges);
850 OldEdge(e2,NumTri,T2,TEdges);
851 OldEdge(Edge1b,numTA,T3,TEdges);
852 OldEdge(Edge2b,numTA,T4,TEdges);
854 /// On remplit les nouveaux triangles avec les edges
855 TTriangles[T1].LinkEdges2Triangle(TEdges,e1,E1,E4);
856 TTriangles[T2].LinkEdges2Triangle(TEdges,e2,E2,E1);
857 TTriangles[T3].LinkEdges2Triangle(TEdges,Edge1b,E3,E4);
858 TTriangles[T4].LinkEdges2Triangle(TEdges,Edge2b,E2,E3);
860 ///On tue le triangle adjacent
861 TTriangles[numTA].Fleche=-1.0;
862 TTriangles[numTA].IP=0;
864 else { ///seulement deux nouveaux triangles
866 Standard_Integer E1,E2,E4;
869 NewEdge(numP2,FinTP,T1,T2,TEdges);
872 NewEdge(FinTP,numP3,T2,-1,TEdges);
875 NewEdge(FinTP,numP1,T1,-1,TEdges);
877 ///On met a jour les anciens edges
878 OldEdge(e1,NumTri,T1,TEdges);
879 OldEdge(e2,NumTri,T2,TEdges);
881 /// On remplit les nouveaux triangles avec les edges
882 TTriangles[T1].LinkEdges2Triangle(TEdges,e1,E1,E4);
883 TTriangles[T2].LinkEdges2Triangle(TEdges,e2,E2,E1);
886 /// Le triangle traite est maintenant obsolete
887 ///***On tue le triangle***
891 TPoints.IncrementNbItems();
894 //=======================================================================
895 //function : MultipleMiddleRefinement
897 //=======================================================================
898 void IntPolyh_Triangle::MultipleMiddleRefinement(const Standard_Integer NbAffinages,
899 const Standard_Integer NumTri,
900 const Handle(Adaptor3d_HSurface)& MySurface,
901 IntPolyh_ArrayOfPoints &TPoints,
902 IntPolyh_ArrayOfTriangles &TTriangles,
903 IntPolyh_ArrayOfEdges & TEdges) {
905 const Standard_Integer FinTTInit = TTriangles.NbItems();
907 //On sait qu'il faut affiner au moins une fois
908 TTriangles[NumTri].MiddleRefinement(NumTri,MySurface,TPoints,
912 Standard_Integer MyNbAffinages=0;
914 MyNbAffinages = 4;//5 est le maximum et on a deja affine une fois
915 //On a decide d'arreter a 5 car avec un triangle on peut en obtenir 1024
916 else MyNbAffinages = NbAffinages-1;//dans tous les cas MyNbAffinages>0
919 //Un affinage peut donner deux ou quatre nouveaux triangles
920 // ils seront ajoute a la fin du tableau de triangles, et auront comme indice
921 // FinTTInit, FinTTInit+1,...
924 Standard_Integer NombreReelsAffinages = 4;
925 for(Standard_Integer iii=1; iii<MyNbAffinages; iii++)
926 NombreReelsAffinages*=4;
927 //Avec ce calcul on fait l'hypothese que chaque triangle affine donne quatre nouveaux triangles
928 //ce qui peut etre faux si on n'affine pas le triangle adjacent
929 //dans quel cas on n'obtient que deux nouveaux triangles
931 Standard_Integer FinTTAffinage = FinTTInit + NombreReelsAffinages;
933 for(Standard_Integer NumTriangle=FinTTInit; NumTriangle < FinTTAffinage; NumTriangle++)
934 TTriangles[NumTriangle].MiddleRefinement(NumTriangle,MySurface,TPoints,
939 //=======================================================================
940 //function : CompareBoxTriangle
942 //=======================================================================
943 Standard_Integer IntPolyh_Triangle::CompareBoxTriangle(const Bnd_Box &b,
944 const IntPolyh_ArrayOfPoints &TPoints) const{
945 Standard_Integer Test=0;
947 const IntPolyh_Point& PA=TPoints[p1];
948 const IntPolyh_Point& PB=TPoints[p2];
949 const IntPolyh_Point& PC=TPoints[p3];
950 gp_Pnt pntA(PA.X(),PA.Y(),PA.Z());
951 gp_Pnt pntB(PB.X(),PB.Y(),PB.Z());
952 gp_Pnt pntC(PC.X(),PC.Y(),PC.Z());
956 maboite.Enlarge(Fleche+MyTolerance);
957 if (maboite.IsOut(b))
962 //Pour gagner du temps on pourrait envisager de garder la boite englobante dans la structure du triangle
965 //=======================================================================
966 //function : MultipleMiddleRefinement2
968 //=======================================================================
969 void IntPolyh_Triangle::MultipleMiddleRefinement2(const Standard_Real CritereAffinage,
970 const Bnd_Box &b,//boite englobante de l'autre surface
971 const Standard_Integer NumTri,
972 const Handle(Adaptor3d_HSurface)& MySurface,
973 IntPolyh_ArrayOfPoints &TPoints,
974 IntPolyh_ArrayOfTriangles &TTriangles,
975 IntPolyh_ArrayOfEdges & TEdges) {
977 const Standard_Integer FinTTInit = TTriangles.NbItems();
978 Standard_Integer CritereArret=FinTTInit+250;
980 //On sait qu'il faut affiner une fois au moins
981 MiddleRefinement(NumTri,MySurface,TPoints,
984 Standard_Integer FinTT = TTriangles.NbItems();// FinTT n'est pas une constante, elle augmente avec l'affinage
986 for(Standard_Integer iii=FinTTInit; iii<(FinTT=TTriangles.NbItems()); iii++) {
987 IntPolyh_Triangle& TriangleCourant = TTriangles[iii];
988 if(TriangleCourant.CompareBoxTriangle(b,TPoints)==0)
989 //On n'affine pas le triangle
990 TriangleCourant.IP=0;
991 else if (TriangleCourant.Fleche > CritereAffinage)
992 TriangleCourant.MiddleRefinement(iii,MySurface,TPoints,
995 if ( FinTT > CritereArret )//critere d'arret 250 nouveaux triangles
1000 //=======================================================================
1001 //function : SetEdgeandOrientation
1003 //=======================================================================
1004 void IntPolyh_Triangle::SetEdgeandOrientation(const Standard_Integer EdgeIndex,
1005 const IntPolyh_ArrayOfEdges &TEdges) {
1006 const Standard_Integer FinTE = TEdges.NbItems();
1008 Standard_Integer PE1 =0,PE2 =0;
1010 Standard_Integer Test=1;
1012 if (EdgeIndex==1) { PE1=p1; PE2=p2; }
1013 else if (EdgeIndex==2) { PE1=p2; PE2=p3; }
1014 else if (EdgeIndex==3) { PE1=p3; PE2=p1; }
1019 for(Standard_Integer iioo=0; iioo<FinTE; iioo++) {
1020 Standard_Integer EFP=TEdges[iioo].FirstPoint();
1022 Standard_Integer ESP=TEdges[iioo].SecondPoint();
1025 SetEdgeOrientation(EdgeIndex,1);
1026 SetEdge(EdgeIndex,iioo);
1035 else if (EFP==PE2) {
1036 Standard_Integer ESP=TEdges[iioo].SecondPoint();
1039 SetEdgeOrientation(EdgeIndex,-1);
1040 SetEdge(EdgeIndex,iioo);
1053 //=======================================================================
1056 //=======================================================================
1057 void IntPolyh_Triangle::Dump (const Standard_Integer i) const
1059 printf("\nTriangle(%3d) : Points %5d %5d %5d Edges %5d %5d %5d fleche: %8f intersection possible %8d intersection: %5d\n"
1060 ,i,p1,p2,p3,e1,e2,e3,Fleche,IP,II);
1064 //=======================================================================
1065 //function : DumpFleche
1067 //=======================================================================
1068 void IntPolyh_Triangle::DumpFleche (const Standard_Integer i) const {
1069 printf("\nTriangle(%3d) fleche: %5f\n",i,Fleche);