1 // File: IntCurve_IntPolyPolyGen.gxx
2 // Created: Tue Oct 13 11:12:26 1992
3 // Author: Laurent BUCHARD
6 // Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169
10 #define No_Standard_RangeError
11 #define No_Standard_OutOfRange
15 #include <Standard_ConstructionError.hxx>
17 #include <IntRes2d_Domain.hxx>
18 #include <IntRes2d_Position.hxx>
19 #include <IntRes2d_Transition.hxx>
20 #include <IntRes2d_IntersectionPoint.hxx>
21 #include <IntRes2d_IntersectionSegment.hxx>
24 #include <IntImpParGen.hxx>
26 #include <Intf_SectionPoint.hxx>
27 #include <Intf_SectionLine.hxx>
28 #include <Intf_TangentZone.hxx>
30 #include <gp_Vec2d.hxx>
32 #include <math_Vector.hxx>
33 #include <math_FunctionSetRoot.hxx>
34 #include <math_NewtonFunctionSetRoot.hxx>
36 //======================================================================
38 // Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169 Begin
39 // #define NBITER_MAX_POLYGON 3
40 #define NBITER_MAX_POLYGON 10
41 // Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169 End
42 #define TOL_CONF_MINI 0.0000000001
43 #define TOL_MINI 0.0000000001
45 //----------------------------------------------------------------------
51 Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
53 ,const Standard_Real u
54 ,const IntRes2d_Domain& D2
56 ,const Standard_Real v
57 ,const Standard_Real TolConf
58 ,IntRes2d_IntersectionPoint& IntPt
59 ,Standard_Boolean& HeadOn1
60 ,Standard_Boolean& HeadOn2
61 ,Standard_Boolean& EndOn1
62 ,Standard_Boolean& EndOn2
63 ,Standard_Integer PosSegment);
66 //======================================================================
67 IntCurve_IntPolyPolyGen::IntCurve_IntPolyPolyGen(void) {
68 done = Standard_False;
70 //======================================================================
71 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
72 ,const IntRes2d_Domain& D1
74 ,const IntRes2d_Domain& D2
75 ,const Standard_Real TheTolConf
76 ,const Standard_Real TheTol)
79 Standard_Boolean AnErrorOccurred = Standard_False;
84 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
85 Standard_Real DV = D2.LastParameter()-D2.FirstParameter();
86 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
87 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
88 Perform(C1,D1,C2,D2,TlConf,Tl,0,DU,DV);
89 //----------------------------------------------------------------------
90 //-- Traitement des points en bouts
91 //----------------------------------------------------------------------
92 Standard_Boolean HeadOn1 = Standard_False;
93 Standard_Boolean HeadOn2 = Standard_False;
94 Standard_Boolean EndOn1 = Standard_False;
95 Standard_Boolean EndOn2 = Standard_False;
97 Standard_Integer n=this->NbPoints();
100 //--------------------------------------------------------------------
101 //-- On ne rejette les points Head Head ... End End
102 //-- si ils figurent deja dans un bout de segment
103 //-- ( On ne peut pas tester les egalites sur les parametres)
104 //-- ( ces points n etant pas trouves a EpsX pres )
105 //-- PosSegment = 1 si Head Head
109 //--------------------------------------------------------------------
110 Standard_Integer PosSegment = 0;
115 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
116 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
117 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
119 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
120 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
121 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
123 if(Pos1 == IntRes2d_Head) {
124 if(Pos2 == IntRes2d_Head) PosSegment|=1;
125 else if(Pos2 == IntRes2d_End) PosSegment|=2;
127 else if(Pos1 == IntRes2d_End) {
128 if(Pos2 == IntRes2d_Head) PosSegment|=4;
129 else if(Pos2 == IntRes2d_End) PosSegment|=8;
133 n=this->NbSegments();
135 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
136 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
137 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
139 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
140 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
141 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
143 if(Pos1 == IntRes2d_Head) {
144 if(Pos2 == IntRes2d_Head) PosSegment|=1;
145 else if(Pos2 == IntRes2d_End) PosSegment|=2;
147 else if(Pos1 == IntRes2d_End) {
148 if(Pos2 == IntRes2d_Head) PosSegment|=4;
149 else if(Pos2 == IntRes2d_End) PosSegment|=8;
152 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
153 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
154 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
156 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
157 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
158 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
160 if(Pos1 == IntRes2d_Head) {
161 if(Pos2 == IntRes2d_Head) PosSegment|=1;
162 else if(Pos2 == IntRes2d_End) PosSegment|=2;
164 else if(Pos1 == IntRes2d_End) {
165 if(Pos2 == IntRes2d_Head) PosSegment|=4;
166 else if(Pos2 == IntRes2d_End) PosSegment|=8;
172 Standard_Real U0 = D1.FirstParameter();
173 Standard_Real U1 = D1.LastParameter();
174 Standard_Real V0 = D2.FirstParameter();
175 Standard_Real V1 = D2.LastParameter();
177 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
178 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
179 IntRes2d_IntersectionPoint IntPt;
181 if(D1.FirstTolerance() || D2.FirstTolerance()) {
182 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
185 if(D1.FirstTolerance() || D2.LastTolerance()) {
186 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
189 if(D1.LastTolerance() || D2.FirstTolerance()) {
190 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
193 if(D1.LastTolerance() || D2.LastTolerance()) {
194 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
197 if(AnErrorOccurred) {
198 //----------------------------------------------------------------------------------
199 //-- On a donne un point approche a la recherche du point exact, et cette recherche
201 //-- Soit le point n'existe pas, soit c'est un point en bout dont un des parameteres
202 //-- est en dehors du domaine de la courbe.
204 //-- Dans le cas contraire, on suppose que les points en bouts ont ete trouves par
205 //-- les interferences des polygones
209 v = TheProjPCur::FindParameter( C2,D1.FirstPoint(),V0,V1,EpsX2);
210 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
216 v = TheProjPCur::FindParameter( C2,D1.LastPoint(),V0,V1,EpsX2);
217 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
222 u = TheProjPCur::FindParameter( C1,D2.FirstPoint(),U0,U1,EpsX1);
224 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
229 u = TheProjPCur::FindParameter( C1,D2.LastPoint(),U0,U1,EpsX1);
231 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
241 //======================================================================
242 //== A u t o I n t e r s e c t i o n
243 //======================================================================
244 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
245 ,const IntRes2d_Domain& D1
246 ,const Standard_Real TheTolConf
247 ,const Standard_Real TheTol)
250 Standard_Boolean AnErrorOccurred = Standard_False;
255 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
256 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
257 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
258 Perform(C1,D1,TlConf,Tl,0,DU,DU);
259 //----------------------------------------------------------------------
260 //-- Traitement des points en bouts
261 //----------------------------------------------------------------------
262 Standard_Boolean HeadOn1 = Standard_False;
263 Standard_Boolean HeadOn2 = Standard_False;
264 Standard_Boolean EndOn1 = Standard_False;
265 Standard_Boolean EndOn2 = Standard_False;
267 Standard_Integer n=this->NbPoints();
270 //--------------------------------------------------------------------
271 //-- On ne rejette les points Head Head ... End End
272 //-- si ils figurent deja dans un bout de segment
273 //-- ( On ne peut pas tester les egalites sur les parametres)
274 //-- ( ces points n etant pas trouves a EpsX pres )
275 //-- PosSegment = 1 si Head Head
279 //--------------------------------------------------------------------
280 Standard_Integer PosSegment = 0;
285 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
286 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
287 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
289 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
290 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
291 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
293 if(Pos1 == IntRes2d_Head) {
294 if(Pos2 == IntRes2d_Head) PosSegment|=1;
295 else if(Pos2 == IntRes2d_End) PosSegment|=2;
297 else if(Pos1 == IntRes2d_End) {
298 if(Pos2 == IntRes2d_Head) PosSegment|=4;
299 else if(Pos2 == IntRes2d_End) PosSegment|=8;
303 n=this->NbSegments();
305 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
306 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
307 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
309 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
310 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
311 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
313 if(Pos1 == IntRes2d_Head) {
314 if(Pos2 == IntRes2d_Head) PosSegment|=1;
315 else if(Pos2 == IntRes2d_End) PosSegment|=2;
317 else if(Pos1 == IntRes2d_End) {
318 if(Pos2 == IntRes2d_Head) PosSegment|=4;
319 else if(Pos2 == IntRes2d_End) PosSegment|=8;
322 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
323 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
324 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
326 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
327 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
328 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
330 if(Pos1 == IntRes2d_Head) {
331 if(Pos2 == IntRes2d_Head) PosSegment|=1;
332 else if(Pos2 == IntRes2d_End) PosSegment|=2;
334 else if(Pos1 == IntRes2d_End) {
335 if(Pos2 == IntRes2d_Head) PosSegment|=4;
336 else if(Pos2 == IntRes2d_End) PosSegment|=8;
340 //======================================================================
344 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
345 ,const IntRes2d_Domain& D1
346 ,const Standard_Real TolConf
347 ,const Standard_Real Tol
348 ,const Standard_Integer NbIter
349 ,const Standard_Real DeltaU
350 ,const Standard_Real) {
352 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
354 Standard_Integer nbsamples;
355 done = Standard_False;
356 Standard_Boolean AnErrorOccurred = Standard_False;
359 nbsamples = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
361 if(NbIter>3 || (NbIter>2 && nbsamples>100)) return;
363 nbsamples*=2; //--- On prend systematiquement 2 fois plus de points que
364 //-- sur une courbe normale.
365 //-- Les courbes auto-intersectantes donne souvent des
366 //-- polygones assez loin de la courbe a parametre ct.
369 if((D1.LastParameter()-D1.FirstParameter())
371 nbsamples=(3*(nbsamples*NbIter)/2);
374 nbsamples=(3*(nbsamples*NbIter))/2;
377 IntCurve_ThePolygon2d Poly1(C1,nbsamples,D1,Tol);
378 if(!Poly1.AutoIntersectionIsPossible()) {
379 done = Standard_True;
383 //----------------------------------------------------------------------
384 //-- Si la deflection est inferieure a la Tolerance de Confusion
385 //-- Alors la deflection du polygone est fixee a TolConf
386 //-- (Detection des Zones de Tangence)
387 //----------------------------------------------------------------------
388 if(Poly1.DeflectionOverEstimation() < TolConf) {
389 Poly1.SetDeflectionOverEstimation(TolConf);
392 IntCurve_InterferencePoly2d InterPP(Poly1);
393 IntCurve_ExactIntersectionPoint EIP(C1,C1,TolConf);
396 //----------------------------------------------------------------------
397 //-- Traitement des SectionPoint
398 //----------------------------------------------------------------------
399 Standard_Integer Nbsp = InterPP.NbSectionPoints();
402 //-- ---------------------------------------------------------------------
403 //-- tri tri tri tri tri tri tri tri tri tri tri tri tri tri
405 Standard_Integer* TriIndex = new Standard_Integer [Nbsp+1];
406 Standard_Integer* PtrSegIndex1 = new Standard_Integer [Nbsp+1];
407 Standard_Integer* PtrSegIndex2 = new Standard_Integer [Nbsp+1];
408 Standard_Boolean Triok;
409 Standard_Integer SegIndex1,SegIndex2,SegIndex_1,SegIndex_2;
410 // Standard_Real ParamOn1,ParamOn2,ParamOn_1,ParamOn_2;
411 Standard_Real ParamOn1,ParamOn2;
414 for( i=1;i<=Nbsp;i++) {
416 const Intf_SectionPoint& SPnt1 = InterPP.PntValue(i);
417 SPnt1.InfoFirst(Type,PtrSegIndex1[i],ParamOn1);
418 SPnt1.InfoSecond(Type,PtrSegIndex2[i],ParamOn2);
425 for(Standard_Integer tr=1;tr<Nbsp;tr++) {
426 SegIndex1=PtrSegIndex1[TriIndex[tr]];
427 SegIndex_1=PtrSegIndex1[TriIndex[tr+1]];
429 SegIndex2=PtrSegIndex2[TriIndex[tr]];
430 SegIndex_2=PtrSegIndex2[TriIndex[tr+1]];
432 if(SegIndex1 > SegIndex_1) {
433 Standard_Integer q=TriIndex[tr];
434 TriIndex[tr]=TriIndex[tr+1];
436 Triok=Standard_False;
438 else if(SegIndex1 == SegIndex_1) {
439 if(SegIndex2 > SegIndex_2) {
440 Standard_Integer q=TriIndex[tr];
441 TriIndex[tr]=TriIndex[tr+1];
443 Triok=Standard_False;
448 while(Triok==Standard_False);
450 //-- supression des doublons Si Si !
451 for(i=1; i<Nbsp;i++) {
452 if( (PtrSegIndex1[TriIndex[i]] == PtrSegIndex1[TriIndex[i+1]])
453 && (PtrSegIndex2[TriIndex[i]] == PtrSegIndex2[TriIndex[i+1]])) {
459 Standard_Integer Nelarg=(Poly1.NbSegments()/20);
460 if(Nelarg<2) Nelarg=2;
462 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
464 const Intf_SectionPoint& SPnt = InterPP.PntValue(TriIndex[sp]);
466 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
467 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
469 if(Abs(SegIndex1-SegIndex2)>1) {
471 EIP.Perform(Poly1,Poly1,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
472 AnErrorOccurred = EIP.AnErrorOccurred();
473 if(EIP.NbRoots()==0) {
474 //-- On supprime tous les segments voisins
475 for(Standard_Integer k=sp+1;k<=Nbsp;k++) {
476 Standard_Integer kk=TriIndex[k];
477 // modified by OFV OCC2502 Tue Apr 29 15:07:45 2003 .Begin
478 // --- avoid negative indicies as well as in outer done
480 if( Abs(SegIndex1-PtrSegIndex1[kk])< Nelarg
481 && Abs(SegIndex2-PtrSegIndex2[kk])< Nelarg) {
485 // modified by OFV OCC2502 Tue Apr 29 15:11:34 2003 .End
488 else if(EIP.NbRoots()>=1) {
489 //--------------------------------------------------------------------
490 //-- On verifie que le point trouve est bien une racine
491 //--------------------------------------------------------------------
494 TheCurveTool::D1(C1,U,P1,Tan1);
495 TheCurveTool::D1(C1,V,P2,Tan2);
496 Standard_Real Dist = P1.Distance(P2);
497 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
499 if(Abs(U-V)<=EpsX1) {
500 //-----------------------------------------
501 //-- Solution non valide
502 //-- Les maths ont du converger vers une
503 //-- solution triviale ( point U = V )
504 //-----------------------------------------
508 //-----------------------------------------------------------------
509 //-- On verifie que le point (u,v) n existe pas deja
511 done = Standard_True;
512 Standard_Integer nbp=NbPoints();
514 for(Standard_Integer p=1; p<=nbp; p++) {
515 const IntRes2d_IntersectionPoint& P=Point(p);
516 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
517 if(Abs(V-P.ParamOnSecond()) <= EpsX1) {
518 Dist = TolConf+1.0; p+=nbp;
523 if(Dist <= TolConf) { //-- Ou le point est deja present
524 IntRes2d_Position Pos1 = IntRes2d_Middle;
525 IntRes2d_Position Pos2 = IntRes2d_Middle;
526 IntRes2d_Transition Trans1,Trans2;
527 //-----------------------------------------------------------------
528 //-- Calcul des Positions des Points sur la courbe
530 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
531 Pos1 = IntRes2d_Head;
532 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
535 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
536 Pos2 = IntRes2d_Head;
537 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
539 //-----------------------------------------------------------------
540 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
542 ,TolConf) == Standard_False) {
543 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
544 TheCurveTool::D2(C1,V,P2,Tan2,Norm2);
545 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
546 ,Pos2,Tan2,Norm2,Trans2
549 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
557 delete [] PtrSegIndex1;
558 delete [] PtrSegIndex2;
562 //----------------------------------------------------------------------
563 //-- Traitement des TangentZone
564 //----------------------------------------------------------------------
565 Standard_Integer Nbtz = InterPP.NbTangentZones();
568 Standard_Real ParamInf=D1.FirstParameter();
569 Standard_Real ParamSup=D1.LastParameter();
570 ParamSup=-RealLast();
572 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
573 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
574 //====================================================================
575 //== Recherche du premier et du dernier point dans la zone de tg.
576 //== ATTENTION LA LISTE N EST PAS TRIEE
577 //====================================================================
578 for(Standard_Integer tzz=1; tzz<=NbPnts; tzz++) {
579 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(tzz);
581 // Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2;
582 Standard_Integer SegIndex1onP1;
584 Standard_Real ParamOnLine;
586 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
587 if(SegIndex1onP1 >= Poly1.NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
588 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
589 Standard_Real Par = Poly1.ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
590 if(ParamSup<Par) ParamSup=Par;
591 if(ParamInf>Par) ParamInf=Par;
594 if(ParamSup > ParamInf) {
595 //-- printf("\n %g -> %g %g -> %g ",D1.FirstParameter(),ParamInf,D1.LastParameter(),ParamSup);
596 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInf)
598 ,TheCurveTool::Value(C1,ParamSup)
600 Perform(C1,RecursD1,TolConf,Tol,NbIter+1,ParamSup-ParamInf,0.0);
603 //----------------------------------------------------------------------
604 done = Standard_True;
608 Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
610 ,const Standard_Real tu
611 ,const IntRes2d_Domain& D2
613 ,const Standard_Real tv
614 ,const Standard_Real TolConf
615 ,IntRes2d_IntersectionPoint& IntPt
616 ,Standard_Boolean& HeadOn1
617 ,Standard_Boolean& HeadOn2
618 ,Standard_Boolean& EndOn1
619 ,Standard_Boolean& EndOn2
620 ,Standard_Integer PosSegment) {
622 gp_Pnt2d P1,P2,SP1,SP2;
623 gp_Vec2d T1,T2,N1,N2;
626 Standard_Real svu = u;
627 Standard_Real svv = v;
629 TheCurveTool::D1(C1,u,P1,T1);
630 TheCurveTool::D1(C2,v,P2,T2);
632 IntRes2d_Position Pos1 = IntRes2d_Middle;
633 IntRes2d_Position Pos2 = IntRes2d_Middle;
634 IntRes2d_Transition Trans1,Trans2;
636 //----------------------------------------------------------------------
637 //-- Head On 1 : Head1 <-> P2
638 if(P2.Distance(D1.FirstPoint())<=D1.FirstTolerance()) {
639 Pos1 = IntRes2d_Head;
640 HeadOn1 = Standard_True;
641 SP1 = D1.FirstPoint();
642 u = D1.FirstParameter();
644 //----------------------------------------------------------------------
645 //-- End On 1 : End1 <-> P2
646 else if(P2.Distance(D1.LastPoint())<=D1.LastTolerance()) {
648 EndOn1 = Standard_True;
649 SP1 = D1.LastPoint();
650 u = D1.LastParameter();
654 //----------------------------------------------------------------------
655 //-- Head On 2 : Head2 <-> P1
656 else if(P1.Distance(D2.FirstPoint())<=D2.FirstTolerance()) {
657 Pos2 = IntRes2d_Head;
658 HeadOn2 = Standard_True;
659 SP2 = D2.FirstPoint();
660 v = D2.FirstParameter();
662 //----------------------------------------------------------------------
663 //-- End On 2 : End2 <-> P1
664 else if(P1.Distance(D2.LastPoint())<=D2.LastTolerance()) {
666 EndOn2 = Standard_True;
667 SP2 = D2.LastPoint();
668 v = D2.LastParameter();
671 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
672 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
675 if((Pos1 != IntRes2d_Middle)||(Pos2 != IntRes2d_Middle)) {
676 if(Pos1 == IntRes2d_Middle) {
677 if(Abs(u-D1.FirstParameter()) <= EpsX1) {
678 Pos1 = IntRes2d_Head;
679 P1 = D1.FirstPoint();
680 HeadOn1 = Standard_True;
682 else if(Abs(u-D1.LastParameter()) <= EpsX1) {
685 EndOn1 = Standard_True;
693 if(Pos2 == IntRes2d_Middle) {
694 if(Abs(v-D2.FirstParameter()) <= EpsX2) {
695 Pos2 = IntRes2d_Head;
696 HeadOn2 = Standard_True;
697 P2 = D2.FirstPoint();
698 if(Pos1 != IntRes2d_Middle) {
699 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
705 else if(Abs(v-D2.LastParameter()) <= EpsX2) {
707 EndOn2 = Standard_True;
709 if(Pos1 != IntRes2d_Middle) {
710 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
719 //--------------------------------------------------------------------
720 //-- On Teste si un point de bout de segment a deja ces trnasitions
721 //-- Si Oui, on ne cree pas de nouveau point
723 //-- PosSegment = 1 si Head Head
727 //--------------------------------------------------------------------
728 if(Pos1 == IntRes2d_Head) {
729 if((Pos2 == IntRes2d_Head)&&(PosSegment & 1)) return(Standard_False);
730 if((Pos2 == IntRes2d_End )&&(PosSegment & 2)) return(Standard_False);
732 else if(Pos1 == IntRes2d_End) {
733 if((Pos2 == IntRes2d_Head)&&(PosSegment & 4)) return(Standard_False);
734 if((Pos2 == IntRes2d_End )&&(PosSegment & 8)) return(Standard_False);
738 if(IntImpParGen::DetermineTransition( Pos1,T1,Trans1,Pos2,T2,Trans2,TolConf)
740 TheCurveTool::D2(C1,svu,P1,T1,N1);
741 TheCurveTool::D2(C2,svv,P2,T2,N2);
742 IntImpParGen::DetermineTransition(Pos1,T1,N1,Trans1,
743 Pos2,T2,N2,Trans2,TolConf);
745 IntPt.SetValues(P1,u,v,Trans1,Trans2,Standard_False);
746 return(Standard_True);
749 return(Standard_False);
758 //======================================================================
759 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
760 ,const IntRes2d_Domain& D1
762 ,const IntRes2d_Domain& D2
763 ,const Standard_Real TolConf
764 ,const Standard_Real Tol
765 ,const Standard_Integer NbIter
766 ,const Standard_Real DeltaU
767 ,const Standard_Real DeltaV) {
769 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
771 Standard_Integer nbsamplesOnC1,nbsamplesOnC2;
772 done = Standard_False;
773 Standard_Boolean AnErrorOccurred = Standard_False;
775 if(NbIter>NBITER_MAX_POLYGON) return;
777 nbsamplesOnC1 = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
779 //// modified by jgv, 5.12.02 for OCC935 ////
780 if (NbIter == 0) // first time
782 if (nbsamplesOnC1 < 20)
787 if ((D1.LastParameter()-D1.FirstParameter()) > 0.5*(DeltaU))
788 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
790 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
792 /////////////////////////////////////////////
794 nbsamplesOnC2 = TheCurveTool::NbSamples(C2,D2.FirstParameter(),D2.LastParameter());
796 //// modified by jgv, 5.12.02 for OCC935 ////
797 if (NbIter == 0) // first time
799 if (nbsamplesOnC2 < 20)
804 if ((D2.LastParameter()-D2.FirstParameter()) > 0.5*(DeltaV))
805 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
807 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
809 /////////////////////////////////////////////
811 IntCurve_ThePolygon2d *PtrPoly1,*PtrPoly2;
812 if(nbsamplesOnC2 > nbsamplesOnC1) {
813 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
814 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
815 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
818 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,PtrPoly1->Bounding());
819 PtrPoly1->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
820 +PtrPoly1->DeflectionOverEstimation());
821 PtrPoly1->ComputeWithBox(C1,PtrPoly2->Bounding());
825 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
826 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
827 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
830 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,PtrPoly2->Bounding());
831 PtrPoly2->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
832 +PtrPoly1->DeflectionOverEstimation());
833 PtrPoly2->ComputeWithBox(C2,PtrPoly1->Bounding());
836 //----------------------------------------------------------------------
837 //-- Si la deflection est inferieure a la Tolerance de Confusion
838 //-- Alors la deflection du polygone est fixee a TolConf
839 //-- (Detection des Zones de Tangence)
840 //----------------------------------------------------------------------
842 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
843 PtrPoly1->SetDeflectionOverEstimation(TolConf);
845 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
846 PtrPoly2->SetDeflectionOverEstimation(TolConf);
848 IntCurve_InterferencePoly2d InterPP(*PtrPoly1,*PtrPoly2);
849 IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf);
852 //----------------------------------------------------------------------
853 //-- Traitement des SectionPoint
854 //----------------------------------------------------------------------
855 Standard_Integer Nbsp = InterPP.NbSectionPoints();
858 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
859 const Intf_SectionPoint& SPnt = InterPP.PntValue(sp);
860 Standard_Integer SegIndex1,SegIndex2;
861 Standard_Real ParamOn1,ParamOn2;
864 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
865 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
866 EIP.Perform(*PtrPoly1,*PtrPoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
867 AnErrorOccurred = EIP.AnErrorOccurred();
868 if(EIP.NbRoots()>=1) {
869 //--------------------------------------------------------------------
870 //-- On verifie que le point trouve est bien une racine
871 //--------------------------------------------------------------------
873 TheCurveTool::D1(C1,U,P1,Tan1);
874 TheCurveTool::D1(C2,V,P2,Tan2);
875 Standard_Real Dist = P1.Distance(P2);
876 //-----------------------------------------------------------------
877 //-- On verifie que le point (u,v) n existe pas deja
879 done = Standard_True;
880 Standard_Integer nbp=NbPoints();
881 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
882 Standard_Real EpsX2 = 10.0*TheCurveTool::EpsX(C2);
884 for(Standard_Integer p=1; p<=nbp; p++) {
885 const IntRes2d_IntersectionPoint& P=Point(p);
886 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
887 if(Abs(V-P.ParamOnSecond()) <= EpsX2) {
888 Dist = TolConf+1.0; p+=nbp;
893 if(Dist <= TolConf) { //-- Ou le point est deja present
894 IntRes2d_Position Pos1 = IntRes2d_Middle;
895 IntRes2d_Position Pos2 = IntRes2d_Middle;
896 IntRes2d_Transition Trans1,Trans2;
897 //-----------------------------------------------------------------
898 //-- Calcul des Positions des Points sur la courbe
900 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
901 Pos1 = IntRes2d_Head;
902 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
905 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
906 Pos2 = IntRes2d_Head;
907 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
909 //-----------------------------------------------------------------
910 //-- Calcul des Transitions (Voir IntImpParGen.cxx)
912 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
914 ,TolConf)==Standard_False) {
916 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
917 TheCurveTool::D2(C2,V,P2,Tan2,Norm2);
918 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
919 ,Pos2,Tan2,Norm2,Trans2
922 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
925 } //-- if(EIP.NbRoots()>=1)
930 //----------------------------------------------------------------------
931 //-- Traitement des TangentZone
932 //----------------------------------------------------------------------
933 Standard_Integer Nbtz = InterPP.NbTangentZones();
934 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
935 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
936 //====================================================================
937 //== Recherche du premier et du dernier point dans la zone de tg.
938 //====================================================================
939 Standard_Real ParamSupOnCurve2,ParamInfOnCurve2;
940 Standard_Real ParamSupOnCurve1,ParamInfOnCurve1;
941 // Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2,SegIndex2onP1,SegIndex2onP2;
942 Standard_Integer SegIndex1onP1,SegIndex1onP2;
944 Standard_Real ParamOnLine;
945 Standard_Real PolyUInf,PolyUSup,PolyVInf,PolyVSup;
946 ParamSupOnCurve2=ParamSupOnCurve1=PolyUSup=PolyVSup=-RealLast();
947 ParamInfOnCurve2=ParamInfOnCurve1=PolyUInf=PolyVInf= RealLast();
948 for(Standard_Integer qq=1;qq<=NbPnts;qq++) {
949 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(qq);
950 //====================================================================
951 //== On discretise sur les zones de tangence
954 //== Deflection < Tolerance
955 //== OU Echantillon < EpsX (normalement la premiere condition est
957 //====================================================================
958 // Standard_Real _PolyUInf,_PolyUSup,_PolyVInf,_PolyVSup;
959 Standard_Real _PolyUInf,_PolyVInf;
961 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
962 if(SegIndex1onP1 >= PtrPoly1->NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
963 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
964 _PolyUInf = PtrPoly1->ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
966 SPnt1.InfoSecond(Type,SegIndex1onP2,ParamOnLine);
967 if(SegIndex1onP2 >= PtrPoly2->NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; }
968 if(SegIndex1onP2 <= 0) { SegIndex1onP2=1; ParamOnLine = 0.0; }
969 _PolyVInf = PtrPoly2->ApproxParamOnCurve(SegIndex1onP2,ParamOnLine);
971 //----------------------------------------------------------------------
973 if(ParamInfOnCurve1 > _PolyUInf) ParamInfOnCurve1=_PolyUInf;
974 if(ParamInfOnCurve2 > _PolyVInf) ParamInfOnCurve2=_PolyVInf;
976 if(ParamSupOnCurve1 < _PolyUInf) ParamSupOnCurve1=_PolyUInf;
977 if(ParamSupOnCurve2 < _PolyVInf) ParamSupOnCurve2=_PolyVInf;
981 PolyUInf= ParamInfOnCurve1;
982 PolyUSup= ParamSupOnCurve1;
983 PolyVInf= ParamInfOnCurve2;
984 PolyVSup= ParamSupOnCurve2;
986 TheCurveTool::D0(C1,PolyUInf,P1);
987 TheCurveTool::D0(C2,PolyVInf,P2);
988 Standard_Real distmemesens = P1.SquareDistance(P2);
989 TheCurveTool::D0(C2,PolyVSup,P2);
990 Standard_Real distdiffsens = P1.SquareDistance(P2);
991 if(distmemesens > distdiffsens) {
992 Standard_Real qwerty=PolyVInf; PolyVInf=PolyVSup; PolyVSup=qwerty;
997 if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf)
998 ||(PtrPoly2->DeflectionOverEstimation() > TolConf))
999 &&(NbIter<NBITER_MAX_POLYGON)) {
1001 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInfOnCurve1)
1002 ,ParamInfOnCurve1,TolConf
1003 ,TheCurveTool::Value(C1,ParamSupOnCurve1)
1004 ,ParamSupOnCurve1,TolConf);
1005 IntRes2d_Domain RecursD2( TheCurveTool::Value(C2,ParamInfOnCurve2)
1006 ,ParamInfOnCurve2,TolConf
1007 ,TheCurveTool::Value(C2,ParamSupOnCurve2)
1008 ,ParamSupOnCurve2,TolConf);
1009 //-- On ne delete pas PtrPoly1(2) ,
1010 //-- ils sont detruits enfin de fct.
1011 //-- !! Pas de return intempestif !!
1012 Perform(C1,RecursD1,C2,RecursD2,Tol,TolConf,NbIter+1,DeltaU,DeltaV);
1015 //-----------------------------------------------------------------
1016 //-- Calcul des Positions des Points sur la courbe et des
1017 //-- Transitions sur chaque borne du segment
1019 IntRes2d_Position Pos1 = IntRes2d_Middle;
1020 IntRes2d_Position Pos2 = IntRes2d_Middle;
1021 IntRes2d_Transition Trans1,Trans2;
1023 TheCurveTool::D1(C1,PolyUInf,P1,Tan1);
1024 TheCurveTool::D1(C2,PolyVInf,P2,Tan2);
1026 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1027 Pos1 = IntRes2d_Head;
1029 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1030 Pos1 = IntRes2d_End;
1032 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1033 Pos2 = IntRes2d_Head;
1035 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1036 Pos2 = IntRes2d_End;
1039 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1040 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1042 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1043 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1045 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1046 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1049 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1054 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1055 == Standard_False) {
1056 TheCurveTool::D2(C1,PolyUInf,P1,Tan1,Norm1);
1057 TheCurveTool::D2(C2,PolyVInf,P2,Tan2,Norm2);
1058 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1059 Pos2,Tan2,Norm2,Trans2,TolConf);
1061 IntRes2d_IntersectionPoint PtSeg1(P1,PolyUInf,PolyVInf
1062 ,Trans1,Trans2,Standard_False);
1063 //----------------------------------------------------------------------
1065 if((Abs(PolyUInf-PolyUSup) <= TheCurveTool::EpsX(C1))
1066 || (Abs(PolyVInf-PolyVSup) <= TheCurveTool::EpsX(C2))) {
1070 TheCurveTool::D1(C1,PolyUSup,P1,Tan1);
1071 TheCurveTool::D1(C2,PolyVSup,P2,Tan2);
1072 Pos1 = IntRes2d_Middle; Pos2 = IntRes2d_Middle;
1074 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1075 Pos1 = IntRes2d_Head;
1077 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1078 Pos1 = IntRes2d_End;
1080 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1081 Pos2 = IntRes2d_Head;
1083 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1084 Pos2 = IntRes2d_End;
1088 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1089 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1091 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1092 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1094 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1095 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1098 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1101 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1103 TheCurveTool::D2(C1,PolyUSup,P1,Tan1,Norm1);
1104 TheCurveTool::D2(C2,PolyVSup,P2,Tan2,Norm2);
1105 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1106 Pos2,Tan2,Norm2,Trans2,TolConf);
1108 IntRes2d_IntersectionPoint PtSeg2(P1,PolyUSup,PolyVSup
1109 ,Trans1,Trans2,Standard_False);
1113 Standard_Boolean Oppos = (Tan1.Dot(Tan2) > 0.0)? Standard_False : Standard_True;
1114 if(ParamInfOnCurve1 > ParamSupOnCurve1) {
1115 IntRes2d_IntersectionSegment Seg(PtSeg2,PtSeg1,Oppos,Standard_False);
1119 IntRes2d_IntersectionSegment Seg(PtSeg1,PtSeg2,Oppos,Standard_False);
1125 //----------------------------------------------------------------------
1128 done = Standard_True;