Added function for loading tri mes using istringstream

This commit is contained in:
iasonmanolas 2022-05-06 16:28:28 +03:00
parent 398df24056
commit f531b16b19
2 changed files with 30 additions and 0 deletions

View File

@ -6,6 +6,9 @@
#include <wrap/io_trimesh/export.h>
#include <wrap/io_trimesh/import.h>
//#include <wrap/nanoply/include/nanoplyWrapper.hpp>
#ifdef POLYSCOPE_DEFINED
#include <polyscope/curve_network.h>
#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<VCGTriMesh>::OpenStream(*this, offInputStream, mask);
if (openingFromStreamErrorCode != 0) {
std::cerr << "Error reading from stream:"
<< vcg::tri::io::ImporterOFF<VCGTriMesh>::ErrorMsg(openingFromStreamErrorCode)
<< std::endl;
return false;
}
vcg::tri::UpdateTopology<VCGTriMesh>::AllocateEdge(*this);
vcg::tri::UpdateTopology<VCGTriMesh>::FaceFace(*this);
vcg::tri::UpdateTopology<VCGTriMesh>::VertexFace(*this);
vcg::tri::UpdateTopology<VCGTriMesh>::VertexEdge(*this);
vcg::tri::UpdateNormal<VCGTriMesh>::PerVertexNormalized(*this);
return true;
}
Eigen::MatrixX3d VCGTriMesh::getVertices() const
{
// vcg::tri::Allocator<VCGTriMesh>::CompactVertexVector(m);

View File

@ -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);