Salome HOME
Porting to OCCT development version: Standard_PI -> M_PI
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WireSplitter.cxx
index e4671d3a2c79410a80cc78dd37db604732c3ddbd..66cd6a6551e9321f4fc73aa580f60d0d5a689149 100755 (executable)
@@ -1,27 +1,26 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
+// License as published by the Free Software Foundation; either
 // version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// File:       GEOMAlgo_WireSplitter.cxx
-// Created:    
-// Author:     Peter KURNEV
-//             <pkv@irinox>
 
+// File:        GEOMAlgo_WireSplitter.cxx
+// Author:      Peter KURNEV
 
 #include <GEOMAlgo_WireSplitter.ixx>
 
 
 static
   void Path (const GeomAdaptor_Surface& aGAS,
-            const TopoDS_Face& myFace,
-            const TopoDS_Vertex& aVa,
-            const TopoDS_Edge& aEOuta,
-            BOP_EdgeInfo& anEdgeInfo,
-            TopTools_SequenceOfShape& aLS,
-            TopTools_SequenceOfShape& aVertVa,
-            TColgp_SequenceOfPnt2d& aCoordVa,
-            BOPTColStd_ListOfListOfShape& myShapes,
-            BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap);
+             const TopoDS_Face& myFace,
+             const TopoDS_Vertex& aVa,
+             const TopoDS_Edge& aEOuta,
+             BOP_EdgeInfo& anEdgeInfo,
+             TopTools_SequenceOfShape& aLS,
+             TopTools_SequenceOfShape& aVertVa,
+             TColgp_SequenceOfPnt2d& aCoordVa,
+             BOPTColStd_ListOfListOfShape& myShapes,
+             BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap);
 
 
 static
@@ -89,32 +88,32 @@ static
 
 static
   void GetNextVertex(const TopoDS_Vertex& aV,
-                    const TopoDS_Edge& aE,
-                    TopoDS_Vertex& aV1);
+                     const TopoDS_Edge& aE,
+                     TopoDS_Vertex& aV1);
 static
   Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
-                              const Standard_Real aAngleOut);
+                               const Standard_Real aAngleOut);
 
 static
   Standard_Real AngleIn(const TopoDS_Edge& aEIn,
-                       const BOP_ListOfEdgeInfo& aLEInfo);
+                        const BOP_ListOfEdgeInfo& aLEInfo);
 
 static
   Standard_Real Angle2D (const TopoDS_Vertex& aV,
-                        const TopoDS_Edge& anEdge,
-                        const TopoDS_Face& myFace,
-                        const GeomAdaptor_Surface& aGAS,
-                        const Standard_Boolean aFlag);
+                         const TopoDS_Edge& anEdge,
+                         const TopoDS_Face& myFace,
+                         const GeomAdaptor_Surface& aGAS,
+                         const Standard_Boolean aFlag);
 static
   gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
-                   const TopoDS_Edge& aE1,
-                   const TopoDS_Face& aF);
+                    const TopoDS_Edge& aE1,
+                    const TopoDS_Face& aF);
 static
   gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
-                     const TopoDS_Face& aF);
+                      const TopoDS_Face& aF);
 static
   Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
-                           const GeomAdaptor_Surface& aGAS);   
+                            const GeomAdaptor_Surface& aGAS);   
 
 static
   Standard_Integer NbWaysOut(const BOP_ListOfEdgeInfo& );
@@ -230,7 +229,7 @@ static
 
       index = mySmartMap.FindIndex(aVertex);
       if (!index) {
-       index=mySmartMap.Add(aVertex, emptyInfo);
+        index=mySmartMap.Add(aVertex, emptyInfo);
       }
       
       BOP_ListOfEdgeInfo& aListOfEInfo=mySmartMap(index);
@@ -241,11 +240,11 @@ static
       TopAbs_Orientation anOr=aVertex.Orientation();
 
       if (anOr==TopAbs_FORWARD) {
-       aEInfo.SetInFlag(Standard_False);
+        aEInfo.SetInFlag(Standard_False);
       }
 
       else if (anOr==TopAbs_REVERSED) {
-       aEInfo.SetInFlag(Standard_True);
+        aEInfo.SetInFlag(Standard_True);
       }
 
       aListOfEInfo.Append(aEInfo);
