|
EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
|
Polygons as a file stores them: vertex coordinates, faces as lists of vertex indices, and named per-vertex and per-face scalar properties. More...
#include <EBGeometry_PolygonSoup.hpp>

Public Types | |
| using | Vec3 = Vec3T< T > |
| Alias for a vector in 3D. | |
Public Member Functions | |
| PolygonSoup ()=default | |
| Default constructor. An empty soup with an empty identifier. | |
| PolygonSoup (std::string a_id) noexcept | |
| Constructor. An empty soup with an identifier. | |
| 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. | |
| const std::string & | getID () const noexcept |
| Get the identifier. | |
| const std::vector< Vec3 > & | getVertexCoordinates () const noexcept |
| Get the vertex coordinates. | |
| const std::vector< std::vector< size_t > > & | getFacets () const noexcept |
| Get the faces. | |
| size_t | numVertices () const noexcept |
| Number of vertices. | |
| size_t | numFacets () const noexcept |
| Number of faces. | |
| bool | hasVertexProperty (const std::string &a_name) const noexcept |
| Whether a vertex property exists. | |
| bool | hasFaceProperty (const std::string &a_name) const noexcept |
| Whether a face property exists. | |
| const std::vector< T > & | getVertexProperty (const std::string &a_name) const |
| Get a vertex property. | |
| const std::vector< T > & | getFaceProperty (const std::string &a_name) const |
| Get a face property. | |
| std::vector< std::string > | getVertexPropertyNames () const |
| Names of the vertex properties. | |
| std::vector< std::string > | getFacePropertyNames () const |
| Names of the face properties. | |
| void | setVertexProperty (const std::string &a_name, std::vector< T > a_data) |
| Add or replace a vertex property. | |
| void | setFaceProperty (const std::string &a_name, std::vector< T > a_data) |
| Add or replace a face property. | |
| bool | isClean () const noexcept |
| Whether the soup is clean: clean() has run, and nothing has changed the geometry since. | |
| size_t | clean () |
| Merge duplicate vertices and remove degenerate faces, carrying the properties along. | |
| DCEL::MeshT< T > | convertToDCEL (Pool &a_pool, Parser::OnDefect a_onDefect=Parser::OnDefect::Throw) const |
| Build a DCEL mesh from the soup. | |
| std::vector< Triangle< T > > | convertToTriangles (Parser::OnDefect a_onDefect=Parser::OnDefect::Throw) const |
| Build flat triangles from the soup. | |
Protected Attributes | |
| std::string | m_id |
| Identifier, usually the file name. | |
| std::vector< Vec3 > | m_vertexCoordinates |
| Vertex coordinates. | |
| std::vector< std::vector< size_t > > | m_facets |
| Faces, each a list of indices into m_vertexCoordinates. | |
| std::map< std::string, std::vector< T > > | m_vertexProperties |
| Vertex properties, one value per vertex. | |
| std::map< std::string, std::vector< T > > | m_faceProperties |
| Face properties, one value per face. | |
| bool | m_isClean = false |
| Whether clean() has run. | |
Polygons as a file stores them: vertex coordinates, faces as lists of vertex indices, and named per-vertex and per-face scalar properties.
Every file reader (Parser::readSTL, readPLY, readVTK, readOBJ and readIntoPolygonSoup) returns one, already cleaned (see clean()). Face i of a clean soup is face i of the DCEL mesh convertToDCEL() builds, so it is the face id that MeshSDF, FlatMeshSDF and TriMeshSDF report from getClosestFace(), and getFaceProperty(name)[i] is that face's property. Vertex i of a clean soup is likewise vertex i of the mesh.
The geometry is set once, at construction; properties can be added afterwards. A soup built by hand is not clean until clean() is called. convertToDCEL() and convertToTriangles() clean a copy of an unclean soup first, so they build the same mesh either way, but only a clean soup's own face and vertex indices match the mesh's.
| T | Floating-point precision for vertex coordinates and properties. |
|
explicitnoexcept |
Constructor. An empty soup with an identifier.
| [in] | a_id | Identifier, usually the file name. ParseError reports it as the file. |
|
noexcept |
Constructor from vertex coordinates and faces, as read.
Not cleaned here, so the input may contain duplicate vertices, degenerate faces, or an out-of-range index; clean() rejects or repairs them.
| [in] | a_id | Identifier, usually the file name. ParseError reports it as the file. |
| [in] | a_vertices | Vertex coordinates. |
| [in] | a_facets | Faces, each a list of indices into a_vertices, in order around the face. |
| size_t EBGeometry::PolygonSoup< T >::clean | ( | ) |
Merge duplicate vertices and remove degenerate faces, carrying the properties along.
In order:
Cleaning a clean soup changes nothing.
| Parser::ParseError,naming | getID() as the file, if the soup fails Soup::isValid(). |
| DCEL::MeshT< T > EBGeometry::PolygonSoup< T >::convertToDCEL | ( | Pool & | a_pool, |
| Parser::OnDefect | a_onDefect = Parser::OnDefect::Throw |
||
| ) | const |
Build a DCEL mesh from the soup.
Cleans a copy first if the soup is not clean (see clean()). Face i and vertex i of a clean soup are face i and vertex i of the mesh. The mesh is attached to a_pool, which must outlive it.
| [in,out] | a_pool | Pool to reserve the mesh's vertex, edge and face storage from. |
| [in] | a_onDefect | Whether faces oriented inconsistently, an edge shared by three or more faces, or faces that fold back onto each other throw (the default) or only print a warning. |
| Parser::ParseError | if the soup cannot describe a mesh: it fails Soup::isValid(), it has no faces, a face visits a vertex twice, the faces cannot be joined into a half-edge mesh (see Soup::findTopologyDefect()), or faces fold back onto each other (see Soup::findFoldedFeature()). With Parser::OnDefect::Warn the last two only print a warning. |
| std::vector< Triangle< T > > EBGeometry::PolygonSoup< T >::convertToTriangles | ( | Parser::OnDefect | a_onDefect = Parser::OnDefect::Throw | ) | const |
Build flat triangles from the soup.
Builds the DCEL mesh as convertToDCEL() does, in a Pool private to this call, and cuts each face into triangles, a polygon by a fan from one of its vertices (the one whose smallest fan triangle is largest), and a zero-area face into none. Each triangle carries the index of the mesh face it was cut from, and the mesh's edge and vertex normals.
| [in] | a_onDefect | As for convertToDCEL(). |
| Parser::ParseError | as convertToDCEL(). |
| const std::vector< T > & EBGeometry::PolygonSoup< T >::getFaceProperty | ( | const std::string & | a_name | ) | const |
Get a face property.
| [in] | a_name | Property name. |
| std::out_of_range | if the property does not exist. |
| std::vector< std::string > EBGeometry::PolygonSoup< T >::getFacePropertyNames | ( | ) | const |
Names of the face properties.
|
noexcept |
Get the faces.
|
noexcept |
Get the identifier.
|
noexcept |
Get the vertex coordinates.
| const std::vector< T > & EBGeometry::PolygonSoup< T >::getVertexProperty | ( | const std::string & | a_name | ) | const |
Get a vertex property.
| [in] | a_name | Property name. |
| std::out_of_range | if the property does not exist. |
| std::vector< std::string > EBGeometry::PolygonSoup< T >::getVertexPropertyNames | ( | ) | const |
Names of the vertex properties.
|
noexcept |
Whether a face property exists.
| [in] | a_name | Property name. |
|
noexcept |
Whether a vertex property exists.
| [in] | a_name | Property name. |
|
noexcept |
Whether the soup is clean: clean() has run, and nothing has changed the geometry since.
|
noexcept |
Number of faces.
|
noexcept |
Number of vertices.
| void EBGeometry::PolygonSoup< T >::setFaceProperty | ( | const std::string & | a_name, |
| std::vector< T > | a_data | ||
| ) |
Add or replace a face property.
| [in] | a_name | Property name. |
| [in] | a_data | One value per face. Its size must be numFacets(); any other size aborts with a message, in every build. |
| void EBGeometry::PolygonSoup< T >::setVertexProperty | ( | const std::string & | a_name, |
| std::vector< T > | a_data | ||
| ) |
Add or replace a vertex property.
| [in] | a_name | Property name. |
| [in] | a_data | One value per vertex. Its size must be numVertices(); any other size aborts with a message, in every build. |
|
protected |
Whether clean() has run.
The geometry is set only by the constructors, so nothing can make a clean soup unclean again. A member function that changes the vertices or faces must reset this flag.