13#include <lagrange/common.h>
14#include <lagrange/utils/assert.h>
15#include <lagrange/utils/safe_cast.h>
28 virtual Index get_dim()
const = 0;
29 virtual Index get_vertex_per_facet()
const = 0;
30 virtual Index get_num_vertices()
const = 0;
31 virtual Index get_num_facets()
const = 0;
33 virtual std::vector<float> vertices_to_float()
const = 0;
34 virtual std::vector<unsigned> indices_to_int()
const = 0;
36 virtual void vertices_to_float(
float* buf)
const = 0;
37 virtual void indices_to_int(
unsigned* buf)
const = 0;
41template <
typename MeshType>
46 using Index = Parent::Index;
49 : m_mesh(std::move(mesh))
54 std::shared_ptr<MeshType> get_mesh_ptr()
const {
return m_mesh; }
56 Index get_dim()
const override {
return m_mesh->get_dim(); }
57 Index get_vertex_per_facet()
const override {
return m_mesh->get_vertex_per_facet(); }
58 Index get_num_vertices()
const override {
return m_mesh->get_num_vertices(); };
59 Index get_num_facets()
const override {
return m_mesh->get_num_facets(); };
61 std::vector<float> vertices_to_float()
const override
63 auto& data = m_mesh->get_vertices();
64 const Index rows = safe_cast<Index>(data.rows());
65 const Index cols = (get_dim() == 3 ? safe_cast<Index>(data.cols()) : 3);
66 const Index size = rows * cols;
70 std::vector<float> float_data;
71 float_data.reserve(size + 1);
72 float_data.resize(size);
73 vertices_to_float(float_data.data());
78 std::vector<unsigned> indices_to_int()
const override
80 auto& data = m_mesh->get_facets();
81 const Index rows = safe_cast<Index>(data.rows());
82 const Index cols = safe_cast<Index>(data.cols());
83 const Index size = rows * cols;
87 std::vector<unsigned> int_data;
88 int_data.reserve(size + 1);
89 int_data.resize(size);
90 indices_to_int(int_data.data());
95 void vertices_to_float(
float* buf)
const override
97 auto& data = m_mesh->get_vertices();
98 const Index rows = safe_cast<Index>(data.rows());
100 if (get_dim() == 3) {
101 const Index cols = safe_cast<Index>(data.cols());
102 for (Index i = 0; i < rows; ++i) {
103 for (Index j = 0; j < cols; ++j) {
104 *(buf++) = safe_cast<float>(data(i, j));
107 }
else if (get_dim() == 2) {
108 for (Index i = 0; i < rows; ++i) {
109 for (Index j = 0; j < 2; ++j) {
110 *(buf++) = safe_cast<float>(data(i, j));
117 void indices_to_int(
unsigned* buf)
const override
119 auto& data = m_mesh->get_facets();
120 const Index rows = safe_cast<Index>(data.rows());
121 const Index cols = safe_cast<Index>(data.cols());
122 for (Index i = 0; i < rows; ++i) {
123 for (Index j = 0; j < cols; ++j) {
124 *(buf++) = safe_cast<unsigned>(data(i, j));
129 std::shared_ptr<MeshType> m_mesh;
Definition: RayCasterMesh.h:43
Definition: RayCasterMesh.h:22
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Main namespace for Lagrange.
Definition: AABBIGL.h:30