@@ -266,10 +265,10 @@ static
       const BOP_EdgeInfo& anEdgeInfo=anIt.Value();
       anIsIn=anEdgeInfo.IsIn();
       if (anIsIn) {
-       aCntIn++;
+        aCntIn++;
       }
       else {
-       aCntOut++;
+        aCntOut++;
       }
     }
     if (aCntIn!=1 || aCntOut!=1) {
@@ -292,13 +291,13 @@ static
       const TopoDS_Shape& aE = anItList.Value();
       
       if (!aMapEE.Contains(aE)) {
-       TopTools_ListOfShape aLEx;
-       aLEx.Append(aE);
-       aMapEE.Add(aE, aLEx);
+        TopTools_ListOfShape aLEx;
+        aLEx.Append(aE);
+        aMapEE.Add(aE, aLEx);
       }
       else {
-       TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
-       aLEx.Append(aE);
+        TopTools_ListOfShape& aLEx=aMapEE.ChangeFromKey(aE);
+        aLEx.Append(aE);
       }
     }
     
@@ -309,20 +308,20 @@ static
       const TopTools_ListOfShape& aLEx=aMapEE(i);
       aNbE=aLEx.Extent();
       if (aNbE==1) {
-       // usual case
-       continue;
+        // usual case
+        continue;
       }
       else if (aNbE==2){
-       const TopoDS_Shape& aE1=aLEx.First();
-       const TopoDS_Shape& aE2=aLEx.Last();
-       if (aE1.IsSame(aE2)) {
-         bFlag=Standard_False;
-         break;
-       }
+        const TopoDS_Shape& aE1=aLEx.First();
+        const TopoDS_Shape& aE2=aLEx.Last();
+        if (aE1.IsSame(aE2)) {
+          bFlag=Standard_False;
+          break;
+        }
       }
       else {
-       bFlag=Standard_False;
-       break;
+        bFlag=Standard_False;
+        break;
       }
     }
     myNothingToDo=myNothingToDo && bFlag;
@@ -350,15 +349,15 @@ static
       //
       anIsIn=anEdgeInfo.IsIn();
       if (anIsIn) {
-       //
-       aVV.Orientation(TopAbs_REVERSED);
-       anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
+        //
+        aVV.Orientation(TopAbs_REVERSED);
+        anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_True);
       }
       // 
       else { // OUT
-       //
-       aVV.Orientation(TopAbs_FORWARD);
-       anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
+        //
+        aVV.Orientation(TopAbs_FORWARD);
+        anAngle=Angle2D (aVV, aE, myFace, aGAS, Standard_False);
       }
       anEdgeInfo.SetAngle(anAngle);
       
@@ -387,13 +386,13 @@ static
       anIsNotPassed=!anEdgeInfo.Passed();
       
       if (anIsOut && anIsNotPassed) {
-       //
-       aLS.Clear();
-       aVertVa.Clear();
-       aCoordVa.Clear();
-       //
-       Path(aGAS, myFace, aVa, aEOuta, anEdgeInfo, aLS, 
-            aVertVa, aCoordVa, myShapes, mySmartMap);
+        //
+        aLS.Clear();
+        aVertVa.Clear();
+        aCoordVa.Clear();
+        //
+        Path(aGAS, myFace, aVa, aEOuta, anEdgeInfo, aLS, 
+             aVertVa, aCoordVa, myShapes, mySmartMap);
       }
     }
   }
@@ -409,16 +408,16 @@ static
       const TopTools_ListOfShape& aLE=anItW.Value();
       TopTools_ListIteratorOfListOfShape anItE(aLE);
       for (; anItE.More(); anItE.Next()) {
-       const TopoDS_Edge& aE=TopoDS::Edge(anItE.Value());
-       aME.Add(aE);
-       TopExp::Vertices(aE, aV1, aV2);
-       aMV.Add(aV1);
-       aMV.Add(aV2);
+        const TopoDS_Edge& aE=TopoDS::Edge(anItE.Value());
+        aME.Add(aE);
+        TopExp::Vertices(aE, aV1, aV2);
+        aMV.Add(aV1);
+        aMV.Add(aV2);
       }
       aNbV=aMV.Extent();
       aNbE=aME.Extent();
       if (aNbV<=aNbE) {
-       aShapes.Append(aLE);
+        aShapes.Append(aLE);
       }
     }
     //
