]> OCCT Git - occt-copy.git/commitdiff
0025357: STL writer does not check the given shape for existing triangulation and...
authorakz <akz@opencascade.com>
Thu, 5 Feb 2015 11:38:59 +0000 (14:38 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 5 Feb 2015 11:40:24 +0000 (14:40 +0300)
StlTransfer.cxx, function StlTransfer::BuildIncrementalMesh(...) fills the StlMesh_Mesh. Before this fix the StlTransfer always force meshing of the passed shape.

Now meshing is completely removed from the StlTransfer. StlWriter can return error status now, for example, if a mesh of the passed shape is empty. In this case file will be not created.

Added test case bugs/xde/bug25357

Avoid the warning on gcc compiler.
Test scripts were modified according to the fix.
     1) bug23192, bug22670, bug23193: removed "isParallel" flag from the command
         arguments. Manually meshing of the shape (as far as meshing was removed
         from STL writer).
     2) bug22898: before the fix writestl always remeshes the shape with a
         deflection, related to the boundery box of the shape. For "hammer" shape
         there is a 38.9076 deflection for mesh. Differences between before writing
         and after reading are dedicated to fact that stl writes triangulation as
         an elements of the spahe (like faces, edges etc.)

15 files changed:
src/QABugs/QABugs_2.cxx
src/StlAPI/StlAPI.cdl
src/StlAPI/StlAPI.cxx
src/StlAPI/StlAPI_Writer.cdl
src/StlAPI/StlAPI_Writer.cxx
src/StlTransfer/StlTransfer.cdl
src/StlTransfer/StlTransfer.cxx
src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx
tests/bugs/fclasses/bug23192_1
tests/bugs/fclasses/bug23192_2
tests/bugs/xde/bug22670_1
tests/bugs/xde/bug22670_2
tests/bugs/xde/bug22898
tests/bugs/xde/bug23193
tests/bugs/xde/bug25357 [new file with mode: 0644]

index 1f5401ece7968681ba5ffba8df6ec23b6399c71d..ca5a272dab12ebad4e7767d5122e8f842995daac 100644 (file)
@@ -33,6 +33,7 @@
 #include <BRep_Tool.hxx>
 #include <BRepAlgoAPI_Section.hxx>
 #include <BRepAlgo_Section.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
 #include <Precision.hxx>
 #include <Standard_ErrorHandler.hxx>
 
@@ -183,8 +184,8 @@ static Standard_Integer OCC1048 (Draw_Interpretor& di, Standard_Integer argc, co
 
   Standard_Real theDeflection = 0.006;
   Handle(StlMesh_Mesh) theStlMesh = new StlMesh_Mesh;
-  StlTransfer::BuildIncrementalMesh(aShape, theDeflection, Standard_False, theStlMesh);
-
+  BRepMesh_IncrementalMesh aMesh(aShape, theDeflection);
+  StlTransfer::RetrieveMesh(aShape, theStlMesh);
   Standard_Integer NBTRIANGLES = theStlMesh->NbTriangles();
   di<<"Info: Number of triangles = "<<NBTRIANGLES<<"\n";
 
index b33d863fb7de75ed72168abcb15600a2bf8a9e04..df77c76bbea1a5a7652f3c9a459569ce09ec546a 100644 (file)
@@ -25,12 +25,21 @@ uses
     StlMesh
      
 is 
+       enumeration ErrorStatus is 
+               ---Purpose: Set of statuses to indicate a type of the error
+               -- occurred during data retrieving and writing operations.
+               StatusOK,
+               MeshIsEmpty,
+               CannotOpenFile
+
+    end ErrorStatus;
+
     class Writer; 
     class Reader; 
     
     Write(aShape      : in Shape from TopoDS;  
           aFile       : in CString from Standard;
-         aAsciiMode  : in Boolean from Standard = Standard_True);
+         aAsciiMode  : in Boolean from Standard = Standard_True) returns ErrorStatus from StlAPI;
          ---Purpose : Convert and write shape to STL format.
          --         file is written in binary if aAsciiMode is False
          --         otherwise it is written in Ascii (by default)
