MySources/vcgtrimesh.hpp

61 lines
2.3 KiB
C++
Raw Normal View History

2020-11-27 11:47:21 +01:00
#ifndef VCGTRIMESH_HPP
#define VCGTRIMESH_HPP
2021-04-08 20:03:23 +02:00
#include "mesh.hpp"
2020-11-27 11:47:21 +01:00
#include <vcg/complex/complex.h>
2021-06-12 11:18:55 +02:00
#include <optional>
2020-11-27 11:47:21 +01:00
2021-04-30 12:13:58 +02:00
#ifdef POLYSCOPE_DEFINED
#include <polyscope/surface_mesh.h>
#endif
2020-11-27 11:47:21 +01:00
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> {};
2021-04-08 20:03:23 +02:00
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>
2021-04-08 20:03:23 +02:00
{};
2020-11-27 11:47:21 +01:00
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>
{};
2020-11-27 11:47:21 +01:00
class VCGTriMesh : public vcg::tri::TriMesh<std::vector<VCGTriMeshVertex>,
std::vector<VCGTriMeshFace>,
2021-04-08 20:03:23 +02:00
std::vector<VCGTriMeshEdge>>,
public Mesh
{
2020-11-27 11:47:21 +01:00
public:
VCGTriMesh();
VCGTriMesh(const std::string &filename);
2022-01-14 14:02:27 +01:00
bool load(const std::filesystem::path &meshFilePath) override;
2020-11-27 11:47:21 +01:00
Eigen::MatrixX3d getVertices() const;
Eigen::MatrixX3i getFaces() const;
2021-04-08 20:03:23 +02:00
bool save(const std::string plyFilename);
2020-11-27 11:47:21 +01:00
template <typename MeshElement> size_t getIndex(const MeshElement &element) {
return vcg::tri::Index<VCGTriMesh>(*this, element);
}
2021-04-08 20:03:23 +02:00
#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();
2021-11-15 10:08:39 +01:00
void moveToCenter();
2020-11-27 11:47:21 +01:00
};
#endif // VCGTRIMESH_HPP