Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/opencascade/Intf_InterferencePolygonPolyhedron.gxx is written in an unsupported language. File is not indexed.

0001 // Created on: 1992-12-21
0002 // Created by: Didier PIFFAULT
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #include <gp_XYZ.hxx>
0018 #include <gp_Vec.hxx>
0019 #include <TColStd_ListOfInteger.hxx>
0020 #include <TColStd_ListIteratorOfListOfInteger.hxx>
0021 #include <Bnd_Box.hxx>
0022 #include <Intf_Tool.hxx>
0023 #include <Bnd_BoundSortBox.hxx>
0024 #include <Intf_Array1OfLin.hxx>
0025 #include <Intf_SectionPoint.hxx>
0026 #include <Intf_SeqOfSectionPoint.hxx>
0027 #include <Intf_TangentZone.hxx>
0028 #include <Intf_SeqOfTangentZone.hxx>
0029 #include <Intf.hxx>
0030 
0031 #include <Extrema_ExtElC.hxx>
0032 #include <Extrema_POnCurv.hxx>
0033 
0034 static const int Pourcent3[4] = {0, 1, 2, 0};
0035 
0036 static Standard_Boolean IsInSegment(const gp_Vec& P1P2,
0037                                     const gp_Vec& P1P,
0038                                     const Standard_Real NP1P2,
0039                                     Standard_Real &Param,
0040                                     const Standard_Real Tolerance) { 
0041   Param = P1P2.Dot(P1P);
0042   Param/= NP1P2;
0043   if(Param > (NP1P2+Tolerance))
0044     return(Standard_False);
0045   if(Param < (-Tolerance))
0046     return(Standard_False);
0047   Param/=NP1P2;
0048   if(Param<0.0) Param=0.0;
0049   if(Param>1.0) Param=1.0;
0050   return(Standard_True);
0051 }
0052     
0053 
0054 //=======================================================================
0055 //function : Intf_InterferencePolygonPolyhedron
0056 //purpose  : Empty constructor
0057 //=======================================================================
0058 
0059 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron() 
0060 : Intf_Interference (Standard_False),
0061   BeginOfClosedPolygon (Standard_False),
0062   iLin (0)
0063 {} 
0064 
0065 //=======================================================================
0066 //function : Intf_InterferencePolygonPolyhedron
0067 //purpose  : Construct and compute an interference between a Polygon3d
0068 //           and a Polyhedron.
0069 //=======================================================================
0070 
0071 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
0072   (const Polygon3d& thePolyg, const Polyhedron& thePolyh) 
0073 : Intf_Interference (Standard_False),
0074   BeginOfClosedPolygon (Standard_False),
0075   iLin (0)
0076 {
0077   Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
0078             ToolPolyh::DeflectionOverEstimation(thePolyh);
0079   if (Tolerance==0.)
0080     Tolerance=Epsilon(1000.);
0081 
0082   if (!ToolPolygon3d::Bounding(thePolyg).IsOut(ToolPolyh::Bounding(thePolyh))) {
0083     Interference(thePolyg, thePolyh);
0084   }
0085 } 
0086 
0087 
0088 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
0089   (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
0090    Bnd_BoundSortBox &PolyhGrid) 
0091 : Intf_Interference (Standard_False),
0092   BeginOfClosedPolygon (Standard_False),
0093   iLin (0)
0094 {
0095   Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
0096             ToolPolyh::DeflectionOverEstimation(thePolyh);
0097   if (Tolerance==0.)
0098     Tolerance=Epsilon(1000.);
0099 
0100   if (!ToolPolygon3d::Bounding(thePolyg).IsOut(ToolPolyh::Bounding(thePolyh))) {
0101     Interference(thePolyg, thePolyh,PolyhGrid);
0102   }
0103 } 
0104 
0105 //=======================================================================
0106 //function : Intf_InterferencePolygonPolyhedron
0107 //purpose  : Construct and compute an interference between a Straight
0108 //           Line and a Polyhedron.
0109 //=======================================================================
0110 
0111 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
0112   (const gp_Lin& theLin, const Polyhedron& thePolyh) 
0113 : Intf_Interference (Standard_False),
0114   BeginOfClosedPolygon (Standard_False),
0115   iLin (0)
0116 {
0117   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0118   if (Tolerance==0.)
0119     Tolerance=Epsilon(1000.);
0120 
0121   BeginOfClosedPolygon=Standard_False;
0122 
0123   Bnd_BoundSortBox PolyhGrid;
0124   PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
0125                        ToolPolyh::ComponentsBounding(thePolyh));
0126   Standard_Integer indTri;
0127 
0128   iLin=0;
0129 
0130   Bnd_Box bofLin;
0131   Intf_Tool btoo;
0132   btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
0133 
0134   TColStd_ListIteratorOfListOfInteger iCl(PolyhGrid.Compare(bofLin));
0135   while (iCl.More()) {
0136     indTri=iCl.Value();
0137     Intersect
0138         (theLin.Location(), 
0139          theLin.Location().Translated(gp_Vec(theLin.Direction())),
0140          Standard_True, indTri, thePolyh);
0141     iCl.Next();
0142   }
0143 }
0144 
0145 
0146 //=======================================================================
0147 //function : Intf_InterferencePolygonPolyhedron
0148 //purpose  : Construct and compute an interference between the Straights
0149 //           Lines in <Obje> and the Polyhedron <thePolyh>.
0150 //=======================================================================
0151 
0152 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron 
0153   (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh) 
0154 : Intf_Interference (Standard_False),
0155   BeginOfClosedPolygon (Standard_False),
0156   iLin (0)
0157 {
0158   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0159   if (Tolerance==0.)
0160     Tolerance=Epsilon(1000.);
0161 
0162   Bnd_Box bofLin;
0163   Intf_Tool bToo;
0164   BeginOfClosedPolygon=Standard_False;
0165 
0166   Bnd_BoundSortBox PolyhGrid;
0167   PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
0168                        ToolPolyh::ComponentsBounding(thePolyh));
0169 
0170   Standard_Integer indTri;
0171 
0172   for (iLin=1; iLin<=theLins.Length(); iLin++) {
0173 
0174 
0175     bToo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
0176 
0177     TColStd_ListIteratorOfListOfInteger ilC(PolyhGrid.Compare(bofLin));
0178 
0179     while (ilC.More()) {
0180       indTri=ilC.Value();
0181       Intersect
0182        (theLins(iLin).Location(), 
0183         theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
0184         Standard_True, indTri, thePolyh);
0185       ilC.Next();
0186     }
0187   }
0188 }
0189 
0190 
0191 //=======================================================================
0192 //function : Perform
0193 //purpose  : 
0194 //=======================================================================
0195 
0196 void Intf_InterferencePolygonPolyhedron::Perform 
0197   (const Polygon3d& thePolyg, const Polyhedron& thePolyh) 
0198 {
0199   SelfInterference(Standard_False);
0200   Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
0201             ToolPolyh::DeflectionOverEstimation(thePolyh);
0202   if (Tolerance==0.)
0203     Tolerance=Epsilon(1000.);
0204 
0205   if (!ToolPolygon3d::Bounding(thePolyg).IsOut
0206       (ToolPolyh::Bounding(thePolyh))) {
0207     Interference(thePolyg, thePolyh);
0208   }
0209 } 
0210 
0211 
0212 //=======================================================================
0213 //function : Perform
0214 //purpose  : 
0215 //=======================================================================
0216 
0217 void Intf_InterferencePolygonPolyhedron::Perform 
0218   (const gp_Lin& theLin, const Polyhedron& thePolyh) 
0219 {
0220   SelfInterference(Standard_False);
0221   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0222   if (Tolerance==0.)
0223     Tolerance=Epsilon(1000.);
0224 
0225   BeginOfClosedPolygon=Standard_False;
0226 
0227   Bnd_BoundSortBox PolyhGrid;
0228   PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
0229                        ToolPolyh::ComponentsBounding(thePolyh));
0230 
0231   Standard_Integer indTri;
0232 
0233   iLin=0;
0234 
0235   Bnd_Box bofLin;
0236   Intf_Tool btoo;
0237   btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
0238 
0239   TColStd_ListIteratorOfListOfInteger lCi(PolyhGrid.Compare(bofLin));
0240   while (lCi.More()) {
0241     indTri=lCi.Value();
0242     Intersect
0243         (theLin.Location(), 
0244          theLin.Location().Translated(gp_Vec(theLin.Direction())),
0245          Standard_True, indTri, thePolyh);
0246     lCi.Next();
0247   }
0248 }
0249 
0250 
0251 //=======================================================================
0252 //function : Perform
0253 //purpose  : Compute an interference between the Straights
0254 //           Lines in <Obje> and the Polyhedron <thePolyh>.
0255 //=======================================================================
0256 
0257 void Intf_InterferencePolygonPolyhedron::Perform  
0258   (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh) 
0259 {
0260   SelfInterference(Standard_False);
0261   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0262   if (Tolerance==0.)
0263     Tolerance=Epsilon(1000.);
0264 
0265   Bnd_Box bofLin;
0266   Intf_Tool Btoo;
0267   BeginOfClosedPolygon=Standard_False;
0268 
0269   Bnd_BoundSortBox PolyhGrid;
0270   PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
0271                        ToolPolyh::ComponentsBounding(thePolyh));
0272 
0273   Standard_Integer indTri;
0274 
0275   for (iLin=1; iLin<=theLins.Length(); iLin++) {
0276 
0277     Btoo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
0278 
0279     TColStd_ListIteratorOfListOfInteger tlC(PolyhGrid.Compare(bofLin));
0280 
0281     while (tlC.More()) {
0282       indTri=tlC.Value();
0283       Intersect
0284        (theLins(iLin).Location(), 
0285         theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
0286         Standard_True, indTri, thePolyh);
0287       tlC.Next();
0288     }
0289   }
0290 }
0291 
0292 
0293 //=======================================================================
0294 //function : Interference
0295 //purpose  : Compare the boundings between  the segment of  <Obje>
0296 //           and the facets of <thePolyh>.
0297 //=======================================================================
0298 
0299 void Intf_InterferencePolygonPolyhedron::Interference 
0300   (const Polygon3d& thePolyg, const Polyhedron& thePolyh)
0301 {
0302 
0303   Bnd_Box bofSeg;
0304 
0305   Bnd_BoundSortBox PolyhGrid;
0306   PolyhGrid.Initialize(ToolPolyh::Bounding(thePolyh),
0307                        ToolPolyh::ComponentsBounding(thePolyh));
0308 
0309   Standard_Integer indTri;
0310   BeginOfClosedPolygon=ToolPolygon3d::Closed(thePolyg);
0311 
0312   Standard_Real defPh = ToolPolyh::DeflectionOverEstimation(thePolyh);
0313 
0314   for (iLin=1; iLin<=ToolPolygon3d::NbSegments(thePolyg); iLin++) {
0315 
0316     bofSeg.SetVoid();
0317     bofSeg.Add(ToolPolygon3d::BeginOfSeg(thePolyg, iLin));
0318     bofSeg.Add(ToolPolygon3d::EndOfSeg(thePolyg, iLin));
0319     bofSeg.Enlarge(ToolPolygon3d::DeflectionOverEstimation(thePolyg));
0320 
0321     TColStd_ListOfInteger maliste;
0322     maliste = PolyhGrid.Compare(bofSeg);
0323     TColStd_ListIteratorOfListOfInteger clt(maliste);
0324     for (; clt.More(); clt.Next()) {
0325       indTri=clt.Value();
0326       gp_Pnt p1 = ToolPolygon3d::BeginOfSeg(thePolyg, iLin);
0327       gp_Pnt p2 = ToolPolygon3d::EndOfSeg(thePolyg, iLin);
0328       Standard_Integer pTri0, pTri1, pTri2;
0329       ToolPolyh::Triangle(thePolyh, indTri, pTri0, pTri1, pTri2);
0330       gp_Pnt Pa=ToolPolyh::Point(thePolyh, pTri0);
0331       gp_Pnt Pb=ToolPolyh::Point(thePolyh, pTri1);
0332       gp_Pnt Pc=ToolPolyh::Point(thePolyh, pTri2);
0333       gp_Vec PaPb(Pa,Pb);
0334       gp_Vec PaPc(Pa,Pc);
0335       gp_Vec Normale = PaPb.Crossed(PaPc);
0336       Standard_Real Norm_Normale=Normale.Magnitude();
0337       if(Norm_Normale<1e-14)
0338         continue;
0339       Normale.Multiply(defPh/Norm_Normale);
0340       gp_Pnt p1m = p1.Translated(-Normale);
0341       gp_Pnt p1p = p1.Translated( Normale);
0342       gp_Pnt p2m = p2.Translated(-Normale);
0343       gp_Pnt p2p = p2.Translated( Normale);
0344       Intersect(p1m, 
0345                 p2p,
0346                 Standard_False, indTri, thePolyh);
0347       Intersect(p1p, 
0348                 p2m,
0349                 Standard_False, indTri, thePolyh);
0350 //      Intersect(ToolPolygon3d::BeginOfSeg(thePolyg, iLin), 
0351 //              ToolPolygon3d::EndOfSeg(thePolyg, iLin),
0352 //              Standard_False, indTri, thePolyh);
0353     }
0354     BeginOfClosedPolygon=Standard_False;
0355   }
0356 }
0357 
0358 
0359 
0360 
0361 
0362 
0363 
0364 
0365 
0366 
0367 
0368 
0369 
0370 
0371 
0372 
0373 
0374 
0375 
0376 
0377 //=======================================================================
0378 //function : Intf_InterferencePolygonPolyhedron
0379 //purpose  : Construct and compute an interference between a Straight
0380 //           Line and a Polyhedron.
0381 //=======================================================================
0382 
0383 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron
0384   (const gp_Lin& theLin, const Polyhedron& thePolyh,
0385    Bnd_BoundSortBox &PolyhGrid) 
0386 : Intf_Interference(Standard_False)
0387 {
0388   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0389   if (Tolerance==0.)
0390     Tolerance=Epsilon(1000.);
0391 
0392   BeginOfClosedPolygon=Standard_False;
0393 
0394   Standard_Integer indTri;
0395 
0396   iLin=0;
0397 
0398   Bnd_Box bofLin;
0399   Intf_Tool btoo;
0400   btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
0401 
0402   TColStd_ListIteratorOfListOfInteger iCl(PolyhGrid.Compare(bofLin));
0403   while (iCl.More()) {
0404     indTri=iCl.Value();
0405     Intersect
0406         (theLin.Location(), 
0407          theLin.Location().Translated(gp_Vec(theLin.Direction())),
0408          Standard_True, indTri, thePolyh);
0409     iCl.Next();
0410   }
0411 }
0412 
0413 
0414 //=======================================================================
0415 //function : Intf_InterferencePolygonPolyhedron
0416 //purpose  : Construct and compute an interference between the Straights
0417 //           Lines in <Obje> and the Polyhedron <thePolyh>.
0418 //=======================================================================
0419 
0420 Intf_InterferencePolygonPolyhedron::Intf_InterferencePolygonPolyhedron 
0421   (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh,
0422    Bnd_BoundSortBox &PolyhGrid) 
0423 : Intf_Interference(Standard_False)
0424 {
0425   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0426   if (Tolerance==0.)
0427     Tolerance=Epsilon(1000.);
0428 
0429   Bnd_Box bofLin;
0430   Intf_Tool bToo;
0431   BeginOfClosedPolygon=Standard_False;
0432 
0433   Standard_Integer indTri;
0434 
0435   for (iLin=1; iLin<=theLins.Length(); iLin++) {
0436 
0437 
0438     bToo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
0439 
0440     TColStd_ListIteratorOfListOfInteger ilC(PolyhGrid.Compare(bofLin));
0441 
0442     while (ilC.More()) {
0443       indTri=ilC.Value();
0444       Intersect
0445        (theLins(iLin).Location(), 
0446         theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
0447         Standard_True, indTri, thePolyh);
0448       ilC.Next();
0449     }
0450   }
0451 }
0452 
0453 
0454 //=======================================================================
0455 //function : Perform
0456 //purpose  : 
0457 //=======================================================================
0458 
0459 void Intf_InterferencePolygonPolyhedron::Perform 
0460   (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
0461    Bnd_BoundSortBox &PolyhGrid) 
0462 {
0463   SelfInterference(Standard_False);
0464   Tolerance=ToolPolygon3d::DeflectionOverEstimation(thePolyg)+
0465             ToolPolyh::DeflectionOverEstimation(thePolyh);
0466   if (Tolerance==0.)
0467     Tolerance=Epsilon(1000.);
0468 
0469   if (!ToolPolygon3d::Bounding(thePolyg).IsOut
0470       (ToolPolyh::Bounding(thePolyh))) {
0471     Interference(thePolyg, thePolyh,PolyhGrid);
0472   }
0473 } 
0474 
0475 
0476 //=======================================================================
0477 //function : Perform
0478 //purpose  : 
0479 //=======================================================================
0480 
0481 void Intf_InterferencePolygonPolyhedron::Perform 
0482   (const gp_Lin& theLin, const Polyhedron& thePolyh,
0483    Bnd_BoundSortBox &PolyhGrid) 
0484 {
0485   SelfInterference(Standard_False);
0486   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0487   if (Tolerance==0.)
0488     Tolerance=Epsilon(1000.);
0489 
0490   BeginOfClosedPolygon=Standard_False;
0491 
0492   Standard_Integer indTri;
0493 
0494   iLin=0;
0495 
0496   Bnd_Box bofLin;
0497   Intf_Tool btoo;
0498   btoo.LinBox(theLin, ToolPolyh::Bounding(thePolyh), bofLin);
0499 
0500   TColStd_ListIteratorOfListOfInteger lCi(PolyhGrid.Compare(bofLin));
0501   while (lCi.More()) {
0502     indTri=lCi.Value();
0503     Intersect
0504         (theLin.Location(), 
0505          theLin.Location().Translated(gp_Vec(theLin.Direction())),
0506          Standard_True, indTri, thePolyh);
0507     lCi.Next();
0508   }
0509 }
0510 
0511 
0512 //=======================================================================
0513 //function : Perform
0514 //purpose  : Compute an interference between the Straights
0515 //           Lines in <Obje> and the Polyhedron <thePolyh>.
0516 //=======================================================================
0517 
0518 void Intf_InterferencePolygonPolyhedron::Perform  
0519   (const Intf_Array1OfLin& theLins, const Polyhedron& thePolyh,
0520    Bnd_BoundSortBox &PolyhGrid) 
0521 {
0522   SelfInterference(Standard_False);
0523   Tolerance=ToolPolyh::DeflectionOverEstimation(thePolyh);
0524   if (Tolerance==0.)
0525     Tolerance=Epsilon(1000.);
0526 
0527   Bnd_Box bofLin;
0528   Intf_Tool Btoo;
0529   BeginOfClosedPolygon=Standard_False;
0530 
0531   Standard_Integer indTri;
0532 
0533   for (iLin=1; iLin<=theLins.Length(); iLin++) {
0534 
0535     Btoo.LinBox(theLins(iLin), ToolPolyh::Bounding(thePolyh), bofLin);
0536 
0537     TColStd_ListIteratorOfListOfInteger tlC(PolyhGrid.Compare(bofLin));
0538 
0539     while (tlC.More()) {
0540       indTri=tlC.Value();
0541       Intersect
0542        (theLins(iLin).Location(), 
0543         theLins(iLin).Location().Translated(gp_Vec(theLins(iLin).Direction())),
0544         Standard_True, indTri, thePolyh);
0545       tlC.Next();
0546     }
0547   }
0548 }
0549 
0550 
0551 
0552 //=======================================================================
0553 //function : Interference
0554 //purpose  : Compare the boundings between  the segment of  <Obje>
0555 //           and the facets of <thePolyh>.
0556 //=======================================================================
0557 
0558 void Intf_InterferencePolygonPolyhedron::Interference 
0559   (const Polygon3d& thePolyg, const Polyhedron& thePolyh,
0560    Bnd_BoundSortBox &PolyhGrid)
0561 {
0562   Bnd_Box bofSeg;
0563 
0564   Standard_Integer indTri;
0565   BeginOfClosedPolygon=ToolPolygon3d::Closed(thePolyg);
0566 
0567   for (iLin=1; iLin<=ToolPolygon3d::NbSegments(thePolyg); iLin++) {
0568 
0569     bofSeg.SetVoid();
0570     bofSeg.Add(ToolPolygon3d::BeginOfSeg(thePolyg, iLin));
0571     bofSeg.Add(ToolPolygon3d::EndOfSeg(thePolyg, iLin));
0572     bofSeg.Enlarge(ToolPolygon3d::DeflectionOverEstimation(thePolyg));
0573 
0574     //  Modified by MKK - Thu Oct  25 12:40:11 2007
0575     Standard_Real defPh = ToolPolyh::DeflectionOverEstimation(thePolyh);
0576     TColStd_ListOfInteger maliste;
0577     maliste = PolyhGrid.Compare(bofSeg);
0578     TColStd_ListIteratorOfListOfInteger clt(maliste);
0579     //  Modified by MKK - Thu Oct  25 12:40:11 2007 Begin
0580     gp_Pnt p1, Beg0;
0581     gp_Pnt p2, End0;
0582     if ( !maliste.IsEmpty() ) {
0583       p1 = ToolPolygon3d::BeginOfSeg(thePolyg, iLin);
0584       p2 = ToolPolygon3d::EndOfSeg(thePolyg, iLin);
0585       Beg0 = p1;
0586       End0 = p2;
0587     }
0588     //  Modified by MKK - Thu Oct  25 12:40:11 2007 End
0589     while (clt.More()) {
0590       indTri=clt.Value();
0591       //  Modified by MKK - Thu Oct  25 12:40:11 2007 Begin
0592 
0593       Standard_Integer pTri[3];
0594       ToolPolyh::Triangle(thePolyh, indTri, pTri[0], pTri[1], pTri[2]);
0595       gp_XYZ triNor;                                   // Vecteur normal.
0596       Standard_Real triDp = 0.;                        // Distance polaire.
0597       
0598       Intf::PlaneEquation(ToolPolyh::Point(thePolyh, pTri[0]),
0599                           ToolPolyh::Point(thePolyh, pTri[1]),
0600                           ToolPolyh::Point(thePolyh, pTri[2]),
0601                           triNor, triDp);
0602 
0603       // enlarge boundary segment
0604       if ( iLin == 1 ) {
0605         gp_XYZ dif = p1.XYZ() - p2.XYZ();
0606         Standard_Real dist = dif.Modulus();
0607         if ( dist > gp::Resolution() ) {
0608           dif /= dist;
0609           Standard_Real aCos = dif * triNor;
0610           aCos = fabs(aCos);
0611           if ( aCos > gp::Resolution() ) {
0612             Standard_Real shift = defPh / aCos;
0613             Beg0.SetXYZ( p1.XYZ() + dif * shift );
0614           }
0615         }
0616       }
0617       else if ( iLin == ToolPolygon3d::NbSegments(thePolyg) ) {
0618         gp_XYZ dif = p2.XYZ() - p1.XYZ();
0619         Standard_Real dist = dif.Modulus();
0620         if ( dist > gp::Resolution() ) {
0621           dif /= dist;
0622           Standard_Real aCos = dif * triNor;
0623           aCos = fabs(aCos);
0624           if ( aCos > gp::Resolution() ) {
0625             Standard_Real shift = defPh / aCos;
0626             End0.SetXYZ( p2.XYZ() + dif * shift );
0627           }
0628         }
0629       }
0630       Standard_Real dBegTri=(triNor*Beg0.XYZ())-triDp; // Distance <p1> plane
0631       Standard_Real dEndTri=(triNor*End0.XYZ())-triDp; // Distance <p2> plane
0632 
0633       Intersect(Beg0, End0, Standard_False, indTri, thePolyh, triNor, triDp, dBegTri, dEndTri);
0634 
0635       //  Modified by MKK - Thu Oct  25 12:40:11 2007 End
0636       clt.Next();
0637     }
0638     BeginOfClosedPolygon=Standard_False;
0639   }
0640 }
0641 
0642 
0643 //=======================================================================
0644 //function : Intersect
0645 //purpose  : Compute the intersection between the segment or the line 
0646 //           and the triangle <TTri>.
0647 //=======================================================================
0648 #if 0 
0649 void Intf_InterferencePolygonPolyhedron::Intersect 
0650 (const gp_Pnt& BegO, const gp_Pnt& EndO, const Standard_Boolean Infinite,
0651  const Standard_Integer TTri, const Polyhedron& thePolyh)
0652 {
0653   Standard_Integer pTri0,pTri1,pTri2;
0654   ToolPolyh::Triangle(thePolyh, TTri, pTri0, pTri1, pTri2);
0655   gp_Pnt Pa=ToolPolyh::Point(thePolyh, pTri0);
0656   gp_Pnt Pb=ToolPolyh::Point(thePolyh, pTri1);
0657   gp_Pnt Pc=ToolPolyh::Point(thePolyh, pTri2);
0658   gp_Vec PaPb(Pa,Pb);
0659   gp_Vec PaPc(Pa,Pc);
0660   gp_Vec Normale = PaPb.Crossed(PaPc);
0661   Standard_Real Norm_Normale=Normale.Magnitude();
0662   if(Norm_Normale<1e-14)
0663     return;
0664   
0665   //-- Equation du Plan 
0666   Standard_Real A=Normale.X()/Norm_Normale;
0667   Standard_Real B=Normale.Y()/Norm_Normale;
0668   Standard_Real C=Normale.Z()/Norm_Normale;
0669   Standard_Real D=-(A*Pa.X()+B*Pa.Y()+C*Pa.Z());
0670   
0671   gp_Vec BegOEndO(BegO,EndO);
0672   Standard_Real Norm_BegOEndO=BegOEndO.Magnitude();
0673   if(Norm_BegOEndO<1e-14) 
0674     return;
0675   Standard_Real Lx=BegOEndO.X()/Norm_BegOEndO;
0676   Standard_Real Ly=BegOEndO.Y()/Norm_BegOEndO;
0677   Standard_Real Lz=BegOEndO.Z()/Norm_BegOEndO;
0678   
0679   Standard_Real Vd=A*Lx+B*Ly+C*Lz;  //-- DirLigne . NormalePlan
0680   
0681   if(Vd==0) { //-- Droite parallele au plan 
0682     return;
0683   }
0684   
0685   
0686   //-- Calcul du parametre sur la ligne 
0687   Standard_Real t=-(A*BegO.X()+B*BegO.Y()+C*BegO.Z()+D) / Vd;
0688   
0689   Standard_Real tol=1e-8; //-- Deflection sur le triangle
0690   if(t<-tol || t>(Norm_BegOEndO+tol)) { 
0691     if(Infinite==Standard_False) {
0692       return;
0693     }
0694   }
0695   //-- On a une intersection droite plan 
0696   //-- On teste si c est dans le triangle 
0697   gp_Pnt PRes(BegO.X()+t*Lx,BegO.Y()+t*Ly,BegO.Z()+t*Lz);
0698   
0699   Standard_Real AbsA=A; if(AbsA<0) AbsA=-AbsA;
0700   Standard_Real AbsB=B; if(AbsB<0) AbsB=-AbsB;
0701   Standard_Real AbsC=C; if(AbsC<0) AbsC=-AbsC;
0702   
0703   Standard_Real Au,Av,Bu,Bv,Cu,Cv,Pu,Pv;
0704   if(AbsA>AbsB) { 
0705     if(AbsA>AbsC) { 
0706       //-- Projeter selon X
0707       Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
0708       Av=Pa.Z(); Bv=Pb.Z(); Cv=Pc.Z(); Pv=PRes.Z();
0709     }
0710     else { 
0711       //-- Projeter selon Z
0712       Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
0713       Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
0714     }
0715   }
0716   else { 
0717     if(AbsB>AbsC) { 
0718       //-- projeter selon Y
0719       Au=Pa.Z(); Bu=Pb.Z(); Cu=Pc.Z(); Pu=PRes.Z();
0720       Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
0721     }
0722     else { 
0723       //-- projeter selon Z
0724       Au=Pa.Y(); Bu=Pb.Y(); Cu=Pc.Y(); Pu=PRes.Y();
0725       Av=Pa.X(); Bv=Pb.X(); Cv=Pc.X(); Pv=PRes.X();
0726     }
0727   }
0728 
0729   Standard_Real ABu=Bu-Au; Standard_Real ABv=Bv-Av;
0730   Standard_Real ACu=Cu-Au; Standard_Real ACv=Cv-Av;
0731   Standard_Real BCu=Cu-Bu; Standard_Real BCv=Cv-Bv;
0732   
0733   Standard_Real t1,t2;
0734   //-- Test sur AB et C
0735   t1=-ABv*Cu + ABu*Cv;
0736   t2=-ABv*Pu + ABu*Pv;
0737   if(t1<0) { if(t2>0) return; } else { if(t2<0) return; } 
0738 
0739   //-- Test sur AC et B
0740   t1=-ACv*Bu + ACu*Bv;
0741   t2=-ACv*Pu + ACu*Pv;
0742   if(t1<0) { if(t2>0) return; } else { if(t2<0) return; } 
0743 
0744   //-- Test sur BC et A
0745   t1=-BCv*Au + BCu*Av;
0746   t2=-BCv*Pu + BCu*Pv;
0747   if(t1<0) { if(t2>0) return; } else { if(t2<0) return; } 
0748 
0749 
0750   Intf_SectionPoint SP(PRes,
0751                        Intf_EDGE, 
0752                        0, 
0753                        iLin, //-- !!!!! VARIABLE STATIQUE 
0754                        t / Norm_BegOEndO, 
0755                        Intf_FACE, 
0756                        TTri, 0, 0.,1.);
0757   mySPoins.Append(SP);
0758 }
0759 #else 
0760 void Intf_InterferencePolygonPolyhedron::Intersect 
0761   (const gp_Pnt& BegO, const gp_Pnt& EndO, const Standard_Boolean Infinite,
0762    const Standard_Integer TTri, const Polyhedron& thePolyh)
0763 {
0764   Intf_PIType typOnG=Intf_EDGE;
0765   Standard_Real t;
0766   Standard_Integer pTri[3];
0767   ToolPolyh::Triangle(thePolyh, TTri, pTri[0], pTri[1], pTri[2]);
0768   gp_XYZ triNor;                                   // Vecteur normal.
0769   Standard_Real triDp;                             // Distance polaire.
0770 
0771   Intf::PlaneEquation(ToolPolyh::Point(thePolyh, pTri[0]),
0772                       ToolPolyh::Point(thePolyh, pTri[1]),
0773                       ToolPolyh::Point(thePolyh, pTri[2]),
0774                       triNor, triDp);
0775 
0776 
0777   Standard_Real dBegTri=(triNor*BegO.XYZ())-triDp; // Distance <BegO> plan
0778   Standard_Real dEndTri=(triNor*EndO.XYZ())-triDp; // Distance <EndO> plan
0779   gp_XYZ segO=EndO.XYZ()-BegO.XYZ();
0780   segO.Normalize();
0781   Standard_Boolean NoIntersectionWithTriangle = Standard_False;
0782 
0783   Standard_Real param;
0784   t = dBegTri-dEndTri;
0785   if (t >= 1.e-16 || t<=-1.e-16)  
0786     param = dBegTri/t;
0787   else param = dBegTri;
0788   Standard_Real floatgap=Epsilon(1000.);
0789   
0790   if (!Infinite) {
0791     if (dBegTri<=floatgap && dBegTri>=-floatgap ) {
0792       param=0.;typOnG=Intf_VERTEX;
0793       if (BeginOfClosedPolygon) 
0794         NoIntersectionWithTriangle = Standard_False;
0795     }
0796     else if (dEndTri<=floatgap && dEndTri>=-floatgap) {
0797       param=1.;typOnG=Intf_VERTEX;
0798       NoIntersectionWithTriangle = Standard_False;
0799     }
0800     if (param<0. || param>1.) {
0801       NoIntersectionWithTriangle = Standard_True;
0802     }
0803   }
0804   if(NoIntersectionWithTriangle == Standard_False) { 
0805     gp_XYZ spLieu=BegO.XYZ()+((EndO.XYZ()-BegO.XYZ())*param);
0806     Standard_Real dPiE[3] = { 0.0, 0.0, 0.0 }, dPtPi[3], sigd;
0807     Standard_Integer is = 0;
0808     Standard_Integer sEdge=-1;
0809     Standard_Integer sVertex=-1;
0810     Standard_Integer tbreak=0;
0811     { //-- is = 0
0812       gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[1]).XYZ()-
0813                   ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
0814       gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[0]).XYZ());
0815       dPtPi[0]=vecP.Modulus();
0816       if (dPtPi[0]<=floatgap) {
0817         sVertex=0;
0818         is=0;
0819         tbreak=1;
0820       }
0821       else { 
0822         gp_XYZ segT_x_vecP(segT^vecP);
0823         Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
0824         sigd = segT_x_vecP*triNor;
0825         if(sigd>floatgap) 
0826           sigd = 1.0;
0827         else if(sigd<-floatgap)
0828           sigd = -1.0;
0829         else {
0830           sigd = 0.0;
0831         }
0832         dPiE[0]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
0833         if (dPiE[0]<=floatgap && dPiE[0]>=-floatgap) {
0834           sEdge=0;
0835           is=0;
0836           tbreak=1;
0837         }
0838       }
0839     }
0840 
0841     if(tbreak==0) { //-- is = 1 
0842       gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[2]).XYZ()-
0843                   ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
0844       gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[1]).XYZ());
0845       dPtPi[1]=vecP.Modulus();
0846       if (dPtPi[1]<=floatgap) {
0847         sVertex=1;
0848         is=1;
0849         tbreak=1;
0850       }
0851       else { 
0852         gp_XYZ segT_x_vecP(segT^vecP);
0853         Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
0854         sigd = segT_x_vecP*triNor;
0855         if(sigd>floatgap) 
0856           sigd = 1.0;
0857         else if(sigd<-floatgap)
0858           sigd = -1.0;
0859         else {
0860           sigd = 0.0;
0861         }
0862         dPiE[1]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
0863         if (dPiE[1]<=floatgap && dPiE[1]>=-floatgap) {
0864           sEdge=1;
0865           is=1;
0866           tbreak=1;
0867         }
0868       }
0869     }
0870     if(tbreak==0) { //-- is = 2
0871       gp_XYZ segT(ToolPolyh::Point(thePolyh, pTri[0]).XYZ()-
0872                   ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
0873       gp_XYZ vecP(spLieu-ToolPolyh::Point(thePolyh, pTri[2]).XYZ());
0874       dPtPi[2]=vecP.Modulus();
0875       if (dPtPi[2]<=floatgap) {
0876         sVertex=2;
0877         is=2;
0878       }
0879       gp_XYZ segT_x_vecP(segT^vecP);
0880       Standard_Real Modulus_segT_x_vecP = segT_x_vecP.Modulus();
0881       sigd = segT_x_vecP*triNor;
0882       if(sigd>floatgap) 
0883         sigd = 1.0;
0884       else if(sigd<-floatgap)
0885         sigd = -1.0;
0886       else {
0887         sigd = 0.0;
0888       }
0889       dPiE[2]=sigd*(Modulus_segT_x_vecP/segT.Modulus());
0890       if (dPiE[2]<=floatgap && dPiE[2]>=-floatgap) {
0891         sEdge=2;
0892         is=2;
0893       }
0894     }
0895     //-- fin for i=0 to 2
0896     // !!cout<<endl;
0897     
0898     Standard_Integer triCon, pedg;
0899     if      (sVertex>-1) {
0900       triCon=TTri;
0901       pedg=pTri[Pourcent3[sVertex+1]];
0902 //--      while (triCon!=0) {
0903 //--    ToolPolyh::TriConnex(thePolyh, triCon,pTri[sVertex],pedg,triCon,pedg);
0904 //--    //-- if (triCon<TTri) return;
0905 //--    if (triCon==TTri) break;
0906 //--      }
0907       Intf_SectionPoint SP(spLieu,
0908                            typOnG, 0, iLin, param, 
0909                            Intf_VERTEX, pTri[is], 0, 0.,
0910                            1.);
0911       mySPoins.Append(SP);
0912     }
0913     else if (sEdge>-1) {
0914       ToolPolyh::TriConnex(thePolyh, TTri, pTri[sEdge], pTri[Pourcent3[sEdge+1]],
0915                            triCon, pedg);
0916       //-- if (triCon<=TTri) return; ???????????????????? LBR 
0917       // !!cout<<" sEdge "<<endl;
0918       Intf_SectionPoint SP(spLieu,
0919                            typOnG, 0, iLin, param, 
0920                            Intf_EDGE, Min(pTri[sEdge], pTri[Pourcent3[sEdge+1]]),
0921                            Max(pTri[sEdge], pTri[Pourcent3[sEdge+1]]), 0.,
0922                            1.);
0923       mySPoins.Append(SP);
0924     }
0925     else if (dPiE[0]>0. && dPiE[1]>0. && dPiE[2]>0.) {
0926       // !!cout<<" 3 Positifs "<<endl;
0927       Intf_SectionPoint SP(spLieu,
0928                            typOnG, 0, iLin, param, 
0929                            Intf_FACE, TTri, 0, 0.,
0930                            1.);
0931       mySPoins.Append(SP);
0932     }
0933 //  Modified by Sergey KHROMOV - Fri Dec  7 14:40:11 2001 Begin
0934     // Sometimes triangulation doesn't cover whole the face. In this
0935     // case it is necessary to take into account the deflection between boundary
0936     // isolines of the surface and boundary trianles. Computed value of this
0937     // deflection is contained in thePolyh.
0938     else {
0939       Standard_Integer i;
0940 
0941       for (i = 1; i <= 3; i++) {
0942         Standard_Integer indP1 = (i == 3) ? pTri[0] : pTri[i];
0943         Standard_Integer indP2 = pTri[i - 1];
0944 
0945         if (ToolPolyh::IsOnBound(thePolyh, indP1, indP2)) {
0946           // For boundary line it is necessary to check the border deflection.
0947           Standard_Real  Deflection = ToolPolyh::GetBorderDeflection(thePolyh);
0948           const gp_Pnt  &BegP       = ToolPolyh::Point(thePolyh, indP1);
0949           const gp_Pnt  &EndP       = ToolPolyh::Point(thePolyh, indP2);
0950           gp_Vec         VecTri(BegP,EndP);
0951           gp_Dir         DirTri(VecTri);
0952           gp_Lin         LinTri(BegP,DirTri);
0953           gp_Pnt         aPOnE(spLieu);
0954           Standard_Real  aDist = LinTri.Distance(aPOnE);
0955 
0956           if (aDist <= Deflection) {
0957             gp_Vec        aVLocPOnE(BegP, aPOnE);
0958             gp_Vec        aVecDirTri(DirTri);
0959             Standard_Real aPar    = aVLocPOnE*aVecDirTri;
0960             Standard_Real aMaxPar = VecTri.Magnitude();
0961 
0962             if (aPar >= 0 && aPar <= aMaxPar) {
0963               Intf_SectionPoint SP(spLieu,
0964                                    typOnG, 0, iLin, param, 
0965                                    Intf_FACE, TTri, 0, 0.,
0966                                    1.);
0967               mySPoins.Append(SP);
0968             }
0969           }
0970         }
0971       }
0972     }
0973 //  Modified by Sergey KHROMOV - Fri Dec  7 14:40:29 2001 End
0974   } //---- if(NoIntersectionWithTriangle == Standard_False)
0975   
0976   //---------------------------------------------------------------------------
0977   //-- On teste la distance entre les cotes du triangle et le polygone 
0978   //-- 
0979   //-- Si cette distance est inferieure a Tolerance, on cree un SP.
0980   //--    
0981   //-- printf("\nIntf_InterferencePolygPolyh : dBegTri=%g dEndTri=%g Tolerance=%g\n",dBegTri,dEndTri,Tolerance);
0982 //  if(Abs(dBegTri) <= Tolerance || Abs(dEndTri) <= Tolerance)
0983   {
0984     gp_Vec VecPol(BegO,EndO);
0985     Standard_Real NVecPol = VecPol.Magnitude();
0986     gp_Dir DirPol(VecPol);
0987     gp_Lin LinPol(BegO,DirPol);
0988     Standard_Real dist2,ParamOnO,ParamOnT;
0989     
0990     for (Standard_Integer i=0; i<3; i++) {
0991       Standard_Integer pTri_ip1pc3 = pTri[Pourcent3[i+1]];
0992       Standard_Integer pTri_i      = pTri[i];
0993       const gp_Pnt& BegT = ToolPolyh::Point(thePolyh, pTri_ip1pc3);
0994       const gp_Pnt& EndT = ToolPolyh::Point(thePolyh, pTri_i);
0995       gp_Vec  VecTri(BegT,EndT);
0996       Standard_Real NVecTri = VecTri.Magnitude();
0997       gp_Dir  DirTri(VecTri);
0998       gp_Lin  LinTri(BegT,DirTri);
0999       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 
1040 void 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)
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.
1055   //Standard_Real triDp = TriDp;                             // Distance polaire.
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;
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.) {
1081       NoIntersectionWithTriangle = Standard_True;
1082     }
1083   }
1084   if(NoIntersectionWithTriangle == Standard_False) { 
1085     gp_XYZ spLieu=BegO.XYZ()+((EndO.XYZ()-BegO.XYZ())*param);
1086     Standard_Real dPiE[3] = { 0.0, 0.0, 0.0 }, dPtPi[3], sigd;
1087     Standard_Integer is = 0;
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);
1262 //  if (Abs(dBegTri) <= Tolerance || Abs(dEndTri) <= Tolerance)
1263   {
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 }