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