62 lines
2.3 KiB
C++
Executable File
62 lines
2.3 KiB
C++
Executable File
#ifndef VCGTRIMESH_HPP
|
|
#define VCGTRIMESH_HPP
|
|
#include "mesh.hpp"
|
|
#include <vcg/complex/complex.h>
|
|
#include <optional>
|
|
|
|
#ifdef POLYSCOPE_DEFINED
|
|
#include <polyscope/surface_mesh.h>
|
|
#endif
|
|
using VertexIndex = size_t;
|
|
class VCGTriMeshVertex;
|
|
class VCGTriMeshEdge;
|
|
class VCGTriMeshFace;
|
|
struct VCGTriMeshUsedTypes
|
|
: public vcg::UsedTypes<vcg::Use<VCGTriMeshVertex>::AsVertexType,
|
|
vcg::Use<VCGTriMeshEdge>::AsEdgeType,
|
|
vcg::Use<VCGTriMeshFace>::AsFaceType> {};
|
|
class VCGTriMeshVertex : public vcg::Vertex<VCGTriMeshUsedTypes,
|
|
vcg::vertex::Coord3d,
|
|
vcg::vertex::Normal3d,
|
|
vcg::vertex::BitFlags,
|
|
vcg::vertex::Color4b,
|
|
vcg::vertex::VFAdj,
|
|
vcg::vertex::Qualityd,
|
|
vcg::vertex::VEAdj>
|
|
{};
|
|
class VCGTriMeshFace
|
|
: public vcg::Face<VCGTriMeshUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj,
|
|
vcg::face::VertexRef, vcg::face::BitFlags,
|
|
vcg::face::Normal3d> {};
|
|
class VCGTriMeshEdge : public vcg::Edge<VCGTriMeshUsedTypes, vcg::edge::VertexRef, vcg::edge::VEAdj>
|
|
{};
|
|
|
|
class VCGTriMesh : public vcg::tri::TriMesh<std::vector<VCGTriMeshVertex>,
|
|
std::vector<VCGTriMeshFace>,
|
|
std::vector<VCGTriMeshEdge>>,
|
|
public Mesh
|
|
{
|
|
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);
|
|
template <typename MeshElement> size_t getIndex(const MeshElement &element) {
|
|
return vcg::tri::Index<VCGTriMesh>(*this, element);
|
|
}
|
|
|
|
#ifdef POLYSCOPE_DEFINED
|
|
polyscope::SurfaceMesh *registerForDrawing(
|
|
const std::optional<std::array<double, 3>> &desiredColor = std::nullopt,
|
|
const bool &shouldEnable = true) const;
|
|
#endif
|
|
Eigen::MatrixX2i getEdges() const;
|
|
void updateEigenEdgeAndVertices();
|
|
void moveToCenter();
|
|
};
|
|
|
|
#endif // VCGTRIMESH_HPP
|