0023468: Include current branch name into default name of directory for test results
[occt.git] / src / IntCurve / IntCurve_IntPolyPolyGen.gxx
CommitLineData
b311480e 1// Created on: 1992-10-13
2// Created by: Laurent BUCHARD
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22// Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169
23
24
25#ifndef DEB
26#define No_Standard_RangeError
27#define No_Standard_OutOfRange
28#endif
29
30
31#include <Standard_ConstructionError.hxx>
32
33#include <IntRes2d_Domain.hxx>
34#include <IntRes2d_Position.hxx>
35#include <IntRes2d_Transition.hxx>
36#include <IntRes2d_IntersectionPoint.hxx>
37#include <IntRes2d_IntersectionSegment.hxx>
38
39
40#include <IntImpParGen.hxx>
41
42#include <Intf_SectionPoint.hxx>
43#include <Intf_SectionLine.hxx>
44#include <Intf_TangentZone.hxx>
9530af27 45#include <Intf_InterferencePolygon2d.hxx>
7fd59977 46
47#include <gp_Vec2d.hxx>
48
49#include <math_Vector.hxx>
50#include <math_FunctionSetRoot.hxx>
51#include <math_NewtonFunctionSetRoot.hxx>
52
53//======================================================================
54
55// Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169 Begin
56// #define NBITER_MAX_POLYGON 3
57#define NBITER_MAX_POLYGON 10
58// Modified by skv - Tue Mar 1 14:22:09 2005 OCC8169 End
59#define TOL_CONF_MINI 0.0000000001
60#define TOL_MINI 0.0000000001
61
62//----------------------------------------------------------------------
63
7fd59977 64
65
66
67
68Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
69 ,const TheCurve& C1
70 ,const Standard_Real u
71 ,const IntRes2d_Domain& D2
72 ,const TheCurve& C2
73 ,const Standard_Real v
74 ,const Standard_Real TolConf
75 ,IntRes2d_IntersectionPoint& IntPt
76 ,Standard_Boolean& HeadOn1
77 ,Standard_Boolean& HeadOn2
78 ,Standard_Boolean& EndOn1
79 ,Standard_Boolean& EndOn2
80 ,Standard_Integer PosSegment);
81
82
83//======================================================================
84IntCurve_IntPolyPolyGen::IntCurve_IntPolyPolyGen(void) {
85 done = Standard_False;
86}
87//======================================================================
88void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
89 ,const IntRes2d_Domain& D1
90 ,const TheCurve& C2
91 ,const IntRes2d_Domain& D2
92 ,const Standard_Real TheTolConf
93 ,const Standard_Real TheTol)
94{
95
41194117 96 Standard_Boolean AnErrorOccurred = Standard_False;
7fd59977 97
98 this->ResetFields();
99 DomainOnCurve1=D1;
100 DomainOnCurve2=D2;
101 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
102 Standard_Real DV = D2.LastParameter()-D2.FirstParameter();
103 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
104 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
105 Perform(C1,D1,C2,D2,TlConf,Tl,0,DU,DV);
106 //----------------------------------------------------------------------
107 //-- Traitement des points en bouts
108 //----------------------------------------------------------------------
109 Standard_Boolean HeadOn1 = Standard_False;
110 Standard_Boolean HeadOn2 = Standard_False;
111 Standard_Boolean EndOn1 = Standard_False;
112 Standard_Boolean EndOn2 = Standard_False;
113 Standard_Integer i;
114 Standard_Integer n=this->NbPoints();
115
116
117 //--------------------------------------------------------------------
118 //-- On ne rejette les points Head Head ... End End
119 //-- si ils figurent deja dans un bout de segment
120 //-- ( On ne peut pas tester les egalites sur les parametres)
121 //-- ( ces points n etant pas trouves a EpsX pres )
122 //-- PosSegment = 1 si Head Head
123 //-- 2 si Head End
124 //-- 4 si End Head
125 //-- 8 si End End
126 //--------------------------------------------------------------------
127 Standard_Integer PosSegment = 0;
128
129
130
131 for(i=1;i<=n;i++) {
132 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
133 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
134 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
135
136 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
137 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
138 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
139
140 if(Pos1 == IntRes2d_Head) {
141 if(Pos2 == IntRes2d_Head) PosSegment|=1;
142 else if(Pos2 == IntRes2d_End) PosSegment|=2;
143 }
144 else if(Pos1 == IntRes2d_End) {
145 if(Pos2 == IntRes2d_Head) PosSegment|=4;
146 else if(Pos2 == IntRes2d_End) PosSegment|=8;
147 }
148 }
149
150 n=this->NbSegments();
151 for(i=1;i<=n;i++) {
152 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
153 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
154 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
155
156 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
157 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
158 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
159
160 if(Pos1 == IntRes2d_Head) {
161 if(Pos2 == IntRes2d_Head) PosSegment|=1;
162 else if(Pos2 == IntRes2d_End) PosSegment|=2;
163 }
164 else if(Pos1 == IntRes2d_End) {
165 if(Pos2 == IntRes2d_Head) PosSegment|=4;
166 else if(Pos2 == IntRes2d_End) PosSegment|=8;
167 }
168
169 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
170 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
171 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
172
173 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
174 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
175 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
176
177 if(Pos1 == IntRes2d_Head) {
178 if(Pos2 == IntRes2d_Head) PosSegment|=1;
179 else if(Pos2 == IntRes2d_End) PosSegment|=2;
180 }
181 else if(Pos1 == IntRes2d_End) {
182 if(Pos2 == IntRes2d_Head) PosSegment|=4;
183 else if(Pos2 == IntRes2d_End) PosSegment|=8;
184 }
185 }
186
187
188
189 Standard_Real U0 = D1.FirstParameter();
190 Standard_Real U1 = D1.LastParameter();
191 Standard_Real V0 = D2.FirstParameter();
192 Standard_Real V1 = D2.LastParameter();
193 Standard_Real v,u;
194 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
195 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
196 IntRes2d_IntersectionPoint IntPt;
197
198 if(D1.FirstTolerance() || D2.FirstTolerance()) {
199 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
200 this->Insert(IntPt);
201 }
202 if(D1.FirstTolerance() || D2.LastTolerance()) {
203 if(HeadOrEndPoint(D1,C1,U0,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
204 this->Insert(IntPt);
205 }
206 if(D1.LastTolerance() || D2.FirstTolerance()) {
207 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V0,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
208 this->Insert(IntPt);
209 }
210 if(D1.LastTolerance() || D2.LastTolerance()) {
211 if(HeadOrEndPoint(D1,C1,U1,D2,C2,V1,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
212 this->Insert(IntPt);
213 }
214 if(AnErrorOccurred) {
215 //----------------------------------------------------------------------------------
216 //-- On a donne un point approche a la recherche du point exact, et cette recherche
217 //-- a echoue.
218 //-- Soit le point n'existe pas, soit c'est un point en bout dont un des parameteres
219 //-- est en dehors du domaine de la courbe.
220 //--
221 //-- Dans le cas contraire, on suppose que les points en bouts ont ete trouves par
222 //-- les interferences des polygones
223 //--
224 if(!HeadOn1) {
225 u = U0;
226 v = TheProjPCur::FindParameter( C2,D1.FirstPoint(),V0,V1,EpsX2);
227 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
228 this->Insert(IntPt);
229 }
230
231 if(!EndOn1) {
232 u = U1;
233 v = TheProjPCur::FindParameter( C2,D1.LastPoint(),V0,V1,EpsX2);
234 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
235 this->Insert(IntPt);
236 }
237
238 if(!HeadOn2) {
239 u = TheProjPCur::FindParameter( C1,D2.FirstPoint(),U0,U1,EpsX1);
240 v = V0;
241 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
242 this->Insert(IntPt);
243 }
244
245 if(!EndOn2) {
246 u = TheProjPCur::FindParameter( C1,D2.LastPoint(),U0,U1,EpsX1);
247 v = V1;
248 if(HeadOrEndPoint(D1,C1,u,D2,C2,v,TheTolConf,IntPt,HeadOn1,HeadOn2,EndOn1,EndOn2,PosSegment))
249 this->Insert(IntPt);
250 }
251 }
252}
253
254
255
256
257
258//======================================================================
259//== A u t o I n t e r s e c t i o n
260//======================================================================
261void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
262 ,const IntRes2d_Domain& D1
263 ,const Standard_Real TheTolConf
264 ,const Standard_Real TheTol)
265{
266
7fd59977 267 this->ResetFields();
268 DomainOnCurve1=D1;
269 DomainOnCurve2=D1;
270 Standard_Real DU = D1.LastParameter()-D1.FirstParameter();
271 Standard_Real Tl=(TheTol < TOL_MINI)? TOL_MINI : TheTol;
272 Standard_Real TlConf=(TheTolConf < TOL_CONF_MINI)? TOL_CONF_MINI : TheTolConf;
273 Perform(C1,D1,TlConf,Tl,0,DU,DU);
274 //----------------------------------------------------------------------
275 //-- Traitement des points en bouts
276 //----------------------------------------------------------------------
277 Standard_Boolean HeadOn1 = Standard_False;
278 Standard_Boolean HeadOn2 = Standard_False;
279 Standard_Boolean EndOn1 = Standard_False;
280 Standard_Boolean EndOn2 = Standard_False;
281 Standard_Integer i;
282 Standard_Integer n=this->NbPoints();
283
284
285 //--------------------------------------------------------------------
286 //-- On ne rejette les points Head Head ... End End
287 //-- si ils figurent deja dans un bout de segment
288 //-- ( On ne peut pas tester les egalites sur les parametres)
289 //-- ( ces points n etant pas trouves a EpsX pres )
290 //-- PosSegment = 1 si Head Head
291 //-- 2 si Head End
292 //-- 4 si End Head
293 //-- 8 si End End
294 //--------------------------------------------------------------------
295 Standard_Integer PosSegment = 0;
296
297
298
299 for(i=1;i<=n;i++) {
300 IntRes2d_Position Pos1 = this->Point(i).TransitionOfFirst().PositionOnCurve();
301 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
302 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
303
304 IntRes2d_Position Pos2 = this->Point(i).TransitionOfSecond().PositionOnCurve();
305 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
306 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
307
308 if(Pos1 == IntRes2d_Head) {
309 if(Pos2 == IntRes2d_Head) PosSegment|=1;
310 else if(Pos2 == IntRes2d_End) PosSegment|=2;
311 }
312 else if(Pos1 == IntRes2d_End) {
313 if(Pos2 == IntRes2d_Head) PosSegment|=4;
314 else if(Pos2 == IntRes2d_End) PosSegment|=8;
315 }
316 }
317
318 n=this->NbSegments();
319 for(i=1;i<=n;i++) {
320 IntRes2d_Position Pos1 = this->Segment(i).FirstPoint().TransitionOfFirst().PositionOnCurve();
321 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
322 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
323
324 IntRes2d_Position Pos2 = this->Segment(i).FirstPoint().TransitionOfSecond().PositionOnCurve();
325 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
326 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
327
328 if(Pos1 == IntRes2d_Head) {
329 if(Pos2 == IntRes2d_Head) PosSegment|=1;
330 else if(Pos2 == IntRes2d_End) PosSegment|=2;
331 }
332 else if(Pos1 == IntRes2d_End) {
333 if(Pos2 == IntRes2d_Head) PosSegment|=4;
334 else if(Pos2 == IntRes2d_End) PosSegment|=8;
335 }
336
337 Pos1 = this->Segment(i).LastPoint().TransitionOfFirst().PositionOnCurve();
338 if(Pos1 == IntRes2d_Head) HeadOn1 = Standard_True;
339 else if(Pos1 == IntRes2d_End) EndOn1 = Standard_True;
340
341 Pos2 = this->Segment(i).LastPoint().TransitionOfSecond().PositionOnCurve();
342 if(Pos2 == IntRes2d_Head) HeadOn2 = Standard_True;
343 else if(Pos2 == IntRes2d_End) EndOn2 = Standard_True;
344
345 if(Pos1 == IntRes2d_Head) {
346 if(Pos2 == IntRes2d_Head) PosSegment|=1;
347 else if(Pos2 == IntRes2d_End) PosSegment|=2;
348 }
349 else if(Pos1 == IntRes2d_End) {
350 if(Pos2 == IntRes2d_Head) PosSegment|=4;
351 else if(Pos2 == IntRes2d_End) PosSegment|=8;
352 }
353 }
354}
355//======================================================================
356
357
358
359void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
360 ,const IntRes2d_Domain& D1
361 ,const Standard_Real TolConf
362 ,const Standard_Real Tol
363 ,const Standard_Integer NbIter
364 ,const Standard_Real DeltaU
365 ,const Standard_Real) {
366
367 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
368 gp_Pnt2d P1,P2;
369 Standard_Integer nbsamples;
370 done = Standard_False;
41194117 371 Standard_Boolean AnErrorOccurred = Standard_False;
7fd59977 372
373
374 nbsamples = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
375
376 if(NbIter>3 || (NbIter>2 && nbsamples>100)) return;
377
378 nbsamples*=2; //--- On prend systematiquement 2 fois plus de points que
379 //-- sur une courbe normale.
380 //-- Les courbes auto-intersectantes donne souvent des
381 //-- polygones assez loin de la courbe a parametre ct.
382
383 if(NbIter>0) {
384 if((D1.LastParameter()-D1.FirstParameter())
385 >0.5*(DeltaU)) {
386 nbsamples=(3*(nbsamples*NbIter)/2);
387 }
388 else {
389 nbsamples=(3*(nbsamples*NbIter))/2;
390 }
391 }
392 IntCurve_ThePolygon2d Poly1(C1,nbsamples,D1,Tol);
393 if(!Poly1.AutoIntersectionIsPossible()) {
394 done = Standard_True;
395 return;
396 }
397 //-- Poly1.Dump();
398 //----------------------------------------------------------------------
399 //-- Si la deflection est inferieure a la Tolerance de Confusion
400 //-- Alors la deflection du polygone est fixee a TolConf
401 //-- (Detection des Zones de Tangence)
402 //----------------------------------------------------------------------
403 if(Poly1.DeflectionOverEstimation() < TolConf) {
404 Poly1.SetDeflectionOverEstimation(TolConf);
405 }
406
9530af27 407 Intf_InterferencePolygon2d InterPP(Poly1);
7fd59977 408 IntCurve_ExactIntersectionPoint EIP(C1,C1,TolConf);
409 Standard_Real U,V;
410
411 //----------------------------------------------------------------------
412 //-- Traitement des SectionPoint
413 //----------------------------------------------------------------------
414 Standard_Integer Nbsp = InterPP.NbSectionPoints();
415 if(Nbsp>=1) {
416
417 //-- ---------------------------------------------------------------------
418 //-- tri tri tri tri tri tri tri tri tri tri tri tri tri tri
419 //--
420 Standard_Integer* TriIndex = new Standard_Integer [Nbsp+1];
421 Standard_Integer* PtrSegIndex1 = new Standard_Integer [Nbsp+1];
422 Standard_Integer* PtrSegIndex2 = new Standard_Integer [Nbsp+1];
423 Standard_Boolean Triok;
424 Standard_Integer SegIndex1,SegIndex2,SegIndex_1,SegIndex_2;
425// Standard_Real ParamOn1,ParamOn2,ParamOn_1,ParamOn_2;
426 Standard_Real ParamOn1,ParamOn2;
427 Intf_PIType Type;
428 Standard_Integer i ;
429 for( i=1;i<=Nbsp;i++) {
430 TriIndex[i]=i;
431 const Intf_SectionPoint& SPnt1 = InterPP.PntValue(i);
432 SPnt1.InfoFirst(Type,PtrSegIndex1[i],ParamOn1);
433 SPnt1.InfoSecond(Type,PtrSegIndex2[i],ParamOn2);
434 }
435
436
437 do {
438 Triok=Standard_True;
439
440 for(Standard_Integer tr=1;tr<Nbsp;tr++) {
441 SegIndex1=PtrSegIndex1[TriIndex[tr]];
442 SegIndex_1=PtrSegIndex1[TriIndex[tr+1]];
443
444 SegIndex2=PtrSegIndex2[TriIndex[tr]];
445 SegIndex_2=PtrSegIndex2[TriIndex[tr+1]];
446
447 if(SegIndex1 > SegIndex_1) {
448 Standard_Integer q=TriIndex[tr];
449 TriIndex[tr]=TriIndex[tr+1];
450 TriIndex[tr+1]=q;
451 Triok=Standard_False;
452 }
453 else if(SegIndex1 == SegIndex_1) {
454 if(SegIndex2 > SegIndex_2) {
455 Standard_Integer q=TriIndex[tr];
456 TriIndex[tr]=TriIndex[tr+1];
457 TriIndex[tr+1]=q;
458 Triok=Standard_False;
459 }
460 }
461 }
462 }
463 while(Triok==Standard_False);
464
465 //-- supression des doublons Si Si !
466 for(i=1; i<Nbsp;i++) {
467 if( (PtrSegIndex1[TriIndex[i]] == PtrSegIndex1[TriIndex[i+1]])
468 && (PtrSegIndex2[TriIndex[i]] == PtrSegIndex2[TriIndex[i+1]])) {
469 TriIndex[i]=-i;
470
471 }
472 }
473
474 Standard_Integer Nelarg=(Poly1.NbSegments()/20);
475 if(Nelarg<2) Nelarg=2;
476
477 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
478 if(TriIndex[sp]>0) {
479 const Intf_SectionPoint& SPnt = InterPP.PntValue(TriIndex[sp]);
480
481 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
482 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
483
484 if(Abs(SegIndex1-SegIndex2)>1) {
485
486 EIP.Perform(Poly1,Poly1,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
487 AnErrorOccurred = EIP.AnErrorOccurred();
488 if(EIP.NbRoots()==0) {
489 //-- On supprime tous les segments voisins
490 for(Standard_Integer k=sp+1;k<=Nbsp;k++) {
491 Standard_Integer kk=TriIndex[k];
492 // modified by OFV OCC2502 Tue Apr 29 15:07:45 2003 .Begin
493 // --- avoid negative indicies as well as in outer done
494 if( kk > 0 ) {
495 if( Abs(SegIndex1-PtrSegIndex1[kk])< Nelarg
496 && Abs(SegIndex2-PtrSegIndex2[kk])< Nelarg) {
497 TriIndex[k]=-k;
498 }
499 }
500 // modified by OFV OCC2502 Tue Apr 29 15:11:34 2003 .End
501 }
502 }
503 else if(EIP.NbRoots()>=1) {
504 //--------------------------------------------------------------------
505 //-- On verifie que le point trouve est bien une racine
506 //--------------------------------------------------------------------
507 EIP.Roots(U,V);
508
509 TheCurveTool::D1(C1,U,P1,Tan1);
510 TheCurveTool::D1(C1,V,P2,Tan2);
511 Standard_Real Dist = P1.Distance(P2);
512 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
513
514 if(Abs(U-V)<=EpsX1) {
515 //-----------------------------------------
516 //-- Solution non valide
517 //-- Les maths ont du converger vers une
518 //-- solution triviale ( point U = V )
519 //-----------------------------------------
520 Dist = TolConf+1.0;
521 }
522
523 //-----------------------------------------------------------------
524 //-- On verifie que le point (u,v) n existe pas deja
525 //--
526 done = Standard_True;
527 Standard_Integer nbp=NbPoints();
528
529 for(Standard_Integer p=1; p<=nbp; p++) {
530 const IntRes2d_IntersectionPoint& P=Point(p);
531 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
532 if(Abs(V-P.ParamOnSecond()) <= EpsX1) {
533 Dist = TolConf+1.0; p+=nbp;
534 }
535 }
536 }
537
538 if(Dist <= TolConf) { //-- Ou le point est deja present
539 IntRes2d_Position Pos1 = IntRes2d_Middle;
540 IntRes2d_Position Pos2 = IntRes2d_Middle;
541 IntRes2d_Transition Trans1,Trans2;
542 //-----------------------------------------------------------------
543 //-- Calcul des Positions des Points sur la courbe
544 //--
545 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
546 Pos1 = IntRes2d_Head;
547 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
548 Pos1 = IntRes2d_End;
549
550 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
551 Pos2 = IntRes2d_Head;
552 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
553 Pos2 = IntRes2d_End;
554 //-----------------------------------------------------------------
555 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
556 ,Pos2,Tan2,Trans2
557 ,TolConf) == Standard_False) {
558 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
559 TheCurveTool::D2(C1,V,P2,Tan2,Norm2);
560 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
561 ,Pos2,Tan2,Norm2,Trans2
562 ,TolConf);
563 }
564 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
565 Insert(IP);
566 }
567 }
568 }
569 }
570 }
571 delete [] TriIndex;
572 delete [] PtrSegIndex1;
573 delete [] PtrSegIndex2;
574 }
575
576
577 //----------------------------------------------------------------------
578 //-- Traitement des TangentZone
579 //----------------------------------------------------------------------
580 Standard_Integer Nbtz = InterPP.NbTangentZones();
581 Nbtz=0;
582 if(Nbtz) {
583 Standard_Real ParamInf=D1.FirstParameter();
584 Standard_Real ParamSup=D1.LastParameter();
585 ParamSup=-RealLast();
586 ParamInf=RealLast();
587 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
588 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
589 //====================================================================
590 //== Recherche du premier et du dernier point dans la zone de tg.
591 //== ATTENTION LA LISTE N EST PAS TRIEE
592 //====================================================================
593 for(Standard_Integer tzz=1; tzz<=NbPnts; tzz++) {
594 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(tzz);
595
596// Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2;
597 Standard_Integer SegIndex1onP1;
598 Intf_PIType Type;
599 Standard_Real ParamOnLine;
600
601 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
602 if(SegIndex1onP1 >= Poly1.NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
603 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
604 Standard_Real Par = Poly1.ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
605 if(ParamSup<Par) ParamSup=Par;
606 if(ParamInf>Par) ParamInf=Par;
607 }
608 }
609 if(ParamSup > ParamInf) {
610 //-- printf("\n %g -> %g %g -> %g ",D1.FirstParameter(),ParamInf,D1.LastParameter(),ParamSup);
611 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInf)
612 ,ParamInf,TolConf
613 ,TheCurveTool::Value(C1,ParamSup)
614 ,ParamSup,TolConf);
615 Perform(C1,RecursD1,TolConf,Tol,NbIter+1,ParamSup-ParamInf,0.0);
616 }
617 }
618 //----------------------------------------------------------------------
619 done = Standard_True;
620}
621
622
623Standard_Boolean HeadOrEndPoint( const IntRes2d_Domain& D1
624 ,const TheCurve& C1
625 ,const Standard_Real tu
626 ,const IntRes2d_Domain& D2
627 ,const TheCurve& C2
628 ,const Standard_Real tv
629 ,const Standard_Real TolConf
630 ,IntRes2d_IntersectionPoint& IntPt
631 ,Standard_Boolean& HeadOn1
632 ,Standard_Boolean& HeadOn2
633 ,Standard_Boolean& EndOn1
634 ,Standard_Boolean& EndOn2
635 ,Standard_Integer PosSegment) {
636
637 gp_Pnt2d P1,P2,SP1,SP2;
638 gp_Vec2d T1,T2,N1,N2;
639 Standard_Real u=tu;
640 Standard_Real v=tv;
641 Standard_Real svu = u;
642 Standard_Real svv = v;
643
644 TheCurveTool::D1(C1,u,P1,T1);
645 TheCurveTool::D1(C2,v,P2,T2);
646
647 IntRes2d_Position Pos1 = IntRes2d_Middle;
648 IntRes2d_Position Pos2 = IntRes2d_Middle;
649 IntRes2d_Transition Trans1,Trans2;
650
651 //----------------------------------------------------------------------
652 //-- Head On 1 : Head1 <-> P2
653 if(P2.Distance(D1.FirstPoint())<=D1.FirstTolerance()) {
654 Pos1 = IntRes2d_Head;
655 HeadOn1 = Standard_True;
656 SP1 = D1.FirstPoint();
657 u = D1.FirstParameter();
658 }
659 //----------------------------------------------------------------------
660 //-- End On 1 : End1 <-> P2
661 else if(P2.Distance(D1.LastPoint())<=D1.LastTolerance()) {
662 Pos1 = IntRes2d_End;
663 EndOn1 = Standard_True;
664 SP1 = D1.LastPoint();
665 u = D1.LastParameter();
666 }
667
668
669 //----------------------------------------------------------------------
670 //-- Head On 2 : Head2 <-> P1
671 else if(P1.Distance(D2.FirstPoint())<=D2.FirstTolerance()) {
672 Pos2 = IntRes2d_Head;
673 HeadOn2 = Standard_True;
674 SP2 = D2.FirstPoint();
675 v = D2.FirstParameter();
676 }
677 //----------------------------------------------------------------------
678 //-- End On 2 : End2 <-> P1
679 else if(P1.Distance(D2.LastPoint())<=D2.LastTolerance()) {
680 Pos2 = IntRes2d_End;
681 EndOn2 = Standard_True;
682 SP2 = D2.LastPoint();
683 v = D2.LastParameter();
684 }
685
686 Standard_Real EpsX1 = TheCurveTool::EpsX(C1);
687 Standard_Real EpsX2 = TheCurveTool::EpsX(C2);
688
689
690 if((Pos1 != IntRes2d_Middle)||(Pos2 != IntRes2d_Middle)) {
691 if(Pos1 == IntRes2d_Middle) {
692 if(Abs(u-D1.FirstParameter()) <= EpsX1) {
693 Pos1 = IntRes2d_Head;
694 P1 = D1.FirstPoint();
695 HeadOn1 = Standard_True;
696 }
697 else if(Abs(u-D1.LastParameter()) <= EpsX1) {
698 Pos1 = IntRes2d_End;
699 P1 = D1.LastPoint();
700 EndOn1 = Standard_True;
701 }
702 }
703 else if(u!=tu) {
704 P1 = SP1;
705 }
706
707
708 if(Pos2 == IntRes2d_Middle) {
709 if(Abs(v-D2.FirstParameter()) <= EpsX2) {
710 Pos2 = IntRes2d_Head;
711 HeadOn2 = Standard_True;
712 P2 = D2.FirstPoint();
713 if(Pos1 != IntRes2d_Middle) {
714 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
715 }
716 else {
717 P2 = P1;
718 }
719 }
720 else if(Abs(v-D2.LastParameter()) <= EpsX2) {
721 Pos2 = IntRes2d_End;
722 EndOn2 = Standard_True;
723 P2 = D2.LastPoint();
724 if(Pos1 != IntRes2d_Middle) {
725 P1.SetCoord(0.5*(P1.X()+P2.X()),0.5*(P1.Y()+P2.Y()));
726 }
727 else {
728 P2 = P1;
729 }
730 }
731 }
732
733
734 //--------------------------------------------------------------------
735 //-- On Teste si un point de bout de segment a deja ces trnasitions
736 //-- Si Oui, on ne cree pas de nouveau point
737 //--
738 //-- PosSegment = 1 si Head Head
739 //-- 2 si Head End
740 //-- 4 si End Head
741 //-- 8 si End End
742 //--------------------------------------------------------------------
743 if(Pos1 == IntRes2d_Head) {
744 if((Pos2 == IntRes2d_Head)&&(PosSegment & 1)) return(Standard_False);
745 if((Pos2 == IntRes2d_End )&&(PosSegment & 2)) return(Standard_False);
746 }
747 else if(Pos1 == IntRes2d_End) {
748 if((Pos2 == IntRes2d_Head)&&(PosSegment & 4)) return(Standard_False);
749 if((Pos2 == IntRes2d_End )&&(PosSegment & 8)) return(Standard_False);
750 }
751
752
753 if(IntImpParGen::DetermineTransition( Pos1,T1,Trans1,Pos2,T2,Trans2,TolConf)
754 == Standard_False) {
755 TheCurveTool::D2(C1,svu,P1,T1,N1);
756 TheCurveTool::D2(C2,svv,P2,T2,N2);
757 IntImpParGen::DetermineTransition(Pos1,T1,N1,Trans1,
758 Pos2,T2,N2,Trans2,TolConf);
759 }
760 IntPt.SetValues(P1,u,v,Trans1,Trans2,Standard_False);
761 return(Standard_True);
762 }
763 else
764 return(Standard_False);
765}
766
767
768
769
770
771
772
773//======================================================================
774void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1
775 ,const IntRes2d_Domain& D1
776 ,const TheCurve& C2
777 ,const IntRes2d_Domain& D2
778 ,const Standard_Real TolConf
779 ,const Standard_Real Tol
780 ,const Standard_Integer NbIter
781 ,const Standard_Real DeltaU
782 ,const Standard_Real DeltaV) {
783
784 gp_Vec2d Tan1,Tan2,Norm1,Norm2;
785 gp_Pnt2d P1,P2;
786 Standard_Integer nbsamplesOnC1,nbsamplesOnC2;
787 done = Standard_False;
41194117 788 Standard_Boolean AnErrorOccurred = Standard_False;
7fd59977 789
790 if(NbIter>NBITER_MAX_POLYGON) return;
791
792 nbsamplesOnC1 = TheCurveTool::NbSamples(C1,D1.FirstParameter(),D1.LastParameter());
793
794 //// modified by jgv, 5.12.02 for OCC935 ////
795 if (NbIter == 0) // first time
796 {
797 if (nbsamplesOnC1 < 20)
798 nbsamplesOnC1 = 20;
799 }
800 else // NbIter > 0
801 {
802 if ((D1.LastParameter()-D1.FirstParameter()) > 0.5*(DeltaU))
803 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
804 else
805 nbsamplesOnC1=(5*(nbsamplesOnC1*NbIter))/4;
806 }
807 /////////////////////////////////////////////
808
809 nbsamplesOnC2 = TheCurveTool::NbSamples(C2,D2.FirstParameter(),D2.LastParameter());
810
811 //// modified by jgv, 5.12.02 for OCC935 ////
812 if (NbIter == 0) // first time
813 {
814 if (nbsamplesOnC2 < 20)
815 nbsamplesOnC2 = 20;
816 }
817 else // NbIter > 0
818 {
819 if ((D2.LastParameter()-D2.FirstParameter()) > 0.5*(DeltaV))
820 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
821 else
822 nbsamplesOnC2=(5*(nbsamplesOnC2*NbIter))/4;
823 }
824 /////////////////////////////////////////////
825
826 IntCurve_ThePolygon2d *PtrPoly1,*PtrPoly2;
827 if(nbsamplesOnC2 > nbsamplesOnC1) {
828 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
829 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
830 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
831 }
832 else {
833 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,PtrPoly1->Bounding());
834 PtrPoly1->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
835 +PtrPoly1->DeflectionOverEstimation());
836 PtrPoly1->ComputeWithBox(C1,PtrPoly2->Bounding());
837 }
838 }
839 else {
840 PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol);
841 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
842 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol);
843 }
844 else {
845 PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,PtrPoly2->Bounding());
846 PtrPoly2->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation()
847 +PtrPoly1->DeflectionOverEstimation());
848 PtrPoly2->ComputeWithBox(C2,PtrPoly1->Bounding());
849 }
850 }
851 //----------------------------------------------------------------------
852 //-- Si la deflection est inferieure a la Tolerance de Confusion
853 //-- Alors la deflection du polygone est fixee a TolConf
854 //-- (Detection des Zones de Tangence)
855 //----------------------------------------------------------------------
856
857 if(PtrPoly1->DeflectionOverEstimation() < TolConf) {
858 PtrPoly1->SetDeflectionOverEstimation(TolConf);
859 }
860 if(PtrPoly2->DeflectionOverEstimation() < TolConf) {
861 PtrPoly2->SetDeflectionOverEstimation(TolConf);
862 }
9530af27 863 Intf_InterferencePolygon2d InterPP(*PtrPoly1,*PtrPoly2);
7fd59977 864 IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf);
865 Standard_Real U,V;
866
867 //----------------------------------------------------------------------
868 //-- Traitement des SectionPoint
869 //----------------------------------------------------------------------
870 Standard_Integer Nbsp = InterPP.NbSectionPoints();
871
872 if(Nbsp>=1) {
873 for(Standard_Integer sp=1; sp <= Nbsp; sp++) {
874 const Intf_SectionPoint& SPnt = InterPP.PntValue(sp);
875 Standard_Integer SegIndex1,SegIndex2;
876 Standard_Real ParamOn1,ParamOn2;
877 Intf_PIType Type;
878
879 SPnt.InfoFirst(Type,SegIndex1,ParamOn1);
880 SPnt.InfoSecond(Type,SegIndex2,ParamOn2);
881 EIP.Perform(*PtrPoly1,*PtrPoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2);
882 AnErrorOccurred = EIP.AnErrorOccurred();
883 if(EIP.NbRoots()>=1) {
884 //--------------------------------------------------------------------
885 //-- On verifie que le point trouve est bien une racine
886 //--------------------------------------------------------------------
887 EIP.Roots(U,V);
888 TheCurveTool::D1(C1,U,P1,Tan1);
889 TheCurveTool::D1(C2,V,P2,Tan2);
890 Standard_Real Dist = P1.Distance(P2);
891 //-----------------------------------------------------------------
892 //-- On verifie que le point (u,v) n existe pas deja
893 //--
894 done = Standard_True;
895 Standard_Integer nbp=NbPoints();
896 Standard_Real EpsX1 = 10.0*TheCurveTool::EpsX(C1);
897 Standard_Real EpsX2 = 10.0*TheCurveTool::EpsX(C2);
898
899 for(Standard_Integer p=1; p<=nbp; p++) {
900 const IntRes2d_IntersectionPoint& P=Point(p);
901 if(Abs(U-P.ParamOnFirst()) <= EpsX1) {
902 if(Abs(V-P.ParamOnSecond()) <= EpsX2) {
903 Dist = TolConf+1.0; p+=nbp;
904 }
905 }
906 }
907
908 if(Dist <= TolConf) { //-- Ou le point est deja present
909 IntRes2d_Position Pos1 = IntRes2d_Middle;
910 IntRes2d_Position Pos2 = IntRes2d_Middle;
911 IntRes2d_Transition Trans1,Trans2;
912 //-----------------------------------------------------------------
913 //-- Calcul des Positions des Points sur la courbe
914 //--
915 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance())
916 Pos1 = IntRes2d_Head;
917 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance())
918 Pos1 = IntRes2d_End;
919
920 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance())
921 Pos2 = IntRes2d_Head;
922 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance())
923 Pos2 = IntRes2d_End;
924 //-----------------------------------------------------------------
925 //-- Calcul des Transitions (Voir IntImpParGen.cxx)
926 //--
927 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1
928 ,Pos2,Tan2,Trans2
929 ,TolConf)==Standard_False) {
930
931 TheCurveTool::D2(C1,U,P1,Tan1,Norm1);
932 TheCurveTool::D2(C2,V,P2,Tan2,Norm2);
933 IntImpParGen::DetermineTransition( Pos1,Tan1,Norm1,Trans1
934 ,Pos2,Tan2,Norm2,Trans2
935 ,TolConf);
936 }
937 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False);
938 Insert(IP);
939 }
940 } //-- if(EIP.NbRoots()>=1)
941 }
942 }
943
944
945 //----------------------------------------------------------------------
946 //-- Traitement des TangentZone
947 //----------------------------------------------------------------------
948 Standard_Integer Nbtz = InterPP.NbTangentZones();
949 for(Standard_Integer tz=1; tz <= Nbtz; tz++) {
950 Standard_Integer NbPnts = InterPP.ZoneValue(tz).NumberOfPoints();
951 //====================================================================
952 //== Recherche du premier et du dernier point dans la zone de tg.
953 //====================================================================
954 Standard_Real ParamSupOnCurve2,ParamInfOnCurve2;
955 Standard_Real ParamSupOnCurve1,ParamInfOnCurve1;
956// Standard_Integer SegIndex,SegIndex1onP1,SegIndex1onP2,SegIndex2onP1,SegIndex2onP2;
957 Standard_Integer SegIndex1onP1,SegIndex1onP2;
958 Intf_PIType Type;
959 Standard_Real ParamOnLine;
960 Standard_Real PolyUInf,PolyUSup,PolyVInf,PolyVSup;
961 ParamSupOnCurve2=ParamSupOnCurve1=PolyUSup=PolyVSup=-RealLast();
962 ParamInfOnCurve2=ParamInfOnCurve1=PolyUInf=PolyVInf= RealLast();
963 for(Standard_Integer qq=1;qq<=NbPnts;qq++) {
964 const Intf_SectionPoint& SPnt1 = InterPP.ZoneValue(tz).GetPoint(qq);
965 //====================================================================
966 //== On discretise sur les zones de tangence
967 //== Test d arret :
968 //== Compteur
969 //== Deflection < Tolerance
970 //== OU Echantillon < EpsX (normalement la premiere condition est
971 //== plus severe)
972 //====================================================================
973// Standard_Real _PolyUInf,_PolyUSup,_PolyVInf,_PolyVSup;
974 Standard_Real _PolyUInf,_PolyVInf;
975
976 SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine);
977 if(SegIndex1onP1 >= PtrPoly1->NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; }
978 if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; }
979 _PolyUInf = PtrPoly1->ApproxParamOnCurve(SegIndex1onP1,ParamOnLine);
980
981 SPnt1.InfoSecond(Type,SegIndex1onP2,ParamOnLine);
982 if(SegIndex1onP2 >= PtrPoly2->NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; }
983 if(SegIndex1onP2 <= 0) { SegIndex1onP2=1; ParamOnLine = 0.0; }
984 _PolyVInf = PtrPoly2->ApproxParamOnCurve(SegIndex1onP2,ParamOnLine);
985
986 //----------------------------------------------------------------------
987
988 if(ParamInfOnCurve1 > _PolyUInf) ParamInfOnCurve1=_PolyUInf;
989 if(ParamInfOnCurve2 > _PolyVInf) ParamInfOnCurve2=_PolyVInf;
990
991 if(ParamSupOnCurve1 < _PolyUInf) ParamSupOnCurve1=_PolyUInf;
992 if(ParamSupOnCurve2 < _PolyVInf) ParamSupOnCurve2=_PolyVInf;
993
994 }
995
996 PolyUInf= ParamInfOnCurve1;
997 PolyUSup= ParamSupOnCurve1;
998 PolyVInf= ParamInfOnCurve2;
999 PolyVSup= ParamSupOnCurve2;
1000
1001 TheCurveTool::D0(C1,PolyUInf,P1);
1002 TheCurveTool::D0(C2,PolyVInf,P2);
1003 Standard_Real distmemesens = P1.SquareDistance(P2);
1004 TheCurveTool::D0(C2,PolyVSup,P2);
1005 Standard_Real distdiffsens = P1.SquareDistance(P2);
1006 if(distmemesens > distdiffsens) {
1007 Standard_Real qwerty=PolyVInf; PolyVInf=PolyVSup; PolyVSup=qwerty;
1008 }
1009
1010
1011
1012 if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf)
1013 ||(PtrPoly2->DeflectionOverEstimation() > TolConf))
1014 &&(NbIter<NBITER_MAX_POLYGON)) {
1015
1016 IntRes2d_Domain RecursD1( TheCurveTool::Value(C1,ParamInfOnCurve1)
1017 ,ParamInfOnCurve1,TolConf
1018 ,TheCurveTool::Value(C1,ParamSupOnCurve1)
1019 ,ParamSupOnCurve1,TolConf);
1020 IntRes2d_Domain RecursD2( TheCurveTool::Value(C2,ParamInfOnCurve2)
1021 ,ParamInfOnCurve2,TolConf
1022 ,TheCurveTool::Value(C2,ParamSupOnCurve2)
1023 ,ParamSupOnCurve2,TolConf);
1024 //-- On ne delete pas PtrPoly1(2) ,
1025 //-- ils sont detruits enfin de fct.
1026 //-- !! Pas de return intempestif !!
1027 Perform(C1,RecursD1,C2,RecursD2,Tol,TolConf,NbIter+1,DeltaU,DeltaV);
1028 }
1029 else {
1030 //-----------------------------------------------------------------
1031 //-- Calcul des Positions des Points sur la courbe et des
1032 //-- Transitions sur chaque borne du segment
1033
1034 IntRes2d_Position Pos1 = IntRes2d_Middle;
1035 IntRes2d_Position Pos2 = IntRes2d_Middle;
1036 IntRes2d_Transition Trans1,Trans2;
1037
1038 TheCurveTool::D1(C1,PolyUInf,P1,Tan1);
1039 TheCurveTool::D1(C2,PolyVInf,P2,Tan2);
1040
1041 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1042 Pos1 = IntRes2d_Head;
1043 }
1044 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1045 Pos1 = IntRes2d_End;
1046 }
1047 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1048 Pos2 = IntRes2d_Head;
1049 }
1050 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1051 Pos2 = IntRes2d_End;
1052 }
1053
1054 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1055 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1056 }
1057 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1058 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1059 }
1060 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1061 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1062 }
1063 else {
1064 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1065 }
1066
1067
1068
1069 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1070 == Standard_False) {
1071 TheCurveTool::D2(C1,PolyUInf,P1,Tan1,Norm1);
1072 TheCurveTool::D2(C2,PolyVInf,P2,Tan2,Norm2);
1073 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1074 Pos2,Tan2,Norm2,Trans2,TolConf);
1075 }
1076 IntRes2d_IntersectionPoint PtSeg1(P1,PolyUInf,PolyVInf
1077 ,Trans1,Trans2,Standard_False);
1078 //----------------------------------------------------------------------
1079
1080 if((Abs(PolyUInf-PolyUSup) <= TheCurveTool::EpsX(C1))
1081 || (Abs(PolyVInf-PolyVSup) <= TheCurveTool::EpsX(C2))) {
1082 Insert(PtSeg1);
1083 }
1084 else {
1085 TheCurveTool::D1(C1,PolyUSup,P1,Tan1);
1086 TheCurveTool::D1(C2,PolyVSup,P2,Tan2);
1087 Pos1 = IntRes2d_Middle; Pos2 = IntRes2d_Middle;
1088
1089 if(P1.Distance(DomainOnCurve1.FirstPoint())<=DomainOnCurve1.FirstTolerance()) {
1090 Pos1 = IntRes2d_Head;
1091 }
1092 else if(P1.Distance(DomainOnCurve1.LastPoint())<=DomainOnCurve1.LastTolerance()) {
1093 Pos1 = IntRes2d_End;
1094 }
1095 if(P2.Distance(DomainOnCurve2.FirstPoint())<=DomainOnCurve2.FirstTolerance()) {
1096 Pos2 = IntRes2d_Head;
1097 }
1098 else if(P2.Distance(DomainOnCurve2.LastPoint())<=DomainOnCurve2.LastTolerance()) {
1099 Pos2 = IntRes2d_End;
1100 }
1101
1102
1103 if(Pos1==IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
1104 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1105 }
1106 else if(Pos1!=IntRes2d_Middle && Pos2==IntRes2d_Middle) {
1107 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1108 }
1109 else if(Abs(ParamInfOnCurve1-ParamSupOnCurve1) > Abs(ParamInfOnCurve2-ParamSupOnCurve2)) {
1110 PolyVInf=TheProjPCur::FindParameter( C2,P1,D2.FirstParameter(),D2.LastParameter(),TheCurveTool::EpsX(C2));
1111 }
1112 else {
1113 PolyUInf=TheProjPCur::FindParameter( C1,P2,D1.FirstParameter(),D1.LastParameter(),TheCurveTool::EpsX(C1));
1114 }
1115
1116 if(IntImpParGen::DetermineTransition( Pos1,Tan1,Trans1,Pos2,Tan2,Trans2,TolConf)
1117 ==Standard_False) {
1118 TheCurveTool::D2(C1,PolyUSup,P1,Tan1,Norm1);
1119 TheCurveTool::D2(C2,PolyVSup,P2,Tan2,Norm2);
1120 IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
1121 Pos2,Tan2,Norm2,Trans2,TolConf);
1122 }
1123 IntRes2d_IntersectionPoint PtSeg2(P1,PolyUSup,PolyVSup
1124 ,Trans1,Trans2,Standard_False);
1125
1126
1127
1128 Standard_Boolean Oppos = (Tan1.Dot(Tan2) > 0.0)? Standard_False : Standard_True;
1129 if(ParamInfOnCurve1 > ParamSupOnCurve1) {
1130 IntRes2d_IntersectionSegment Seg(PtSeg2,PtSeg1,Oppos,Standard_False);
1131 Append(Seg);
1132 }
1133 else {
1134 IntRes2d_IntersectionSegment Seg(PtSeg1,PtSeg2,Oppos,Standard_False);
1135 Append(Seg);
1136 }
1137 }
1138 }
1139 }
1140 //----------------------------------------------------------------------
1141 delete PtrPoly1;
1142 delete PtrPoly2;
1143 done = Standard_True;
1144}
1145