]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx
Salome HOME
[GITHUB #1] updated TUI command doc for make sphere from point and radius
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn2.cxx
old mode 100755 (executable)
new mode 100644 (file)
index c255e35..3450930
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //              <pkv@irinox>
 //
 #include <GEOMAlgo_FinderShapeOn2.hxx>
-#include <math.h>
-
-#include <Basics_OCCTVersion.hxx>
+#include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
+#include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
+#include <GEOMAlgo_ListIteratorOfListOfPnt.hxx>
+#include <GEOMAlgo_PassKey.hxx>
+#include <GEOMAlgo_StateCollector.hxx>
+#include <GEOMAlgo_SurfaceTools.hxx>
 
-#include <Precision.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <TColStd_MapOfInteger.hxx>
+#include <GEOMUtils.hxx>
 
-#include <gp_Trsf.hxx>
-#include <gp_Cylinder.hxx>
+#include <Bnd_Box.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+#include <BRepTools.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Surface.hxx>
+#include <Geom2d_Line.hxx>
+#include <Geom2dAdaptor_Curve.hxx>
+#include <Geom2dHatch_Hatcher.hxx>
+#include <gp_Dir2d.hxx>
+#include <gp_Pnt2d.hxx>
 #include <gp_Pnt.hxx>
-
-#include <TColgp_Array1OfPnt.hxx>
-
+#include <gp_Trsf.hxx>
+#include <HatchGen_Domain.hxx>
+#include <IntTools_Tools.hxx>
 #include <Poly_Array1OfTriangle.hxx>
-#include <Poly_Triangle.hxx>
+#include <Poly_Polygon3D.hxx>
 #include <Poly_PolygonOnTriangulation.hxx>
+#include <Poly_Triangle.hxx>
 #include <Poly_Triangulation.hxx>
-#include <Poly_Polygon3D.hxx>
-
-#include <Geom_Curve.hxx>
-#include <Geom_Surface.hxx>
-#include <GeomAdaptor_Surface.hxx>
-#include <GeomAbs_SurfaceType.hxx>
-#include <GeomAdaptor_Curve.hxx>
-#include <GeomAbs_CurveType.hxx>
-
+#include <Precision.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TColStd_MapOfInteger.hxx>
 #include <TopAbs_State.hxx>
-
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopLoc_Location.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Edge.hxx>
-
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-
 #include <TopTools_IndexedMapOfShape.hxx>
-
-#include <BRep_Tool.hxx>
-#include <BRepLib_MakeEdge.hxx>
-
-#include <GEOMAlgo_ListIteratorOfListOfPnt.hxx>
-#include <GEOMAlgo_SurfaceTools.hxx>
-#include <GEOMAlgo_StateCollector.hxx>
-#include <GEOMAlgo_FinderShapeOn.hxx>
-
-#include <GEOMAlgo_PassKey.hxx>
-#include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
-#include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
-//
-#include <gp_Dir2d.hxx>
-#include <gp_Pnt2d.hxx>
-#include <Geom2d_Line.hxx>
-#include <Geom2dAdaptor_Curve.hxx>
-#include <Geom2dHatch_Hatcher.hxx>
-#include <TColStd_ListOfInteger.hxx>
-#include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <HatchGen_Domain.hxx>
-#include <Geom2dHatch_Hatcher.hxx>
-#if OCC_VERSION_LARGE > 0x06070100
 #include <IntTools_Context.hxx>
-#else
-#include <BOPInt_Context.hxx>
-#endif
-#include <BRepTools.hxx>
-#include <IntTools_Tools.hxx>
 
 //=======================================================================
 //function : 
@@ -370,7 +346,7 @@ void GEOMAlgo_FinderShapeOn2::ProcessEdges()
   //
   Standard_Boolean bIsConformState, bIsToBreak;
   Standard_Integer i, aNb, iCnt, iErr;
-  TopAbs_State aSt;
+  TopAbs_State aSt = TopAbs_UNKNOWN; // todo: aSt must be explicitly initilized to avoid warning (see below)
   TopTools_IndexedMapOfShape aM;
   TopExp_Explorer aExp;
   GEOMAlgo_ListIteratorOfListOfPnt aIt;
@@ -383,6 +359,8 @@ void GEOMAlgo_FinderShapeOn2::ProcessEdges()
     //
     const TopoDS_Edge& aE=TopoDS::Edge(aM(i));
     //
+    bIsConformState=Standard_False;
+    //
     aExp.Init(aE, TopAbs_VERTEX);
     for (; aExp.More(); aExp.Next()) {
       const TopoDS_Shape& aV=aExp.Current();
@@ -402,7 +380,7 @@ void GEOMAlgo_FinderShapeOn2::ProcessEdges()
     }
     //
     if (BRep_Tool::Degenerated(aE)) {
-      myMSS.Add(aE, aSt);
+      myMSS.Add(aE, aSt); // todo: aSt must be explicitly initilized to avoid warning (see above)
       continue;
     }
     //
@@ -496,6 +474,9 @@ void GEOMAlgo_FinderShapeOn2::ProcessFaces()
       }
     }
     //
