1 // Created on: 1992-10-22
2 // Created by: Christophe MARION
3 // Copyright (c) 1992-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.
22 #include <Bnd_Box.hxx>
26 #include <HLRBRep_Curve.hxx>
27 #include <HLRBRep_CurveTool.hxx>
28 #include <HLRBRep_EdgeData.hxx>
29 #include <HLRBRep_Intersector.hxx>
30 #include <HLRBRep_SurfaceTool.hxx>
31 #include <HLRBRep_ThePolygonOfInterCSurf.hxx>
32 #include <HLRBRep_ThePolyhedronOfInterCSurf.hxx>
33 #include <IntCurveSurface_IntersectionPoint.hxx>
34 #include <IntCurveSurface_IntersectionSegment.hxx>
35 #include <IntImpParGen.hxx>
36 #include <IntRes2d_IntersectionPoint.hxx>
37 #include <IntRes2d_IntersectionSegment.hxx>
38 #include <IntRes2d_Position.hxx>
39 #include <IntRes2d_Transition.hxx>
40 #include <StdFail_UndefinedDerivative.hxx>
46 static Standard_Integer NbIntersCS=0;
47 static Standard_Integer NbIntersCSVides=0;
48 static Standard_Integer NbIntersAuto=0;
49 static Standard_Integer NbIntersSimulate=0;
50 static Standard_Integer NbInters=0;
51 static Standard_Integer NbIntersVides=0;
52 static Standard_Integer NbInters1Segment=0;
53 static Standard_Integer NbInters1Point=0;
54 static Standard_Integer NbIntersNPoints=0;
55 static Standard_Integer NbIntersNSegments=0;
56 static Standard_Integer NbIntersPointEtSegment=0;
59 //=======================================================================
60 //function : HLRBRep_Intersector
62 //=======================================================================
64 HLRBRep_Intersector::HLRBRep_Intersector () :
69 printf("\n--------------------------------------");
70 printf("\nNbIntersSimulate : %6d",NbIntersSimulate);
71 printf("\nNbIntersCrvSurf : %6d",NbIntersCS);
72 printf("\n -> vide : %6d",NbIntersCSVides);
73 printf("\nNbAutoInters : %6d\n",NbIntersAuto);
74 printf("\nNbInters : %6d",NbInters);
75 printf("\n Vides : %6d",NbIntersVides);
76 printf("\n 1 Segment : %6d",NbInters1Segment);
77 printf("\n 1 Point : %6d",NbInters1Point);
78 printf("\n >1 Point : %6d",NbIntersNPoints);
79 printf("\n >1 Segment : %6d",NbIntersNSegments);
80 printf("\n >1 Pt et Seg : %6d",NbIntersPointEtSegment);
81 printf("\n--------------------------------------\n");
83 NbIntersSimulate=NbIntersAuto=NbIntersCS
84 =NbInters=NbIntersVides=NbInters1Segment=NbInters1Point=NbIntersNPoints
85 = NbIntersNSegments=NbIntersPointEtSegment=NbIntersCSVides=0;
88 // Set minimal number of samples in case of HLR polygonal intersector.
89 const Standard_Integer aMinNbHLRSamples = 4;
90 myIntersector.SetMinNbSamples(aMinNbHLRSamples);
93 //=======================================================================
96 //=======================================================================
98 void HLRBRep_Intersector::Perform (const Standard_Address A1,
99 const Standard_Real da1,
100 const Standard_Real db1)
107 Standard_Address myC1 = ((HLRBRep_EdgeData*) A1)->Curve();
111 gp_Pnt2d pa,pb;//,pa1,pb1;
112 Standard_Real a,b,d,tol;
113 Standard_ShortReal ta,tb;
115 ((HLRBRep_EdgeData*) A1)->Status().Bounds(a,ta,b,tb);
117 if (da1 != 0) a = a + d * da1;
118 if (db1 != 0) b = b - d * db1;
119 ((HLRBRep_Curve*)myC1)->D0(a,pa);
120 ((HLRBRep_Curve*)myC1)->D0(b,pb);
121 a = ((HLRBRep_Curve*)myC1)->Parameter2d(a);
122 b = ((HLRBRep_Curve*)myC1)->Parameter2d(b);
123 IntRes2d_Domain D1(pa,a,(Standard_Real)ta,pb,b,(Standard_Real)tb);
125 //modified by jgv, 18.04.2016 for OCC27341
126 //tol = (Standard_Real)(((HLRBRep_EdgeData*) A1)->Tolerance());
127 tol = Precision::Confusion();
128 //////////////////////////////////////////
130 myIntersector.Perform(myC1,D1,tol,tol);
133 //=======================================================================
136 //=======================================================================
138 void HLRBRep_Intersector::Perform (const Standard_Integer /*nA*/,
139 const Standard_Address A1,
140 const Standard_Real da1,
141 const Standard_Real db1,
142 const Standard_Integer /*nB*/,
143 const Standard_Address A2,
144 const Standard_Real da2,
145 const Standard_Real db2,
146 const Standard_Boolean EnBout)
155 Standard_Address myC1 = ((HLRBRep_EdgeData*) A1)->Curve();
156 Standard_Address myC2 = ((HLRBRep_EdgeData*) A2)->Curve();
160 gp_Pnt2d pa1,pb1,pa2,pb2;
161 gp_Vec2d va1,vb1,va2,vb2;
162 Standard_Real a1,b1,a2,b2,d,dd,tol,tol1,tol2;
163 Standard_ShortReal ta,tb;
165 //modified by jgv, 18.04.2016 for OCC27341
166 //tol1 = (Standard_Real)(((HLRBRep_EdgeData*) A1)->Tolerance());
167 //tol2 = (Standard_Real)(((HLRBRep_EdgeData*) A2)->Tolerance());
168 tol1 = Precision::Confusion();
169 tol2 = Precision::Confusion();
170 //////////////////////////////////////////
171 if (tol1 > tol2) tol = tol1;
175 Standard_Boolean PasBon;
176 Standard_Real decalagea1=100.0;
177 Standard_Real decalagea2=100.0;
178 Standard_Real decalageb1=100.0;
179 Standard_Real decalageb2=100.0;
181 PasBon=Standard_False;
182 ((HLRBRep_EdgeData*) A1)->Status().Bounds(a1,ta,b1,tb); //-- -> Parametres 3d
183 Standard_Real mtol = tol;
188 Standard_Real pdist = tol;
189 if(pdist<0.0000001) pdist = 0.0000001;
193 //-- a = a + d * da1;
194 ((HLRBRep_Curve*)myC1)->D1(a1,pa1,va1);
195 Standard_Real qwe=va1.Magnitude();
197 dd=pdist*decalagea1/qwe;
202 a1+= d * da1; decalagea1=-1;
206 a1+=d * da1; decalagea1=-1;
211 //-- b = b - d * db1;
212 ((HLRBRep_Curve*)myC1)->D1(b1,pb1,vb1);
213 Standard_Real qwe=vb1.Magnitude();
215 dd=pdist*decalageb1/qwe;
220 b1-= d * db1; decalageb1=-1;
224 b1-=d * db1; decalageb1=-1;
229 // if(EnBout) { //-- ************************************************************
230 // Standard_Real d=b1-a1;
237 ((HLRBRep_Curve*)myC1)->D0(a1,pa1);
238 ((HLRBRep_Curve*)myC1)->D0(b1,pb1);
240 a1 = ((HLRBRep_Curve*)myC1)->Parameter2d(a1);
241 b1 = ((HLRBRep_Curve*)myC1)->Parameter2d(b1);
247 if(ta>tol) ta=(Standard_ShortReal) tol;
248 if(tb>tol) tb=(Standard_ShortReal) tol;
250 IntRes2d_Domain D1(pa1,a1,(Standard_Real)ta,pb1,b1,(Standard_Real)tb);
252 ((HLRBRep_EdgeData*) A2)->Status().Bounds(a2,ta,b2,tb);
260 //-- a = a + d * da2;
261 ((HLRBRep_Curve*)myC2)->D1(a2,pa2,va2);
262 Standard_Real qwe=va2.Magnitude();
264 dd=pdist*decalagea2/qwe;
269 a2+= d * da2; decalagea2=-1;
273 a2+=d * da2; decalagea2=-1;
278 //-- b = b - d * db2;
279 ((HLRBRep_Curve*)myC2)->D1(b2,pb2,vb2);
280 Standard_Real qwe=vb2.Magnitude();
282 dd=pdist*decalageb2/qwe;
287 b2-= d * db2; decalageb2=-1;
291 b2-=d * db2; decalageb2=-1;
297 // if(EnBout) { //-- ************************************************************
298 // Standard_Real d=b2-a2;
308 ((HLRBRep_Curve*)myC2)->D0(a2,pa2);
309 ((HLRBRep_Curve*)myC2)->D0(b2,pb2);
311 a2 = ((HLRBRep_Curve*)myC2)->Parameter2d(a2);
312 b2 = ((HLRBRep_Curve*)myC2)->Parameter2d(b2);
318 if(ta>tol) ta=(Standard_ShortReal) tol;
319 if(tb>tol) tb=(Standard_ShortReal) tol;
321 IntRes2d_Domain D2(pa2,a2,(Standard_Real)ta,pb2,b2,(Standard_Real)tb);
325 Standard_Real a1a2 = (da1 || da2)? pa1.Distance(pa2) : RealLast();
326 Standard_Real a1b2 = (da1 || db2)? pa1.Distance(pb2) : RealLast();
327 Standard_Real b1a2 = (db1 || da2)? pb1.Distance(pa2) : RealLast();
328 Standard_Real b1b2 = (db1 || db2)? pb1.Distance(pb2) : RealLast();
330 Standard_Integer cote=1;
331 Standard_Real mindist = a1a2; //-- cas 1
332 if(mindist>a1b2) { mindist = a1b2; cote=2; }
333 if(mindist>b1a2) { mindist = b1a2; cote=3; }
334 if(mindist>b1b2) { mindist = b1b2; cote=4; }
338 //--printf("\n----- Edge %3d %3d [%7.5g %7.5g] [%7.5g %7.5g] Mindist:%8.5g 1000*Tol:%8.5g\n",
339 //-- nA,nB,decalagea1,decalageb1,decalagea2,decalageb2,mindist,1000.0*tol);
342 if(mindist < tol*1000) {
343 PasBon=Standard_True;
345 case 1: { decalagea1*=2; decalagea2*=2; break; }
346 case 2: { decalagea1*=2; decalageb2*=2; break; }
347 case 3: { decalageb1*=2; decalagea2*=2; break; }
348 default: { decalageb1*=2; decalageb2*=2; break; }
350 if(decalagea1<0.0 || decalagea2<0.0 || decalageb1<0.0 || decalageb2<=0.0) {
351 PasBon=Standard_False;
355 if(PasBon==Standard_False) {
356 myIntersector.Perform(myC1,D1,myC2,D2,tol,tol);
366 if(myIntersector.NbPoints()==1) {
367 if(myIntersector.NbSegments()==0) {
371 NbIntersPointEtSegment++;
374 else if(myIntersector.NbPoints()==0) {
375 if(myIntersector.NbSegments()==0) {
378 else if(myIntersector.NbSegments()==1) {
386 if(myIntersector.NbSegments()==0) {
390 NbIntersPointEtSegment++;
396 //=======================================================================
397 //function : SimulateOnePoint
399 //=======================================================================
401 void HLRBRep_Intersector::SimulateOnePoint(const Standard_Address A1,
402 const Standard_Real u,
403 const Standard_Address A2,
404 const Standard_Real v) {
408 Standard_Address myC1 = ((HLRBRep_EdgeData*) A1)->Curve();
409 Standard_Address myC2 = ((HLRBRep_EdgeData*) A2)->Curve();
411 Standard_Real u3= ((HLRBRep_Curve*)myC1)->Parameter3d(u);
412 Standard_Real v3= ((HLRBRep_Curve*)myC2)->Parameter3d(v);
415 ((HLRBRep_Curve*)myC1)->D1(u3,P13,T13);
416 ((HLRBRep_Curve*)myC2)->D1(v3,P23,T23);
418 IntRes2d_Transition Tr1,Tr2;
419 IntRes2d_Position Pos1,Pos2;
420 Pos1=Pos2=IntRes2d_Middle;
422 IntImpParGen::DetermineTransition(Pos1,T13,Tr1,Pos2,T23,Tr2,0.0);
424 mySinglePoint.SetValues(P13,u,v,Tr1,Tr2,Standard_False);
429 //=======================================================================
432 //=======================================================================
434 void HLRBRep_Intersector::Load (Standard_Address& A)
437 if (myPolyhedron != NULL) {
438 delete (HLRBRep_ThePolyhedronOfInterCSurf*)myPolyhedron;
443 //=======================================================================
446 //=======================================================================
448 void HLRBRep_Intersector::Perform (const gp_Lin& L,
449 const Standard_Real P)
452 GeomAbs_SurfaceType typ = HLRBRep_SurfaceTool::GetType(mySurface);
455 case GeomAbs_Cylinder :
457 case GeomAbs_Sphere :
459 myCSIntersector.Perform(L,mySurface);
463 if (myPolyhedron == NULL) {
464 Standard_Integer nbsu,nbsv;
465 Standard_Real u1,v1,u2,v2;
466 u1 = HLRBRep_SurfaceTool::FirstUParameter(mySurface);
467 v1 = HLRBRep_SurfaceTool::FirstVParameter(mySurface);
468 u2 = HLRBRep_SurfaceTool::LastUParameter(mySurface);
469 v2 = HLRBRep_SurfaceTool::LastVParameter(mySurface);
470 nbsu = HLRBRep_SurfaceTool::NbSamplesU(mySurface,u1,u2);
471 nbsv = HLRBRep_SurfaceTool::NbSamplesV(mySurface,v1,v2);
472 myPolyhedron = (Standard_Address)
473 (new HLRBRep_ThePolyhedronOfInterCSurf
474 (mySurface,nbsu,nbsv,u1,v1,u2,v2));
476 Standard_Real x0,y0,z0,x1,y1,z1,pmin,pmax;//,pp;
477 ((HLRBRep_ThePolyhedronOfInterCSurf*)myPolyhedron)
478 ->Bounding().Get(x0,y0,z0,x1,y1,z1);
480 pmax = pmin = ElCLib::Parameter(L, gp_Pnt((x1+x0)*0.5,
483 Standard_Real d = (x1-x0) + (y1-y0) + (z1-z0);
486 if (pmin > P) pmin = P - d;
487 if (pmax > P) pmax = P;
488 HLRBRep_ThePolygonOfInterCSurf Polygon(L,pmin,pmax,3);
489 myCSIntersector.Perform(L,Polygon,mySurface,
490 *((HLRBRep_ThePolyhedronOfInterCSurf*)
494 //-- On va rejeter tous les points de parametres > P
496 p = ElCLib::Parameter(L, gp_Pnt(x0,y0,z0)); pmin=pmax=p;
497 p = ElCLib::Parameter(L, gp_Pnt(x0,y0,z1)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
499 p = ElCLib::Parameter(L, gp_Pnt(x1,y0,z0)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
500 p = ElCLib::Parameter(L, gp_Pnt(x1,y0,z1)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
502 p = ElCLib::Parameter(L, gp_Pnt(x0,y1,z0)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
503 p = ElCLib::Parameter(L, gp_Pnt(x0,y1,z1)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
505 p = ElCLib::Parameter(L, gp_Pnt(x1,y1,z0)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
506 p = ElCLib::Parameter(L, gp_Pnt(x1,y1,z1)); if(pmin>p) pmin=p; if(pmax<p) pmax=p;
507 pmin-=0.000001; pmax+=0.000001;
509 if(pmin>P) { pmin=pmax+1; pmax=pmax+2; } //-- on va rejeter avec les boites
511 if(pmax>P) pmax=P+0.0000001;
513 HLRBRep_ThePolygonOfInterCSurf Polygon(L,pmin,pmax,3);
514 myCSIntersector.Perform(L,Polygon,mySurface,
515 *((HLRBRep_ThePolyhedronOfInterCSurf*)
525 if(myCSIntersector.NbPoints()==0) {
532 //=======================================================================
535 //=======================================================================
537 Standard_Boolean HLRBRep_Intersector::IsDone () const
539 if(myTypePerform == 1)
540 return myIntersector .IsDone();
541 else if(myTypePerform ==2)
542 return myCSIntersector.IsDone();
544 return(Standard_True);
547 //=======================================================================
548 //function : NbPoints
550 //=======================================================================
552 Standard_Integer HLRBRep_Intersector::NbPoints() const
554 if(myTypePerform==43) return(0);
556 if (myTypePerform == 1)
557 return myIntersector .NbPoints();
558 else if(myTypePerform == 2)
559 return myCSIntersector.NbPoints();
564 //=======================================================================
567 //=======================================================================
569 const IntRes2d_IntersectionPoint &
570 HLRBRep_Intersector::Point (const Standard_Integer N) const
573 return(mySinglePoint);
575 return myIntersector.Point(N);
578 //=======================================================================
581 //=======================================================================
583 const IntCurveSurface_IntersectionPoint &
584 HLRBRep_Intersector::CSPoint (const Standard_Integer N) const
586 return myCSIntersector.Point(N);
589 //=======================================================================
590 //function : NbSegments
592 //=======================================================================
594 Standard_Integer HLRBRep_Intersector::NbSegments () const
596 if(myTypePerform == 1)
597 return myIntersector .NbSegments();
598 else if(myTypePerform==2)
599 return myCSIntersector.NbSegments();
604 //=======================================================================
607 //=======================================================================
609 const IntRes2d_IntersectionSegment &
610 HLRBRep_Intersector::Segment (const Standard_Integer N) const
612 return myIntersector .Segment(N);
615 //=======================================================================
616 //function : CSSegment
618 //=======================================================================
620 const IntCurveSurface_IntersectionSegment &
621 HLRBRep_Intersector::CSSegment (const Standard_Integer N) const
623 return myCSIntersector.Segment(N);
626 //=======================================================================
629 //=======================================================================
631 void HLRBRep_Intersector::Destroy ()
633 if (myPolyhedron != NULL)
634 delete (HLRBRep_ThePolyhedronOfInterCSurf *)myPolyhedron;
646 /* ********************************************************************************
648 sauvegarde de l etat du 23 janvier 98
651 void HLRBRep_Intersector::Perform (const Standard_Integer nA,
652 const Standard_Address A1,
653 const Standard_Real da1,
654 const Standard_Real db1,
655 const Standard_Integer nB,
656 const Standard_Address A2,
657 const Standard_Real da2,
658 const Standard_Real db2,
659 const Standard_Boolean EnBout)
661 Standard_Address myC1 = ((HLRBRep_EdgeData*) A1)->Curve();
662 Standard_Address myC2 = ((HLRBRep_EdgeData*) A2)->Curve();
667 Standard_Real a,b,d,tol,tol1,tol2;
668 Standard_ShortReal ta,tb;
670 tol1 = (Standard_Real)(((HLRBRep_EdgeData*) A1)->Tolerance());
671 tol2 = (Standard_Real)(((HLRBRep_EdgeData*) A2)->Tolerance());
672 if (tol1 > tol2) tol = tol1;
675 ((HLRBRep_EdgeData*) A1)->Status().Bounds(a,ta,b,tb); //-- -> Parametres 3d
676 Standard_Real mtol = tol;
680 if (da1 != 0) a = a + d * da1;
681 if (db1 != 0) b = b - d * db1;
682 ((HLRBRep_Curve*)myC1)->D0(a,pa);
683 ((HLRBRep_Curve*)myC1)->D0(b,pb);
685 a = ((HLRBRep_Curve*)myC1)->Parameter2d(a);
686 b = ((HLRBRep_Curve*)myC1)->Parameter2d(b);
696 IntRes2d_Domain D1(pa,a,(Standard_Real)ta,pb,b,(Standard_Real)tb);
698 ((HLRBRep_EdgeData*) A2)->Status().Bounds(a,ta,b,tb);
704 if (da2 != 0) a = a + d * da2;
705 if (db2 != 0) b = b - d * db2;
706 ((HLRBRep_Curve*)myC2)->D0(a,pa);
707 ((HLRBRep_Curve*)myC2)->D0(b,pb);
709 a = ((HLRBRep_Curve*)myC2)->Parameter2d(a);
710 b = ((HLRBRep_Curve*)myC2)->Parameter2d(b);
720 IntRes2d_Domain D2(pa,a,(Standard_Real)ta,pb,b,(Standard_Real)tb);
722 myIntersector.Perform(myC1,D1,myC2,D2,tol,tol);
730 if(myIntersector.NbPoints()==1) {
731 if(myIntersector.NbSegments()==0) {
735 NbIntersPointEtSegment++;
738 else if(myIntersector.NbPoints()==0) {
739 if(myIntersector.NbSegments()==0) {
742 else if(myIntersector.NbSegments()==1) {
750 if(myIntersector.NbSegments()==0) {
754 NbIntersPointEtSegment++;
759 ******************************************************************************** */