index 00fa295400bab221433cd12e470b85ef5fbef50b..e89adde25c5cec08e049699e01d032f1c4f5d1bb 100644 (file)
 #include <StlAPI_Writer.hxx>
 #include <StlAPI_Reader.hxx>
 
-void StlAPI::Write(const TopoDS_Shape& aShape,
+StlAPI_ErrorStatus StlAPI::Write(const TopoDS_Shape& aShape,
                   const Standard_CString aFile,
                   const Standard_Boolean aAsciiMode) 
 {
   StlAPI_Writer writer;
   writer.ASCIIMode() = aAsciiMode;
-  writer.Write (aShape, aFile);
+  return writer.Write (aShape, aFile);
 }
 
 
index 38f468bcbae80541f4f72f073585e5fbef3ed4d0..2264ec10ccd39d947ba1f3bb4f9638a1bf3b7796 100644 (file)
@@ -21,34 +21,12 @@ class Writer from StlAPI
 
 uses
     Shape from TopoDS,
-    Mesh from StlMesh
+    Mesh from StlMesh,
+       ErrorStatus from StlAPI
 is
-    Create;
+       Create;
         ---Purpose: Creates a writer object with
-        -- default parameters: ASCIIMode, RelativeMode, SetCoefficent,
-        -- SetDeflection. These parameters may be modified. 
-
-    SetDeflection(me: in out; aDeflection : in Real from Standard);
-       ---Purpose: Sets the deflection of the meshing algorithm. 
-       --    Deflection is used, only if relative mode is false
-
-    SetCoefficient(me: in out; aCoefficient : in Real from Standard);
-       ---Purpose: Sets the coeffiecient for computation of deflection through 
-       --          relative size of shape. Default value = 0.001
-
-    RelativeMode(me: in out) returns Boolean;
-               ---C++: return &
-       ---Purpose: Returns the address to the
-       -- flag defining the relative mode for writing the file.
-       -- This address may be used to either read or change the flag.
-       -- If the mode returns True (default value), the
-       -- deflection is calculated from the relative size of the
-       -- shape. If the mode returns False, the user defined deflection is used. 
-       -- Example
-       -- Read:
-       -- Standard_Boolean val = Writer.RelativeMode( );
-       -- Modify:
-       -- Writer.RelativeMode( ) = Standard_True; 
+        -- default parameters: ASCIIMode.
         
     ASCIIMode(me: in out) returns Boolean;
        ---C++: return &
@@ -61,14 +39,11 @@ is
         
     Write(me         : in out; 
           aShape     : Shape from TopoDS; 
-          aFileName  : CString from Standard; 
-          InParallel : Boolean from Standard = Standard_False);
+          aFileName  : CString from Standard) returns ErrorStatus from StlAPI;
        ---Purpose: Converts a given shape to STL format and writes it to file with a given filename.
+               --- \return the error state.
     
 fields
-    theRelativeMode : Boolean from Standard;
     theASCIIMode    : Boolean from Standard;
-    theDeflection   : Real from Standard;
-    theCoefficient   : Real from Standard;
     theStlMesh      : Mesh from StlMesh;
 end Writer;
index 9037efae15400eb229b2a862528f0af1ba2baf57..d0f365389d3bea9c5607c9b554e71c083285c9d9 100644 (file)
 #include <BRepBndLib.hxx>
 #include <OSD_Path.hxx>
 
