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