EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Functions
EBGeometry::Soup Namespace Reference

Namespace containing basic functionality for turning planar-polygon soups into DCEL meshes. More...

Functions

template<typename T >
static bool containsDegeneratePolygons (const std::vector< EBGeometry::Vec3T< T > > &a_vertices, const std::vector< std::vector< size_t > > &a_facets)
 Check if a polygon soup contains degenerate polygons.
 
template<typename T >
static bool isValid (const std::vector< EBGeometry::Vec3T< T > > &a_vertices, const std::vector< std::vector< size_t > > &a_facets, std::string &a_reason)
 Check that a polygon soup can describe a mesh at all.
 
template<typename T >
static std::vector< size_t > compress (std::vector< EBGeometry::Vec3T< T > > &a_vertices, std::vector< std::vector< size_t > > &a_facets)
 Compress a polygon soup by removing duplicate vertices.
 
template<typename T >
static bool isZeroArea (const std::vector< EBGeometry::Vec3T< T > > &a_vertices, const std::vector< size_t > &a_facet) noexcept
 Whether a polygon has zero area to within rounding.
 
template<typename T >
static std::vector< size_t > removeDegeneratePolygons (const std::vector< EBGeometry::Vec3T< T > > &a_vertices, std::vector< std::vector< size_t > > &a_facets)
 Remove degenerate polygons from a compressed polygon soup, repairing the mesh around them.
 
static std::string findRepeatedVertex (const std::vector< std::vector< size_t > > &a_facets)
 Find a polygon that visits a vertex twice.
 
static std::string findTopologyDefect (const std::vector< std::vector< size_t > > &a_facets)
 Find a defect that stops a compressed, cleaned polygon soup from forming a half-edge mesh.
 
template<typename T >
static std::string findFoldedFeature (const EBGeometry::DCEL::MeshT< T > &a_mesh)
 Find an edge or vertex of a half-edge mesh whose pseudonormal is zero.
 
template<typename T >
static void soupToDCEL (EBGeometry::DCEL::MeshT< T > &a_mesh, Pool &a_pool, const std::vector< EBGeometry::Vec3T< T > > &a_vertices, const std::vector< std::vector< size_t > > &a_facets, const std::string &a_id)
 Convert a polygon soup into a DCEL half-edge mesh.
 
template<typename T >
static void reconcilePairEdgesDCEL (EBGeometry::DCEL::MeshT< T > &a_mesh)
 Reconcile pair edges: link each half-edge with its reverse.
 

Detailed Description

Namespace containing basic functionality for turning planar-polygon soups into DCEL meshes.

Function Documentation

◆ compress()

template<typename T >
static std::vector< size_t > EBGeometry::Soup::compress ( std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
std::vector< std::vector< size_t > > &  a_facets 
)
inlinestatic

Compress a polygon soup by removing duplicate vertices.

After this call, a_vertices contains only unique vertex positions, sorted lexicographically, and a_facets has been updated to reference the new indices. Compressing a compressed soup changes nothing.

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in,out]a_verticesVertex coordinate list; duplicates are removed in place.
[in,out]a_facetsIndex lists; updated to reference the compressed vertex list.
Returns
For each original vertex, its index in the compressed list.

◆ containsDegeneratePolygons()

template<typename T >
static bool EBGeometry::Soup::containsDegeneratePolygons ( const std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
const std::vector< std::vector< size_t > > &  a_facets 
)
inlinestatic

Check if a polygon soup contains degenerate polygons.

A polygon is degenerate if it has fewer than 3 vertices, if two or more of its vertices coincide, or if it has zero area (see isZeroArea()).

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in]a_verticesVertex coordinate list.
[in]a_facetsIndex lists defining each polygon face.
Returns
True if any face is degenerate, false otherwise.

◆ findFoldedFeature()

template<typename T >
static std::string EBGeometry::Soup::findFoldedFeature ( const EBGeometry::DCEL::MeshT< T > &  a_mesh)
inlinestatic

Find an edge or vertex of a half-edge mesh whose pseudonormal is zero.

Run after soupToDCEL(). An edge's pseudonormal is zero when the faces on either side of it fold back onto each other, and a vertex's when the faces around it cancel out. The sign of the distance near such a feature is undefined. A vertex that no face uses is not reported.

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in]a_meshMesh to check.
Returns
A description of the first such feature, or an empty string if there is none.

◆ findRepeatedVertex()

static std::string EBGeometry::Soup::findRepeatedVertex ( const std::vector< std::vector< size_t > > &  a_facets)
inlinestatic

Find a polygon that visits a vertex twice.

Such a polygon corrupts the half-edge mesh built from it, so the file readers reject it even when told to load other defects with a warning (Parser::OnDefect::Warn). findTopologyDefect() reports it too.

Parameters
[in]a_facetsIndex lists.
Returns
A description of the first such polygon, or an empty string if there is none.

◆ findTopologyDefect()

static std::string EBGeometry::Soup::findTopologyDefect ( const std::vector< std::vector< size_t > > &  a_facets)
inlinestatic

Find a defect that stops a compressed, cleaned polygon soup from forming a half-edge mesh.

