]> OCCT Git - occt-copy.git/commitdiff
0028026: Modeling Data - BRepTools::Clean() does not clean all triangulation from...
authorakaftasev <akaftasev@opencascade.com>
Fri, 27 Nov 2020 15:07:39 +0000 (18:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 20 Jan 2021 18:25:44 +0000 (21:25 +0300)
Added flag for force clean triangulation and treatment for it
Command "trinfo" now show number of polygons on triangulation

src/BRepTools/BRepTools.cxx
src/BRepTools/BRepTools.hxx
src/DBRep/DBRep.cxx
src/MeshTest/MeshTest.cxx
tests/bugs/moddata_3/bug28026 [new file with mode: 0644]

index b5c9b397709ec7972adac83c3e93c3b2ba180143..4dd05b89264844f6e91672d07f744c62fcb2a6bc 100644 (file)
@@ -763,7 +763,7 @@ Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
 //purpose  : 
 //=======================================================================
 
-void BRepTools::Clean (const TopoDS_Shape& theShape)
+void BRepTools::Clean (const TopoDS_Shape& theShape, const Standard_Boolean theForce)
 {
   if (theShape.IsNull())
     return;
@@ -809,8 +809,8 @@ void BRepTools::Clean (const TopoDS_Shape& theShape)
     TopExp_Explorer aEdgeIt(aFace, TopAbs_EDGE);
     for (; aEdgeIt.More(); aEdgeIt.Next())
     {
-      const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current());
-      aBuilder.UpdateEdge(aEdge, aNullPoly, aTriangulation, aLoc);
+      const TopoDS_Edge& anEdge = TopoDS::Edge(aEdgeIt.Current());
+      aBuilder.UpdateEdge(anEdge, aNullPoly, aTriangulation, aLoc);
     }
 
     aBuilder.UpdateFace(aFace, aNullTriangulation);
@@ -821,27 +821,50 @@ void BRepTools::Clean (const TopoDS_Shape& theShape)
   TopExp_Explorer aEdgeIt (theShape, TopAbs_EDGE);
   for (; aEdgeIt.More (); aEdgeIt.Next ())
   {
-    TopoDS_Edge anEdgeNoLoc = TopoDS::Edge (aEdgeIt.Value());
-    anEdgeNoLoc.Location (anEmptyLoc);
+    TopoDS_Edge anEdge = TopoDS::Edge(aEdgeIt.Value()); 
+    anEdge.Location(anEmptyLoc);
 
-    if (!aShapeMap.Add (anEdgeNoLoc))
+    if (!aShapeMap.Add(anEdge))
     {
       // the edge has already been processed
       continue;
     }
 
-    if (!BRep_Tool::IsGeometric (TopoDS::Edge (anEdgeNoLoc)))
+    if (!BRep_Tool::IsGeometric(TopoDS::Edge(anEdge)))
     {
       // Do not remove polygon 3d as there is no curve to recompute it.
       continue;
     }
 
     TopLoc_Location aLoc;
-    Handle (Poly_Polygon3D) aPoly3d = BRep_Tool::Polygon3D (anEdgeNoLoc, aLoc);
-    if (aPoly3d.IsNull())
-      continue;
+    Handle(Poly_Polygon3D) aPoly3d = BRep_Tool::Polygon3D(anEdge, aLoc);
 
-    aBuilder.UpdateEdge (anEdgeNoLoc, aNullPoly3d);
+    if (!aPoly3d.IsNull())
+    {
+      aBuilder.UpdateEdge(anEdge, aNullPoly3d);
+    }
+    if (theForce)
+    {
+      Handle(BRep_CurveRepresentation) aCR;
+      BRep_TEdge* aTE = static_cast<BRep_TEdge*>(anEdge.TShape().get());
+      BRep_ListOfCurveRepresentation& aLCR = aTE->ChangeCurves();
+      BRep_ListIteratorOfListOfCurveRepresentation anIterCR(aLCR);
+
+      // find and remove all representations
+      while (anIterCR.More())
+      {
+        aCR = anIterCR.Value();
+        if (aCR->IsPolygonOnTriangulation())
+        {
+          aLCR.Remove(anIterCR);
+        }
+        else
+        {
+          anIterCR.Next();
+        }
+      }
+      aTE->Modified(Standard_True);
+    }
   }
 }
 //=======================================================================
@@ -875,7 +898,6 @@ void BRepTools::CleanGeometry(const TopoDS_Shape& theShape)
   for (TopExp_Explorer aEdgeIt2(theShape, TopAbs_EDGE); aEdgeIt2.More(); aEdgeIt2.Next())
   {
     const TopoDS_Edge& anEdge = TopoDS::Edge(aEdgeIt2.Current());
-
     aBuilder.UpdateEdge(anEdge, Handle(Geom_Curve)(),
       TopLoc_Location(), BRep_Tool::Tolerance(anEdge));
   }
index 1a8b80f8669cd5b094eda49f176d05c4ac29b13d..99766fc10fce9a569d14d2f22aeee33c5cb1a154 100644 (file)
@@ -154,7 +154,10 @@ public:
   //! triangulations and polygons 3d of the edges.
   //! In case polygonal representation is the only available representation
   //! for the shape (shape does not have geometry) it is not removed.
-  Standard_EXPORT static void Clean (const TopoDS_Shape& S);
+  //! @param theShape  [in] the shape to clean
+  //! @param theForce  [in] allows removing all polygonal representations from the shape,
+  //!                       including polygons on triangulations irrelevant for the faces of the given shape.
+  Standard_EXPORT static void Clean (const TopoDS_Shape& theShape, const Standard_Boolean theForce = Standard_False);
   
   //! Removes geometry (curves and surfaces) from all edges and faces of the shape
   Standard_EXPORT static void CleanGeometry(const TopoDS_Shape& theShape);
index 43727a7ac6ee201409800c1ab58b3ea04ce8a4a6..63e6e3dd5303359915bcc219b49887f88fe82af0 100644 (file)
@@ -369,26 +369,56 @@ static Standard_Integer triangles(Draw_Interpretor& ,
 // tclean
 //=======================================================================
 
-static Standard_Integer tclean(Draw_Interpretor& 
-                              Standard_Integer n, const char** a)
+static Standard_Integer tclean(Draw_Interpretor& di,
+  Standard_Integer n, const char** a)
 {
-  if (n == 1) return 1;
-
-  Standard_Integer aStart = 1;
   Standard_Boolean toRemoveGeometry = Standard_False;
-  if (strcmp(a[1], "-geom") == 0)
+  Standard_Boolean isForceClean = Standard_False;
+
+  if (n <= 1)
   {
-    aStart++;
-    toRemoveGeometry = Standard_True;
+    di.PrintHelp(a[0]);
+    return 1;
   }
-
-  for (Standard_Integer i = aStart; i < n; i++) {
-    TopoDS_Shape S = DBRep::Get(a[i]);
-    if (toRemoveGeometry)
-      BRepTools::CleanGeometry(S);
+  TopoDS_Compound aCompound;
+  BRep_Builder().MakeCompound(aCompound);
+  for (Standard_Integer anArgIter = 1; anArgIter < n; ++anArgIter)
+  {
+    if (strcmp(a[anArgIter], "-geom") == 0)
+    {
+      toRemoveGeometry = Standard_True;
+    }
+    else if (strcmp(a[anArgIter], "-force") == 0)
+    {
+      isForceClean = Standard_True;
+    }
     else
-      BRepTools::Clean(S);
+    {
+      TopoDS_Shape aShape = DBRep::Get(a[anArgIter]);
+      if (aShape.IsNull())
+      {
+        di << "Syntax error : NULL shape '"<< a[anArgIter] << "'";
+        return 1;
+      }
+      BRep_Builder().Add(aCompound, aShape);
+    }
   }
+  if (aCompound.NbChildren() == 0)
+  {
+    di << "Syntax error : wrong number of arguments";
+    di.PrintHelp(a[0]);
+    return 1;
+  }
+  if (isForceClean && toRemoveGeometry)
+  {
+    di << "Syntax error: wrong usage of arguments: do not use 'force' and 'geom' flags together";
+    return 1;
+  }
+
+  if (toRemoveGeometry)
+    BRepTools::CleanGeometry(aCompound);
+  else
+    BRepTools::Clean(aCompound, isForceClean);
   return 0;
 }
 
@@ -1621,9 +1651,11 @@ void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
   theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
   theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
   theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
-  theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n" 
-                   "\t erase geometry objects from shapes - key is used or \n"
-                   "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n",
+  theCommands.Add("tclean", "tclean [-force] [-geom] [name1]..., depending on using or not key -geom, \n" 
+                   "\t\t -geom  : erase geometry\n"
+                   "\t\t          if [-geom] is omitted - erase triangulations and \n"
+                   "\t\t          polygons on triangulations from shapes \n"
+                   "\t\t -force : force delete all representations not relevant to the given shape \n",
                     __FILE__, tclean, g); 
   theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
   theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
index 80f41a3ab1ec8f82683ea55c34f428b535f5e5d2..7b9b1c662584bce6e63608612d42c468ee108566 100644 (file)
@@ -43,6 +43,9 @@
 #include <Poly_Connect.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
+#include <BRep_CurveRepresentation.hxx>
+#include <BRep_TEdge.hxx>
+#include <TopExp.hxx> 
 
 #include <BRepMesh_Context.hxx>
 #include <BRepMesh_FaceDiscret.hxx>
@@ -441,7 +444,7 @@ static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n,
   TopLoc_Location L;
 
   Standard_Real MaxDeflection = 0.0;
-  Standard_Integer nbtriangles = 0, nbnodes = 0;
+  Standard_Integer nbtriangles = 0, nbnodes = 0, nbrepresentations = 0;
   for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
     TopoDS_Face F = TopoDS::Face(ex.Current());
     T = BRep_Tool::Triangulation(F, L);
@@ -452,11 +455,32 @@ static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n,
         MaxDeflection = T->Deflection();
     }
   }
+  TopTools_IndexedMapOfShape anEdges;
+  TopExp::MapShapes(S, TopAbs_EDGE, anEdges);
+  for (int i = 1; i<=anEdges.Extent(); ++i)
+  {
+    const TopoDS_Edge& anEdge = TopoDS::Edge(anEdges(i));
+    Handle(BRep_CurveRepresentation) aCR;
+    BRep_TEdge* aTE = static_cast<BRep_TEdge*>(anEdge.TShape().get());
+    const BRep_ListOfCurveRepresentation& aLCR = aTE->Curves();
+    BRep_ListIteratorOfListOfCurveRepresentation anIterCR(aLCR);
+
+    while (anIterCR.More()) {
+      aCR = anIterCR.Value();
+      if (aCR->IsPolygonOnTriangulation())
+      {
+        nbrepresentations++;
+      }
+      anIterCR.Next();
+    }
+  }
 
   di<<"\n";
-  di<<"This shape contains " <<nbtriangles<<" triangles.\n";
-  di<<"                    " <<nbnodes    <<" nodes.\n";
-  di<<"Maximal deflection " <<MaxDeflection<<"\n";
+  di << "This shape contains " << nbtriangles << " triangles.\n";
+  di << "                    " << nbnodes << " nodes.\n";
+  di << "                    " << nbrepresentations << " polygons on triangulation .\n";;
+  di << "Maximal deflection " << MaxDeflection << "\n";
+  
   di<<"\n";
 #ifdef OCCT_DEBUG_MESH_CHRONO
   Standard_Real tot, addp, unif, contr, inter;
diff --git a/tests/bugs/moddata_3/bug28026 b/tests/bugs/moddata_3/bug28026
new file mode 100644 (file)
index 0000000..af7cf8f
--- /dev/null
@@ -0,0 +1,20 @@
+puts "========================================================================================="
+puts "OCC28026: Modeling Data - BRepTools::Clean() does not clean all triangulation from shape "
+puts "========================================================================================="
+puts ""
+
+restore [locate_data_file bug28026_Ball.brep] b
+
+set expected {"0 triangles" "0 nodes"
+              "0 polygons on triangulation"
+              "Maximal deflection 0"}
+
+tclean b -force
+set output [trinfo b]
+  
+foreach data ${expected} {
+    if ![regexp $data $output] {
+       puts "Error: Not cleanned all trinfo in '$data'"
+       break; 
+    }
+}