-#define MAX2(X, Y)      (  Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
-#define MAX3(X, Y, Z)   ( MAX2 ( MAX2(X,Y) , Z) )
-
 StlAPI_Writer::StlAPI_Writer()
 {
   theStlMesh = new StlMesh_Mesh;
   theASCIIMode = Standard_True;
-  theDeflection = 0.01;
-  theRelativeMode = Standard_True;
-  theCoefficient = 0.001;
-}
-
-void StlAPI_Writer::SetDeflection(const Standard_Real aDeflection) 
-{
-  theDeflection = aDeflection;
-}
-void StlAPI_Writer::SetCoefficient(const Standard_Real aCoefficient) 
-{
-  theCoefficient = aCoefficient;
-}
-
-Standard_Boolean& StlAPI_Writer::RelativeMode() 
-{
-  return theRelativeMode;
 }
 
 Standard_Boolean& StlAPI_Writer::ASCIIMode() 
@@ -50,23 +30,26 @@ Standard_Boolean& StlAPI_Writer::ASCIIMode()
   return theASCIIMode;
 }
 
-void StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName, const Standard_Boolean theInParallel) 
+StlAPI_ErrorStatus StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName)
 {
   OSD_Path aFile(theFileName);
-  if (theRelativeMode) {
-    Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-    Bnd_Box Total;
-    BRepBndLib::Add(theShape, Total);
-    Total.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
-    theDeflection = MAX3(aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*theCoefficient;
-  }
-  StlTransfer::BuildIncrementalMesh(theShape, theDeflection, theInParallel, theStlMesh);
+  StlTransfer::RetrieveMesh(theShape, theStlMesh);
+
+  if (theStlMesh.IsNull() || theStlMesh->IsEmpty())
+    return StlAPI_MeshIsEmpty;
+
   // Write the built mesh
+  Standard_Boolean wasFileOpened = Standard_False;
   if (theASCIIMode) {
-    RWStl::WriteAscii(theStlMesh, aFile);
+    wasFileOpened = RWStl::WriteAscii(theStlMesh, aFile);
     }  
   else {
-    RWStl::WriteBinary(theStlMesh, aFile);
+    wasFileOpened = RWStl::WriteBinary(theStlMesh, aFile);
     }
+
+  if (!wasFileOpened)
+    return StlAPI_CannotOpenFile;
+
+  return StlAPI_StatusOK;
 }
 
index 40a3c2639fba3cebf37d02ed82e21e4c85e6fdd7..2d3e66bc48e4325a46cbee9cdbb427d43ff87e7b 100644 (file)
 package StlTransfer 
 
        ---Purpose: The  package   Algorithm  for Meshing   implements
-       --          facilities to compute  the Mesh data-structure, as
-       --          defined in package StlMesh, from a shape of package
-       --          TopoDS.  The triangulation  is  computed  with the
-       --          Delaunay      algorithm   implemented in   package
-       --          BRepMesh.  The  result   is  stored  in  the  mesh
+       --          facilities to retrieve the Mesh data-structure from a shape of package
+       --          TopoDS.  The triangulation  should be computed before.  
+       --          The  result   is  stored  in  the  mesh
        --          data-structure Mesh from package StlMesh.
        --          
 
@@ -31,11 +29,9 @@ uses
     TopoDS
 
 is
-    BuildIncrementalMesh (Shape      : in      Shape from TopoDS; 
-                         Deflection : in      Real  from Standard;
-                         InParallel : in      Boolean from Standard;
-                         Mesh       : Mesh  from StlMesh)
-     raises ConstructionError;
+    RetrieveMesh (Shape      : in      Shape from TopoDS; 
+                 Mesh       : Mesh  from StlMesh);
+               ---Purpose: Retrieve a Mesh data-structure from the Shape, convert and store it into the Mesh.            
 end StlTransfer;
 
 
index d440ecf0700558591a440337be0cc88425f3b49e..e485a87962fa9d470f385493e812a8d32b820abd 100644 (file)
@@ -108,16 +108,9 @@ static void Normal(const TopoDS_Face&  aFace,
   }
   
 }