+    //
+    bIsConformState=Standard_False;
+    //
     aExp.Init(aF, TopAbs_EDGE);
     for (; aExp.More(); aExp.Next()) {
       const TopoDS_Shape& aE=aExp.Current();
@@ -579,6 +560,9 @@ void GEOMAlgo_FinderShapeOn2::ProcessSolids()
     const TopoDS_Shape& aSd=aM(i);
     aMF.Clear();
     TopExp::MapShapes(aSd, TopAbs_FACE, aMF);
+    //
+    bIsConformState=Standard_False;
+    //
     aNbF=aMF.Extent();
     for (j=1; j<=aNbF; ++j) {
       const TopoDS_Shape& aF=aMF(j);
@@ -612,7 +596,7 @@ void GEOMAlgo_FinderShapeOn2::ProcessSolids()
 void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF,
                                           GEOMAlgo_ListOfPnt& aLP)
 {
-  Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNb, iCnt;//, aNbMax, *pIds;
+  Standard_Integer j, j1, j2, k, n[4], aNx, aNb, iCnt;//, aNbLinks, aNbMax, *pIds;
   TopLoc_Location aLoc;
   Handle(Poly_Triangulation) aTRF;
   TColStd_MapOfInteger aMBN;
@@ -624,24 +608,21 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF,
   //
   aLP.Clear();
   //
-  aTRF=BRep_Tool::Triangulation(aF, aLoc);
-  if (aTRF.IsNull()) {
-    if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aF)) {
-      myWarningStatus=20; // no triangulation found
-      return;
-    }
-    aTRF=BRep_Tool::Triangulation(aF, aLoc);
+  if (!GEOMUtils::MeshShape(aF, /*deflection*/0.001, /*forced*/false,
+                            /*angle deflection*/0.349066, /*isRelative*/true,
+                            /*doPostCheck*/true)) {
+    myWarningStatus=20; // no triangulation found
+    return;
   }
+  aTRF=BRep_Tool::Triangulation(aF, aLoc);
   //
   const gp_Trsf& aTrsf=aLoc.Transformation();
-  const Poly_Array1OfTriangle& aTrs=aTRF->Triangles();
-  const TColgp_Array1OfPnt& aNodes=aTRF->Nodes();
   //
   // map link/nbtriangles
-  j1=aTrs.Lower();
-  j2=aTrs.Upper();
+  j1 = 1;
+  j2 = aTRF->NbTriangles();
   for (j=j1; j<=j2; ++j) {
-    const Poly_Triangle& aTr=aTrs(j);
+    const Poly_Triangle& aTr = aTRF->Triangle(j);
     aTr.Get(n[0], n[1], n[2]);
     n[3]=n[0];
     for (k=0; k<3; ++k) {
@@ -659,7 +640,6 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF,
   }
   //
   // boundary nodes aMBN
-  aNbLinks=aMPKI.Extent();
   aIt.Initialize(aMPKI);
   for (; aIt.More(); aIt.Next()) {
     iCnt=aIt.Value();
@@ -674,11 +654,11 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF,
   }
   //
   // inner nodes=all_nodes - boundary_nodes
-  j1=aNodes.Lower();
-  j2=aNodes.Upper();
+  j1=1;
+  j2=aTRF->NbNodes();
   for (j=j1; j<=j2; ++j) {
     if (!aMBN.Contains(j)) {
-      aP=aNodes(j).Transformed(aTrsf);
+      aP=aTRF->Node(j).Transformed(aTrsf);
       aLP.Append(aP);
     }
   }
@@ -766,16 +746,15 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE,
   gp_Pnt aP;
   //
   aLP.Clear();
+  if (!GEOMUtils::MeshShape(aE, /*deflection*/0.001, /*forced*/false,
+                            /*angle deflection*/0.349066, /*isRelative*/true,
+                            /*doPostCheck*/true)) {
+    myErrorStatus=20; // no triangulation found
+    return;
+  }
   BRep_Tool::PolygonOnTriangulation(aE, aPTE, aTRE, aLoc);
   if (aTRE.IsNull() || aPTE.IsNull()) {
     Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(aE, aLoc);
-    if (aPE.IsNull()) {
-      if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aE)) {
-        myErrorStatus=20; // no triangulation found
-        return;
-      }
-      aPE = BRep_Tool::Polygon3D(aE, aLoc);
-    }
     const gp_Trsf& aTrsf=aLoc.Transformation();
     const TColgp_Array1OfPnt& aNodes=aPE->Nodes();
     //
@@ -788,13 +767,12 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE,
   }
   else {
     const gp_Trsf& aTrsf=aLoc.Transformation();
-    const TColgp_Array1OfPnt& aNodes=aTRE->Nodes();
     //
     aNbNodes=aPTE->NbNodes();
     const TColStd_Array1OfInteger& aInds=aPTE->Nodes();
     for (j=2; j<aNbNodes; ++j) {
       aIndex=aInds(j);
-      aP=aNodes(aIndex).Transformed(aTrsf);
+      aP=aTRE->Node(aIndex).Transformed(aTrsf);
       aLP.Append(aP);
     }
   }
