Antkeeper  0.0.1
mesh.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_GEOM_MESH_HPP
21 #define ANTKEEPER_GEOM_MESH_HPP
22 
24 #include <vector>
25 
26 namespace geom {
27 
33 class mesh
34 {
35 public:
36  struct vertex;
37  struct edge;
38  struct face;
39 
43  struct vertex
44  {
46  std::size_t index;
47 
50 
53  };
54 
58  struct edge
59  {
61  std::size_t index;
62 
65 
68 
71 
74 
77  };
78 
82  struct face
83  {
85  std::size_t index;
86 
89  };
90 
94  typedef std::vector<edge*> loop;
95 
99  constexpr mesh() noexcept = default;
100 
104  mesh(const mesh& other);
105 
109  ~mesh() noexcept;
110 
118  mesh& operator=(const mesh& other);
119 
123  void clear() noexcept;
124 
135 
144  mesh::edge* add_edge(mesh::vertex* a, mesh::vertex* b);
145 
157  mesh::face* add_face(const loop& loop);
158 
164  void remove_face(mesh::face* face);
165 
171  void remove_edge(mesh::edge* edge);
172 
179 
181  const std::vector<mesh::vertex*>& get_vertices() const;
182 
184  const std::vector<mesh::edge*>& get_edges() const;
185 
187  const std::vector<mesh::face*>& get_faces() const;
188 
189 private:
190  mesh::edge* find_free_incident(mesh::vertex* vertex) const;
191  mesh::edge* find_free_incident(mesh::edge* start_edge, mesh::edge* end_edge) const;
192  bool make_adjacent(mesh::edge* in_edge, mesh::edge* out_edge);
193 
194  std::vector<mesh::vertex*> vertices;
195  std::vector<mesh::edge*> edges;
196  std::vector<mesh::face*> faces;
197 };
198 
199 inline const std::vector<mesh::vertex*>& mesh::get_vertices() const
200 {
201  return vertices;
202 }
203 
204 inline const std::vector<mesh::edge*>& mesh::get_edges() const
205 {
206  return edges;
207 }
208 
209 inline const std::vector<mesh::face*>& mesh::get_faces() const
210 {
211  return faces;
212 }
213 
214 } // namespace geom
215 
216 #endif // ANTKEEPER_GEOM_MESH_HPP
Half-edge mesh.
Definition: mesh.hpp:34
void remove_vertex(mesh::vertex *vertex)
Removes a vertex, all dependent edges, and all dependent faces from the mesh.
Definition: mesh.cpp:330
const std::vector< mesh::edge * > & get_edges() const
Returns the mesh edges.
Definition: mesh.hpp:204
void remove_face(mesh::face *face)
Removes a face from the mesh.
Definition: mesh.cpp:264
mesh::face * add_face(const loop &loop)
Adds a face to the mesh.
Definition: mesh.cpp:212
const std::vector< mesh::face * > & get_faces() const
Returns the mesh faces.
Definition: mesh.hpp:209
mesh::vertex * add_vertex(const float3 &position)
Adds a vertex to the mesh.
Definition: mesh.cpp:145
void clear() noexcept
Removes all vertices, edges, and faces from the mesh.
Definition: mesh.cpp:123
std::vector< edge * > loop
List of edges which form a face.
Definition: mesh.hpp:94
constexpr mesh() noexcept=default
Constructs a mesh.
mesh::edge * add_edge(mesh::vertex *a, mesh::vertex *b)
Adds two half edges to the mesh.
Definition: mesh.cpp:159
const std::vector< mesh::vertex * > & get_vertices() const
Returns the mesh vertices.
Definition: mesh.hpp:199
void remove_edge(mesh::edge *edge)
Removes an edge and all dependent faces from the mesh.
Definition: mesh.cpp:288
Geometric algorithms.
Definition: cartesian.hpp:26
@ position
Vertex position (vec3)
Half-edge mesh edge, containing its index and pointers to its starting vertex, parent face,...
Definition: mesh.hpp:59
mesh::face * face
Pointer to the face on the left of this edge.
Definition: mesh.hpp:67
std::size_t index
Index of this edge.
Definition: mesh.hpp:61
mesh::edge * next
Pointer to the next edge in the parent face.
Definition: mesh.hpp:73
mesh::vertex * vertex
Pointer to the vertex at which the edge starts.
Definition: mesh.hpp:64
mesh::edge * symmetric
Pointer to the symmetric edge.
Definition: mesh.hpp:76
mesh::edge * previous
Pointer to the previous edge in the parent face.
Definition: mesh.hpp:70
Half-edge mesh face, containing its index and a pointer to its first edge.
Definition: mesh.hpp:83
mesh::edge * edge
Pointer to the first edge in this face.
Definition: mesh.hpp:88
std::size_t index
Index of this face.
Definition: mesh.hpp:85
Half-edge mesh vertex, containing its index, a pointer to its parent edge, and its position vector.
Definition: mesh.hpp:44
float3 position
Vertex position.
Definition: mesh.hpp:52
mesh::edge * edge
Pointer to the edge to which this vertex belongs.
Definition: mesh.hpp:49
std::size_t index
Index of this vertex.
Definition: mesh.hpp:46