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: GPL-3.0-or-later
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
24#include "EBGeometry_Pool.hpp"
26#include "EBGeometry_Vec.hpp"
27
28namespace EBGeometry {
29
45template <typename T>
47{
48 static_assert(std::is_floating_point_v<T>, "PolygonSoup<T>: T must be a floating-point type");
49
50public:
54 using Vec3 = Vec3T<T>;
55
59 PolygonSoup() = default;
60
65 explicit PolygonSoup(std::string a_id) noexcept;
66
75 PolygonSoup(std::string a_id, std::vector<Vec3> a_vertices, std::vector<std::vector<size_t>> a_facets) noexcept;
76
81 [[nodiscard]] const std::string&
82 getID() const noexcept;
83
88 [[nodiscard]] const std::vector<Vec3>&
89 getVertexCoordinates() const noexcept;
90
95 [[nodiscard]] const std::vector<std::vector<size_t>>&
96 getFacets() const noexcept;
97
102 [[nodiscard]] size_t
103 numVertices() const noexcept;
104
109 [[nodiscard]] size_t
110 numFacets() const noexcept;
111
117 [[nodiscard]] bool
118 hasVertexProperty(const std::string& a_name) const noexcept;
119
125 [[nodiscard]] bool
126 hasFaceProperty(const std::string& a_name) const noexcept;
127
134 [[nodiscard]] const std::vector<T>&
135 getVertexProperty(const std::string& a_name) const;
136
143 [[nodiscard]] const std::vector<T>&
144 getFaceProperty(const std::string& a_name) const;
145
150 [[nodiscard]] std::vector<std::string>
152
157 [[nodiscard]] std::vector<std::string>
159
166 void
167 setVertexProperty(const std::string& a_name, std::vector<T> a_data);
168
175 void
176 setFaceProperty(const std::string& a_name, std::vector<T> a_data);
177
182 [[nodiscard]] bool
183 isClean() const noexcept;
184
200 size_t
202
217 [[nodiscard]] DCEL::MeshT<T>
218 convertToDCEL(Pool& a_pool, Parser::OnDefect a_onDefect = Parser::OnDefect::Throw) const;
219
230 [[nodiscard]] std::vector<Triangle<T>>
231 convertToTriangles(Parser::OnDefect a_onDefect = Parser::OnDefect::Throw) const;
232
233protected:
237 std::string m_id;
238
243
247 std::vector<std::vector<size_t>> m_facets;
248
252 std::map<std::string, std::vector<T>> m_vertexProperties;
253
257 std::map<std::string, std::vector<T>> m_faceProperties;
258
264 bool m_isClean = false;
265};
266
267} // namespace EBGeometry
268
269#include "EBGeometry_PolygonSoupImplem.hpp"
270
271#endif
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
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:47
bool m_isClean
Whether clean() has run.
Definition EBGeometry_PolygonSoup.hpp:264
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:252
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:242
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:237
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:247
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.
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.
PolygonSoup()=default
Default constructor. An empty soup with an empty identifier.
PolygonSoup(std::string a_id) noexcept
Constructor. An empty soup with an identifier.
std::map< std::string, std::vector< T > > m_faceProperties
Face properties, one value per face.
Definition EBGeometry_PolygonSoup.hpp:257
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:183
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