EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_PolygonSoup.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
11#ifndef EBGEOMETRY_POLYGONSOUP_HPP
12#define EBGEOMETRY_POLYGONSOUP_HPP
13
14// Std includes
15#include <cstddef>
16#include <map>
17#include <string>
18#include <type_traits>
19#include <vector>
20
21// Our includes
25#include "EBGeometry_Pool.hpp"
27#include "EBGeometry_Vec.hpp"
28
29namespace EBGeometry {
30
46template <typename T>
48{
49 static_assert(std::is_floating_point_v<T>, "PolygonSoup<T>: T must be a floating-point type");
50
51public:
55 using Vec3 = Vec3T<T>;
56
60 PolygonSoup() = default;
61
66 explicit PolygonSoup(std::string a_id) noexcept;
67
76 PolygonSoup(std::string a_id, std::vector<Vec3> a_vertices, std::vector<std::vector<size_t>> a_facets) noexcept;
77
82 [[nodiscard]] const std::string&
83 getID() const noexcept;
84
89 [[nodiscard]] const std::vector<Vec3>&
90 getVertexCoordinates() const noexcept;
91
96 [[nodiscard]] const std::vector<std::vector<size_t>>&
97 getFacets() const noexcept;
98
103 [[nodiscard]] size_t
104 numVertices() const noexcept;
105
110 [[nodiscard]] size_t
111 numFacets() const noexcept;
112
118 [[nodiscard]] bool
119 hasVertexProperty(const std::string& a_name) const noexcept;
120
126 [[nodiscard]] bool
127 hasFaceProperty(const std::string& a_name) const noexcept;
128
135 [[nodiscard]] const std::vector<T>&
136 getVertexProperty(const std::string& a_name) const;
137
144 [[nodiscard]] const std::vector<T>&
145 getFaceProperty(const std::string& a_name) const;
146
151 [[nodiscard]] std::vector<std::string>
153
158 [[nodiscard]] std::vector<std::string>
160
167 void
168 setVertexProperty(const std::string& a_name, std::vector<T> a_data);
169
176 void
177 setFaceProperty(const std::string& a_name, std::vector<T> a_data);
178
183 [[nodiscard]] const FaceGroups&
184 getFaceGroups() const noexcept;
185
191 void
193
198 [[nodiscard]] bool
199 isClean() const noexcept;
200
216 size_t
218
233 [[nodiscard]] DCEL::MeshT<T>
234 convertToDCEL(Pool& a_pool, Parser::OnDefect a_onDefect = Parser::OnDefect::Throw) const;
235
246 [[nodiscard]] std::vector<Triangle<T>>
247 convertToTriangles(Parser::OnDefect a_onDefect = Parser::OnDefect::Throw) const;
248
249protected:
253 std::string m_id;
254
259
263 std::vector<std::vector<size_t>> m_facets;
264
268 std::map<std::string, std::vector<T>> m_vertexProperties;
269
273 std::map<std::string, std::vector<T>> m_faceProperties;
274
279
285 bool m_isClean = false;
286};
287
288} // namespace EBGeometry
289
290#include "EBGeometry_PolygonSoupImplem.hpp"
291
292#endif
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
FaceGroups: named groups of a mesh's faces, as a file names them.
Declaration of the exception the file readers throw.
Growable bump arena for the GPU memory foundation.
Declaration of a triangle class with signed distance functionality.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Polygons as a file stores them: vertex coordinates, faces as lists of vertex indices,...
Definition EBGeometry_PolygonSoup.hpp:48
bool m_isClean
Whether clean() has run.
Definition EBGeometry_PolygonSoup.hpp:285
void setVertexProperty(const std::string &a_name, std::vector< T > a_data)
Add or replace a vertex property.
const std::string & getID() const noexcept
Get the identifier.
std::map< std::string, std::vector< T > > m_vertexProperties
Vertex properties, one value per vertex.
Definition EBGeometry_PolygonSoup.hpp:268
void setFaceProperty(const std::string &a_name, std::vector< T > a_data)
Add or replace a face property.
const std::vector< Vec3 > & getVertexCoordinates() const noexcept
Get the vertex coordinates.
size_t clean()
Merge duplicate vertices and remove degenerate faces, carrying the properties along.
std::vector< Vec3 > m_vertexCoordinates
Vertex coordinates.
Definition EBGeometry_PolygonSoup.hpp:258
bool hasVertexProperty(const std::string &a_name) const noexcept
Whether a vertex property exists.
std::vector< std::string > getVertexPropertyNames() const
Names of the vertex properties.
std::string m_id
Identifier, usually the file name.
Definition EBGeometry_PolygonSoup.hpp:253
DCEL::MeshT< T > convertToDCEL(Pool &a_pool, Parser::OnDefect a_onDefect=Parser::OnDefect::Throw) const
Build a DCEL mesh from the soup.
std::vector< std::vector< size_t > > m_facets
Faces, each a list of indices into m_vertexCoordinates.
Definition EBGeometry_PolygonSoup.hpp:263
const std::vector< std::vector< size_t > > & getFacets() const noexcept
Get the faces.
PolygonSoup(std::string a_id, std::vector< Vec3 > a_vertices, std::vector< std::vector< size_t > > a_facets) noexcept
Constructor from vertex coordinates and faces, as read.
bool isClean() const noexcept
Whether the soup is clean: clean() has run, and nothing has changed the geometry since.
size_t numFacets() const noexcept
Number of faces.
FaceGroups m_faceGroups
The named groups of the faces.
Definition EBGeometry_PolygonSoup.hpp:278
std::vector< Triangle< T > > convertToTriangles(Parser::OnDefect a_onDefect=Parser::OnDefect::Throw) const
Build flat triangles from the soup.
std::vector< std::string > getFacePropertyNames() const
Names of the face properties.
const FaceGroups & getFaceGroups() const noexcept
The named groups of the faces: an OBJ file's g and o groups, or an ASCII STL file's named solids.
PolygonSoup()=default
Default constructor. An empty soup with an empty identifier.
PolygonSoup(std::string a_id) noexcept
Constructor. An empty soup with an identifier.
void setFaceGroups(FaceGroups a_groups)
Add or replace the named groups of the faces.
std::map< std::string, std::vector< T > > m_faceProperties
Face properties, one value per face.
Definition EBGeometry_PolygonSoup.hpp:273
const std::vector< T > & getFaceProperty(const std::string &a_name) const
Get a face property.
size_t numVertices() const noexcept
Number of vertices.
const std::vector< T > & getVertexProperty(const std::string &a_name) const
Get a vertex property.
bool hasFaceProperty(const std::string &a_name) const noexcept
Whether a face property exists.
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
Triangle class with signed distance functionality.
Definition EBGeometry_Triangle.hpp:52
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Named groups of a mesh's faces: an OBJ file's g and o groups, or the named solids of an ASCII STL fil...
Definition EBGeometry_FaceGroups.hpp:29