-void StlTransfer::BuildIncrementalMesh (const TopoDS_Shape&  Shape,
-                                                                               const Standard_Real  Deflection,
-                                                                               const Standard_Boolean  InParallel,
+void StlTransfer::RetrieveMesh (const TopoDS_Shape&  Shape,
                                                                                const Handle(StlMesh_Mesh)& Mesh)
 {
-  if (Deflection <= Precision::Confusion ()) {
-    Standard_ConstructionError::Raise ("StlTransfer::BuildIncrementalMesh");
-    }
-  
-  BRepMesh_IncrementalMesh aMesher(Shape, Deflection, Standard_False, 0.5, InParallel);
   for (TopExp_Explorer itf(Shape,TopAbs_FACE); itf.More(); itf.Next()) {
     TopoDS_Face face = TopoDS::Face(itf.Current());
     TopLoc_Location Loc, loc;
@@ -125,7 +118,7 @@ void StlTransfer::BuildIncrementalMesh (const TopoDS_Shape&  Shape,
     if (theTriangulation.IsNull()) continue; //Meshing was not done for this face!
     Poly_Array1OfTriangle theTriangles(1,theTriangulation->NbTriangles());
     theTriangles.Assign(theTriangulation->Triangles());
-    Mesh->AddDomain (Deflection);
+    Mesh->AddDomain (theTriangulation->Deflection());
     
     TColgp_Array1OfPnt thePoints(1, theTriangulation->NbNodes());
     thePoints.Assign(theTriangulation->Nodes());
index 6b658488c167fe7638bcfa609bb8952d829cbaa3..47f6f18fc22ba346b670caa90241cc765b4dd069 100644 (file)
@@ -92,21 +92,25 @@ extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theNam
 static Standard_Integer writestl
 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc < 3 || argc > 5) {
+  if (argc < 3 || argc > 4) {
     di << "Use: " << argv[0]
-    << " shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]" << "\n";
+    << " shape file [ascii/binary (0/1) : 1 by default]" << "\n";
   } else {
     TopoDS_Shape aShape = DBRep::Get(argv[1]);
     Standard_Boolean isASCIIMode = Standard_False;
-    Standard_Boolean isInParallel = Standard_False;
-    if (argc > 3) {
+    if (argc == 4) {
       isASCIIMode = (Draw::Atoi(argv[3]) == 0);
-      if (argc > 4)
-        isInParallel = (Draw::Atoi(argv[4]) == 1);
     }
     StlAPI_Writer aWriter;
     aWriter.ASCIIMode() = isASCIIMode;
-    aWriter.Write (aShape, argv[2], isInParallel);
+    StlAPI_ErrorStatus aStatus = aWriter.Write (aShape, argv[2]);
+
+    switch (aStatus)
+    {
+    case StlAPI_MeshIsEmpty: di << "** Error **: Mesh is empty. Please, compute triangulation before."; break;
+    case StlAPI_CannotOpenFile: di << "** Error **: Cannot create/open a file with the passed name."; break;
+    case StlAPI_StatusOK: default: break;
+    }
   }
   return 0;
 }
index be5324df5559cebcb5b159eb09b7846f356e61cc..6b250902f5866e9b7cf84a79ea3e98a78f5ccb78 100755 (executable)
@@ -14,11 +14,11 @@ set aFile $imagedir/${test_image}.stl
 file delete ${aFile}
 
 set anASCIImode 1
-set InParallel 0
 
 box res 10 10 10
+incmesh res 0.1
 
-writestl res ${aFile} ${anASCIImode} ${InParallel}
+writestl res ${aFile} ${anASCIImode}
 catch {exec chmod 777 ${aFile}}
 
 if { [file exists ${aFile}] } {
index 7e54e964db7bfa08c6813cbfe2acd448ad5f3f6a..158cd5e3567f25286ec4f58cc99619bdc2b46b26 100755 (executable)
@@ -14,11 +14,11 @@ set aFile $imagedir/${test_image}.stl
 file delete ${aFile}
 
 set anASCIImode 0
-set InParallel 0
 
 box res 10 10 10
+incmesh res 0.1
 
-writestl res ${aFile} ${anASCIImode} ${InParallel}
+writestl res ${aFile} ${anASCIImode}
 catch {exec chmod 777 ${aFile}}
 
 if { [file exists ${aFile}] } {
index 9c74bea8dfa68191a79d5041c785292ca1115296..ff3cb0591abe0aa035eb50b7e8e26a5ddd96af0c 100755 (executable)
@@ -13,6 +13,8 @@ readstl res_mesh [locate_data_file OMF6391_box.stl]
 set aFile ${imagedir}/OCC22670.stl
 file delete ${aFile}
 
+incmesh res_mesh 0.1
+
 set anASCIImode 0
 writestl res_mesh ${aFile} ${anASCIImode}
 catch {exec chmod 777 ${aFile}}
index b9077ad3f3ff254f0df652f49d97699edc8c7a05..818b62a3cff5915be7a0f8cf2f8049b43891e807 100755 (executable)
@@ -25,10 +25,11 @@ if { [catch { readstl res_mesh $filepath } catch_result] } {
 
     set aFile $imagedir/${test_image}.stl
     catch {exec rm -f ${aFile}}
+     
+    incmesh res_mesh 0.1   
 
     set anASCIImode 0
-    set InParallel 1
-    writestl res_mesh ${aFile} ${anASCIImode} ${InParallel}
+    writestl res_mesh ${aFile} ${anASCIImode}
     catch {exec chmod 777 ${aFile}}
 
     readstl result ${aFile}
index 58c5b2561c0cc77008985a613b2c2be52b7b4e5b..b1972c96ffebb87b8302f0e3b83e0a404ade6948 100644 (file)
@@ -42,6 +42,7 @@ tolerance step_1
 checkarea step_1 3.978e8 1e6 0.001
 
 # STL
+incmesh hammer 38.9076
 writestl hammer $imagedir/hammer.stl 
 readstl stl $imagedir/hammer.stl
 checkshape stl
index 13578a17c67c5491708e28d26e434e2a1eb00171..73f0e0b8d5e7b06af70f8906d06fe15c5224e1c2 100755 (executable)
@@ -12,6 +12,7 @@ set aFile $imagedir/bug23193_sample.stl
 
 vinit
 stepread [locate_data_file bug23193_sample.stp] a *
+incmesh a_1 1
 writestl a_1 ${aFile} 0
 
 meshfromstl m1 ${aFile}
diff --git a/tests/bugs/xde/bug25357 b/tests/bugs/xde/bug25357
new file mode 100644 (file)
index 0000000..758bedc
--- /dev/null
@@ -0,0 +1,47 @@
+puts "=========="
+puts "OCC25357"
+puts "=========="
+puts ""
+#######################################################################################
+# STL writer does not check the given shape for existing triangulation and remeshes 
+# shape using BRepMesh in force mode
+#######################################################################################
+
+set aFile ${imagedir}/${test_image}.stl
+file delete -force ${aFile}
+
+set anASCIImode 0
+
+ptorus res 10 8
+incmesh res 0.5
+
+#decho off
+set LogBefore [trinfo res]
+#decho on
+
+writestl res ${aFile} ${anASCIImode}
+
+#decho off
+set LogAfter [trinfo res]
+#decho on
+
+set status 1
+if { ![file exists ${aFile}] } {
+  set status 0
+}
+
+# Check file size
+set filesize [ file size ${aFile} ]
+if { ${filesize} == 0 } {
+  set status 0
+}
+
+if { $LogBefore != $LogAfter } {
+  set status 0
+}
+
+if {$status == 1} {
+  puts "OK: STL writer check given shape"
+} else {
+  puts "Error: STL writer does not check given shape"
+}