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 //----------------------------------------------------------------------
47 static Standard_Boolean AnErrorOccurred=Standard_False;
52 Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
54 ,const Standard_Real u
55 ,const IntRes2d_Domain& D2
57 ,const Standard_Real v
58 ,const Standard_Real TolConf
59 ,IntRes2d_IntersectionPoint& IntPt
60 ,Standard_Boolean& HeadOn1
61 ,Standard_Boolean& HeadOn2
62 ,Standard_Boolean& EndOn1
63 ,Standard_Boolean& EndOn2
64 ,Standard_Integer PosSegment);
67 //======================================================================
68 IntCurve_IntPolyPolyGen::IntCurve_IntPolyPolyGen(void) {
69 done = Standard_False;
71 //======================================================================
72 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
73 ,const IntRes2d_Domain& D1
75 ,const IntRes2d_Domain& D2
76 ,const Standard_Real TheTolConf
77 ,const Standard_Real TheTol)
80 AnErrorOccurred = Standard_False;
85 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
86 Standard_Real DV = D2.LastParameter()-D2.FirstParameter();
87 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
88 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
89 Perform(C1,D1,C2,D2,TlConf,Tl,0,DU,DV);
90 //----------------------------------------------------------------------
91 //-- Traitement des points en bouts
92 //----------------------------------------------------------------------
93 Standard_Boolean HeadOn1 = Standard_False;
94 Standard_Boolean HeadOn2 = Standard_False;
95 Standard_Boolean EndOn1 = Standard_False;
96 Standard_Boolean EndOn2 = Standard_False;
98 Standard_Integer n=this->NbPoints();
101 //--------------------------------------------------------------------
102 //-- On ne rejette les points Head Head ... End End
103 //-- si ils figurent deja dans un bout de segment
104 //-- ( On ne peut pas tester les egalites sur les parametres)
105 //-- ( ces points n etant pas trouves a EpsX pres )
106 //-- PosSegment = 1 si Head Head
110 //--------------------------------------------------------------------
111 Standard_Integer PosSegment = 0;
116 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
117 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
118 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
120 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
121 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
122 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
124 if(Pos1 == IntRes2d_Head) {
125 if(Pos2 == IntRes2d_Head) PosSegment|=1;
126 else if(Pos2 == IntRes2d_End) PosSegment|=2;
128 else if(Pos1 == IntRes2d_End) {
129 if(Pos2 == IntRes2d_Head) PosSegment|=4;
130 else if(Pos2 == IntRes2d_End) PosSegment|=8;
134 n=this->NbSegments();
136 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
137 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
138 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
140 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
141 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
142 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
144 if(Pos1 == IntRes2d_Head) {
145 if(Pos2 == IntRes2d_Head) PosSegment|=1;
146 else if(Pos2 == IntRes2d_End) PosSegment|=2;
148 else if(Pos1 == IntRes2d_End) {
149 if(Pos2 == IntRes2d_Head) PosSegment|=4;
150 else if(Pos2 == IntRes2d_End) PosSegment|=8;
153 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
154 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
155 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
157 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
158 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
159 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
161 if(Pos1 == IntRes2d_Head) {
162 if(Pos2 == IntRes2d_Head) PosSegment|=1;
163 else if(Pos2 == IntRes2d_End) PosSegment|=2;
165 else if(Pos1 == IntRes2d_End) {
166 if(Pos2 == IntRes2d_Head) PosSegment|=4;
167 else if(Pos2 == IntRes2d_End) PosSegment|=8;
173 Standard_Real U0 = D1.FirstParameter();
174 Standard_Real U1 = D1.LastParameter();
175 Standard_Real V0 = D2.FirstParameter();
176 Standard_Real V1 = D2.LastParameter();
178 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
179 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
180 IntRes2d_IntersectionPoint IntPt;
182 if(D1.FirstTolerance() || D2.FirstTolerance()) {
183 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
186 if(D1.FirstTolerance() || D2.LastTolerance()) {
187 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
190 if(D1.LastTolerance() || D2.FirstTolerance()) {
191 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
194 if(D1.LastTolerance() || D2.LastTolerance()) {
195 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
198 if(AnErrorOccurred) {
199 //----------------------------------------------------------------------------------
200 //-- On a donne un point approche a la recherche du point exact, et cette recherche
202 //-- Soit le point n'existe pas, soit c'est un point en bout dont un des parameteres
203 //-- est en dehors du domaine de la courbe.
205 //-- Dans le cas contraire, on suppose que les points en bouts ont ete trouves par
206 //-- les interferences des polygones
210 v = TheProjPCur::FindParameter( C2,D1.FirstPoint(),V0,V1,EpsX2);
211 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
217 v = TheProjPCur::FindParameter( C2,D1.LastPoint(),V0,V1,EpsX2);
218 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
223 u = TheProjPCur::FindParameter( C1,D2.FirstPoint(),U0,U1,EpsX1);
225 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
230 u = TheProjPCur::FindParameter( C1,D2.LastPoint(),U0,U1,EpsX1);
232 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
242 //======================================================================
243 //== A u t o I n t e r s e c t i o n
244 //======================================================================
245 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
246 ,const IntRes2d_Domain& D1
247 ,const Standard_Real TheTolConf
248 ,const Standard_Real TheTol)
251 AnErrorOccurred = Standard_False;
256 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
257 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
258 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
259 Perform(C1,D1,TlConf,Tl,0,DU,DU);
260 //----------------------------------------------------------------------
261 //-- Traitement des points en bouts
262 //----------------------------------------------------------------------
263 Standard_Boolean HeadOn1 = Standard_False;
264 Standard_Boolean HeadOn2 = Standard_False;
265 Standard_Boolean EndOn1 = Standard_False;
266 Standard_Boolean EndOn2 = Standard_False;
268 Standard_Integer n=this->NbPoints();
271 //--------------------------------------------------------------------
272 //-- On ne rejette les points Head Head ... End End
273 //-- si ils figurent deja dans un bout de segment
274 //-- ( On ne peut pas tester les egalites sur les parametres)
275 //-- ( ces points n etant pas trouves a EpsX pres )
276 //-- PosSegment = 1 si Head Head
280 //--------------------------------------------------------------------
281 Standard_Integer PosSegment = 0;
286 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
287 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
288 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
290 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
291 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
292 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
294 if(Pos1 == IntRes2d_Head) {
295 if(Pos2 == IntRes2d_Head) PosSegment|=1;
296 else if(Pos2 == IntRes2d_End) PosSegment|=2;
298 else if(Pos1 == IntRes2d_End) {
299 if(Pos2 == IntRes2d_Head) PosSegment|=4;
300 else if(Pos2 == IntRes2d_End) PosSegment|=8;
304 n=this->NbSegments();
306 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
307 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
308 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
310 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
311 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
312 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
314 if(Pos1 == IntRes2d_Head) {
315 if(Pos2 == IntRes2d_Head) PosSegment|=1;
316 else if(Pos2 == IntRes2d_End) PosSegment|=2;
318 else if(Pos1 == IntRes2d_End) {
319 if(Pos2 == IntRes2d_Head) PosSegment|=4;
320 else if(Pos2 == IntRes2d_End) PosSegment|=8;
323 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
324 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
325 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
327 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
328 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
329 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
331 if(Pos1 == IntRes2d_Head) {
332 if(Pos2 == IntRes2d_Head) PosSegment|=1;
333 else if(Pos2 == IntRes2d_End) PosSegment|=2;
335 else if(Pos1 == IntRes2d_End) {
336 if(Pos2 == IntRes2d_Head) PosSegment|=4;
337 else if(Pos2 == IntRes2d_End) PosSegment|=8;
341 //======================================================================
345 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
346 ,const IntRes2d_Domain& D1
347 ,const Standard_Real TolConf
348 ,const Standard_Real Tol
349 ,const Standard_Integer NbIter
350 ,const Standard_Real DeltaU
351 ,const Standard_Real) {
353 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
355 Standard_Integer nbsamples;
356 done = 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;
774 if(NbIter>NBITER_MAX_POLYGON) return;
776 nbsamplesOnC1 = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
778 //// modified by jgv, 5.12.02 for OCC935 ////
779 if (NbIter == 0) // first time
781 if (nbsamplesOnC1 < 20)
786 if ((D1.LastParameter()-D1.FirstParameter()) > 0.5*(DeltaU))
787 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
789 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
791 /////////////////////////////////////////////
793 nbsamplesOnC2 = TheCurveTool::NbSamples(C2,D2.FirstParameter(),D2.LastParameter());
795 //// modified by jgv, 5.12.02 for OCC935 ////
796 if (NbIter == 0) // first time
798 if (nbsamplesOnC2 < 20)
803 if ((D2.LastParameter()-D2.FirstParameter()) > 0.5*(DeltaV))
804 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
806 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
808 /////////////////////////////////////////////
810 IntCurve_ThePolygon2d *PtrPoly1,*PtrPoly2;
811 if(nbsamplesOnC2 > nbsamplesOnC1) {
812 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
813 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
814 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
817 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,PtrPoly1->Bounding());
818 PtrPoly1->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
819 +PtrPoly1->DeflectionOverEstimation());
820 PtrPoly1->ComputeWithBox(C1,PtrPoly2->Bounding());
824 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
825 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
826 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
829 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,PtrPoly2->Bounding());
830 PtrPoly2->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
831 +PtrPoly1->DeflectionOverEstimation());
832 PtrPoly2->ComputeWithBox(C2,PtrPoly1->Bounding());
835 //----------------------------------------------------------------------
836 //-- Si la deflection est inferieure a la Tolerance de Confusion
837 //-- Alors la deflection du polygone est fixee a TolConf
838 //-- (Detection des Zones de Tangence)
839 //----------------------------------------------------------------------
841 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
842 PtrPoly1->SetDeflectionOverEstimation(TolConf);
844 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
845 PtrPoly2->SetDeflectionOverEstimation(TolConf);
847 IntCurve_InterferencePoly2d InterPP(*PtrPoly1,*PtrPoly2);
848 IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf);
851 //----------------------------------------------------------------------
852 //-- Traitement des SectionPoint
853 //----------------------------------------------------------------------
854 Standard_Integer Nbsp = InterPP.NbSectionPoints();
857 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
858 const Intf_SectionPoint& SPnt = InterPP.PntValue(sp);
859 Standard_Integer SegIndex1,SegIndex2;
860 Standard_Real ParamOn1,ParamOn2;
863 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
864 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
865 EIP.Perform(*PtrPoly1,*PtrPoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
866 AnErrorOccurred = EIP.AnErrorOccurred();
867 if(EIP.NbRoots()>=1) {
868 //--------------------------------------------------------------------
869 //-- On verifie que le point trouve est bien une racine
870 //--------------------------------------------------------------------
872 TheCurveTool::D1(C1,U,P1,Tan1);
873 TheCurveTool::D1(C2,V,P2,Tan2);
874 Standard_Real Dist = P1.Distance(P2);
875 //-----------------------------------------------------------------
876 //-- On verifie que le point (u,v) n existe pas deja
878 done = Standard_True;
879 Standard_Integer nbp=NbPoints();
880 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
881 Standard_Real EpsX2 = 10.0*TheCurveTool::EpsX(C2);
883 for(Standard_Integer p=1; p<=nbp; p++) {
884 const IntRes2d_IntersectionPoint& P=Point(p);
885 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
886 if(Abs(V-P.ParamOnSecond()) <= EpsX2) {
887 Dist = TolConf+1.0; p+=nbp;
892 if(Dist <= TolConf) { //-- Ou le point est deja present
893 IntRes2d_Position Pos1 = IntRes2d_Middle;
894 IntRes2d_Position Pos2 = IntRes2d_Middle;
895 IntRes2d_Transition Trans1,Trans2;
896 //-----------------------------------------------------------------
897 //-- Calcul des Positions des Points sur la courbe
899 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
900 Pos1 = IntRes2d_Head;
901 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
904 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
905 Pos2 = IntRes2d_Head;
906 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
908 //-----------------------------------------------------------------
909 //-- Calcul des Transitions (Voir IntImpParGen.cxx)
911 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
913 ,TolConf)==Standard_False) {
915 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
916 TheCurveTool::D2(C2,V,P2,Tan2,Norm2);
917 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
918 ,Pos2,Tan2,Norm2,Trans2
921 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
924 } //-- if(EIP.NbRoots()>=1)
929 //----------------------------------------------------------------------
930 //-- Traitement des TangentZone
931 //----------------------------------------------------------------------
932 Standard_Integer Nbtz = InterPP.NbTangentZones();
933 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
934 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
935 //====================================================================
936 //== Recherche du premier et du dernier point dans la zone de tg.
937 //====================================================================
938 Standard_Real ParamSupOnCurve2,ParamInfOnCurve2;
939 Standard_Real ParamSupOnCurve1,ParamInfOnCurve1;
940 // Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2,SegIndex2onP1,SegIndex2onP2;
941 Standard_Integer SegIndex1onP1,SegIndex1onP2;
943 Standard_Real ParamOnLine;
944 Standard_Real PolyUInf,PolyUSup,PolyVInf,PolyVSup;
945 ParamSupOnCurve2=ParamSupOnCurve1=PolyUSup=PolyVSup=-RealLast();
946 ParamInfOnCurve2=ParamInfOnCurve1=PolyUInf=PolyVInf= RealLast();
947 for(Standard_Integer qq=1;qq<=NbPnts;qq++) {
948 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(qq);
949 //====================================================================
950 //== On discretise sur les zones de tangence
953 //== Deflection < Tolerance
954 //== OU Echantillon < EpsX (normalement la premiere condition est
956 //====================================================================
957 // Standard_Real _PolyUInf,_PolyUSup,_PolyVInf,_PolyVSup;
958 Standard_Real _PolyUInf,_PolyVInf;
960 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
961 if(SegIndex1onP1 >= PtrPoly1->NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
962 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
963 _PolyUInf = PtrPoly1->ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
965 SPnt1.InfoSecond(Type,SegIndex1onP2,ParamOnLine);
966 if(SegIndex1onP2 >= PtrPoly2->NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; }
967 if(SegIndex1onP2 <= 0) { SegIndex1onP2=1; ParamOnLine = 0.0; }
968 _PolyVInf = PtrPoly2->ApproxParamOnCurve(SegIndex1onP2,ParamOnLine);
970 //----------------------------------------------------------------------
972 if(ParamInfOnCurve1 > _PolyUInf) ParamInfOnCurve1=_PolyUInf;
973 if(ParamInfOnCurve2 > _PolyVInf) ParamInfOnCurve2=_PolyVInf;
975 if(ParamSupOnCurve1 < _PolyUInf) ParamSupOnCurve1=_PolyUInf;
976 if(ParamSupOnCurve2 < _PolyVInf) ParamSupOnCurve2=_PolyVInf;
980 PolyUInf= ParamInfOnCurve1;
981 PolyUSup= ParamSupOnCurve1;
982 PolyVInf= ParamInfOnCurve2;
983 PolyVSup= ParamSupOnCurve2;
985 TheCurveTool::D0(C1,PolyUInf,P1);
986 TheCurveTool::D0(C2,PolyVInf,P2);
987 Standard_Real distmemesens = P1.SquareDistance(P2);
988 TheCurveTool::D0(C2,PolyVSup,P2);
989 Standard_Real distdiffsens = P1.SquareDistance(P2);
990 if(distmemesens > distdiffsens) {
991 Standard_Real qwerty=PolyVInf; PolyVInf=PolyVSup; PolyVSup=qwerty;
996 if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf)
997 ||(PtrPoly2->DeflectionOverEstimation() > TolConf))
998 &&(NbIter<NBITER_MAX_POLYGON)) {
1000 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInfOnCurve1)
1001 ,ParamInfOnCurve1,TolConf
1002 ,TheCurveTool::Value(C1,ParamSupOnCurve1)
1003 ,ParamSupOnCurve1,TolConf);
1004 IntRes2d_Domain RecursD2( TheCurveTool::Value(C2,ParamInfOnCurve2)
1005 ,ParamInfOnCurve2,TolConf
1006 ,TheCurveTool::Value(C2,ParamSupOnCurve2)
1007 ,ParamSupOnCurve2,TolConf);
1008 //-- On ne delete pas PtrPoly1(2) ,
1009 //-- ils sont detruits enfin de fct.
1010 //-- !! Pas de return intempestif !!
1011 Perform(C1,RecursD1,C2,RecursD2,Tol,TolConf,NbIter+1,DeltaU,DeltaV);
1014 //-----------------------------------------------------------------
1015 //-- Calcul des Positions des Points sur la courbe et des
1016 //-- Transitions sur chaque borne du segment
1018 IntRes2d_Position Pos1 = IntRes2d_Middle;
1019 IntRes2d_Position Pos2 = IntRes2d_Middle;
1020 IntRes2d_Transition Trans1,Trans2;
1022 TheCurveTool::D1(C1,PolyUInf,P1,Tan1);
1023 TheCurveTool::D1(C2,PolyVInf,P2,Tan2);
1025 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1026 Pos1 = IntRes2d_Head;
1028 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1029 Pos1 = IntRes2d_End;
1031 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1032 Pos2 = IntRes2d_Head;
1034 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1035 Pos2 = IntRes2d_End;
1038 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1039 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1041 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1042 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1044 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1045 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1048 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1053 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1054 == Standard_False) {
1055 TheCurveTool::D2(C1,PolyUInf,P1,Tan1,Norm1);
1056 TheCurveTool::D2(C2,PolyVInf,P2,Tan2,Norm2);
1057 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1058 Pos2,Tan2,Norm2,Trans2,TolConf);
1060 IntRes2d_IntersectionPoint PtSeg1(P1,PolyUInf,PolyVInf
1061 ,Trans1,Trans2,Standard_False);
1062 //----------------------------------------------------------------------
1064 if((Abs(PolyUInf-PolyUSup) <= TheCurveTool::EpsX(C1))
1065 || (Abs(PolyVInf-PolyVSup) <= TheCurveTool::EpsX(C2))) {
1069 TheCurveTool::D1(C1,PolyUSup,P1,Tan1);
1070 TheCurveTool::D1(C2,PolyVSup,P2,Tan2);
1071 Pos1 = IntRes2d_Middle; Pos2 = IntRes2d_Middle;
1073 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1074 Pos1 = IntRes2d_Head;
1076 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1077 Pos1 = IntRes2d_End;
1079 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1080 Pos2 = IntRes2d_Head;
1082 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1083 Pos2 = IntRes2d_End;
1087 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1088 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1090 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1091 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1093 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1094 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1097 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1100 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1102 TheCurveTool::D2(C1,PolyUSup,P1,Tan1,Norm1);
1103 TheCurveTool::D2(C2,PolyVSup,P2,Tan2,Norm2);
1104 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1105 Pos2,Tan2,Norm2,Trans2,TolConf);
1107 IntRes2d_IntersectionPoint PtSeg2(P1,PolyUSup,PolyVSup
1108 ,Trans1,Trans2,Standard_False);
1112 Standard_Boolean Oppos = (Tan1.Dot(Tan2) > 0.0)? Standard_False : Standard_True;
1113 if(ParamInfOnCurve1 > ParamSupOnCurve1) {
1114 IntRes2d_IntersectionSegment Seg(PtSeg2,PtSeg1,Oppos,Standard_False);
1118 IntRes2d_IntersectionSegment Seg(PtSeg1,PtSeg2,Oppos,Standard_False);
1124 //----------------------------------------------------------------------
1127 done = Standard_True;