MySources/polymesh.hpp

76 lines
2.7 KiB
C++
Raw Normal View History

2020-11-27 11:47:21 +01:00
#ifndef POLYMESH_HPP
#define POLYMESH_HPP
2021-03-15 18:04:29 +01:00
#include "mesh.hpp"
2020-11-27 11:47:21 +01:00
#include "vcg/complex/complex.h"
#include <filesystem>
#include <wrap/io_trimesh/import.h>
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
2021-03-15 18:04:29 +01:00
: public vcg::tri::TriMesh<std::vector<PVertex>, std::vector<PFace>>,
public Mesh {
2020-11-27 11:47:21 +01:00
public:
2021-03-15 18:04:29 +01:00
virtual bool load(const std::string &filename) override {
int mask;
vcg::tri::io::Importer<VCGPolyMesh>::LoadMask(filename.c_str(), mask);
int error = vcg::tri::io::Importer<VCGPolyMesh>::Open(
*this, filename.c_str(), mask);
if (error != 0) {
return false;
}
// vcg::tri::io::ImporterOBJ<VCGPolyMesh>::Open();
2020-11-27 11:47:21 +01:00
// 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);
2021-03-15 18:04:29 +01:00
return true;
2020-11-27 11:47:21 +01:00
}
2021-03-15 18:04:29 +01:00
#ifdef POLYSCOPE_DEFINED
void registerForDrawing(){
}
#endif
2020-11-27 11:47:21 +01:00
};
#endif // POLYMESH_HPP