]> OCCT Git - occt-copy.git/commitdiff
reading of multidomain stl files into separate Poly_Triangulation objects (draft) CR0-InteractiveDemonstrator CR31080
authorisn <isn@opencascade.com>
Thu, 28 Jun 2018 14:46:25 +0000 (17:46 +0300)
committeralex <alex>
Wed, 16 Oct 2019 05:51:29 +0000 (08:51 +0300)
src/RWStl/RWStl.cxx
src/RWStl/RWStl.hxx
src/RWStl/RWStl_Reader.cxx
src/RWStl/RWStl_Reader.hxx
src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx

index 0d053347b1ecdf5c32e586de5152403c7dc59068..c34ab669e27bc14ed1eafbd04a28527a48d1fe56 100644 (file)
@@ -97,9 +97,25 @@ namespace
       return aPoly;
     }
 
+    //! Add new solid
+    virtual void AddSolid() Standard_OVERRIDE
+    {
+      Handle(Poly_Triangulation) aCurrentTri = GetTriangulation();
+      myTriangulationList.Append(aCurrentTri);
+      myNodes.Clear();
+      myTriangles.Clear();
+    }
+
+    NCollection_Sequence<Handle(Poly_Triangulation)> GetTriangulationList()
+    {
+      return myTriangulationList;
+    }
+
+
   private:
     NCollection_Vector<gp_XYZ> myNodes;
     NCollection_Vector<Poly_Triangle> myTriangles;
+    NCollection_Sequence<Handle(Poly_Triangulation)> myTriangulationList;
   };
 
 }
@@ -118,6 +134,17 @@ Handle(Poly_Triangulation) RWStl::ReadFile (const Standard_CString theFile,
   return aReader.GetTriangulation();
 }
 
+//=============================================================================
+//function : ReadFile
+//purpose  :
+//=============================================================================
+void RWStl::ReadFile(const Standard_CString theFile, NCollection_Sequence<Handle(Poly_Triangulation)>& theTriangList)
+{
+  Reader aReader;
+  aReader.Read(theFile, Handle(Message_ProgressIndicator)(), true);
+  theTriangList = aReader.GetTriangulationList();
+}
+
 //=============================================================================
 //function : ReadFile
 //purpose  :
index bea270f6fe4bfa8616c74a150098d921f7e2983b..ae640c8131edcde7f9242898fc1870b5551d7607 100644 (file)
@@ -50,6 +50,8 @@ public:
   Standard_EXPORT static Handle(Poly_Triangulation) ReadFile (const Standard_CString theFile,
                                                               const Handle(Message_ProgressIndicator)& aProgInd = Handle(Message_ProgressIndicator)());
 
+  Standard_EXPORT static void ReadFile(const Standard_CString theFile, NCollection_Sequence<Handle(Poly_Triangulation)>& theTriangList);
+
   //! Read triangulation from a binary STL file
   //! In case of error, returns Null handle.
   Standard_EXPORT static Handle(Poly_Triangulation) ReadBinary (const OSD_Path& thePath,
index 556f31fd94ad521135a7c425d02bb82c89e6a882..0886cd025ae1174b18b1f719758fd5879e5bfc98 100644 (file)
@@ -126,7 +126,8 @@ namespace
 //==============================================================================
 
 Standard_Boolean RWStl_Reader::Read (const char* theFile,
-                                     const Handle(Message_ProgressIndicator)& theProgress)
+                                     const Handle(Message_ProgressIndicator)& theProgress,
+                                     bool IsMultiSolid)
 {
   std::filebuf aBuf;
   OSD_OpenStream (aBuf, theFile, std::ios::in | std::ios::binary);
@@ -165,6 +166,8 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile,
       }
     }
     aStream >> std::ws; // skip any white spaces
+    if (IsMultiSolid)
+      AddSolid();
   }
   return ! aStream.fail();
 }
index 9687093900dc811dd17249fd12e36c71396d85fb..2d87aaf9464f1b44d806cab91ad06ffc5355afa3 100644 (file)
@@ -39,7 +39,8 @@ public:
   //! Format is recognized automatically by analysis of the file header.
   //! Returns true if success, false on error or user break.
   Standard_EXPORT Standard_Boolean Read (const char* theFile,
-                                         const Handle(Message_ProgressIndicator)& theProgress);
+                                         const Handle(Message_ProgressIndicator)& theProgress,
+                                         bool IsMultiSolid = false);
 
   //! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200).
   //! The function attempts to put back the read symbols to the stream which thus must support ungetc().
@@ -74,6 +75,8 @@ public:
   //! Should create new triangle built on specified nodes in the target model.
   virtual void AddTriangle (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3) = 0;
 
+  virtual void AddSolid() = 0;
+
 };
 
 #endif
index cf86dc0b4ffff29104f2dc15faaee7aa0003d9d5..8fd4dce8c1f35f8ba31c0f543ba55e3815120cd5 100644 (file)
@@ -411,6 +411,22 @@ static Standard_Integer ReadObj (Draw_Interpretor& theDI,
     {
       aFilePath = theArgVec[anArgIter];
     }
+    else if (theArgc == 4 && strcmp("multi", theArgv[3]) == 0)
+    {
+      NCollection_Sequence<Handle(Poly_Triangulation)> theTriangList;
+      RWStl::ReadFile(theArgv[2], theTriangList);
+      BRep_Builder aB;
+      TopoDS_Compound aCmp;
+      aB.MakeCompound(aCmp);
+      for (int i = 1; i <= theTriangList.Length(); i++)
+      { 
+        TopoDS_Face aFace;
+        aB.MakeFace(aFace);
+        aB.UpdateFace(aFace, theTriangList(i));
+        aB.Add(aCmp, aFace);
+      }
+      DBRep::Set(theArgv[1], aCmp);
+    }
     else
     {
       std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";