Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IntCurve / IntCurve_IntPolyPolyGen.gxx
CommitLineData
7fd59977 1// File: IntCurve_IntPolyPolyGen.gxx
2// Created: Tue Oct 13 11:12:26 1992
3// Author: Laurent BUCHARD
4// <lbr@sdsun2>
5
6// Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169
7
8
9#ifndef DEB
10#define No_Standard_RangeError
11#define No_Standard_OutOfRange
12#endif
13
14
15#include <Standard_ConstructionError.hxx>
16
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>
22
23
24#include <IntImpParGen.hxx>
25
26#include <Intf_SectionPoint.hxx>
27#include <Intf_SectionLine.hxx>
28#include <Intf_TangentZone.hxx>
29
30#include <gp_Vec2d.hxx>
31
32#include <math_Vector.hxx>
33#include <math_FunctionSetRoot.hxx>
34#include <math_NewtonFunctionSetRoot.hxx>
35
36//======================================================================
37
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
44
45//----------------------------------------------------------------------
46
47static Standard_Boolean AnErrorOccurred=Standard_False;
48
49
50
51
52Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
53 ,const TheCurve& C1
54 ,const Standard_Real u
55 ,const IntRes2d_Domain& D2
56 ,const TheCurve& C2
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);
65
66
67//======================================================================
68IntCurve_IntPolyPolyGen::IntCurve_IntPolyPolyGen(void) {
69 done = Standard_False;
70}
71//======================================================================
72void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
73 ,const IntRes2d_Domain& D1
74 ,const TheCurve& C2
75 ,const IntRes2d_Domain& D2
76 ,const Standard_Real TheTolConf
77 ,const Standard_Real TheTol)
78{
79
80 AnErrorOccurred = Standard_False;
81
82 this->ResetFields();
83 DomainOnCurve1=D1;
84 DomainOnCurve2=D2;
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;
97 Standard_Integer i;
98 Standard_Integer n=this->NbPoints();
99
100
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
107 //-- 2 si Head End
108 //-- 4 si End Head
109 //-- 8 si End End
110 //--------------------------------------------------------------------
111 Standard_Integer PosSegment = 0;
112
113
114
115 for(i=1;i<=n;i++) {
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;
119
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;
123
124 if(Pos1 == IntRes2d_Head) {
125 if(Pos2 == IntRes2d_Head) PosSegment|=1;
126 else if(Pos2 == IntRes2d_End) PosSegment|=2;
127 }
128 else if(Pos1 == IntRes2d_End) {
129 if(Pos2 == IntRes2d_Head) PosSegment|=4;
130 else if(Pos2 == IntRes2d_End) PosSegment|=8;
131 }
132 }
133
134 n=this->NbSegments();
135 for(i=1;i<=n;i++) {
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;
139
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;
143
144 if(Pos1 == IntRes2d_Head) {
145 if(Pos2 == IntRes2d_Head) PosSegment|=1;
146 else if(Pos2 == IntRes2d_End) PosSegment|=2;
147 }
148 else if(Pos1 == IntRes2d_End) {
149 if(Pos2 == IntRes2d_Head) PosSegment|=4;
150 else if(Pos2 == IntRes2d_End) PosSegment|=8;
151 }
152
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;
156
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;
160
161 if(Pos1 == IntRes2d_Head) {
162 if(Pos2 == IntRes2d_Head) PosSegment|=1;
163 else if(Pos2 == IntRes2d_End) PosSegment|=2;
164 }
165 else if(Pos1 == IntRes2d_End) {
166 if(Pos2 == IntRes2d_Head) PosSegment|=4;
167 else if(Pos2 == IntRes2d_End) PosSegment|=8;
168 }
169 }
170
171
172
173 Standard_Real U0 = D1.FirstParameter();
174 Standard_Real U1 = D1.LastParameter();
175 Standard_Real V0 = D2.FirstParameter();
176 Standard_Real V1 = D2.LastParameter();
177 Standard_Real v,u;
178 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
179 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
180 IntRes2d_IntersectionPoint IntPt;
181
182 if(D1.FirstTolerance() || D2.FirstTolerance()) {
183 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
184 this->Insert(IntPt);
185 }
186 if(D1.FirstTolerance() || D2.LastTolerance()) {
187 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
188 this->Insert(IntPt);
189 }
190 if(D1.LastTolerance() || D2.FirstTolerance()) {
191 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
192 this->Insert(IntPt);
193 }
194 if(D1.LastTolerance() || D2.LastTolerance()) {
195 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
196 this->Insert(IntPt);
197 }
198 if(AnErrorOccurred) {
199 //----------------------------------------------------------------------------------
200 //-- On a donne un point approche a la recherche du point exact, et cette recherche
201 //-- a echoue.
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.
204 //--
205 //-- Dans le cas contraire, on suppose que les points en bouts ont ete trouves par
206 //-- les interferences des polygones
207 //--
208 if(!HeadOn1) {
209 u = U0;
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))
212 this->Insert(IntPt);
213 }
214
215 if(!EndOn1) {
216 u = U1;
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))
219 this->Insert(IntPt);
220 }
221
222 if(!HeadOn2) {
223 u = TheProjPCur::FindParameter( C1,D2.FirstPoint(),U0,U1,EpsX1);
224 v = V0;
225 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
226 this->Insert(IntPt);
227 }
228
229 if(!EndOn2) {
230 u = TheProjPCur::FindParameter( C1,D2.LastPoint(),U0,U1,EpsX1);
231 v = V1;
232 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
233 this->Insert(IntPt);
234 }
235 }
236}
237
238
239
240
241
242//======================================================================
243//== A u t o I n t e r s e c t i o n
244//======================================================================
245void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
246 ,const IntRes2d_Domain& D1
247 ,const Standard_Real TheTolConf
248 ,const Standard_Real TheTol)
249{
250
251 AnErrorOccurred = Standard_False;
252
253 this->ResetFields();
254 DomainOnCurve1=D1;
255 DomainOnCurve2=D1;
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;
267 Standard_Integer i;
268 Standard_Integer n=this->NbPoints();
269
270
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
277 //-- 2 si Head End
278 //-- 4 si End Head
279 //-- 8 si End End
280 //--------------------------------------------------------------------
281 Standard_Integer PosSegment = 0;
282
283
284
285 for(i=1;i<=n;i++) {
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;
289
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;
293
294 if(Pos1 == IntRes2d_Head) {
295 if(Pos2 == IntRes2d_Head) PosSegment|=1;
296 else if(Pos2 == IntRes2d_End) PosSegment|=2;
297 }
298 else if(Pos1 == IntRes2d_End) {
299 if(Pos2 == IntRes2d_Head) PosSegment|=4;
300 else if(Pos2 == IntRes2d_End) PosSegment|=8;
301 }
302 }
303
304 n=this->NbSegments();
305 for(i=1;i<=n;i++) {
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;
309
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;
313
314 if(Pos1 == IntRes2d_Head) {
315 if(Pos2 == IntRes2d_Head) PosSegment|=1;
316 else if(Pos2 == IntRes2d_End) PosSegment|=2;
317 }
318 else if(Pos1 == IntRes2d_End) {
319 if(Pos2 == IntRes2d_Head) PosSegment|=4;
320 else if(Pos2 == IntRes2d_End) PosSegment|=8;
321 }
322
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;
326
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;
330
331 if(Pos1 == IntRes2d_Head) {
332 if(Pos2 == IntRes2d_Head) PosSegment|=1;
333 else if(Pos2 == IntRes2d_End) PosSegment|=2;
334 }
335 else if(Pos1 == IntRes2d_End) {
336 if(Pos2 == IntRes2d_Head) PosSegment|=4;
337 else if(Pos2 == IntRes2d_End) PosSegment|=8;
338 }
339 }
340}
341//======================================================================
342
343
344
345void 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) {
352
353 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
354 gp_Pnt2d P1,P2;
355 Standard_Integer nbsamples;
356 done = Standard_False;
357
358
359 nbsamples = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
360
361 if(NbIter>3 || (NbIter>2 && nbsamples>100)) return;
362
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.
367
368 if(NbIter>0) {
369 if((D1.LastParameter()-D1.FirstParameter())
370 >0.5*(DeltaU)) {
371 nbsamples=(3*(nbsamples*NbIter)/2);
372 }
373 else {
374 nbsamples=(3*(nbsamples*NbIter))/2;
375 }
376 }
377 IntCurve_ThePolygon2d Poly1(C1,nbsamples,D1,Tol);
378 if(!Poly1.AutoIntersectionIsPossible()) {
379 done = Standard_True;
380 return;
381 }
382 //-- Poly1.Dump();
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);
390 }
391
392 IntCurve_InterferencePoly2d InterPP(Poly1);
393 IntCurve_ExactIntersectionPoint EIP(C1,C1,TolConf);
394 Standard_Real U,V;
395
396 //----------------------------------------------------------------------
397 //-- Traitement des SectionPoint
398 //----------------------------------------------------------------------
399 Standard_Integer Nbsp = InterPP.NbSectionPoints();
400 if(Nbsp>=1) {
401
402 //-- ---------------------------------------------------------------------
403 //-- tri tri tri tri tri tri tri tri tri tri tri tri tri tri
404 //--
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;
412 Intf_PIType Type;
413 Standard_Integer i ;
414 for( i=1;i<=Nbsp;i++) {
415 TriIndex[i]=i;
416 const Intf_SectionPoint& SPnt1 = InterPP.PntValue(i);
417 SPnt1.InfoFirst(Type,PtrSegIndex1[i],ParamOn1);
418 SPnt1.InfoSecond(Type,PtrSegIndex2[i],ParamOn2);
419 }
420
421
422 do {
423 Triok=Standard_True;
424
425 for(Standard_Integer tr=1;tr<Nbsp;tr++) {
426 SegIndex1=PtrSegIndex1[TriIndex[tr]];
427 SegIndex_1=PtrSegIndex1[TriIndex[tr+1]];
428
429 SegIndex2=PtrSegIndex2[TriIndex[tr]];
430 SegIndex_2=PtrSegIndex2[TriIndex[tr+1]];
431
432 if(SegIndex1 > SegIndex_1) {
433 Standard_Integer q=TriIndex[tr];
434 TriIndex[tr]=TriIndex[tr+1];
435 TriIndex[tr+1]=q;
436 Triok=Standard_False;
437 }
438 else if(SegIndex1 == SegIndex_1) {
439 if(SegIndex2 > SegIndex_2) {
440 Standard_Integer q=TriIndex[tr];
441 TriIndex[tr]=TriIndex[tr+1];
442 TriIndex[tr+1]=q;
443 Triok=Standard_False;
444 }
445 }
446 }
447 }
448 while(Triok==Standard_False);
449
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]])) {
454 TriIndex[i]=-i;
455
456 }
457 }
458
459 Standard_Integer Nelarg=(Poly1.NbSegments()/20);
460 if(Nelarg<2) Nelarg=2;
461
462 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
463 if(TriIndex[sp]>0) {
464 const Intf_SectionPoint& SPnt = InterPP.PntValue(TriIndex[sp]);
465
466 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
467 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
468
469 if(Abs(SegIndex1-SegIndex2)>1) {
470
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
479 if( kk > 0 ) {
480 if( Abs(SegIndex1-PtrSegIndex1[kk])< Nelarg
481 && Abs(SegIndex2-PtrSegIndex2[kk])< Nelarg) {
482 TriIndex[k]=-k;
483 }
484 }
485 // modified by OFV OCC2502 Tue Apr 29 15:11:34 2003 .End
486 }
487 }
488 else if(EIP.NbRoots()>=1) {
489 //--------------------------------------------------------------------
490 //-- On verifie que le point trouve est bien une racine
491 //--------------------------------------------------------------------
492 EIP.Roots(U,V);
493
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);
498
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 //-----------------------------------------
505 Dist = TolConf+1.0;
506 }
507
508 //-----------------------------------------------------------------
509 //-- On verifie que le point (u,v) n existe pas deja
510 //--
511 done = Standard_True;
512 Standard_Integer nbp=NbPoints();
513
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;
519 }
520 }
521 }
522
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
529 //--
530 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
531 Pos1 = IntRes2d_Head;
532 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
533 Pos1 = IntRes2d_End;
534
535 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
536 Pos2 = IntRes2d_Head;
537 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
538 Pos2 = IntRes2d_End;
539 //-----------------------------------------------------------------
540 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
541 ,Pos2,Tan2,Trans2
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
547 ,TolConf);
548 }
549 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
550 Insert(IP);
551 }
552 }
553 }
554 }
555 }
556 delete [] TriIndex;
557 delete [] PtrSegIndex1;
558 delete [] PtrSegIndex2;
559 }
560
561
562 //----------------------------------------------------------------------
563 //-- Traitement des TangentZone
564 //----------------------------------------------------------------------
565 Standard_Integer Nbtz = InterPP.NbTangentZones();
566 Nbtz=0;
567 if(Nbtz) {
568 Standard_Real ParamInf=D1.FirstParameter();
569 Standard_Real ParamSup=D1.LastParameter();
570 ParamSup=-RealLast();
571 ParamInf=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);
580
581// Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2;
582 Standard_Integer SegIndex1onP1;
583 Intf_PIType Type;
584 Standard_Real ParamOnLine;
585
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;
592 }
593 }
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)
597 ,ParamInf,TolConf
598 ,TheCurveTool::Value(C1,ParamSup)
599 ,ParamSup,TolConf);
600 Perform(C1,RecursD1,TolConf,Tol,NbIter+1,ParamSup-ParamInf,0.0);
601 }
602 }
603 //----------------------------------------------------------------------
604 done = Standard_True;
605}
606
607
608Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
609 ,const TheCurve& C1
610 ,const Standard_Real tu
611 ,const IntRes2d_Domain& D2
612 ,const TheCurve& C2
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) {
621
622 gp_Pnt2d P1,P2,SP1,SP2;
623 gp_Vec2d T1,T2,N1,N2;
624 Standard_Real u=tu;
625 Standard_Real v=tv;
626 Standard_Real svu = u;
627 Standard_Real svv = v;
628
629 TheCurveTool::D1(C1,u,P1,T1);
630 TheCurveTool::D1(C2,v,P2,T2);
631
632 IntRes2d_Position Pos1 = IntRes2d_Middle;
633 IntRes2d_Position Pos2 = IntRes2d_Middle;
634 IntRes2d_Transition Trans1,Trans2;
635
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();
643 }
644 //----------------------------------------------------------------------
645 //-- End On 1 : End1 <-> P2
646 else if(P2.Distance(D1.LastPoint())<=D1.LastTolerance()) {
647 Pos1 = IntRes2d_End;
648 EndOn1 = Standard_True;
649 SP1 = D1.LastPoint();
650 u = D1.LastParameter();
651 }
652
653
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();
661 }
662 //----------------------------------------------------------------------
663 //-- End On 2 : End2 <-> P1
664 else if(P1.Distance(D2.LastPoint())<=D2.LastTolerance()) {
665 Pos2 = IntRes2d_End;
666 EndOn2 = Standard_True;
667 SP2 = D2.LastPoint();
668 v = D2.LastParameter();
669 }
670
671 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
672 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
673
674
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;
681 }
682 else if(Abs(u-D1.LastParameter()) <= EpsX1) {
683 Pos1 = IntRes2d_End;
684 P1 = D1.LastPoint();
685 EndOn1 = Standard_True;
686 }
687 }
688 else if(u!=tu) {
689 P1 = SP1;
690 }
691
692
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()));
700 }
701 else {
702 P2 = P1;
703 }
704 }
705 else if(Abs(v-D2.LastParameter()) <= EpsX2) {
706 Pos2 = IntRes2d_End;
707 EndOn2 = Standard_True;
708 P2 = D2.LastPoint();
709 if(Pos1 != IntRes2d_Middle) {
710 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
711 }
712 else {
713 P2 = P1;
714 }
715 }
716 }
717
718
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
722 //--
723 //-- PosSegment = 1 si Head Head
724 //-- 2 si Head End
725 //-- 4 si End Head
726 //-- 8 si End End
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);
731 }
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);
735 }
736
737
738 if(IntImpParGen::DetermineTransition( Pos1,T1,Trans1,Pos2,T2,Trans2,TolConf)
739 == Standard_False) {
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);
744 }
745 IntPt.SetValues(P1,u,v,Trans1,Trans2,Standard_False);
746 return(Standard_True);
747 }
748 else
749 return(Standard_False);
750}
751
752
753
754
755
756
757
758//======================================================================
759void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
760 ,const IntRes2d_Domain& D1
761 ,const TheCurve& C2
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) {
768
769 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
770 gp_Pnt2d P1,P2;
771 Standard_Integer nbsamplesOnC1,nbsamplesOnC2;
772 done = Standard_False;
773
774 if(NbIter>NBITER_MAX_POLYGON) return;
775
776 nbsamplesOnC1 = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
777
778 //// modified by jgv, 5.12.02 for OCC935 ////
779 if (NbIter == 0) // first time
780 {
781 if (nbsamplesOnC1 < 20)
782 nbsamplesOnC1 = 20;
783 }
784 else // NbIter > 0
785 {
786 if ((D1.LastParameter()-D1.FirstParameter()) > 0.5*(DeltaU))
787 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
788 else
789 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
790 }
791 /////////////////////////////////////////////
792
793 nbsamplesOnC2 = TheCurveTool::NbSamples(C2,D2.FirstParameter(),D2.LastParameter());
794
795 //// modified by jgv, 5.12.02 for OCC935 ////
796 if (NbIter == 0) // first time
797 {
798 if (nbsamplesOnC2 < 20)
799 nbsamplesOnC2 = 20;
800 }
801 else // NbIter > 0
802 {
803 if ((D2.LastParameter()-D2.FirstParameter()) > 0.5*(DeltaV))
804 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
805 else
806 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
807 }
808 /////////////////////////////////////////////
809
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);
815 }
816 else {
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());
821 }
822 }
823 else {
824 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
825 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
826 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
827 }
828 else {
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());
833 }
834 }
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 //----------------------------------------------------------------------
840
841 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
842 PtrPoly1->SetDeflectionOverEstimation(TolConf);
843 }
844 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
845 PtrPoly2->SetDeflectionOverEstimation(TolConf);
846 }
847 IntCurve_InterferencePoly2d InterPP(*PtrPoly1,*PtrPoly2);
848 IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf);
849 Standard_Real U,V;
850
851 //----------------------------------------------------------------------
852 //-- Traitement des SectionPoint
853 //----------------------------------------------------------------------
854 Standard_Integer Nbsp = InterPP.NbSectionPoints();
855
856 if(Nbsp>=1) {
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;
861 Intf_PIType Type;
862
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 //--------------------------------------------------------------------
871 EIP.Roots(U,V);
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
877 //--
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);
882
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;
888 }
889 }
890 }
891
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
898 //--
899 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
900 Pos1 = IntRes2d_Head;
901 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
902 Pos1 = IntRes2d_End;
903
904 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
905 Pos2 = IntRes2d_Head;
906 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
907 Pos2 = IntRes2d_End;
908 //-----------------------------------------------------------------
909 //-- Calcul des Transitions (Voir IntImpParGen.cxx)
910 //--
911 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
912 ,Pos2,Tan2,Trans2
913 ,TolConf)==Standard_False) {
914
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
919 ,TolConf);
920 }
921 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
922 Insert(IP);
923 }
924 } //-- if(EIP.NbRoots()>=1)
925 }
926 }
927
928
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;
942 Intf_PIType Type;
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
951 //== Test d arret :
952 //== Compteur
953 //== Deflection < Tolerance
954 //== OU Echantillon < EpsX (normalement la premiere condition est
955 //== plus severe)
956 //====================================================================
957// Standard_Real _PolyUInf,_PolyUSup,_PolyVInf,_PolyVSup;
958 Standard_Real _PolyUInf,_PolyVInf;
959
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);
964
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);
969
970 //----------------------------------------------------------------------
971
972 if(ParamInfOnCurve1 > _PolyUInf) ParamInfOnCurve1=_PolyUInf;
973 if(ParamInfOnCurve2 > _PolyVInf) ParamInfOnCurve2=_PolyVInf;
974
975 if(ParamSupOnCurve1 < _PolyUInf) ParamSupOnCurve1=_PolyUInf;
976 if(ParamSupOnCurve2 < _PolyVInf) ParamSupOnCurve2=_PolyVInf;
977
978 }
979
980 PolyUInf= ParamInfOnCurve1;
981 PolyUSup= ParamSupOnCurve1;
982 PolyVInf= ParamInfOnCurve2;
983 PolyVSup= ParamSupOnCurve2;
984
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;
992 }
993
994
995
996 if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf)
997 ||(PtrPoly2->DeflectionOverEstimation() > TolConf))
998 &&(NbIter<NBITER_MAX_POLYGON)) {
999
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);
1012 }
1013 else {
1014 //-----------------------------------------------------------------
1015 //-- Calcul des Positions des Points sur la courbe et des
1016 //-- Transitions sur chaque borne du segment
1017
1018 IntRes2d_Position Pos1 = IntRes2d_Middle;
1019 IntRes2d_Position Pos2 = IntRes2d_Middle;
1020 IntRes2d_Transition Trans1,Trans2;
1021
1022 TheCurveTool::D1(C1,PolyUInf,P1,Tan1);
1023 TheCurveTool::D1(C2,PolyVInf,P2,Tan2);
1024
1025 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1026 Pos1 = IntRes2d_Head;
1027 }
1028 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1029 Pos1 = IntRes2d_End;
1030 }
1031 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1032 Pos2 = IntRes2d_Head;
1033 }
1034 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1035 Pos2 = IntRes2d_End;
1036 }
1037
1038 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1039 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1040 }
1041 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1042 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1043 }
1044 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1045 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1046 }
1047 else {
1048 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1049 }
1050
1051
1052
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);
1059 }
1060 IntRes2d_IntersectionPoint PtSeg1(P1,PolyUInf,PolyVInf
1061 ,Trans1,Trans2,Standard_False);
1062 //----------------------------------------------------------------------
1063
1064 if((Abs(PolyUInf-PolyUSup) <= TheCurveTool::EpsX(C1))
1065 || (Abs(PolyVInf-PolyVSup) <= TheCurveTool::EpsX(C2))) {
1066 Insert(PtSeg1);
1067 }
1068 else {
1069 TheCurveTool::D1(C1,PolyUSup,P1,Tan1);
1070 TheCurveTool::D1(C2,PolyVSup,P2,Tan2);
1071 Pos1 = IntRes2d_Middle; Pos2 = IntRes2d_Middle;
1072
1073 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1074 Pos1 = IntRes2d_Head;
1075 }
1076 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1077 Pos1 = IntRes2d_End;
1078 }
1079 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1080 Pos2 = IntRes2d_Head;
1081 }
1082 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1083 Pos2 = IntRes2d_End;
1084 }
1085
1086
1087 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1088 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1089 }
1090 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1091 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1092 }
1093 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1094 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1095 }
1096 else {
1097 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1098 }
1099
1100 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1101 ==Standard_False) {
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);
1106 }
1107 IntRes2d_IntersectionPoint PtSeg2(P1,PolyUSup,PolyVSup
1108 ,Trans1,Trans2,Standard_False);
1109
1110
1111
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);
1115 Append(Seg);
1116 }
1117 else {
1118 IntRes2d_IntersectionSegment Seg(PtSeg1,PtSeg2,Oppos,Standard_False);
1119 Append(Seg);
1120 }
1121 }
1122 }
1123 }
1124 //----------------------------------------------------------------------
1125 delete PtrPoly1;
1126 delete PtrPoly2;
1127 done = Standard_True;
1128}
1129