diff --git a/vcgtrimesh.cpp b/vcgtrimesh.cpp index c40696d..512ebe1 100755 --- a/vcgtrimesh.cpp +++ b/vcgtrimesh.cpp @@ -6,6 +6,9 @@ #include #include //#include +#ifdef POLYSCOPE_DEFINED +#include +#endif bool VCGTriMesh::load(const std::filesystem::__cxx11::path &meshFilePath) { assert(std::filesystem::exists(meshFilePath)); @@ -36,6 +39,32 @@ bool VCGTriMesh::load(const std::filesystem::__cxx11::path &meshFilePath) { return true; } +bool VCGTriMesh::load(std::istringstream &offInputStream) +{ + Clear(); + // assert(plyFileHasAllRequiredFields(plyFilename)); + // Load the ply file + int mask = 0; + mask |= vcg::tri::io::Mask::IOM_VERTCOORD; + mask |= vcg::tri::io::Mask::IOM_VERTNORMAL; + mask |= vcg::tri::io::Mask::IOM_VERTCOLOR; + mask |= vcg::tri::io::Mask::IOM_EDGEINDEX; + const bool openingFromStreamErrorCode + = vcg::tri::io::ImporterOFF::OpenStream(*this, offInputStream, mask); + if (openingFromStreamErrorCode != 0) { + std::cerr << "Error reading from stream:" + << vcg::tri::io::ImporterOFF::ErrorMsg(openingFromStreamErrorCode) + << std::endl; + return false; + } + vcg::tri::UpdateTopology::AllocateEdge(*this); + vcg::tri::UpdateTopology::FaceFace(*this); + vcg::tri::UpdateTopology::VertexFace(*this); + vcg::tri::UpdateTopology::VertexEdge(*this); + vcg::tri::UpdateNormal::PerVertexNormalized(*this); + return true; +} + Eigen::MatrixX3d VCGTriMesh::getVertices() const { // vcg::tri::Allocator::CompactVertexVector(m); diff --git a/vcgtrimesh.hpp b/vcgtrimesh.hpp index c871075..57252fc 100755 --- a/vcgtrimesh.hpp +++ b/vcgtrimesh.hpp @@ -40,6 +40,7 @@ public: VCGTriMesh(); VCGTriMesh(const std::string &filename); bool load(const std::filesystem::path &meshFilePath) override; + bool load(std::istringstream &offInputStream); Eigen::MatrixX3d getVertices() const; Eigen::MatrixX3i getFaces() const; bool save(const std::string plyFilename);