@@ -854,60 +832,3 @@ void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE,
 // 40- point can not be classified
 // 41- invalid data for classifier
 // 42- can not compute hatching 
-
-/*
-// A
-if (!aNb && myNbPntsMin) {
-    // try to fill it yourself
-    Standard_Boolean bIsDone;
-    Standard_Integer aN1, aN2;
-    Handle(Geom_Surface) aS;
-    GeomAdaptor_Surface aGAS;
-    GeomAbs_SurfaceType aType;
-    //
-    aS=BRep_Tool::Surface(aF);
-    aGAS.Load(aS);
-    aType=aGAS.GetType();
-    if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) {
-      // inner links
-      aNbLinks=aMPKI.Extent();
-      aIt.Initialize(aMPKI);
-      for (; aIt.More(); aIt.Next()) {
-        iCnt=aIt.Value();
-        if (iCnt>1) {
-          // take the first having occured inner link
-          // and discretize it
-          const GEOMAlgo_PassKey& aPK=aIt.Key();
-          //
-          aN1=(Standard_Integer)aPK.Id(1);
-          aN2=(Standard_Integer)aPK.Id(2);
-          //
-          aP1=aNodes(aN1).Transformed(aTrsf);
-          aP2=aNodes(aN2).Transformed(aTrsf);
-          //
-          if (aType==GeomAbs_Cylinder) {
-            gp_Cylinder aCyl;
-            //
-            aCyl=aGAS.Cylinder();
-            if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, myTolerance)) {
-              continue;
-            }
-          }
-          //
-          BRepLib_MakeEdge aBME(aP1, aP2);
-          bIsDone=aBME.IsDone();
-          if (!bIsDone) {
-            myErrorStatus=30; //can not obtain the line fron the link
-            return;
-          }
-          //
-          const TopoDS_Shape& aSx=aBME.Shape();
-          const TopoDS_Edge& aE=TopoDS::Edge(aSx);
-          //
-          InnerPoints(aE, myNbPntsMin, aLP);
-          break;
-        }// if (iCnt>1)
-      }// for (; aIt.More(); aIt.Next())
-    }// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder)
-  }// if (!aNb && myNbPntsMin) {
-*/