From 961713db5278cb9d694b4d33630789c7eed75c3f Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 28 Jun 2018 17:46:25 +0300 Subject: [PATCH] reading of multidomain stl files into separate Poly_Triangulation objects (draft) --- src/RWStl/RWStl.cxx | 27 +++++++++++++++++++++++++++ src/RWStl/RWStl.hxx | 2 ++ src/RWStl/RWStl_Reader.cxx | 5 ++++- src/RWStl/RWStl_Reader.hxx | 5 ++++- src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx | 16 ++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/RWStl/RWStl.cxx b/src/RWStl/RWStl.cxx index 0d053347b1..c34ab669e2 100644 --- a/src/RWStl/RWStl.cxx +++ b/src/RWStl/RWStl.cxx @@ -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 GetTriangulationList() + { + return myTriangulationList; + } + + private: NCollection_Vector myNodes; NCollection_Vector myTriangles; + NCollection_Sequence 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& theTriangList) +{ + Reader aReader; + aReader.Read(theFile, Handle(Message_ProgressIndicator)(), true); + theTriangList = aReader.GetTriangulationList(); +} + //============================================================================= //function : ReadFile //purpose : diff --git a/src/RWStl/RWStl.hxx b/src/RWStl/RWStl.hxx index bea270f6fe..ae640c8131 100644 --- a/src/RWStl/RWStl.hxx +++ b/src/RWStl/RWStl.hxx @@ -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& 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, diff --git a/src/RWStl/RWStl_Reader.cxx b/src/RWStl/RWStl_Reader.cxx index 556f31fd94..0886cd025a 100644 --- a/src/RWStl/RWStl_Reader.cxx +++ b/src/RWStl/RWStl_Reader.cxx @@ -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(); } diff --git a/src/RWStl/RWStl_Reader.hxx b/src/RWStl/RWStl_Reader.hxx index 9687093900..2d87aaf946 100644 --- a/src/RWStl/RWStl_Reader.hxx +++ b/src/RWStl/RWStl_Reader.hxx @@ -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 diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index cf86dc0b4f..8fd4dce8c1 100644 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -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 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"; -- 2.39.5