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