@@ -437,16 +436,16 @@ static
 // purpose: 
 //=======================================================================
   void Path (const GeomAdaptor_Surface& aGAS,
-            const TopoDS_Face& myFace,
-            const TopoDS_Vertex& aVa,
-            const TopoDS_Edge& aEOuta,
-            BOP_EdgeInfo& anEdgeInfo,
-            TopTools_SequenceOfShape& aLS,
-            TopTools_SequenceOfShape& aVertVa,
-            TColgp_SequenceOfPnt2d& aCoordVa,
-            BOPTColStd_ListOfListOfShape& myShapes,
-            BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap)
-                              
+             const TopoDS_Face& myFace,
+             const TopoDS_Vertex& aVa,
+             const TopoDS_Edge& aEOuta,
+             BOP_EdgeInfo& anEdgeInfo,
+             TopTools_SequenceOfShape& aLS,
+             TopTools_SequenceOfShape& aVertVa,
+             TColgp_SequenceOfPnt2d& aCoordVa,
+             BOPTColStd_ListOfListOfShape& myShapes,
+             BOP_IndexedDataMapOfVertexListEdgeInfo& mySmartMap)
+                               
 {
   Standard_Integer i,j, aNb, aNbj;
   Standard_Real aTol, anAngleIn, anAngleOut, anAngle, aMinAngle;
@@ -484,10 +483,10 @@ static
 
   gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
 
-  const BOP_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb);
+  //const BOP_ListOfEdgeInfo& aLEInfoVb=mySmartMap.FindFromKey(aVb);
   //
   aTol=2.*Tolerance2D(aVb, aGAS);
-  aTol2=aTol*aTol;
+  aTol2=10.*aTol*aTol;
   //
   aNb=aLS.Length();
   if (aNb>0) {
@@ -505,51 +504,51 @@ static
       anIsSameV2d=Standard_False;
 
       if (anIsSameV) {
-       anIsSameV2d = Standard_True;
-       //
-       aD2=aPaPrev.SquareDistance(aPb);
-       anIsSameV2d =aD2<aTol2;
+        anIsSameV2d = Standard_True;
+        //
+        aD2=aPaPrev.SquareDistance(aPb);
+        anIsSameV2d =aD2<aTol2;
       }//if (anIsSameV) {
       //
       if (anIsSameV && anIsSameV2d) {
-       myShapes.Append(aBuf);
-       //
-       TopTools_SequenceOfShape aLSt, aVertVat;
-       TColgp_SequenceOfPnt2d aCoordVat;
-       //
-       aNbj=i-1;
-       if (aNbj<1) {
-         //
-         aLS.Clear();
-         aVertVa.Clear();
-         aCoordVa.Clear();
-         //
-         return;
-       }
-
-       aVb=TopoDS::Vertex(aVertVa(i));
-
-       for (j=1; j<=aNbj; j++) {
-         aLSt.Append(aLS(j));
-         aVertVat.Append(aVertVa(j));
-         aCoordVat.Append(aCoordVa(j));
-       }
-       //
-       aLS.Clear();
-       aVertVa.Clear();
-       aCoordVa.Clear();
-
-       aLS=aLSt;
-       aVertVa=aVertVat;
-       aCoordVa=aCoordVat;
-       //
-       break;
+        myShapes.Append(aBuf);
+        //
+        TopTools_SequenceOfShape aLSt, aVertVat;
+        TColgp_SequenceOfPnt2d aCoordVat;
+        //
+        aNbj=i-1;
+        if (aNbj<1) {
+          //
+          aLS.Clear();
+          aVertVa.Clear();
+          aCoordVa.Clear();
+          //
+          return;
+        }
+
+        aVb=TopoDS::Vertex(aVertVa(i));
+
+        for (j=1; j<=aNbj; j++) {
+          aLSt.Append(aLS(j));
+          aVertVat.Append(aVertVa(j));
+          aCoordVat.Append(aCoordVa(j));
+        }
+        //
+        aLS.Clear();
+        aVertVa.Clear();
+        aCoordVa.Clear();
+
+        aLS=aLSt;
+        aVertVa=aVertVat;
+        aCoordVa=aCoordVat;
+        //
+        break;
       }
     }
   }
   //
   aTol2D=2.*Tolerance2D(aVb, aGAS);
