Add generic cg::triangle_mesh convex body
This commit is contained in:
parent
52969c718a
commit
a5812c02c8
1 changed files with 64 additions and 0 deletions
64
libs/cg/include/psemek/cg/body/triangle_mesh.hpp
Normal file
64
libs/cg/include/psemek/cg/body/triangle_mesh.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/cg/body/body.hpp>
|
||||
#include <psemek/geom/simplex.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace psemek::cg
|
||||
{
|
||||
template <typename T, typename Index = std::uint32_t>
|
||||
struct triangle_mesh
|
||||
{
|
||||
triangle_mesh() = default;
|
||||
triangle_mesh(std::vector<geom::point<T, 3>> vertices, std::vector<geom::triangle<Index>> triangles);
|
||||
|
||||
std::vector<geom::point<T, 3>> vertices;
|
||||
std::vector<geom::triangle<Index>> triangles;
|
||||
std::vector<geom::segment<Index>> edges;
|
||||
std::vector<geom::vector<T, 3>> edge_directions;
|
||||
};
|
||||
|
||||
template <typename T, typename Index>
|
||||
triangle_mesh<T, Index>::triangle_mesh(std::vector<geom::point<T, 3>> vertices, std::vector<geom::triangle<Index>> triangles)
|
||||
: vertices(std::move(vertices))
|
||||
, triangles(std::move(triangles))
|
||||
{
|
||||
for (auto const & t : this->triangles)
|
||||
{
|
||||
// Add each edge just once
|
||||
if (t[0] < t[1]) edges.push_back({t[0], t[1]});
|
||||
if (t[1] < t[2]) edges.push_back({t[1], t[2]});
|
||||
if (t[2] < t[0]) edges.push_back({t[2], t[0]});
|
||||
}
|
||||
|
||||
for (auto const & e : edges)
|
||||
edge_directions.push_back(geom::normalized(this->vertices[e[1]] - this->vertices[e[0]]));
|
||||
}
|
||||
|
||||
template <typename T, typename Index>
|
||||
auto const & vertices(triangle_mesh<T, Index> const & m)
|
||||
{
|
||||
return m.vertices;
|
||||
}
|
||||
|
||||
template <typename T, typename Index>
|
||||
auto const & edges(triangle_mesh<T, Index> const & m)
|
||||
{
|
||||
return m.edges;
|
||||
}
|
||||
|
||||
template <typename T, typename Index>
|
||||
auto const & edge_directions(triangle_mesh<T, Index> const & m)
|
||||
{
|
||||
return m.edge_directions;
|
||||
}
|
||||
|
||||
template <typename T, typename Index>
|
||||
auto const & triangles(triangle_mesh<T, Index> const & m)
|
||||
{
|
||||
return m.triangles;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue