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