0022550: Fixing data races
[occt.git] / src / Intf / Intf_InterferencePolygonPolyhedron.gxx
CommitLineData
7fd59977 1// File: Intf_InterferencePolygonPolyhedron.gxx
2// Created: Mon Dec 21 10:59:07 1992
3// Author: Didier PIFFAULT
4// <dpf@phylox>
5
6#include <gp_XYZ.hxx>
7#include <gp_Vec.hxx>
8#include <TColStd_ListOfInteger.hxx>
9#include <TColStd_ListIteratorOfListOfInteger.hxx>
10#include <Bnd_Box.hxx>
11#include <Intf_Tool.hxx>
12#include <Bnd_BoundSortBox.hxx>
13#include <Intf_Array1OfLin.hxx>
14#include <Intf_SectionPoint.hxx>
15#include <Intf_SeqOfSectionPoint.hxx>
16#include <Intf_TangentZone.hxx>
17#include <Intf_SeqOfTangentZone.hxx>
18#include <Intf.hxx>
19
7fd59977 20#include <Extrema_ExtElC.hxx>
21#include <Extrema_POnCurv.hxx>
22
41194117
K
23static const int Pourcent3[4] = {0, 1, 2, 0};
24
7fd59977 25static Standard_Boolean IsInSegment(const gp_Vec& P1P2,
26 const gp_Vec& P1P,
27 const Standard_Real NP1P2,
28 Standard_Real &Param,
29 const Standard_Real Tolerance) {
30 Param = P1P2.Dot(P1P);
31 Param/= NP1P2;
32 if(Param > (NP1P2+Tolerance))
33 return(Standard_False);
34 if(Param < (-Tolerance))
35 return(Standard_False);
36 Param/=NP1P2;
37 if(Param<0.0) Param=0.0;
38 if(Param>1.0) Param=1.0;
39 return(Standard_True);
40}
41
42
43//=======================================================================
44//function : Intf_InterferencePolygonPolyhedron
45//purpose : Empty constructor
46//=======================================================================
47
48Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron()
41194117
K
49: Intf_Interference (Standard_False),
50 BeginOfClosedPolygon (Standard_False),
51 iLin (0)
7fd59977 52{}
53
54//=======================================================================
55//function : Intf_InterferencePolygonPolyhedron
56//purpose : Construct and compute an interference beetween a Polygon3d
57// and a Polyhedron.
58//=======================================================================
59
7fd59977 60Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
61 (const Polygon3d& thePolyg, const Polyhedron& thePolyh)
41194117
K
62: Intf_Interference (Standard_False),
63 BeginOfClosedPolygon (Standard_False),
64 iLin (0)
7fd59977 65{
66 Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
67 ToolPolyh::DeflectionOverEstimation(thePolyh);
68 if (Tolerance==0.)
69 Tolerance=Epsilon(1000.);
70
71 if (!ToolPolygon3d::Bounding(thePolyg).IsOut(ToolPolyh::Bounding(thePolyh))) {
72 Interference(thePolyg, thePolyh);
73 }
74}
75
76
7fd59977 77Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
78 (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
79 Bnd_BoundSortBox &PolyhGrid)
41194117
K
80: Intf_Interference (Standard_False),
81 BeginOfClosedPolygon (Standard_False),
82 iLin (0)
7fd59977 83{
84 Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
85 ToolPolyh::DeflectionOverEstimation(thePolyh);
86 if (Tolerance==0.)
87 Tolerance=Epsilon(1000.);
88
89 if (!ToolPolygon3d::Bounding(thePolyg).IsOut(ToolPolyh::Bounding(thePolyh))) {
90 Interference(thePolyg, thePolyh,PolyhGrid);
91 }
92}
93
94//=======================================================================
95//function : Intf_InterferencePolygonPolyhedron
96//purpose : Construct and compute an interference beetween a Straight
97// Line and a Polyhedron.
98//=======================================================================
99
100Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
101 (const gp_Lin& theLin, const Polyhedron& thePolyh)
41194117
K
102: Intf_Interference (Standard_False),
103 BeginOfClosedPolygon (Standard_False),
104 iLin (0)
7fd59977 105{
106 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
107 if (Tolerance==0.)
108 Tolerance=Epsilon(1000.);
109
110 BeginOfClosedPolygon=Standard_False;
111
112 Bnd_BoundSortBox PolyhGrid;
113 PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
114 ToolPolyh::ComponentsBounding(thePolyh));
115 Standard_Integer indTri;
116
117 iLin=0;
118
119 Bnd_Box bofLin;
120 Intf_Tool btoo;
121 btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
122
123 TColStd_ListIteratorOfListOfInteger iCl(PolyhGrid.Compare(bofLin));
124 while (iCl.More()) {
125 indTri=iCl.Value();
126 Intersect
127 (theLin.Location(),
128 theLin.Location().Translated(gp_Vec(theLin.Direction())),
129 Standard_True, indTri, thePolyh);
130 iCl.Next();
131 }
132}
133
134
135//=======================================================================
136//function : Intf_InterferencePolygonPolyhedron
137//purpose : Construct and compute an interference beetween the Straights
138// Lines in <Obje> and the Polyhedron <thePolyh>.
139//=======================================================================
140
141Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
142 (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh)
41194117
K
143: Intf_Interference (Standard_False),
144 BeginOfClosedPolygon (Standard_False),
145 iLin (0)
7fd59977 146{
147 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
148 if (Tolerance==0.)
149 Tolerance=Epsilon(1000.);
150
151 Bnd_Box bofLin;
152 Intf_Tool bToo;
153 BeginOfClosedPolygon=Standard_False;
154
155 Bnd_BoundSortBox PolyhGrid;
156 PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
157 ToolPolyh::ComponentsBounding(thePolyh));
158
159 Standard_Integer indTri;
160
161 for (iLin=1; iLin<=theLins.Length(); iLin++) {
162
163
164 bToo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
165
166 TColStd_ListIteratorOfListOfInteger ilC(PolyhGrid.Compare(bofLin));
167
168 while (ilC.More()) {
169 indTri=ilC.Value();
170 Intersect
171 (theLins(iLin).Location(),
172 theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
173 Standard_True, indTri, thePolyh);
174 ilC.Next();
175 }
176 }
177}
178
179
180//=======================================================================
181//function : Perform
182//purpose :
183//=======================================================================
184
185void Intf_InterferencePolygonPolyhedron::Perform
186 (const Polygon3d& thePolyg, const Polyhedron& thePolyh)
187{
188 SelfInterference(Standard_False);
189 Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
190 ToolPolyh::DeflectionOverEstimation(thePolyh);
191 if (Tolerance==0.)
192 Tolerance=Epsilon(1000.);
193
194 if (!ToolPolygon3d::Bounding(thePolyg).IsOut
195 (ToolPolyh::Bounding(thePolyh))) {
196 Interference(thePolyg, thePolyh);
197 }
198}
199
200
201//=======================================================================
202//function : Perform
203//purpose :
204//=======================================================================
205
206void Intf_InterferencePolygonPolyhedron::Perform
207 (const gp_Lin& theLin, const Polyhedron& thePolyh)
208{
209 SelfInterference(Standard_False);
210 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
211 if (Tolerance==0.)
212 Tolerance=Epsilon(1000.);
213
214 BeginOfClosedPolygon=Standard_False;
215
216 Bnd_BoundSortBox PolyhGrid;
217 PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
218 ToolPolyh::ComponentsBounding(thePolyh));
219
220 Standard_Integer indTri;
221
222 iLin=0;
223
224 Bnd_Box bofLin;
225 Intf_Tool btoo;
226 btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
227
228 TColStd_ListIteratorOfListOfInteger lCi(PolyhGrid.Compare(bofLin));
229 while (lCi.More()) {
230 indTri=lCi.Value();
231 Intersect
232 (theLin.Location(),
233 theLin.Location().Translated(gp_Vec(theLin.Direction())),
234 Standard_True, indTri, thePolyh);
235 lCi.Next();
236 }
237}
238
239
240//=======================================================================
241//function : Perform
242//purpose : Compute an interference beetween the Straights
243// Lines in <Obje> and the Polyhedron <thePolyh>.
244//=======================================================================
245
246void Intf_InterferencePolygonPolyhedron::Perform
247 (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh)
248{
249 SelfInterference(Standard_False);
250 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
251 if (Tolerance==0.)
252 Tolerance=Epsilon(1000.);
253
254 Bnd_Box bofLin;
255 Intf_Tool Btoo;
256 BeginOfClosedPolygon=Standard_False;
257
258 Bnd_BoundSortBox PolyhGrid;
259 PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
260 ToolPolyh::ComponentsBounding(thePolyh));
261
262 Standard_Integer indTri;
263
264 for (iLin=1; iLin<=theLins.Length(); iLin++) {
265
266 Btoo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
267
268 TColStd_ListIteratorOfListOfInteger tlC(PolyhGrid.Compare(bofLin));
269
270 while (tlC.More()) {
271 indTri=tlC.Value();
272 Intersect
273 (theLins(iLin).Location(),
274 theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
275 Standard_True, indTri, thePolyh);
276 tlC.Next();
277 }
278 }
279}
280
281
282//=======================================================================
283//function : Interference
284//purpose : Compare the boundings beetween the segment of <Obje>
285// and the facets of <thePolyh>.
286//=======================================================================
287
288void Intf_InterferencePolygonPolyhedron::Interference
289 (const Polygon3d& thePolyg, const Polyhedron& thePolyh)
290{
291
292 Bnd_Box bofSeg;
293
294 Bnd_BoundSortBox PolyhGrid;
295 PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
296 ToolPolyh::ComponentsBounding(thePolyh));
297
298 Standard_Integer indTri;
299 BeginOfClosedPolygon=ToolPolygon3d::Closed(thePolyg);
300
301 Standard_Real defPh = ToolPolyh::DeflectionOverEstimation(thePolyh);
302
303 for (iLin=1; iLin<=ToolPolygon3d::NbSegments(thePolyg); iLin++) {
304
305 bofSeg.SetVoid();
306 bofSeg.Add(ToolPolygon3d::BeginOfSeg(thePolyg, iLin));
307 bofSeg.Add(ToolPolygon3d::EndOfSeg(thePolyg, iLin));
308 bofSeg.Enlarge(ToolPolygon3d::DeflectionOverEstimation(thePolyg));
309
310 TColStd_ListOfInteger maliste;
311 maliste = PolyhGrid.Compare(bofSeg);
312 TColStd_ListIteratorOfListOfInteger clt(maliste);
313 for (; clt.More(); clt.Next()) {
314 indTri=clt.Value();
315 gp_Pnt p1 = ToolPolygon3d::BeginOfSeg(thePolyg, iLin);
316 gp_Pnt p2 = ToolPolygon3d::EndOfSeg(thePolyg, iLin);
317 Standard_Integer pTri0, pTri1, pTri2;
318 ToolPolyh::Triangle(thePolyh, indTri, pTri0, pTri1, pTri2);
319 gp_Pnt Pa=ToolPolyh::Point(thePolyh, pTri0);
320 gp_Pnt Pb=ToolPolyh::Point(thePolyh, pTri1);
321 gp_Pnt Pc=ToolPolyh::Point(thePolyh, pTri2);
322 gp_Vec PaPb(Pa,Pb);
323 gp_Vec PaPc(Pa,Pc);
324 gp_Vec Normale = PaPb.Crossed(PaPc);
325 Standard_Real Norm_Normale=Normale.Magnitude();
326 if(Norm_Normale<1e-14)
327 continue;
328 Normale.Multiply(defPh/Norm_Normale);
329 gp_Pnt p1m = p1.Translated(-Normale);
330 gp_Pnt p1p = p1.Translated( Normale);
331 gp_Pnt p2m = p2.Translated(-Normale);
332 gp_Pnt p2p = p2.Translated( Normale);
333 Intersect(p1m,
334 p2p,
335 Standard_False, indTri, thePolyh);
336 Intersect(p1p,
337 p2m,
338 Standard_False, indTri, thePolyh);
339// Intersect(ToolPolygon3d::BeginOfSeg(thePolyg, iLin),
340// ToolPolygon3d::EndOfSeg(thePolyg, iLin),
341// Standard_False, indTri, thePolyh);
342 }
343 BeginOfClosedPolygon=Standard_False;
344 }
345}
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366//=======================================================================
367//function : Intf_InterferencePolygonPolyhedron
368//purpose : Construct and compute an interference beetween a Straight
369// Line and a Polyhedron.
370//=======================================================================
371
372Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
373 (const gp_Lin& theLin, const Polyhedron& thePolyh,
374 Bnd_BoundSortBox &PolyhGrid)
375: Intf_Interference(Standard_False)
376{
377 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
378 if (Tolerance==0.)
379 Tolerance=Epsilon(1000.);
380
381 BeginOfClosedPolygon=Standard_False;
382
383 Standard_Integer indTri;
384
385 iLin=0;
386
387 Bnd_Box bofLin;
388 Intf_Tool btoo;
389 btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
390
391 TColStd_ListIteratorOfListOfInteger iCl(PolyhGrid.Compare(bofLin));
392 while (iCl.More()) {
393 indTri=iCl.Value();
394 Intersect
395 (theLin.Location(),
396 theLin.Location().Translated(gp_Vec(theLin.Direction())),
397 Standard_True, indTri, thePolyh);
398 iCl.Next();
399 }
400}
401
402
403//=======================================================================
404//function : Intf_InterferencePolygonPolyhedron
405//purpose : Construct and compute an interference beetween the Straights
406// Lines in <Obje> and the Polyhedron <thePolyh>.
407//=======================================================================
408
409Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
410 (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh,
411 Bnd_BoundSortBox &PolyhGrid)
412: Intf_Interference(Standard_False)
413{
414 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
415 if (Tolerance==0.)
416 Tolerance=Epsilon(1000.);
417
418 Bnd_Box bofLin;
419 Intf_Tool bToo;
420 BeginOfClosedPolygon=Standard_False;
421
422 Standard_Integer indTri;
423
424 for (iLin=1; iLin<=theLins.Length(); iLin++) {
425
426
427 bToo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
428
429 TColStd_ListIteratorOfListOfInteger ilC(PolyhGrid.Compare(bofLin));
430
431 while (ilC.More()) {
432 indTri=ilC.Value();
433 Intersect
434 (theLins(iLin).Location(),
435 theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
436 Standard_True, indTri, thePolyh);
437 ilC.Next();
438 }
439 }
440}
441
442
443//=======================================================================
444//function : Perform
445//purpose :
446//=======================================================================
447
448void Intf_InterferencePolygonPolyhedron::Perform
449 (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
450 Bnd_BoundSortBox &PolyhGrid)
451{
452 SelfInterference(Standard_False);
453 Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
454 ToolPolyh::DeflectionOverEstimation(thePolyh);
455 if (Tolerance==0.)
456 Tolerance=Epsilon(1000.);
457
458 if (!ToolPolygon3d::Bounding(thePolyg).IsOut
459 (ToolPolyh::Bounding(thePolyh))) {
460 Interference(thePolyg, thePolyh,PolyhGrid);
461 }
462}
463
464
465//=======================================================================
466//function : Perform
467//purpose :
468//=======================================================================
469
470void Intf_InterferencePolygonPolyhedron::Perform
471 (const gp_Lin& theLin, const Polyhedron& thePolyh,
472 Bnd_BoundSortBox &PolyhGrid)
473{
474 SelfInterference(Standard_False);
475 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
476 if (Tolerance==0.)
477 Tolerance=Epsilon(1000.);
478
479 BeginOfClosedPolygon=Standard_False;
480
481 Standard_Integer indTri;
482
483 iLin=0;
484
485 Bnd_Box bofLin;
486 Intf_Tool btoo;
487 btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
488
489 TColStd_ListIteratorOfListOfInteger lCi(PolyhGrid.Compare(bofLin));
490 while (lCi.More()) {
491 indTri=lCi.Value();
492 Intersect
493 (theLin.Location(),
494 theLin.Location().Translated(gp_Vec(theLin.Direction())),
495 Standard_True, indTri, thePolyh);
496 lCi.Next();
497 }
498}
499
500
501//=======================================================================
502//function : Perform
503//purpose : Compute an interference beetween the Straights
504// Lines in <Obje> and the Polyhedron <thePolyh>.
505//=======================================================================
506
507void Intf_InterferencePolygonPolyhedron::Perform
508 (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh,
509 Bnd_BoundSortBox &PolyhGrid)
510{
511 SelfInterference(Standard_False);
512 Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
513 if (Tolerance==0.)
514 Tolerance=Epsilon(1000.);
515
516 Bnd_Box bofLin;
517 Intf_Tool Btoo;
518 BeginOfClosedPolygon=Standard_False;
519
520 Standard_Integer indTri;
521
522 for (iLin=1; iLin<=theLins.Length(); iLin++) {
523
524 Btoo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
525
526 TColStd_ListIteratorOfListOfInteger tlC(PolyhGrid.Compare(bofLin));
527
528 while (tlC.More()) {
529 indTri=tlC.Value();
530 Intersect
531 (theLins(iLin).Location(),
532 theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
533 Standard_True, indTri, thePolyh);
534 tlC.Next();
535 }
536 }
537}
538
539
540
541//=======================================================================
542//function : Interference
543//purpose : Compare the boundings beetween the segment of <Obje>
544// and the facets of <thePolyh>.
545//=======================================================================
546
547void Intf_InterferencePolygonPolyhedron::Interference
548 (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
549 Bnd_BoundSortBox &PolyhGrid)
550{
551 Bnd_Box bofSeg;
552
553 Standard_Integer indTri;
554 BeginOfClosedPolygon=ToolPolygon3d::Closed(thePolyg);
555
556 for (iLin=1; iLin<=ToolPolygon3d::NbSegments(thePolyg); iLin++) {
557
558 bofSeg.SetVoid();
559 bofSeg.Add(ToolPolygon3d::BeginOfSeg(thePolyg, iLin));
560 bofSeg.Add(ToolPolygon3d::EndOfSeg(thePolyg, iLin));
561 bofSeg.Enlarge(ToolPolygon3d::DeflectionOverEstimation(thePolyg));
562
563 // Modified by MKK - Thu Oct 25 12:40:11 2007
564 Standard_Real defPh = ToolPolyh::DeflectionOverEstimation(thePolyh);
565 TColStd_ListOfInteger maliste;
566 maliste = PolyhGrid.Compare(bofSeg);
567 TColStd_ListIteratorOfListOfInteger clt(maliste);
568 // Modified by MKK - Thu Oct 25 12:40:11 2007 Begin
569 gp_Pnt p1, Beg0;
570 gp_Pnt p2, End0;
571 if ( !maliste.IsEmpty() ) {
572 p1 = ToolPolygon3d::BeginOfSeg(thePolyg, iLin);
573 p2 = ToolPolygon3d::EndOfSeg(thePolyg, iLin);
574 Beg0 = p1;
575 End0 = p2;
576 }
577 // Modified by MKK - Thu Oct 25 12:40:11 2007 End
578 while (clt.More()) {
579 indTri=clt.Value();
580 // Modified by MKK - Thu Oct 25 12:40:11 2007 Begin
581 Standard_Integer prevSize = mySPoins.Length();
582
583 Standard_Integer pTri[3];
584 ToolPolyh::Triangle(thePolyh, indTri, pTri[0], pTri[1], pTri[2]);
585 gp_XYZ triNor; // Vecteur normal.
586 Standard_Real triDp = 0.; // Distance polaire.
587
588 Intf::PlaneEquation(ToolPolyh::Point(thePolyh, pTri[0]),
589 ToolPolyh::Point(thePolyh, pTri[1]),
590 ToolPolyh::Point(thePolyh, pTri[2]),
591 triNor, triDp);
592
593 // enlarge boundary segment
594 if ( iLin == 1 ) {
595 gp_XYZ dif = p1.XYZ() - p2.XYZ();
596 Standard_Real dist = dif.Modulus();
597 if ( dist > gp::Resolution() ) {
598 dif /= dist;
599 Standard_Real aCos = dif * triNor;
600 aCos = fabs(aCos);
601 if ( aCos > gp::Resolution() ) {
602 Standard_Real shift = defPh / aCos;
603 Beg0.SetXYZ( p1.XYZ() + dif * shift );
604 }
605 }
606 }
607 else if ( iLin == ToolPolygon3d::NbSegments(thePolyg) ) {
608 gp_XYZ dif = p2.XYZ() - p1.XYZ();
609 Standard_Real dist = dif.Modulus();
610 if ( dist > gp::Resolution() ) {
611 dif /= dist;
612 Standard_Real aCos = dif * triNor;
613 aCos = fabs(aCos);
614 if ( aCos > gp::Resolution() ) {
615 Standard_Real shift = defPh / aCos;
616 End0.SetXYZ( p2.XYZ() + dif * shift );
617 }
618 }
619 }
620 Standard_Real dBegTri=(triNor*Beg0.XYZ())-triDp; // Distance <p1> plane
621 Standard_Real dEndTri=(triNor*End0.XYZ())-triDp; // Distance <p2> plane
622
623 Intersect(Beg0, End0, Standard_False, indTri, thePolyh, triNor, triDp, dBegTri, dEndTri);
624
625 // Modified by MKK - Thu Oct 25 12:40:11 2007 End
626 clt.Next();
627 }
628 BeginOfClosedPolygon=Standard_False;
629 }
630}
631
632
7fd59977 633//=======================================================================
634//function : Intersect
635//purpose : Compute the intersection beetween the segment or the line
636// and the triangle <TTri>.
637//=======================================================================
638#if 0
639void Intf_InterferencePolygonPolyhedron::Intersect
640(const gp_Pnt& BegO, const gp_Pnt& EndO, const Standard_Boolean Infinite,
641 const Standard_Integer TTri, const Polyhedron& thePolyh)
642{
643 Standard_Integer pTri0,pTri1,pTri2;
644 ToolPolyh::Triangle(thePolyh, TTri, pTri0, pTri1, pTri2);
645 gp_Pnt Pa=ToolPolyh::Point(thePolyh, pTri0);
646 gp_Pnt Pb=ToolPolyh::Point(thePolyh, pTri1);
647 gp_Pnt Pc=ToolPolyh::Point(thePolyh, pTri2);
648 gp_Vec PaPb(Pa,Pb);
649 gp_Vec PaPc(Pa,Pc);
650 gp_Vec Normale = PaPb.Crossed(PaPc);
651 Standard_Real Norm_Normale=Normale.Magnitude();
652 if(Norm_Normale<1e-14)
653 return;
654
655 //-- Equation du Plan
656 Standard_Real A=Normale.X()/Norm_Normale;
657 Standard_Real B=Normale.Y()/Norm_Normale;
658 Standard_Real C=Normale.Z()/Norm_Normale;
659 Standard_Real D=-(A*Pa.X()+B*Pa.Y()+C*Pa.Z());
660
661 gp_Vec BegOEndO(BegO,EndO);
662 Standard_Real Norm_BegOEndO=BegOEndO.Magnitude();
663 if(Norm_BegOEndO<1e-14)
664 return;
665 Standard_Real Lx=BegOEndO.X()/Norm_BegOEndO;
666 Standard_Real Ly=BegOEndO.Y()/Norm_BegOEndO;
667 Standard_Real Lz=BegOEndO.Z()/Norm_BegOEndO;
668
669 Standard_Real Vd=A*Lx+B*Ly+C*Lz; //-- DirLigne . NormalePlan
670
671 if(Vd==0) { //-- Droite parallele au plan
672 return;
673 }
674
675
676 //-- Calcul du parametre sur la ligne
677 Standard_Real t=-(A*BegO.X()+B*BegO.Y()+C*BegO.Z()+D) / Vd;
678
679 Standard_Real tol=1e-8; //-- Deflection sur le triangle
680 if(t<-tol || t>(Norm_BegOEndO+tol)) {
681 if(Infinite==Standard_False) {
682 return;
683 }
684 }
685 //-- On a une intersection droite plan
686 //-- On teste si c est dans le triangle
687 gp_Pnt PRes(BegO.X()+t*Lx,BegO.Y()+t*Ly,BegO.Z()+t*Lz);
688
689 Standard_Real AbsA=A; if(AbsA<0) AbsA=-AbsA;
690 Standard_Real AbsB=B; if(AbsB<0) AbsB=-AbsB;
691 Standard_Real AbsC=C; if(AbsC<0) AbsC=-AbsC;
692
693 Standard_Real Au,Av,Bu,Bv,Cu,Cv,Pu,Pv;
694 if(AbsA>AbsB) {
695 if(AbsA>AbsC) {
696 //-- Projeter selon X
697 Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
698 Av=Pa.Z(); Bv=Pb.Z(); Cv=Pc.Z(); Pv=PRes.Z();
699 }
700 else {
701 //-- Projeter selon Z
702 Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
703 Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
704 }
705 }
706 else {
707 if(AbsB>AbsC) {
708 //-- projeter selon Y
709 Au=Pa.Z(); Bu=Pb.Z(); Cu=Pc.Z(); Pu=PRes.Z();
710 Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
711 }
712 else {
713 //-- projeter selon Z
714 Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
715 Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
716 }
717 }
718
719 Standard_Real ABu=Bu-Au; Standard_Real ABv=Bv-Av;
720 Standard_Real ACu=Cu-Au; Standard_Real ACv=Cv-Av;
721 Standard_Real BCu=Cu-Bu; Standard_Real BCv=Cv-Bv;
722
723 Standard_Real t1,t2;
724 //-- Test sur AB et C
725 t1=-ABv*Cu + ABu*Cv;
726 t2=-ABv*Pu + ABu*Pv;
727 if(t1<0) { if(t2>0) return; } else { if(t2<0) return; }
728
729 //-- Test sur AC et B
730 t1=-ACv*Bu + ACu*Bv;
731 t2=-ACv*Pu + ACu*Pv;
732 if(t1<0) { if(t2>0) return; } else { if(t2<0) return; }
733
734 //-- Test sur BC et A
735 t1=-BCv*Au + BCu*Av;
736 t2=-BCv*Pu + BCu*Pv;
737 if(t1<0) { if(t2>0) return; } else { if(t2<0) return; }
738
739
740 Intf_SectionPoint SP(PRes,
741 Intf_EDGE,
742 0,
743 iLin, //-- !!!!! VARIABLE STATIQUE
744 t / Norm_BegOEndO,
745 Intf_FACE,
746 TTri, 0, 0.,1.);
747 mySPoins.Append(SP);
748}
749#else
750void Intf_InterferencePolygonPolyhedron::Intersect
751 (const gp_Pnt& BegO, const gp_Pnt& EndO, const Standard_Boolean Infinite,
752 const Standard_Integer TTri, const Polyhedron& thePolyh)
753{
754 Intf_PIType typOnG=Intf_EDGE;
755 Standard_Real t;
756 Standard_Integer pTri[3];
757 ToolPolyh::Triangle(thePolyh, TTri, pTri[0], pTri[1], pTri[2]);
758 gp_XYZ triNor; // Vecteur normal.
759 Standard_Real triDp; // Distance polaire.
760
761 Intf::PlaneEquation(ToolPolyh::Point(thePolyh, pTri[0]),
762 ToolPolyh::Point(thePolyh, pTri[1]),
763 ToolPolyh::Point(thePolyh, pTri[2]),
764 triNor, triDp);
765
766
767 Standard_Real dBegTri=(triNor*BegO.XYZ())-triDp; // Distance <BegO> plan
768 Standard_Real dEndTri=(triNor*EndO.XYZ())-triDp; // Distance <EndO> plan
769 gp_XYZ segO=EndO.XYZ()-BegO.XYZ();
770 segO.Normalize();
7fd59977 771 Standard_Boolean NoIntersectionWithTriangle = Standard_False;
772 Standard_Boolean PolygonCutsPlane = Standard_True;
773
7fd59977 774 Standard_Real param;
775 t = dBegTri-dEndTri;
776 if (t >= 1.e-16 || t<=-1.e-16)
777 param = dBegTri/t;
778 else param = dBegTri;
779 Standard_Real floatgap=Epsilon(1000.);
780
781 if (!Infinite) {
782 if (dBegTri<=floatgap && dBegTri>=-floatgap ) {
783 param=0.;typOnG=Intf_VERTEX;
784 if (BeginOfClosedPolygon)
785 NoIntersectionWithTriangle = Standard_False;
786 }
787 else if (dEndTri<=floatgap && dEndTri>=-floatgap) {
788 param=1.;typOnG=Intf_VERTEX;
789 NoIntersectionWithTriangle = Standard_False;
790 }
791 if (param<0. || param>1.) {
792 PolygonCutsPlane = Standard_False;
793 NoIntersectionWithTriangle = Standard_True;
794 }
795 }
796 if(NoIntersectionWithTriangle == Standard_False) {
797 gp_XYZ spLieu=BegO.XYZ()+((EndO.XYZ()-BegO.XYZ())*param);
798 Standard_Real dPiE[3], dPtPi[3], sigd;
41194117 799 Standard_Integer is = 0;
7fd59977 800 Standard_Integer sEdge=-1;
801 Standard_Integer sVertex=-1;
7fd59977 802 Standard_Integer tbreak=0;
803 { //-- is = 0
804 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[1]).XYZ()-
805 ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
806 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
807 dPtPi[0]=vecP.Modulus();
808 if (dPtPi[0]<=floatgap) {
809 sVertex=0;
810 is=0;
811 tbreak=1;
812 }
813 else {
814 gp_XYZ segT_x_vecP(segT^vecP);
815 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
816 sigd = segT_x_vecP*triNor;
817 if(sigd>floatgap)
818 sigd = 1.0;
819 else if(sigd<-floatgap)
820 sigd = -1.0;
821 else {
822 sigd = 0.0;
823 }
824 dPiE[0]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
825 if (dPiE[0]<=floatgap && dPiE[0]>=-floatgap) {
826 sEdge=0;
827 is=0;
828 tbreak=1;
829 }
830 }
831 }
41194117 832
7fd59977 833 if(tbreak==0) { //-- is = 1
834 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[2]).XYZ()-
835 ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
836 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
837 dPtPi[1]=vecP.Modulus();
838 if (dPtPi[1]<=floatgap) {
839 sVertex=1;
840 is=1;
841 tbreak=1;
842 }
843 else {
844 gp_XYZ segT_x_vecP(segT^vecP);
845 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
846 sigd = segT_x_vecP*triNor;
847 if(sigd>floatgap)
848 sigd = 1.0;
849 else if(sigd<-floatgap)
850 sigd = -1.0;
851 else {
852 sigd = 0.0;
853 }
854 dPiE[1]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
855 if (dPiE[1]<=floatgap && dPiE[1]>=-floatgap) {
856 sEdge=1;
857 is=1;
858 tbreak=1;
859 }
860 }
861 }
862 if(tbreak==0) { //-- is = 2
863 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[0]).XYZ()-
864 ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
865 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
866 dPtPi[2]=vecP.Modulus();
867 if (dPtPi[2]<=floatgap) {
868 sVertex=2;
869 is=2;
870 }
871 gp_XYZ segT_x_vecP(segT^vecP);
872 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
873 sigd = segT_x_vecP*triNor;
874 if(sigd>floatgap)
875 sigd = 1.0;
876 else if(sigd<-floatgap)
877 sigd = -1.0;
878 else {
879 sigd = 0.0;
880 }
881 dPiE[2]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
882 if (dPiE[2]<=floatgap && dPiE[2]>=-floatgap) {
883 sEdge=2;
884 is=2;
885 }
886 }
887 //-- fin for i=0 to 2
888 // !!cout<<endl;
889
890 Standard_Integer triCon, pedg;
891 if (sVertex>-1) {
892 triCon=TTri;
893 pedg=pTri[Pourcent3[sVertex+1]];
894//-- while (triCon!=0) {
895//-- ToolPolyh::TriConnex(thePolyh, triCon,pTri[sVertex],pedg,triCon,pedg);
896//-- //-- if (triCon<TTri) return;
897//-- if (triCon==TTri) break;
898//-- }
899 Intf_SectionPoint SP(spLieu,
900 typOnG, 0, iLin, param,
901 Intf_VERTEX, pTri[is], 0, 0.,
902 1.);
903 mySPoins.Append(SP);
904 }
905 else if (sEdge>-1) {
906 ToolPolyh::TriConnex(thePolyh, TTri, pTri[sEdge], pTri[Pourcent3[sEdge+1]],
907 triCon, pedg);
908 //-- if (triCon<=TTri) return; ???????????????????? LBR
909 // !!cout<<" sEdge "<<endl;
910 Intf_SectionPoint SP(spLieu,
911 typOnG, 0, iLin, param,
912 Intf_EDGE, Min(pTri[sEdge], pTri[Pourcent3[sEdge+1]]),
913 Max(pTri[sEdge], pTri[Pourcent3[sEdge+1]]), 0.,
914 1.);
915 mySPoins.Append(SP);
916 }
917 else if (dPiE[0]>0. && dPiE[1]>0. && dPiE[2]>0.) {
918 // !!cout<<" 3 Positifs "<<endl;
919 Intf_SectionPoint SP(spLieu,
920 typOnG, 0, iLin, param,
921 Intf_FACE, TTri, 0, 0.,
922 1.);
923 mySPoins.Append(SP);
924 }
925// Modified by Sergey KHROMOV - Fri Dec 7 14:40:11 2001 Begin
926 // Sometimes triangulation doesn't cover whole the face. In this
927 // case it is necessary to take into account the deflection between boundary
928 // isolines of the surface and boundary trianles. Computed value of this
929 // deflection is contained in thePolyh.
930 else {
931 Standard_Integer i;
932
933 for (i = 1; i <= 3; i++) {
934 Standard_Integer indP1 = (i == 3) ? pTri[0] : pTri[i];
935 Standard_Integer indP2 = pTri[i - 1];
936
937 if (ToolPolyh::IsOnBound(thePolyh, indP1, indP2)) {
938 // For boundary line it is necessary to check the border deflection.
939 Standard_Real Deflection = ToolPolyh::GetBorderDeflection(thePolyh);
940 const gp_Pnt &BegP = ToolPolyh::Point(thePolyh, indP1);
941 const gp_Pnt &EndP = ToolPolyh::Point(thePolyh, indP2);
942 gp_Vec VecTri(BegP,EndP);
943 gp_Dir DirTri(VecTri);
944 gp_Lin LinTri(BegP,DirTri);
945 gp_Pnt aPOnE(spLieu);
946 Standard_Real aDist = LinTri.Distance(aPOnE);
947
948 if (aDist <= Deflection) {
949 gp_Vec aVLocPOnE(BegP, aPOnE);
950 gp_Vec aVecDirTri(DirTri);
951 Standard_Real aPar = aVLocPOnE*aVecDirTri;
952 Standard_Real aMaxPar = VecTri.Magnitude();
953
954 if (aPar >= 0 && aPar <= aMaxPar) {
955 Intf_SectionPoint SP(spLieu,
956 typOnG, 0, iLin, param,
957 Intf_FACE, TTri, 0, 0.,
958 1.);
959 mySPoins.Append(SP);
960 }
961 }
962 }
963 }
964 }
965// Modified by Sergey KHROMOV - Fri Dec 7 14:40:29 2001 End
966 } //---- if(NoIntersectionWithTriangle == Standard_False)
967
968 //---------------------------------------------------------------------------
969 //-- On teste la distance entre les cotes du triangle et le polygone
970 //--
971 //-- Si cette distance est inferieure a Tolerance, on cree un SP.
972 //--
973 //-- printf("\nIntf_InterferencePolygPolyh : dBegTri=%g dEndTri=%g Tolerance=%g\n",dBegTri,dEndTri,Tolerance);
974 if(1 || (Abs(dBegTri) <= Tolerance)
975 || (Abs(dEndTri) <= Tolerance)) {
976 gp_Vec VecPol(BegO,EndO);
977 Standard_Real NVecPol = VecPol.Magnitude();
978 gp_Dir DirPol(VecPol);
979 gp_Lin LinPol(BegO,DirPol);
980 Standard_Real dist2,ParamOnO,ParamOnT;
981
982 for (Standard_Integer i=0; i<3; i++) {
983 Standard_Integer pTri_ip1pc3 = pTri[Pourcent3[i+1]];
984 Standard_Integer pTri_i = pTri[i];
985 const gp_Pnt& BegT = ToolPolyh::Point(thePolyh, pTri_ip1pc3);
986 const gp_Pnt& EndT = ToolPolyh::Point(thePolyh, pTri_i);
987 gp_Vec VecTri(BegT,EndT);
988 Standard_Real NVecTri = VecTri.Magnitude();
989 gp_Dir DirTri(VecTri);
990 gp_Lin LinTri(BegT,DirTri);
991 Extrema_ExtElC Extrema(LinPol,LinTri,0.00000001);
992 if(Extrema.IsDone()) {
993 if(Extrema.IsParallel() == Standard_False) {
994 if(Extrema.NbExt()) {
995 dist2 = Extrema.SquareDistance();
996 if(dist2<=Tolerance * Tolerance) {
997 Extrema_POnCurv POnC1,POnC2;
998 Extrema.Points(1,POnC1,POnC2);
999 const gp_Pnt& PO = POnC1.Value();
1000 const gp_Pnt& PT = POnC2.Value();
1001 //--cout<<" ** Nouveau "<<dist2<<endl;
1002 if(IsInSegment(VecPol,gp_Vec(BegO,PO),NVecPol,ParamOnO,Tolerance)) {
1003 if(IsInSegment(VecTri,gp_Vec(BegT,PT),NVecTri,ParamOnT,Tolerance)) {
1004 //-- cout<<" * "<<endl;
1005 gp_XYZ spLieu=BegT.XYZ()+((EndT.XYZ()-BegT.XYZ())*param);
1006 Standard_Integer tmin,tmax;
1007 if(pTri_i>pTri_ip1pc3) {
1008 tmin=pTri_ip1pc3; tmax=pTri_i;
1009 }
1010 else {
1011 tmax=pTri_ip1pc3; tmin=pTri_i;
1012 }
1013 Intf_SectionPoint SP(spLieu,
1014 typOnG, 0, iLin, ParamOnO,
1015 Intf_EDGE,
1016 tmin,
1017 tmax, 0.,
1018 1.);
1019 mySPoins.Append(SP);
1020 }
1021 }
1022 }
1023 }
1024 }
1025 }
1026 }
1027 }
1028}
1029
1030#endif
1031
1032void Intf_InterferencePolygonPolyhedron::Intersect
1033 (const gp_Pnt& BegO, const gp_Pnt& EndO, const Standard_Boolean Infinite,
1034 const Standard_Integer TTri, const Polyhedron& thePolyh, const gp_XYZ& TriNormal,
1035 const Standard_Real TriDp, const Standard_Real dBegTri, const Standard_Real dEndTri)
1036{
1037 Intf_PIType typOnG=Intf_EDGE;
1038 Standard_Real t;
1039 Standard_Integer pTri[3];
1040 ToolPolyh::Triangle(thePolyh, TTri, pTri[0], pTri[1], pTri[2]);
1041 gp_XYZ triNor = TriNormal; // Vecteur normal.
1042 Standard_Real triDp = TriDp; // Distance polaire.
1043
1044
1045// Standard_Real dBegTri=(triNor*BegO.XYZ())-triDp; // Distance <BegO> plan
1046// Standard_Real dEndTri=(triNor*EndO.XYZ())-triDp; // Distance <EndO> plan
1047
1048 Standard_Boolean NoIntersectionWithTriangle = Standard_False;
1049 Standard_Boolean PolygonCutsPlane = Standard_True;
1050
1051 Standard_Real param;
1052 t = dBegTri-dEndTri;
1053 if (t >= 1.e-16 || t<=-1.e-16)
1054 param = dBegTri/t;
1055 else param = dBegTri;
1056 Standard_Real floatgap=Epsilon(1000.);
1057
1058 if (!Infinite) {
1059 if (dBegTri<=floatgap && dBegTri>=-floatgap ) {
1060 param=0.;typOnG=Intf_VERTEX;
1061 if (BeginOfClosedPolygon)
1062 NoIntersectionWithTriangle = Standard_False;
1063 }
1064 else if (dEndTri<=floatgap && dEndTri>=-floatgap) {
1065 param=1.;typOnG=Intf_VERTEX;
1066 NoIntersectionWithTriangle = Standard_False;
1067 }
1068 if (param<0. || param>1.) {
1069 PolygonCutsPlane = Standard_False;
1070 NoIntersectionWithTriangle = Standard_True;
1071 }
1072 }
1073 if(NoIntersectionWithTriangle == Standard_False) {
1074 gp_XYZ spLieu=BegO.XYZ()+((EndO.XYZ()-BegO.XYZ())*param);
1075 Standard_Real dPiE[3], dPtPi[3], sigd;
41194117 1076 Standard_Integer is = 0;
7fd59977 1077 Standard_Integer sEdge=-1;
1078 Standard_Integer sVertex=-1;
1079 Standard_Integer tbreak=0;
1080 { //-- is = 0
1081 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[1]).XYZ()-
1082 ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
1083 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
1084 dPtPi[0]=vecP.Modulus();
1085 if (dPtPi[0]<=floatgap) {
1086 sVertex=0;
1087 is=0;
1088 tbreak=1;
1089 }
1090 else {
1091 gp_XYZ segT_x_vecP(segT^vecP);
1092 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
1093 sigd = segT_x_vecP*triNor;
1094 if(sigd>floatgap)
1095 sigd = 1.0;
1096 else if(sigd<-floatgap)
1097 sigd = -1.0;
1098 else {
1099 sigd = 0.0;
1100 }
1101 dPiE[0]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
1102 if (dPiE[0]<=floatgap && dPiE[0]>=-floatgap) {
1103 sEdge=0;
1104 is=0;
1105 tbreak=1;
1106 }
1107 }
1108 }
1109
1110 if(tbreak==0) { //-- is = 1
1111 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[2]).XYZ()-
1112 ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
1113 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
1114 dPtPi[1]=vecP.Modulus();
1115 if (dPtPi[1]<=floatgap) {
1116 sVertex=1;
1117 is=1;
1118 tbreak=1;
1119 }
1120 else {
1121 gp_XYZ segT_x_vecP(segT^vecP);
1122 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
1123 sigd = segT_x_vecP*triNor;
1124 if(sigd>floatgap)
1125 sigd = 1.0;
1126 else if(sigd<-floatgap)
1127 sigd = -1.0;
1128 else {
1129 sigd = 0.0;
1130 }
1131 dPiE[1]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
1132 if (dPiE[1]<=floatgap && dPiE[1]>=-floatgap) {
1133 sEdge=1;
1134 is=1;
1135 tbreak=1;
1136 }
1137 }
1138 }
1139 if(tbreak==0) { //-- is = 2
1140 gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[0]).XYZ()-
1141 ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
1142 gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
1143 dPtPi[2]=vecP.Modulus();
1144 if (dPtPi[2]<=floatgap) {
1145 sVertex=2;
1146 is=2;
1147 }
1148 gp_XYZ segT_x_vecP(segT^vecP);
1149 Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
1150 sigd = segT_x_vecP*triNor;
1151 if(sigd>floatgap)
1152 sigd = 1.0;
1153 else if(sigd<-floatgap)
1154 sigd = -1.0;
1155 else {
1156 sigd = 0.0;
1157 }
1158 dPiE[2]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
1159 if (dPiE[2]<=floatgap && dPiE[2]>=-floatgap) {
1160 sEdge=2;
1161 is=2;
1162 }
1163 }
1164 //-- fin for i=0 to 2
1165 // !!cout<<endl;
1166
1167 Standard_Integer triCon, pedg;
1168 if (sVertex>-1) {
1169 triCon=TTri;
1170 pedg=pTri[Pourcent3[sVertex+1]];
1171//-- while (triCon!=0) {
1172//-- ToolPolyh::TriConnex(thePolyh, triCon,pTri[sVertex],pedg,triCon,pedg);
1173//-- //-- if (triCon<TTri) return;
1174//-- if (triCon==TTri) break;
1175//-- }
1176 Intf_SectionPoint SP(spLieu,
1177 typOnG, 0, iLin, param,
1178 Intf_VERTEX, pTri[is], 0, 0.,
1179 1.);
1180 mySPoins.Append(SP);
1181 }
1182 else if (sEdge>-1) {
1183 ToolPolyh::TriConnex(thePolyh, TTri, pTri[sEdge], pTri[Pourcent3[sEdge+1]],
1184 triCon, pedg);
1185 //-- if (triCon<=TTri) return; ???????????????????? LBR
1186 // !!cout<<" sEdge "<<endl;
1187 Intf_SectionPoint SP(spLieu,
1188 typOnG, 0, iLin, param,
1189 Intf_EDGE, Min(pTri[sEdge], pTri[Pourcent3[sEdge+1]]),
1190 Max(pTri[sEdge], pTri[Pourcent3[sEdge+1]]), 0.,
1191 1.);
1192 mySPoins.Append(SP);
1193 }
1194 else if (dPiE[0]>0. && dPiE[1]>0. && dPiE[2]>0.) {
1195 // !!cout<<" 3 Positifs "<<endl;
1196 Intf_SectionPoint SP(spLieu,
1197 typOnG, 0, iLin, param,
1198 Intf_FACE, TTri, 0, 0.,
1199 1.);
1200 mySPoins.Append(SP);
1201 }
1202// Modified by Sergey KHROMOV - Fri Dec 7 14:40:11 2001 Begin
1203 // Sometimes triangulation doesn't cover whole the face. In this
1204 // case it is necessary to take into account the deflection between boundary
1205 // isolines of the surface and boundary trianles. Computed value of this
1206 // deflection is contained in thePolyh.
1207 else {
1208 Standard_Integer i;
1209
1210 for (i = 1; i <= 3; i++) {
1211 Standard_Integer indP1 = (i == 3) ? pTri[0] : pTri[i];
1212 Standard_Integer indP2 = pTri[i - 1];
1213
1214 if (ToolPolyh::IsOnBound(thePolyh, indP1, indP2)) {
1215 // For boundary line it is necessary to check the border deflection.
1216 Standard_Real Deflection = ToolPolyh::GetBorderDeflection(thePolyh);
1217 const gp_Pnt &BegP = ToolPolyh::Point(thePolyh, indP1);
1218 const gp_Pnt &EndP = ToolPolyh::Point(thePolyh, indP2);
1219 gp_Vec VecTri(BegP,EndP);
1220 gp_Dir DirTri(VecTri);
1221 gp_Lin LinTri(BegP,DirTri);
1222 gp_Pnt aPOnE(spLieu);
1223 Standard_Real aDist = LinTri.Distance(aPOnE);
1224
1225 if (aDist <= Deflection) {
1226 gp_Vec aVLocPOnE(BegP, aPOnE);
1227 gp_Vec aVecDirTri(DirTri);
1228 Standard_Real aPar = aVLocPOnE*aVecDirTri;
1229 Standard_Real aMaxPar = VecTri.Magnitude();
1230
1231 if (aPar >= 0 && aPar <= aMaxPar) {
1232 Intf_SectionPoint SP(spLieu,
1233 typOnG, 0, iLin, param,
1234 Intf_FACE, TTri, 0, 0.,
1235 1.);
1236 mySPoins.Append(SP);
1237 }
1238 }
1239 }
1240 }
1241 }
1242// Modified by Sergey KHROMOV - Fri Dec 7 14:40:29 2001 End
1243 } //---- if(NoIntersectionWithTriangle == Standard_False)
1244
1245 //---------------------------------------------------------------------------
1246 //-- On teste la distance entre les cotes du triangle et le polygone
1247 //--
1248 //-- Si cette distance est inferieure a Tolerance, on cree un SP.
1249 //--
1250 //-- printf("\nIntf_InterferencePolygPolyh : dBegTri=%g dEndTri=%g Tolerance=%g\n",dBegTri,dEndTri,Tolerance);
1251 if(1 || (Abs(dBegTri) <= Tolerance)
1252 || (Abs(dEndTri) <= Tolerance)) {
1253 gp_Vec VecPol(BegO,EndO);
1254 Standard_Real NVecPol = VecPol.Magnitude();
1255 gp_Dir DirPol(VecPol);
1256 gp_Lin LinPol(BegO,DirPol);
1257 Standard_Real dist2,ParamOnO,ParamOnT;
1258
1259 for (Standard_Integer i=0; i<3; i++) {
1260 Standard_Integer pTri_ip1pc3 = pTri[Pourcent3[i+1]];
1261 Standard_Integer pTri_i = pTri[i];
1262 const gp_Pnt& BegT = ToolPolyh::Point(thePolyh, pTri_ip1pc3);
1263 const gp_Pnt& EndT = ToolPolyh::Point(thePolyh, pTri_i);
1264 gp_Vec VecTri(BegT,EndT);
1265 Standard_Real NVecTri = VecTri.Magnitude();
1266 gp_Dir DirTri(VecTri);
1267 gp_Lin LinTri(BegT,DirTri);
1268 Extrema_ExtElC Extrema(LinPol,LinTri,0.00000001);
1269 if(Extrema.IsDone()) {
1270 if(Extrema.IsParallel() == Standard_False) {
1271 if(Extrema.NbExt()) {
1272 dist2 = Extrema.SquareDistance();
1273 if(dist2<=Tolerance * Tolerance) {
1274 Extrema_POnCurv POnC1,POnC2;
1275 Extrema.Points(1,POnC1,POnC2);
1276 const gp_Pnt& PO = POnC1.Value();
1277 const gp_Pnt& PT = POnC2.Value();
1278 //--cout<<" ** Nouveau "<<dist2<<endl;
1279 if(IsInSegment(VecPol,gp_Vec(BegO,PO),NVecPol,ParamOnO,Tolerance)) {
1280 if(IsInSegment(VecTri,gp_Vec(BegT,PT),NVecTri,ParamOnT,Tolerance)) {
1281 //-- cout<<" * "<<endl;
1282 gp_XYZ spLieu=BegT.XYZ()+((EndT.XYZ()-BegT.XYZ())*param);
1283 Standard_Integer tmin,tmax;
1284 if(pTri_i>pTri_ip1pc3) {
1285 tmin=pTri_ip1pc3; tmax=pTri_i;
1286 }
1287 else {
1288 tmax=pTri_ip1pc3; tmin=pTri_i;
1289 }
1290 Intf_SectionPoint SP(spLieu,
1291 typOnG, 0, iLin, ParamOnO,
1292 Intf_EDGE,
1293 tmin,
1294 tmax, 0.,
1295 1.);
1296 mySPoins.Append(SP);
1297 }
1298 }
1299 }
1300 }
1301 }
1302 }
1303 }
1304 }
1305}