-  aTol2D2=aTol2D*aTol2D;
+  aTol2D2=100.*aTol2D*aTol2D;
   //
   // anAngleIn in Vb from edge aEOuta
   const BOP_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb);
@@ -580,15 +579,15 @@ static
       iCnt=NbWaysOut (aLEInfo);
       //
       if (!iCnt) {
-       // no way to go . (Error)
-       return ;
+        // no way to go . (Error)
+        return ;
       }
       //
       if (iCnt==1) {
-       // the one and only way to go out .
-       pEdgeInfo=&anEI;
-       anIsFound=Standard_True;
-       break;
+        // the one and only way to go out .
+        pEdgeInfo=&anEI;
+        anIsFound=Standard_True;
+        break;
       }
       //
       // Look for minimal angle and make the choice.
@@ -598,7 +597,7 @@ static
       //
       aD2=aP2Dx.SquareDistance(aPb);
       if (aD2 > aTol2D2){
-       continue;
+        continue;
       }
       //
       //
@@ -606,9 +605,9 @@ static
       //
       anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
       if (anAngle < aMinAngle) {
-       aMinAngle=anAngle;
-       pEdgeInfo=&anEI;
-       anIsFound=Standard_True;
+        aMinAngle=anAngle;
+        pEdgeInfo=&anEI;
+        anIsFound=Standard_True;
       }
     }
   } // for (; anIt.More(); anIt.Next()) 
@@ -621,14 +620,14 @@ static
   aEOutb=pEdgeInfo->Edge();
   //
   Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS, 
