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)
253 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
254 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
255 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
256 Perform(C1,D1,TlConf,Tl,0,DU,DU);
257 //----------------------------------------------------------------------
258 //-- Traitement des points en bouts
259 //----------------------------------------------------------------------
260 Standard_Boolean HeadOn1 = Standard_False;
261 Standard_Boolean HeadOn2 = Standard_False;
262 Standard_Boolean EndOn1 = Standard_False;
263 Standard_Boolean EndOn2 = Standard_False;
265 Standard_Integer n=this->NbPoints();
268 //--------------------------------------------------------------------
269 //-- On ne rejette les points Head Head ... End End
270 //-- si ils figurent deja dans un bout de segment
271 //-- ( On ne peut pas tester les egalites sur les parametres)
272 //-- ( ces points n etant pas trouves a EpsX pres )
273 //-- PosSegment = 1 si Head Head
277 //--------------------------------------------------------------------
278 Standard_Integer PosSegment = 0;
283 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
284 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
285 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
287 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
288 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
289 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
291 if(Pos1 == IntRes2d_Head) {
292 if(Pos2 == IntRes2d_Head) PosSegment|=1;
293 else if(Pos2 == IntRes2d_End) PosSegment|=2;
295 else if(Pos1 == IntRes2d_End) {
296 if(Pos2 == IntRes2d_Head) PosSegment|=4;
297 else if(Pos2 == IntRes2d_End) PosSegment|=8;
301 n=this->NbSegments();
303 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
304 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
305 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
307 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
308 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
309 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
311 if(Pos1 == IntRes2d_Head) {
312 if(Pos2 == IntRes2d_Head) PosSegment|=1;
313 else if(Pos2 == IntRes2d_End) PosSegment|=2;
315 else if(Pos1 == IntRes2d_End) {
316 if(Pos2 == IntRes2d_Head) PosSegment|=4;
317 else if(Pos2 == IntRes2d_End) PosSegment|=8;
320 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
321 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
322 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
324 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
325 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
326 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
328 if(Pos1 == IntRes2d_Head) {
329 if(Pos2 == IntRes2d_Head) PosSegment|=1;
330 else if(Pos2 == IntRes2d_End) PosSegment|=2;
332 else if(Pos1 == IntRes2d_End) {
333 if(Pos2 == IntRes2d_Head) PosSegment|=4;
334 else if(Pos2 == IntRes2d_End) PosSegment|=8;
338 //======================================================================
342 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
343 ,const IntRes2d_Domain& D1
344 ,const Standard_Real TolConf
345 ,const Standard_Real Tol
346 ,const Standard_Integer NbIter
347 ,const Standard_Real DeltaU
348 ,const Standard_Real) {
350 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
352 Standard_Integer nbsamples;
353 done = Standard_False;
354 Standard_Boolean AnErrorOccurred = Standard_False;
357 nbsamples = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
359 if(NbIter>3 || (NbIter>2 && nbsamples>100)) return;
361 nbsamples*=2; //--- On prend systematiquement 2 fois plus de points que
362 //-- sur une courbe normale.
363 //-- Les courbes auto-intersectantes donne souvent des
364 //-- polygones assez loin de la courbe a parametre ct.
367 if((D1.LastParameter()-D1.FirstParameter())
369 nbsamples=(3*(nbsamples*NbIter)/2);
372 nbsamples=(3*(nbsamples*NbIter))/2;
375 IntCurve_ThePolygon2d Poly1(C1,nbsamples,D1,Tol);
376 if(!Poly1.AutoIntersectionIsPossible()) {
377 done = Standard_True;
381 //----------------------------------------------------------------------
382 //-- Si la deflection est inferieure a la Tolerance de Confusion
383 //-- Alors la deflection du polygone est fixee a TolConf
384 //-- (Detection des Zones de Tangence)
385 //----------------------------------------------------------------------
386 if(Poly1.DeflectionOverEstimation() < TolConf) {
387 Poly1.SetDeflectionOverEstimation(TolConf);
390 IntCurve_InterferencePoly2d InterPP(Poly1);
391 IntCurve_ExactIntersectionPoint EIP(C1,C1,TolConf);
394 //----------------------------------------------------------------------
395 //-- Traitement des SectionPoint
396 //----------------------------------------------------------------------
397 Standard_Integer Nbsp = InterPP.NbSectionPoints();
400 //-- ---------------------------------------------------------------------
401 //-- tri tri tri tri tri tri tri tri tri tri tri tri tri tri
403 Standard_Integer* TriIndex = new Standard_Integer [Nbsp+1];
404 Standard_Integer* PtrSegIndex1 = new Standard_Integer [Nbsp+1];
405 Standard_Integer* PtrSegIndex2 = new Standard_Integer [Nbsp+1];
406 Standard_Boolean Triok;
407 Standard_Integer SegIndex1,SegIndex2,SegIndex_1,SegIndex_2;
408 // Standard_Real ParamOn1,ParamOn2,ParamOn_1,ParamOn_2;
409 Standard_Real ParamOn1,ParamOn2;
412 for( i=1;i<=Nbsp;i++) {
414 const Intf_SectionPoint& SPnt1 = InterPP.PntValue(i);
415 SPnt1.InfoFirst(Type,PtrSegIndex1[i],ParamOn1);
416 SPnt1.InfoSecond(Type,PtrSegIndex2[i],ParamOn2);
423 for(Standard_Integer tr=1;tr<Nbsp;tr++) {
424 SegIndex1=PtrSegIndex1[TriIndex[tr]];
425 SegIndex_1=PtrSegIndex1[TriIndex[tr+1]];
427 SegIndex2=PtrSegIndex2[TriIndex[tr]];
428 SegIndex_2=PtrSegIndex2[TriIndex[tr+1]];
430 if(SegIndex1 > SegIndex_1) {
431 Standard_Integer q=TriIndex[tr];
432 TriIndex[tr]=TriIndex[tr+1];
434 Triok=Standard_False;
436 else if(SegIndex1 == SegIndex_1) {
437 if(SegIndex2 > SegIndex_2) {
438 Standard_Integer q=TriIndex[tr];
439 TriIndex[tr]=TriIndex[tr+1];
441 Triok=Standard_False;
446 while(Triok==Standard_False);
448 //-- supression des doublons Si Si !
449 for(i=1; i<Nbsp;i++) {
450 if( (PtrSegIndex1[TriIndex[i]] == PtrSegIndex1[TriIndex[i+1]])
451 && (PtrSegIndex2[TriIndex[i]] == PtrSegIndex2[TriIndex[i+1]])) {
457 Standard_Integer Nelarg=(Poly1.NbSegments()/20);
458 if(Nelarg<2) Nelarg=2;
460 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
462 const Intf_SectionPoint& SPnt = InterPP.PntValue(TriIndex[sp]);
464 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
465 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
467 if(Abs(SegIndex1-SegIndex2)>1) {
469 EIP.Perform(Poly1,Poly1,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
470 AnErrorOccurred = EIP.AnErrorOccurred();
471 if(EIP.NbRoots()==0) {
472 //-- On supprime tous les segments voisins
473 for(Standard_Integer k=sp+1;k<=Nbsp;k++) {
474 Standard_Integer kk=TriIndex[k];
475 // modified by OFV OCC2502 Tue Apr 29 15:07:45 2003 .Begin
476 // --- avoid negative indicies as well as in outer done
478 if( Abs(SegIndex1-PtrSegIndex1[kk])< Nelarg
479 && Abs(SegIndex2-PtrSegIndex2[kk])< Nelarg) {
483 // modified by OFV OCC2502 Tue Apr 29 15:11:34 2003 .End
486 else if(EIP.NbRoots()>=1) {
487 //--------------------------------------------------------------------
488 //-- On verifie que le point trouve est bien une racine
489 //--------------------------------------------------------------------
492 TheCurveTool::D1(C1,U,P1,Tan1);
493 TheCurveTool::D1(C1,V,P2,Tan2);
494 Standard_Real Dist = P1.Distance(P2);
495 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
497 if(Abs(U-V)<=EpsX1) {
498 //-----------------------------------------
499 //-- Solution non valide
500 //-- Les maths ont du converger vers une
501 //-- solution triviale ( point U = V )
502 //-----------------------------------------
506 //-----------------------------------------------------------------
507 //-- On verifie que le point (u,v) n existe pas deja
509 done = Standard_True;
510 Standard_Integer nbp=NbPoints();
512 for(Standard_Integer p=1; p<=nbp; p++) {
513 const IntRes2d_IntersectionPoint& P=Point(p);
514 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
515 if(Abs(V-P.ParamOnSecond()) <= EpsX1) {
516 Dist = TolConf+1.0; p+=nbp;
521 if(Dist <= TolConf) { //-- Ou le point est deja present
522 IntRes2d_Position Pos1 = IntRes2d_Middle;
523 IntRes2d_Position Pos2 = IntRes2d_Middle;
524 IntRes2d_Transition Trans1,Trans2;
525 //-----------------------------------------------------------------
526 //-- Calcul des Positions des Points sur la courbe
528 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
529 Pos1 = IntRes2d_Head;
530 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
533 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
534 Pos2 = IntRes2d_Head;
535 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
537 //-----------------------------------------------------------------
538 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
540 ,TolConf) == Standard_False) {
541 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
542 TheCurveTool::D2(C1,V,P2,Tan2,Norm2);
543 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
544 ,Pos2,Tan2,Norm2,Trans2
547 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
555 delete [] PtrSegIndex1;
556 delete [] PtrSegIndex2;
560 //----------------------------------------------------------------------
561 //-- Traitement des TangentZone
562 //----------------------------------------------------------------------
563 Standard_Integer Nbtz = InterPP.NbTangentZones();
566 Standard_Real ParamInf=D1.FirstParameter();
567 Standard_Real ParamSup=D1.LastParameter();
568 ParamSup=-RealLast();
570 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
571 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
572 //====================================================================
573 //== Recherche du premier et du dernier point dans la zone de tg.
574 //== ATTENTION LA LISTE N EST PAS TRIEE
575 //====================================================================
576 for(Standard_Integer tzz=1; tzz<=NbPnts; tzz++) {
577 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(tzz);
579 // Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2;
580 Standard_Integer SegIndex1onP1;
582 Standard_Real ParamOnLine;
584 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
585 if(SegIndex1onP1 >= Poly1.NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
586 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
587 Standard_Real Par = Poly1.ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
588 if(ParamSup<Par) ParamSup=Par;
589 if(ParamInf>Par) ParamInf=Par;
592 if(ParamSup > ParamInf) {
593 //-- printf("\n %g -> %g %g -> %g ",D1.FirstParameter(),ParamInf,D1.LastParameter(),ParamSup);
594 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInf)
596 ,TheCurveTool::Value(C1,ParamSup)
598 Perform(C1,RecursD1,TolConf,Tol,NbIter+1,ParamSup-ParamInf,0.0);
601 //----------------------------------------------------------------------
602 done = Standard_True;
606 Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
608 ,const Standard_Real tu
609 ,const IntRes2d_Domain& D2
611 ,const Standard_Real tv
612 ,const Standard_Real TolConf
613 ,IntRes2d_IntersectionPoint& IntPt
614 ,Standard_Boolean& HeadOn1
615 ,Standard_Boolean& HeadOn2
616 ,Standard_Boolean& EndOn1
617 ,Standard_Boolean& EndOn2
618 ,Standard_Integer PosSegment) {
620 gp_Pnt2d P1,P2,SP1,SP2;
621 gp_Vec2d T1,T2,N1,N2;
624 Standard_Real svu = u;
625 Standard_Real svv = v;
627 TheCurveTool::D1(C1,u,P1,T1);
628 TheCurveTool::D1(C2,v,P2,T2);
630 IntRes2d_Position Pos1 = IntRes2d_Middle;
631 IntRes2d_Position Pos2 = IntRes2d_Middle;
632 IntRes2d_Transition Trans1,Trans2;
634 //----------------------------------------------------------------------
635 //-- Head On 1 : Head1 <-> P2
636 if(P2.Distance(D1.FirstPoint())<=D1.FirstTolerance()) {
637 Pos1 = IntRes2d_Head;
638 HeadOn1 = Standard_True;
639 SP1 = D1.FirstPoint();
640 u = D1.FirstParameter();
642 //----------------------------------------------------------------------
643 //-- End On 1 : End1 <-> P2
644 else if(P2.Distance(D1.LastPoint())<=D1.LastTolerance()) {
646 EndOn1 = Standard_True;
647 SP1 = D1.LastPoint();
648 u = D1.LastParameter();
652 //----------------------------------------------------------------------
653 //-- Head On 2 : Head2 <-> P1
654 else if(P1.Distance(D2.FirstPoint())<=D2.FirstTolerance()) {
655 Pos2 = IntRes2d_Head;
656 HeadOn2 = Standard_True;
657 SP2 = D2.FirstPoint();
658 v = D2.FirstParameter();
660 //----------------------------------------------------------------------
661 //-- End On 2 : End2 <-> P1
662 else if(P1.Distance(D2.LastPoint())<=D2.LastTolerance()) {
664 EndOn2 = Standard_True;
665 SP2 = D2.LastPoint();
666 v = D2.LastParameter();
669 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
670 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
673 if((Pos1 != IntRes2d_Middle)||(Pos2 != IntRes2d_Middle)) {
674 if(Pos1 == IntRes2d_Middle) {
675 if(Abs(u-D1.FirstParameter()) <= EpsX1) {
676 Pos1 = IntRes2d_Head;
677 P1 = D1.FirstPoint();
678 HeadOn1 = Standard_True;
680 else if(Abs(u-D1.LastParameter()) <= EpsX1) {
683 EndOn1 = Standard_True;
691 if(Pos2 == IntRes2d_Middle) {
692 if(Abs(v-D2.FirstParameter()) <= EpsX2) {
693 Pos2 = IntRes2d_Head;
694 HeadOn2 = Standard_True;
695 P2 = D2.FirstPoint();
696 if(Pos1 != IntRes2d_Middle) {
697 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
703 else if(Abs(v-D2.LastParameter()) <= EpsX2) {
705 EndOn2 = Standard_True;
707 if(Pos1 != IntRes2d_Middle) {
708 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
717 //--------------------------------------------------------------------
718 //-- On Teste si un point de bout de segment a deja ces trnasitions
719 //-- Si Oui, on ne cree pas de nouveau point
721 //-- PosSegment = 1 si Head Head
725 //--------------------------------------------------------------------
726 if(Pos1 == IntRes2d_Head) {
727 if((Pos2 == IntRes2d_Head)&&(PosSegment & 1)) return(Standard_False);
728 if((Pos2 == IntRes2d_End )&&(PosSegment & 2)) return(Standard_False);
730 else if(Pos1 == IntRes2d_End) {
731 if((Pos2 == IntRes2d_Head)&&(PosSegment & 4)) return(Standard_False);
732 if((Pos2 == IntRes2d_End )&&(PosSegment & 8)) return(Standard_False);
736 if(IntImpParGen::DetermineTransition( Pos1,T1,Trans1,Pos2,T2,Trans2,TolConf)
738 TheCurveTool::D2(C1,svu,P1,T1,N1);
739 TheCurveTool::D2(C2,svv,P2,T2,N2);
740 IntImpParGen::DetermineTransition(Pos1,T1,N1,Trans1,
741 Pos2,T2,N2,Trans2,TolConf);
743 IntPt.SetValues(P1,u,v,Trans1,Trans2,Standard_False);
744 return(Standard_True);
747 return(Standard_False);
756 //======================================================================
757 void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
758 ,const IntRes2d_Domain& D1
760 ,const IntRes2d_Domain& D2
761 ,const Standard_Real TolConf
762 ,const Standard_Real Tol
763 ,const Standard_Integer NbIter
764 ,const Standard_Real DeltaU
765 ,const Standard_Real DeltaV) {
767 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
769 Standard_Integer nbsamplesOnC1,nbsamplesOnC2;
770 done = Standard_False;
771 Standard_Boolean AnErrorOccurred = Standard_False;
773 if(NbIter>NBITER_MAX_POLYGON) return;
775 nbsamplesOnC1 = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
777 //// modified by jgv, 5.12.02 for OCC935 ////
778 if (NbIter == 0) // first time
780 if (nbsamplesOnC1 < 20)
785 if ((D1.LastParameter()-D1.FirstParameter()) > 0.5*(DeltaU))
786 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
788 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
790 /////////////////////////////////////////////
792 nbsamplesOnC2 = TheCurveTool::NbSamples(C2,D2.FirstParameter(),D2.LastParameter());
794 //// modified by jgv, 5.12.02 for OCC935 ////
795 if (NbIter == 0) // first time
797 if (nbsamplesOnC2 < 20)
802 if ((D2.LastParameter()-D2.FirstParameter()) > 0.5*(DeltaV))
803 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
805 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
807 /////////////////////////////////////////////
809 IntCurve_ThePolygon2d *PtrPoly1,*PtrPoly2;
810 if(nbsamplesOnC2 > nbsamplesOnC1) {
811 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
812 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
813 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
816 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,PtrPoly1->Bounding());
817 PtrPoly1->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
818 +PtrPoly1->DeflectionOverEstimation());
819 PtrPoly1->ComputeWithBox(C1,PtrPoly2->Bounding());
823 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
824 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
825 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
828 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,PtrPoly2->Bounding());
829 PtrPoly2->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
830 +PtrPoly1->DeflectionOverEstimation());
831 PtrPoly2->ComputeWithBox(C2,PtrPoly1->Bounding());
834 //----------------------------------------------------------------------
835 //-- Si la deflection est inferieure a la Tolerance de Confusion
836 //-- Alors la deflection du polygone est fixee a TolConf
837 //-- (Detection des Zones de Tangence)
838 //----------------------------------------------------------------------
840 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
841 PtrPoly1->SetDeflectionOverEstimation(TolConf);
843 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
844 PtrPoly2->SetDeflectionOverEstimation(TolConf);
846 IntCurve_InterferencePoly2d InterPP(*PtrPoly1,*PtrPoly2);
847 IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf);
850 //----------------------------------------------------------------------
851 //-- Traitement des SectionPoint
852 //----------------------------------------------------------------------
853 Standard_Integer Nbsp = InterPP.NbSectionPoints();
856 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
857 const Intf_SectionPoint& SPnt = InterPP.PntValue(sp);
858 Standard_Integer SegIndex1,SegIndex2;
859 Standard_Real ParamOn1,ParamOn2;
862 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
863 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
864 EIP.Perform(*PtrPoly1,*PtrPoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
865 AnErrorOccurred = EIP.AnErrorOccurred();
866 if(EIP.NbRoots()>=1) {
867 //--------------------------------------------------------------------
868 //-- On verifie que le point trouve est bien une racine
869 //--------------------------------------------------------------------
871 TheCurveTool::D1(C1,U,P1,Tan1);
872 TheCurveTool::D1(C2,V,P2,Tan2);
873 Standard_Real Dist = P1.Distance(P2);
874 //-----------------------------------------------------------------
875 //-- On verifie que le point (u,v) n existe pas deja
877 done = Standard_True;
878 Standard_Integer nbp=NbPoints();
879 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
880 Standard_Real EpsX2 = 10.0*TheCurveTool::EpsX(C2);
882 for(Standard_Integer p=1; p<=nbp; p++) {
883 const IntRes2d_IntersectionPoint& P=Point(p);
884 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
885 if(Abs(V-P.ParamOnSecond()) <= EpsX2) {
886 Dist = TolConf+1.0; p+=nbp;
891 if(Dist <= TolConf) { //-- Ou le point est deja present
892 IntRes2d_Position Pos1 = IntRes2d_Middle;
893 IntRes2d_Position Pos2 = IntRes2d_Middle;
894 IntRes2d_Transition Trans1,Trans2;
895 //-----------------------------------------------------------------
896 //-- Calcul des Positions des Points sur la courbe
898 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
899 Pos1 = IntRes2d_Head;
900 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
903 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
904 Pos2 = IntRes2d_Head;
905 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
907 //-----------------------------------------------------------------
908 //-- Calcul des Transitions (Voir IntImpParGen.cxx)
910 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
912 ,TolConf)==Standard_False) {
914 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
915 TheCurveTool::D2(C2,V,P2,Tan2,Norm2);
916 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
917 ,Pos2,Tan2,Norm2,Trans2
920 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
923 } //-- if(EIP.NbRoots()>=1)
928 //----------------------------------------------------------------------
929 //-- Traitement des TangentZone
930 //----------------------------------------------------------------------
931 Standard_Integer Nbtz = InterPP.NbTangentZones();
932 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
933 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
934 //====================================================================
935 //== Recherche du premier et du dernier point dans la zone de tg.
936 //====================================================================
937 Standard_Real ParamSupOnCurve2,ParamInfOnCurve2;
938 Standard_Real ParamSupOnCurve1,ParamInfOnCurve1;
939 // Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2,SegIndex2onP1,SegIndex2onP2;
940 Standard_Integer SegIndex1onP1,SegIndex1onP2;
942 Standard_Real ParamOnLine;
943 Standard_Real PolyUInf,PolyUSup,PolyVInf,PolyVSup;
944 ParamSupOnCurve2=ParamSupOnCurve1=PolyUSup=PolyVSup=-RealLast();
945 ParamInfOnCurve2=ParamInfOnCurve1=PolyUInf=PolyVInf= RealLast();
946 for(Standard_Integer qq=1;qq<=NbPnts;qq++) {
947 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(qq);
948 //====================================================================
949 //== On discretise sur les zones de tangence
952 //== Deflection < Tolerance
953 //== OU Echantillon < EpsX (normalement la premiere condition est
955 //====================================================================
956 // Standard_Real _PolyUInf,_PolyUSup,_PolyVInf,_PolyVSup;
957 Standard_Real _PolyUInf,_PolyVInf;
959 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
960 if(SegIndex1onP1 >= PtrPoly1->NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
961 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
962 _PolyUInf = PtrPoly1->ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
964 SPnt1.InfoSecond(Type,SegIndex1onP2,ParamOnLine);
965 if(SegIndex1onP2 >= PtrPoly2->NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; }
966 if(SegIndex1onP2 <= 0) { SegIndex1onP2=1; ParamOnLine = 0.0; }
967 _PolyVInf = PtrPoly2->ApproxParamOnCurve(SegIndex1onP2,ParamOnLine);
969 //----------------------------------------------------------------------
971 if(ParamInfOnCurve1 > _PolyUInf) ParamInfOnCurve1=_PolyUInf;
972 if(ParamInfOnCurve2 > _PolyVInf) ParamInfOnCurve2=_PolyVInf;
974 if(ParamSupOnCurve1 < _PolyUInf) ParamSupOnCurve1=_PolyUInf;
975 if(ParamSupOnCurve2 < _PolyVInf) ParamSupOnCurve2=_PolyVInf;
979 PolyUInf= ParamInfOnCurve1;
980 PolyUSup= ParamSupOnCurve1;
981 PolyVInf= ParamInfOnCurve2;
982 PolyVSup= ParamSupOnCurve2;
984 TheCurveTool::D0(C1,PolyUInf,P1);
985 TheCurveTool::D0(C2,PolyVInf,P2);
986 Standard_Real distmemesens = P1.SquareDistance(P2);
987 TheCurveTool::D0(C2,PolyVSup,P2);
988 Standard_Real distdiffsens = P1.SquareDistance(P2);
989 if(distmemesens > distdiffsens) {
990 Standard_Real qwerty=PolyVInf; PolyVInf=PolyVSup; PolyVSup=qwerty;
995 if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf)
996 ||(PtrPoly2->DeflectionOverEstimation() > TolConf))
997 &&(NbIter<NBITER_MAX_POLYGON)) {
999 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInfOnCurve1)
1000 ,ParamInfOnCurve1,TolConf
1001 ,TheCurveTool::Value(C1,ParamSupOnCurve1)
1002 ,ParamSupOnCurve1,TolConf);
1003 IntRes2d_Domain RecursD2( TheCurveTool::Value(C2,ParamInfOnCurve2)
1004 ,ParamInfOnCurve2,TolConf
1005 ,TheCurveTool::Value(C2,ParamSupOnCurve2)
1006 ,ParamSupOnCurve2,TolConf);
1007 //-- On ne delete pas PtrPoly1(2) ,
1008 //-- ils sont detruits enfin de fct.
1009 //-- !! Pas de return intempestif !!
1010 Perform(C1,RecursD1,C2,RecursD2,Tol,TolConf,NbIter+1,DeltaU,DeltaV);
1013 //-----------------------------------------------------------------
1014 //-- Calcul des Positions des Points sur la courbe et des
1015 //-- Transitions sur chaque borne du segment
1017 IntRes2d_Position Pos1 = IntRes2d_Middle;
1018 IntRes2d_Position Pos2 = IntRes2d_Middle;
1019 IntRes2d_Transition Trans1,Trans2;
1021 TheCurveTool::D1(C1,PolyUInf,P1,Tan1);
1022 TheCurveTool::D1(C2,PolyVInf,P2,Tan2);
1024 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1025 Pos1 = IntRes2d_Head;
1027 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1028 Pos1 = IntRes2d_End;
1030 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1031 Pos2 = IntRes2d_Head;
1033 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1034 Pos2 = IntRes2d_End;
1037 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1038 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1040 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1041 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1043 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1044 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1047 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1052 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1053 == Standard_False) {
1054 TheCurveTool::D2(C1,PolyUInf,P1,Tan1,Norm1);
1055 TheCurveTool::D2(C2,PolyVInf,P2,Tan2,Norm2);
1056 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1057 Pos2,Tan2,Norm2,Trans2,TolConf);
1059 IntRes2d_IntersectionPoint PtSeg1(P1,PolyUInf,PolyVInf
1060 ,Trans1,Trans2,Standard_False);
1061 //----------------------------------------------------------------------
1063 if((Abs(PolyUInf-PolyUSup) <= TheCurveTool::EpsX(C1))
1064 || (Abs(PolyVInf-PolyVSup) <= TheCurveTool::EpsX(C2))) {
1068 TheCurveTool::D1(C1,PolyUSup,P1,Tan1);
1069 TheCurveTool::D1(C2,PolyVSup,P2,Tan2);
1070 Pos1 = IntRes2d_Middle; Pos2 = IntRes2d_Middle;
1072 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1073 Pos1 = IntRes2d_Head;
1075 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1076 Pos1 = IntRes2d_End;
1078 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1079 Pos2 = IntRes2d_Head;
1081 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1082 Pos2 = IntRes2d_End;
1086 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1087 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1089 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1090 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1092 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1093 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1096 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1099 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1101 TheCurveTool::D2(C1,PolyUSup,P1,Tan1,Norm1);
1102 TheCurveTool::D2(C2,PolyVSup,P2,Tan2,Norm2);
1103 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1104 Pos2,Tan2,Norm2,Trans2,TolConf);
1106 IntRes2d_IntersectionPoint PtSeg2(P1,PolyUSup,PolyVSup
1107 ,Trans1,Trans2,Standard_False);
1111 Standard_Boolean Oppos = (Tan1.Dot(Tan2) > 0.0)? Standard_False : Standard_True;
1112 if(ParamInfOnCurve1 > ParamSupOnCurve1) {
1113 IntRes2d_IntersectionSegment Seg(PtSeg2,PtSeg1,Oppos,Standard_False);
1117 IntRes2d_IntersectionSegment Seg(PtSeg1,PtSeg2,Oppos,Standard_False);
1123 //----------------------------------------------------------------------
1126 done = Standard_True;