MySources/polymesh.hpp

65 lines
2.6 KiB
C++

#ifndef POLYMESH_HPP
#define POLYMESH_HPP
#include "vcg/complex/complex.h"
#include <filesystem>
#include <wrap/io_trimesh/import.h>
//#include <wrap/nanoply/include/nanoplyWrapper.hpp>
class PFace;
class PVertex;
struct PUsedTypes : public vcg::UsedTypes<vcg::Use<PVertex>::AsVertexType,
vcg::Use<PFace>::AsFaceType> {};
class PVertex : public vcg::Vertex<PUsedTypes, vcg::vertex::Coord3d,
vcg::vertex::Normal3d, vcg::vertex::Mark,
vcg::vertex::Qualityf, vcg::vertex::BitFlags,
vcg::vertex::VFAdj> {};
class PFace
: public vcg::Face<
PUsedTypes,
vcg::face::PolyInfo // this is necessary if you use component in
// vcg/simplex/face/component_polygon.h
// It says "this class is a polygon and the memory for its components
// (e.g. pointer to its vertices will be allocated dynamically")
,
vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj )
,
vcg::face::PFVAdj,
vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj )
,
vcg::face::BitFlags // bit flags
,
vcg::face::Qualityf // quality
,
vcg::face::Normal3f // normal
> {};
class VCGPolyMesh
: public vcg::tri::TriMesh<std::vector<PVertex>, // the vector of vertices
std::vector<PFace> // the vector of faces
> {
public:
void loadFromPlyFile(const std::string &filename) {
vcg::tri::io::ImporterOBJ<VCGPolyMesh>::Info info;
vcg::tri::io::ImporterOBJ<VCGPolyMesh>::Open(*this, filename.c_str(), info);
// unsigned int mask = 0;
// mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTCOORD;
// mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTNORMAL;
// mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_VERTCOLOR;
// mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_EDGEINDEX;
// mask |= nanoply::NanoPlyWrapper<VCGPolyMesh>::IO_FACEINDEX;
// if (nanoply::NanoPlyWrapper<VCGPolyMesh>::LoadModel(
// std::filesystem::absolute(filename).c_str(), *this, mask) !=
// 0) {
// std::cout << "Could not load tri mesh" << std::endl;
// }
vcg::tri::UpdateTopology<VCGPolyMesh>::FaceFace(*this);
// vcg::tri::UpdateTopology<VCGPolyMesh>::VertexFace(*this);
vcg::tri::UpdateNormal<VCGPolyMesh>::PerVertexNormalized(*this);
}
};
#endif // POLYMESH_HPP