-       aVertVa, aCoordVa, myShapes, mySmartMap);
+        aVertVa, aCoordVa, myShapes, mySmartMap);
 }
 //=======================================================================
 // function:  Coord2dVf
 // purpose:
 //=======================================================================
  gp_Pnt2d Coord2dVf (const TopoDS_Edge& aE,
-                    const TopoDS_Face& aF)
+                     const TopoDS_Face& aF)
 {
   Standard_Real aCoord=99.;
   gp_Pnt2d aP2D1(aCoord, aCoord);
@@ -650,7 +649,7 @@ static
 // purpose:
 //=======================================================================
  Standard_Real Tolerance2D (const TopoDS_Vertex& aV,
-                           const GeomAdaptor_Surface& aGAS)                 
+                            const GeomAdaptor_Surface& aGAS)                 
 {
   Standard_Real aTol2D, anUr, aVr, aTolV3D;
   GeomAbs_SurfaceType aType;
@@ -664,9 +663,7 @@ static
   //
   if (aType==GeomAbs_BSplineSurface||
       aType==GeomAbs_Sphere||
-      //modified by NIZNHY-PKV Wed Nov 29 10:18:50 2006f
       GeomAbs_SurfaceOfRevolution) {
-    //modified by NIZNHY-PKV Wed Nov 29 10:18:55 2006t
     if (aTol2D < aTolV3D) {
       aTol2D=aTolV3D;
     }
@@ -683,8 +680,8 @@ static
 // purpose:
 //=======================================================================
  gp_Pnt2d Coord2d (const TopoDS_Vertex& aV1,
-                  const TopoDS_Edge& aE1,
-                  const TopoDS_Face& aF)
+                   const TopoDS_Edge& aE1,
+                   const TopoDS_Face& aF)
 {
   Standard_Real aT, aFirst, aLast;
   Handle(Geom2d_Curve) aC2D;
@@ -701,7 +698,7 @@ static
 // purpose:
 //=======================================================================
  Standard_Real AngleIn(const TopoDS_Edge& aEIn,
-                      const BOP_ListOfEdgeInfo& aLEInfo)
+                       const BOP_ListOfEdgeInfo& aLEInfo)
 {
   Standard_Real anAngleIn;
   Standard_Boolean anIsIn;
@@ -726,9 +723,9 @@ static
 // purpose:
 //=======================================================================
  Standard_Real ClockWiseAngle(const Standard_Real aAngleIn,
-                             const Standard_Real aAngleOut)
+                              const Standard_Real aAngleOut)
 {
-  Standard_Real aTwoPi=Standard_PI+Standard_PI;
+  Standard_Real aTwoPi = M_PI+M_PI;
   Standard_Real dA, A1, A2, AIn, AOut ;
 
   AIn=aAngleIn;
@@ -741,7 +738,7 @@ static
     AOut=AOut-aTwoPi;
   }
 
-  A1=AIn+Standard_PI;
+  A1 = AIn + M_PI;
   
   if (A1 >= aTwoPi) {
     A1=A1-aTwoPi;
@@ -752,9 +749,13 @@ static
   dA=A1-A2;
   if (dA <= 0.) {
     dA=aTwoPi+dA;
+    //modified by NIZNHY-PKV Thu Feb 17 08:26:39 2011f
+    if (dA <= 1.e-14) {
+      dA=aTwoPi;
+    }
+    //modified by NIZNHY-PKV Thu Feb 17 08:26:42 2011t
   }
   //xx
-  //else if (dA <= 1.e-15) {
   else if (dA <= 1.e-14) {
     dA=aTwoPi;
   }
@@ -765,8 +766,8 @@ static
 // purpose: 
 //=======================================================================
  void GetNextVertex(const TopoDS_Vertex& aV,
-                   const TopoDS_Edge& aE,
-                   TopoDS_Vertex& aV1)
+                    const TopoDS_Edge& aE,
+                    TopoDS_Vertex& aV1)
 {
   TopoDS_Iterator aIt;
   //
@@ -785,29 +786,31 @@ static
 // purpose: 
 //=======================================================================
   Standard_Real Angle2D (const TopoDS_Vertex& aV,
-                        const TopoDS_Edge& anEdge,
-                        const TopoDS_Face& myFace,
-                        const GeomAdaptor_Surface& aGAS,
-                        const Standard_Boolean aFlag)
+                         const TopoDS_Edge& anEdge,
+                         const TopoDS_Face& myFace,
+                         const GeomAdaptor_Surface& aGAS,
+                         const Standard_Boolean aFlag)
 {
-  Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle;
-  
+  Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle, aTX;
+  gp_Pnt2d aPV, aPV1;
+  gp_Vec2d aV2D;
   Handle(Geom2d_Curve) aC2D;
-  
-  BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D, 
-                                   aFirst, aLast, aToler, Standard_True);
-
+  //
   aTV=BRep_Tool::Parameter (aV, anEdge, myFace);
-  if (Precision::IsInfinite(aTV))
+  if (Precision::IsInfinite(aTV)) {
     return 0.;
-
+  }
+  //
+  BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D, 
+                                    aFirst, aLast, aToler, Standard_True);
   //dt=1.e-7;
-  dt=Tolerance2D(aV, aGAS);
-  
-  if(dt > (aLast - aFirst) * 0.25) {
+  dt=2.*Tolerance2D(aV, aGAS);
+  //
+  aTX=0.25*(aLast - aFirst);
+  if(dt > aTX) {
     // to save direction of the curve as much as it possible
     // in the case of big tolerances
-    dt = (aLast - aFirst) * 0.25
+    dt = aTX
   }
   //
   if (fabs (aTV-aFirst) < fabs(aTV - aLast)) {
@@ -816,27 +819,22 @@ static
   else {
     aTV1=aTV - dt;
   }
-  
-  gp_Pnt2d aPV, aPV1;
+  //
   aC2D->D0 (aTV, aPV);
   aC2D->D0 (aTV1, aPV1);
-  
-  gp_Vec2d aV2D;
   //
   if (aFlag) {//IN
     gp_Vec2d aV2DIn(aPV1, aPV);
-    //
     aV2D=aV2DIn;
   }
-
   else {
     gp_Vec2d aV2DOut(aPV, aPV1);
     aV2D=aV2DOut;
   }
-
+  //
   gp_Dir2d aDir2D(aV2D);
   anAngle=Angle(aDir2D);
-
+  //
   return anAngle;
 }
 //=======================================================================
@@ -849,7 +847,7 @@ Standard_Real Angle (const gp_Dir2d& aDir2D)
   Standard_Real anAngle = aRefDir.Angle(aDir2D);
 
   if (anAngle < 0.)
-    anAngle += Standard_PI + Standard_PI;
+    anAngle += M_PI + M_PI;
 
   return anAngle;
 }