supereight2
Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3 * SPDX-FileCopyrightText: 2019-2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
4 * SPDX-FileCopyrightText: 2021 Nils Funk
5 * SPDX-FileCopyrightText: 2021 Sotiris Papatheodorou
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef SE_MESH_FACE_HPP
10#define SE_MESH_FACE_HPP
11
12#include <Eigen/StdVector>
13#include <array>
14#include <cstdint>
15#include <map>
16#include <optional>
19#include <se/common/rgb.hpp>
22#include <vector>
23
24namespace se {
25
26template<size_t NumVertexes, Colour ColB>
28
29template<size_t NumVertexes>
31 std::array<RGB, NumVertexes> vertexes;
33};
34
35
36
37template<size_t NumVertexes, Id IdB>
39
40template<size_t NumVertexes>
42 id_t id = id_t(0);
43};
44
45
46
47template<size_t NumVertexes, Colour ColB = Colour::Off, Id IdB = Id::Off>
48struct MeshFace {
49 std::array<Eigen::Vector3f, NumVertexes> vertexes;
52 std::int8_t scale = 0;
53
54 static constexpr size_t num_vertexes = NumVertexes;
55 static constexpr Colour col_ = ColB;
56 static constexpr Id id_ = IdB;
57
58 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59};
60
61
62
69template<typename FaceT>
70using Mesh = std::vector<FaceT>;
71
72template<Colour ColB = Colour::Off, Id IdB = Id::Off>
74
75template<Colour ColB = Colour::Off, Id IdB = Id::Off>
77
78template<Colour ColB = Colour::Off, Id IdB = Id::Off>
80
81template<Colour ColB = Colour::Off, Id IdB = Id::Off>
83
84
85
87template<Colour ColB, Id IdB>
89
90
91
92namespace id {
93
94struct IdInfo {
95 Eigen::Vector3f centroid = Eigen::Vector3f::Zero();
96 Eigen::AlignedBox3f aabb;
97 size_t num_vertices = 0;
98 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
99};
100
104template<typename FaceT, typename = std::enable_if_t<FaceT::id_ == Id::On>>
105std::map<id_t, IdInfo> mesh_id_info(const Mesh<FaceT>& mesh);
106
108template<typename FaceT, typename = std::enable_if_t<FaceT::id_ == Id::On>>
109std::map<id_t, Mesh<FaceT>> extract_id_meshes(const Mesh<FaceT>& mesh);
110
117template<typename FaceT, typename ExtractIdF, typename = std::enable_if_t<FaceT::id_ == Id::On>>
118std::map<id_t, Mesh<FaceT>> extract_id_meshes(const Mesh<FaceT>& mesh, ExtractIdF extract_id);
119
121template<typename FaceT, typename = std::enable_if_t<FaceT::id_ == Id::On>>
123 const bool enable_shading = true,
124 const Eigen::Vector3f& light_dir_W = Eigen::Vector3f(-1, 0, -1),
125 const RGB ambient = RGB{0x40, 0x40, 0x40});
126
127} // namespace id
128
129
130
131namespace meshing {
132
133struct Vertex {
134 Vertex(const Eigen::Vector3f& position) : position(position)
135 {
136 }
137
138 Eigen::Vector3f position;
139 std::optional<Eigen::Vector3f> normal;
140 std::optional<RGB> color;
141
142 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
143};
144
145template<size_t NumFaceVertices = 3>
147 public:
148 std::vector<Vertex, Eigen::aligned_allocator<Vertex>> vertices;
149 std::vector<size_t> indices; // faces
150
151 static constexpr size_t num_face_vertices = NumFaceVertices;
152
153 void merge(const VertexIndexMesh& other);
154
156
157 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
158};
159
160} // namespace meshing
161} // namespace se
162
163#include "impl/mesh_impl.hpp"
164
165#endif // SE_MESH_FACE_HPP
Definition image.hpp:19
Definition mesh.hpp:146
void merge(const VertexIndexMesh &other)
std::vector< size_t > indices
Definition mesh.hpp:149
std::vector< Vertex, Eigen::aligned_allocator< Vertex > > vertices
Definition mesh.hpp:148
static constexpr size_t num_face_vertices
Definition mesh.hpp:151
void colour_mesh_by_id(Mesh< FaceT > &mesh, const bool enable_shading=true, const Eigen::Vector3f &light_dir_W=Eigen::Vector3f(-1, 0, -1), const RGB ambient=RGB{0x40, 0x40, 0x40})
Colour the faces of mesh by their ID.
std::map< id_t, IdInfo > mesh_id_info(const Mesh< FaceT > &mesh)
Return information about all identifiers in mesh.
std::map< id_t, Mesh< FaceT > > extract_id_meshes(const Mesh< FaceT > &mesh)
Extract per-identifier meshes for all identifiers in mesh.
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
TriangleMesh< ColB, IdB > quad_to_triangle_mesh(const QuadMesh< ColB, IdB > &quad_mesh)
Return a triangle mesh containig two triangles for each face of quad_mesh.
uint16_t id_t
The type used to represent identifiers.
Definition type_util.hpp:60
std::vector< FaceT > Mesh
Meshes are represented as lists of faces.
Definition mesh.hpp:70
Id
Definition setup_util.hpp:20
Mesh< Triangle< ColB, IdB > > TriangleMesh
Definition mesh.hpp:76
Colour
Definition setup_util.hpp:19
std::array< RGB, NumVertexes > vertexes
Definition mesh.hpp:31
Definition mesh.hpp:27
Definition mesh.hpp:38
Definition mesh.hpp:48
std::int8_t scale
Definition mesh.hpp:52
MeshFaceIdData< NumVertexes, IdB > id
Definition mesh.hpp:51
MeshFaceColourData< NumVertexes, ColB > colour
Definition mesh.hpp:50
static constexpr Colour col_
Definition mesh.hpp:55
static constexpr size_t num_vertexes
Definition mesh.hpp:54
std::array< Eigen::Vector3f, NumVertexes > vertexes
Definition mesh.hpp:49
static constexpr Id id_
Definition mesh.hpp:56
A colour represented as a Red-Green-Blue tuple with 8-bits per channel.
Definition rgb.hpp:18
Definition mesh.hpp:94
Eigen::AlignedBox3f aabb
Definition mesh.hpp:96
Eigen::Vector3f centroid
Definition mesh.hpp:95
size_t num_vertices
Definition mesh.hpp:97
Definition mesh.hpp:133
Eigen::Vector3f position
Definition mesh.hpp:138
std::optional< RGB > color
Definition mesh.hpp:140
Vertex(const Eigen::Vector3f &position)
Definition mesh.hpp:134
std::optional< Eigen::Vector3f > normal
Definition mesh.hpp:139