Run after compress() and removeDegeneratePolygons(). Reports the first of:

  • a polygon that visits a vertex twice;
  • an edge traversed in the same direction by two polygons. That happens when two neighboring polygons have opposite orientations, and whenever three or more polygons share an edge.

An edge used by only one polygon (a hole in the surface) is not a defect here.

Parameters
[in]a_facetsIndex lists.
Returns
A description of the defect, or an empty string if there is none.

◆ isValid()

template<typename T >
static bool EBGeometry::Soup::isValid ( const std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
const std::vector< std::vector< size_t > > &  a_facets,
std::string &  a_reason 
)
inlinestatic

Check that a polygon soup can describe a mesh at all.

Every vertex index must refer to an existing vertex, and every vertex coordinate must be finite. A soup read from a corrupted file typically fails one of these; the other Soup functions assume both.

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in]a_verticesVertex coordinate list.
[in]a_facetsIndex lists defining each polygon face.
[out]a_reasonWhy the soup is invalid; untouched if it is valid.
Returns
True if the soup is valid.

◆ isZeroArea()

template<typename T >
static bool EBGeometry::Soup::isZeroArea ( const std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
const std::vector< size_t > &  a_facet 
)
inlinestaticnoexcept

Whether a polygon has zero area to within rounding.

Uses the polygon's Newell normal, whose length is twice the area of a planar polygon (summed from the positions relative to its first vertex, so that the answer does not depend on where the polygon is), and compares it against 64 machine epsilons times the square of the polygon's longest edge. This catches exactly collinear vertices after rounding, not merely thin polygons.

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in]a_verticesVertex coordinate list.
[in]a_facetIndex list of one polygon.
Returns
True if the polygon's area is zero to within rounding.

◆ reconcilePairEdgesDCEL()

template<typename T >
static void EBGeometry::Soup::reconcilePairEdgesDCEL ( EBGeometry::DCEL::MeshT< T > &  a_mesh)
inlinestatic

Reconcile pair edges: link each half-edge with its reverse.

First builds a transient vertex-to-outgoing-half-edges table in one pass over the edges (not stored on the mesh). Then, for every half-edge (u→v), it scans the half-edges starting at v for one whose next edge starts at u – the reverse half-edge (v→u) – and sets the pair-edge index on both. O(V + E) for bounded vertex valence; no circulation, so it needs no pair edges already set. Aborts, in every build, if a half-edge's origin vertex or next edge is not a valid index (possible only in a mesh assembled by hand).

Template Parameters
TFloating-point precision type.
Parameters
[in,out]a_meshMesh whose half-edges are reconciled in place. Must already be attached to the Pool its storage was reserved from, which its first reserveX() call does.

◆ removeDegeneratePolygons()

template<typename T >
static std::vector< size_t > EBGeometry::Soup::removeDegeneratePolygons ( const std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
std::vector< std::vector< size_t > > &  a_facets 
)
inlinestatic

Remove degenerate polygons from a compressed polygon soup, repairing the mesh around them.

Run after compress(), so that coincident vertices share an index. For each facet:

  • Repeated consecutive vertex indices are merged. A facet left with fewer than three vertices is removed; the facets around it pair up with each other directly.
  • A zero-area triangle (three collinear vertices) is a T-junction filler: its middle vertex lies on its longest edge, and the facet across that edge has one fewer vertex than the geometry needs. The triangle is removed and its middle vertex is inserted into that facet between the longest edge's endpoints. The neighbor becomes a planar polygon with one straight-angle vertex, and the mesh stays closed. Without the repair, the triangle has no normal, and every edge and vertex pseudonormal next to it is wrong.
  • Any other zero-area facet, and a zero-area triangle with no facet across its longest edge, is removed.
Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[in]a_verticesCompressed vertex coordinate list.
[in,out]a_facetsIndex lists; degenerate facets are removed, and neighbors of repaired T-junctions gain a vertex.
Returns
For each facet kept, its index in the original a_facets. Its size is the number kept.

◆ soupToDCEL()

template<typename T >
static void EBGeometry::Soup::soupToDCEL ( EBGeometry::DCEL::MeshT< T > &  a_mesh,
Pool &  a_pool,
const std::vector< EBGeometry::Vec3T< T > > &  a_vertices,
const std::vector< std::vector< size_t > > &  a_facets,
const std::string &  a_id 
)
inlinestatic

Convert a polygon soup into a DCEL half-edge mesh.

Builds vertices, half-edges, and faces from the input arrays, reconciles pair edges, runs a mesh sanity check, and computes the mesh normals (angle-weighted vertex normals). a_mesh is attached to a_pool by the first reserve here and is queryable from that point on, including across the reserves that follow – a_pool need not be frozen, and may stay open for further meshes. Aborts, in every build, on a face with fewer than 3 vertices, a vertex index outside a_vertices, or more vertices, half-edges or faces than 32-bit indices can number; the file readers never pass any of these.

Template Parameters
TFloating-point precision type for vertex coordinates.
Parameters
[out]a_meshOutput DCEL mesh populated by this call.
[in,out]a_poolPool to reserve a_mesh's vertex/edge/face storage from.
[in]a_verticesCompressed vertex coordinate list.
[in]a_facetsIndex lists defining each polygon face.
[in]a_idIdentifier string used in diagnostic messages.