0026106: BRepMesh - revision of data model
[occt.git] / src / MeshTest / MeshTest.cxx
index 9ee7595..02501b9 100644 (file)
@@ -28,8 +28,8 @@
 #include <BRepMesh_DataStructureOfDelaun.hxx>
 #include <BRepMesh_Delaun.hxx>
 #include <BRepMesh_Edge.hxx>
-#include <BRepMesh_FastDiscret.hxx>
 #include <BRepMesh_IncrementalMesh.hxx>
+#include <IMeshTools_Parameters.hxx>
 #include <BRepMesh_Triangle.hxx>
 #include <BRepMesh_Vertex.hxx>
 #include <BRepTest.hxx>
@@ -80,6 +80,7 @@
 #include <TopoDS_Wire.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
+#include <IMeshData_Status.hxx>
 
 #include <stdio.h>
 //epa Memory leaks test
@@ -140,14 +141,7 @@ options:\n\
     return 0;
   }
 
-  Standard_Real aLinDeflection     = Max(Draw::Atof(argv[2]), Precision::Confusion());
-  Standard_Real aAngDeflection     = 0.5;
-  Standard_Real aMinSize           = Precision::Confusion();
-  Standard_Boolean isRelative      = Standard_False;
-  Standard_Boolean isInParallel    = Standard_False;
-  Standard_Boolean isIntVertices   = Standard_True;
-  Standard_Boolean isControlSurDef = Standard_True;
-  Standard_Boolean isAdaptiveMin   = Standard_False;
+  IMeshTools_Parameters aMeshParams;
 
   if (nbarg > 3)
   {
@@ -160,22 +154,22 @@ options:\n\
       if (aOpt == "")
         continue;
       else if (aOpt == "-relative")
-        isRelative = Standard_True;
+        aMeshParams.Relative = Standard_True;
       else if (aOpt == "-parallel")
-        isInParallel = Standard_True;
+        aMeshParams.InParallel = Standard_True;
       else if (aOpt == "-int_vert_off")
-        isIntVertices = Standard_False;
+        aMeshParams.InternalVerticesMode = Standard_False;
       else if (aOpt == "-surf_def_off")
-        isControlSurDef = Standard_False;
-      else if (aOpt == "-adaptive")
-        isAdaptiveMin   = Standard_True;
+        aMeshParams.ControlSurfaceDeflection = Standard_False;
       else if (i < nbarg)
       {
         Standard_Real aVal = Draw::Atof(argv[i++]);
         if (aOpt == "-a")
-          aAngDeflection = aVal * M_PI / 180.;
+        {
+          aMeshParams.Angle = aVal * M_PI / 180.;
+        }
         else if (aOpt == "-min")
-          aMinSize = aVal;
+          aMeshParams.MinSize = aVal;
         else
           --i;
       }
@@ -183,47 +177,53 @@ options:\n\
   }
 
   di << "Incremental Mesh, multi-threading "
-     << (isInParallel ? "ON" : "OFF") << "\n";
-
-  BRepMesh_FastDiscret::Parameters aMeshParams;
-  aMeshParams.Deflection = aLinDeflection;
-  aMeshParams.Angle = aAngDeflection;
-  aMeshParams.Relative =  isRelative;
-  aMeshParams.InParallel = isInParallel;
-  aMeshParams.MinSize = aMinSize;
-  aMeshParams.InternalVerticesMode = isIntVertices;
-  aMeshParams.ControlSurfaceDeflection = isControlSurDef;
-  aMeshParams.AdaptiveMin = isAdaptiveMin;
-  
+     << (aMeshParams.InParallel ? "ON" : "OFF") << "\n";
+
   BRepMesh_IncrementalMesh aMesher (aShape, aMeshParams);
 
   di << "Meshing statuses: ";
-  Standard_Integer statusFlags = aMesher.GetStatusFlags();
-  if( !statusFlags )
+  const Standard_Integer aStatus = aMesher.GetStatusFlags();
+  if (!aStatus)
   {
     di << "NoError";
   }
   else
   {
     Standard_Integer i;
-    for( i = 0; i < 4; i++ )
+    for (i = 0; i < 8; i++)
     {
-      if( (statusFlags >> i) & (Standard_Integer)1 )
+      Standard_Integer aFlag = aStatus & (1 << i);
+      if (aFlag)
       {
-        switch(i+1)
+        switch ((IMeshData_Status) aFlag)
         {
-          case 1:
-            di << "OpenWire ";
-            break;
-          case 2:
-            di << "SelfIntersectingWire ";
-            break;
-          case 3:
-            di << "Failure ";
-            break;
-          case 4:
-            di << "ReMesh ";
-            break;
+        case IMeshData_OpenWire:
+          di << "OpenWire ";
+          break;
+        case IMeshData_SelfIntersectingWire:
+          di << "SelfIntersectingWire ";
+          break;
+        case IMeshData_Failure:
+          di << "Failure ";
+          break;
+        case IMeshData_ReMesh:
+          di << "ReMesh ";
+          break;
+        case IMeshData_UnorientedWire:
+          di << "UnorientedWire ";
+          break;
+        case IMeshData_TooFewPoints:
+          di << "TooFewPoints ";
+          break;
+        case IMeshData_Outdated:
+          di << "Outdated ";
+          break;
+        case IMeshData_Reused:
+          di << "Reused ";
+          break;
+        case IMeshData_NoError:
+        default:
+          break;
         }
       }
     }
@@ -401,114 +401,6 @@ static Standard_Integer MemLeakTest(Draw_Interpretor&, Standard_Integer /*nbarg*
   return 0;
 }
 
-//=======================================================================
-//function : fastdiscret
-//purpose  : 
-//=======================================================================
-
-static Standard_Integer fastdiscret(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
-{
-  if (nbarg < 3) return 1;
-
-  TopoDS_Shape S = DBRep::Get(argv[1]);
-  if (S.IsNull()) return 1;
-
-  const Standard_Real d = Draw::Atof(argv[2]);
-
-  Bnd_Box B;
-  BRepBndLib::Add(S,B);
-  BRepMesh_FastDiscret::Parameters aParams;
-  aParams.Deflection = d;
-  aParams.Angle = 0.5;
-  BRepMesh_FastDiscret MESH(B,aParams);
-
-  //Standard_Integer NbIterations = MESH.NbIterations();
-  //if (nbarg > 4) NbIterations = Draw::Atoi(argv[4]);
-  //MESH.NbIterations() = NbIterations;
-
-  di<<"Starting FastDiscret with :\n";
-  di<<"  Deflection="<<d<<"\n";
-  di<<"  Angle="<<0.5<<"\n";
-
-  Handle(Poly_Triangulation) T;
-  BRep_Builder aBuilder;
-  TopExp_Explorer ex;
-
-  // Clear existing triangulations
-  for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
-    aBuilder.UpdateFace(TopoDS::Face(ex.Current()),T);
-
-  MESH.Perform(S);
-
-  TopoDS_Compound aCompGood, aCompFailed, aCompViolating;
-
-  TopLoc_Location L;
-  Standard_Integer nbtriangles = 0, nbnodes = 0, nbfailed = 0, nbviolating = 0;
-  Standard_Real maxdef = 0.0;
-  for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
-  {
-    T = BRep_Tool::Triangulation(TopoDS::Face(ex.Current()),L);
-    if (T.IsNull())
-    {
-      nbfailed++;
-      if (aCompFailed.IsNull())
-        aBuilder.MakeCompound(aCompFailed);
-      aBuilder.Add(aCompFailed,ex.Current());
-    }
-    else
-    {
-      nbtriangles += T->NbTriangles();
-      nbnodes += T->NbNodes();
-      if (T->Deflection() > maxdef) maxdef = T->Deflection();
-      if (T->Deflection() > d)
-      {
-        nbviolating++;
-        if (aCompViolating.IsNull())
-          aBuilder.MakeCompound(aCompViolating);
-        aBuilder.Add(aCompViolating,ex.Current());
-      }
-      else
-      {
-        if (aCompGood.IsNull())
-          aBuilder.MakeCompound(aCompGood);
-        aBuilder.Add(aCompGood,ex.Current());
-      }
-    }
-  }
-
-  if (!aCompGood.IsNull())
-  {
-    char name[256];
-    strcpy(name,argv[1]);
-    strcat(name,"_good");
-    DBRep::Set(name,aCompGood);
-  }
-  if (!aCompFailed.IsNull())
-  {
-    char name[256];
-    strcpy(name,argv[1]);
-    strcat(name,"_failed");
-    DBRep::Set(name,aCompFailed);
-  }
-  if (!aCompViolating.IsNull())
-  {
-    char name[256];
-    strcpy(name,argv[1]);
-    strcat(name,"_violating");
-    DBRep::Set(name,aCompViolating);
-  }
-
-  di<<"FastDiscret completed with :\n";
-  di<<"  MaxDeflection="<<maxdef<<"\n";
-  di<<"  NbNodes="<<nbnodes<<"\n";
-  di<<"  NbTriangles="<<nbtriangles<<"\n";
-  di<<"  NbFailed="<<nbfailed<<"\n";
-  di<<"  NbViolating="<<nbviolating<<"\n";
-
-  return 0;
-}
-
-
 //=======================================================================
 //function : triangule
 //purpose  : 
@@ -1771,7 +1663,6 @@ void  MeshTest::Commands(Draw_Interpretor& theCommands)
   theCommands.Add("incmesh","Builds triangular mesh for the shape, run w/o args for help",__FILE__, incrementalmesh, g);
   theCommands.Add("tessellate","Builds triangular mesh for the surface, run w/o args for help",__FILE__, tessellate, g);
   theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g);
-  theCommands.Add("fastdiscret","fastdiscret shape deflection",__FILE__, fastdiscret, g);
   theCommands.Add("mesh","mesh result Shape deflection",__FILE__, triangule, g);
   theCommands.Add("addshape","addshape meshname Shape [deflection]",__FILE__, addshape, g);
   //theCommands.Add("smooth","smooth meshname",__FILE__, smooth, g);