EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
EBGeometry::PolygonSoup< T > Class Template Reference

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>

Collaboration diagram for EBGeometry::PolygonSoup< T >:
Collaboration graph
[legend]

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.
 

Detailed Description

template<typename T>
class EBGeometry::PolygonSoup< T >

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.

Template Parameters
TFloating-point precision for vertex coordinates and properties.

Constructor & Destructor Documentation

◆ PolygonSoup() [1/2]

template<typename T >
EBGeometry::PolygonSoup< T >::PolygonSoup ( std::string  a_id)
explicitnoexcept

Constructor. An empty soup with an identifier.

Parameters
[in]a_idIdentifier, usually the file name. ParseError reports it as the file.

◆ PolygonSoup() [2/2]

template<typename T >
EBGeometry::PolygonSoup< T >::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.

Not cleaned here, so the input may contain duplicate vertices, degenerate faces, or an out-of-range index; clean() rejects or repairs them.

Parameters
[in]a_idIdentifier, usually the file name. ParseError reports it as the file.
[in]a_verticesVertex coordinates.
[in]a_facetsFaces, each a list of indices into a_vertices, in order around the face.

Member Function Documentation

◆ clean()

template<typename T >
size_t EBGeometry::PolygonSoup< T >::clean ( )

Merge duplicate vertices and remove degenerate faces, carrying the properties along.

In order:

  • Soup::isValid(): a vertex index out of range, or a non-finite coordinate, throws.
  • Soup::compress(): vertices at the same position merge into one, and the vertices are sorted lexicographically. A merged vertex takes its properties from the first of them in the input.
  • Soup::removeDegeneratePolygons(): faces with fewer than three distinct vertices, and zero-area faces, are removed, and the T-junctions such a face filled are repaired. The remaining faces keep their order, and their properties.

Cleaning a clean soup changes nothing.

Returns
The number of faces removed.
Exceptions
Parser::ParseError,naminggetID() as the file, if the soup fails Soup::isValid().

◆ convertToDCEL()

template<typename T >
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.

Parameters
[in,out]a_poolPool to reserve the mesh's vertex, edge and face storage from.
[in]a_onDefectWhether 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.
Returns
The mesh, by value.
Exceptions
Parser::ParseErrorif 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.

◆ convertToTriangles()

template<typename T >
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.

Parameters
[in]a_onDefectAs for convertToDCEL().
Returns
The triangles, by value.
Exceptions
Parser::ParseErroras convertToDCEL().

◆ getFaceProperty()

template<typename T >
const std::vector< T > & EBGeometry::PolygonSoup< T >::getFaceProperty ( const std::string &  a_name) const

Get a face property.

Parameters
[in]a_nameProperty name.
Returns
One value per face.
Exceptions
std::out_of_rangeif the property does not exist.

◆ getFacePropertyNames()

template<typename T >
std::vector< std::string > EBGeometry::PolygonSoup< T >::getFacePropertyNames ( ) const

Names of the face properties.

Returns
The names, sorted.

◆ getFacets()

template<typename T >
const std::vector< std::vector< size_t > > & EBGeometry::PolygonSoup< T >::getFacets ( ) const
noexcept

Get the faces.

Returns
For each face, the indices of its vertices in order around it.

◆ getID()

template<typename T >
const std::string & EBGeometry::PolygonSoup< T >::getID ( ) const
noexcept

Get the identifier.

Returns
The identifier, usually the file name.

◆ getVertexCoordinates()

template<typename T >
const std::vector< Vec3 > & EBGeometry::PolygonSoup< T >::getVertexCoordinates ( ) const
noexcept

Get the vertex coordinates.

Returns
The vertex coordinates.

◆ getVertexProperty()

template<typename T >
const std::vector< T > & EBGeometry::PolygonSoup< T >::getVertexProperty ( const std::string &  a_name) const

Get a vertex property.

Parameters
[in]a_nameProperty name.
Returns
One value per vertex.
Exceptions
std::out_of_rangeif the property does not exist.

◆ getVertexPropertyNames()

template<typename T >
std::vector< std::string > EBGeometry::PolygonSoup< T >::getVertexPropertyNames ( ) const

Names of the vertex properties.

Returns
The names, sorted.

◆ hasFaceProperty()

template<typename T >
bool EBGeometry::PolygonSoup< T >::hasFaceProperty ( const std::string &  a_name) const
noexcept

Whether a face property exists.

Parameters
[in]a_nameProperty name.
Returns
True if the soup has a face property of that name.

◆ hasVertexProperty()

template<typename T >
bool EBGeometry::PolygonSoup< T >::hasVertexProperty ( const std::string &  a_name) const
noexcept

Whether a vertex property exists.

Parameters
[in]a_nameProperty name.
Returns
True if the soup has a vertex property of that name.

◆ isClean()

template<typename T >
bool EBGeometry::PolygonSoup< T >::isClean ( ) const
noexcept

Whether the soup is clean: clean() has run, and nothing has changed the geometry since.

Returns
True if the soup is clean.

◆ numFacets()

template<typename T >
size_t EBGeometry::PolygonSoup< T >::numFacets ( ) const
noexcept

Number of faces.

Returns
getFacets().size().

◆ numVertices()

template<typename T >
size_t EBGeometry::PolygonSoup< T >::numVertices ( ) const
noexcept

Number of vertices.

Returns
getVertexCoordinates().size().

◆ setFaceProperty()

template<typename T >
void EBGeometry::PolygonSoup< T >::setFaceProperty ( const std::string &  a_name,
std::vector< T >  a_data 
)

Add or replace a face property.

Parameters
[in]a_nameProperty name.
[in]a_dataOne value per face. Its size must be numFacets(); any other size aborts with a message, in every build.

◆ setVertexProperty()

template<typename T >
void EBGeometry::PolygonSoup< T >::setVertexProperty ( const std::string &  a_name,
std::vector< T >  a_data 
)

Add or replace a vertex property.

Parameters
[in]a_nameProperty name.
[in]a_dataOne value per vertex. Its size must be numVertices(); any other size aborts with a message, in every build.

Member Data Documentation

◆ m_isClean

template<typename T >
bool EBGeometry::PolygonSoup< T >::m_isClean = false
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.


The documentation for this class was generated from the following file: