0028680: Data Exchange - allow reading of multi-domain STL files
authorabv <abv@opencascade.com>
Sun, 30 Jul 2017 18:29:17 +0000 (21:29 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 1 Aug 2017 20:48:20 +0000 (23:48 +0300)
Method RWStl::Read() is improved to support reading multi-domain STL files.

Test added: bugs stlvrml bug28680

src/RWStl/RWStl_Reader.cxx
src/RWStl/RWStl_Reader.hxx
tests/bugs/stlvrml/bug28680 [new file with mode: 0644]

index 84082bc4cf380e2942d7990f6e66ca88579f6042..ca2e28dcee1a4c58880ed37da17c3edf8a67befc 100644 (file)
@@ -132,18 +132,31 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile,
   }
 
   Standard_IStream aStream (&aBuf);
-  if (IsAscii (aStream))
-  {
-    // get length of file to feed progress indicator
-    aStream.seekg (0, aStream.end);
-    std::streampos theEnd = aStream.tellg();
-    aStream.seekg (0, aStream.beg);
-    return ReadAscii (aStream, theEnd, theProgress);
-  }
-  else
+
+  // get length of file to feed progress indicator in Ascii mode
+  aStream.seekg (0, aStream.end);
+  std::streampos theEnd = aStream.tellg();
+  aStream.seekg (0, aStream.beg);
+
+  while (!aStream.eof() && !aStream.bad())
   {
-    return ReadBinary (aStream, theProgress);
+    if (IsAscii (aStream))
+    {
+      if (!ReadAscii (aStream, theEnd, theProgress))
+      {
+        break;
+      }
+    }
+    else
+    {
+      if (!ReadBinary (aStream, theProgress))
+      {
+        break;
+      }
+    }
+    aStream >> std::ws; // skip any white spaces
   }
+  return !aStream.bad();
 }
 
 //==============================================================================
index c8f3cc547643d1e6a3ba2bffaba723e9c6ad2c0e..9687093900dc811dd17249fd12e36c71396d85fb 100644 (file)
@@ -33,6 +33,8 @@ class RWStl_Reader : public Standard_Transient
 public:
 
   //! Reads data from STL file (either binary or Ascii).
+  //! This function supports reading multi-domain STL files formed by concatenation of several "plain" files.
+  //! The mesh nodes are not merged between domains.
   //! Unicode paths can be given in UTF-8 encoding.
   //! Format is recognized automatically by analysis of the file header.
   //! Returns true if success, false on error or user break.
diff --git a/tests/bugs/stlvrml/bug28680 b/tests/bugs/stlvrml/bug28680
new file mode 100644 (file)
index 0000000..03d360b
--- /dev/null
@@ -0,0 +1,8 @@
+readstl m [locate_data_file bug28680_sample01b.stl] triangulation
+
+# Number of triangles check
+checktrinfo m -tri 62075 -nod 31879
+
+# Visual check
+checkview -display m -3d -vdispmode 0 -path ${imagedir}/${test_image}_edges.png
+checkview -display m -3d -vdispmode 1 -path ${imagedir}/${test_image}_shading.png