Easy3D 2.5.3
PolyMesh Class Reference

Data structure representing a polyhedral mesh. More...

#include <easy3d/core/poly_mesh.h>

Inheritance diagram for PolyMesh:
Model

Classes

class  BaseHandle
 
struct  Cell
 
struct  CellConnectivity
 
class  CellContainer
 
class  CellIterator
 
class  CellProperty
 
struct  Edge
 
struct  EdgeConnectivity
 
class  EdgeContainer
 
class  EdgeIterator
 
class  EdgeProperty
 
struct  Face
 
class  FaceContainer
 
class  FaceIterator
 
class  FaceProperty
 
struct  HalfFace
 
struct  HalfFaceConnectivity
 
class  HalffaceContainer
 
class  HalfFaceIterator
 
class  HalfFaceProperty
 
class  ModelProperty
 
struct  Vertex
 
struct  VertexConnectivity
 
class  VertexContainer
 
class  VertexIterator
 
class  VertexProperty
 

Public Member Functions

Construct, destruct, assignment
 PolyMesh ()
 default constructor
 
 ~PolyMesh () override=default
 
 PolyMesh (const PolyMesh &rhs)
 copy constructor: copies rhs to *this. performs a deep copy of all properties.
 
PolyMeshoperator= (const PolyMesh &rhs)
 assign rhs to *this. performs a deep copy of all properties.
 
PolyMeshassign (const PolyMesh &rhs)
 assign rhs to *this. does not copy custom properties.
 
File IO
bool read (const std::string &filename)
 Read mesh from a PM file filename. Mainly for quick debug purposes. Client code should use PolyMeshIO. More...
 
bool write (const std::string &filename) const
 Write mesh to a PM file filename. Mainly for quick debug purposes. Client code should use PolyMeshIO. More...
 
Add new elements by hand
Vertex add_vertex (const vec3 &p)
 add a new vertex with position p
 
Cell add_cell (const std::vector< HalfFace > &faces)
 
Cell add_tetra (HalfFace f0, HalfFace f1, HalfFace f2, HalfFace f3)
 
Cell add_tetra (Vertex v0, Vertex v1, Vertex v2, Vertex v3)
 
Cell add_hexa (Vertex v0, Vertex v1, Vertex v2, Vertex v3, Vertex v4, Vertex v5, Vertex v6, Vertex v7)
 
HalfFace add_face (const std::vector< Vertex > &vertices)
 
HalfFace add_triangle (Vertex v0, Vertex v1, Vertex v2)
 
HalfFace add_quad (Vertex v0, Vertex v1, Vertex v2, Vertex v3)
 
Memory Management
unsigned int n_vertices () const
 returns number of vertices in the mesh
 
unsigned int n_edges () const
 returns number of edges in the mesh
 
unsigned int n_halffaces () const
 returns number of halffaces in the mesh
 
unsigned int n_faces () const
 returns number of faces in the mesh
 
unsigned int n_cells () const
 returns number of cells in the mesh
 
void clear ()
 Removes all vertices, edges, halffaces, faces, cells and properties. More...
 
void resize (unsigned int nv, unsigned int ne, unsigned int nf, unsigned int nc)
 
bool is_valid (Vertex v) const
 return whether vertex v is valid, i.e. the index is stores it within the array bounds.
 
bool is_valid (Edge e) const
 return whether edge e is valid, i.e. the index is stores it within the array bounds.
 
bool is_valid (HalfFace h) const
 return whether halfface h is valid, i.e. the index is stores it within the array bounds.
 
bool is_valid (Face f) const
 return whether face f is valid, i.e. the index is stores it within the array bounds.
 
bool is_valid (Cell c) const
 return whether cell h is valid, i.e. the index is stores it within the array bounds.
 
Property handling
template<class T >
VertexProperty< T > add_vertex_property (const std::string &name, const T t=T())
 
template<class T >
EdgeProperty< T > add_edge_property (const std::string &name, const T t=T())
 
template<class T >
HalfFaceProperty< T > add_halfface_property (const std::string &name, const T t=T())
 
template<class T >
FaceProperty< T > add_face_property (const std::string &name, const T t=T())
 
template<class T >
CellProperty< T > add_cell_property (const std::string &name, const T t=T())
 
template<class T >
ModelProperty< T > add_model_property (const std::string &name, const T t=T())
 Adds a model property of type T with name name and default value t. More...
 
template<class T >
VertexProperty< T > get_vertex_property (const std::string &name) const
 
template<class T >
EdgeProperty< T > get_edge_property (const std::string &name) const
 
template<class T >
HalfFaceProperty< T > get_halfface_property (const std::string &name) const
 
template<class T >
FaceProperty< T > get_face_property (const std::string &name) const
 
template<class T >
CellProperty< T > get_cell_property (const std::string &name) const
 
template<class T >
ModelProperty< T > get_model_property (const std::string &name) const
 Gets the model property named name of type T. More...
 
template<class T >
VertexProperty< T > vertex_property (const std::string &name, const T t=T())
 
template<class T >
EdgeProperty< T > edge_property (const std::string &name, const T t=T())
 
template<class T >
HalfFaceProperty< T > halfface_property (const std::string &name, const T t=T())
 
template<class T >
FaceProperty< T > face_property (const std::string &name, const T t=T())
 
template<class T >
CellProperty< T > cell_property (const std::string &name, const T t=T())
 
template<class T >
ModelProperty< T > model_property (const std::string &name, const T t=T())
 
template<class T >
bool remove_vertex_property (VertexProperty< T > &p)
 remove the vertex property p
 
bool remove_vertex_property (const std::string &n)
 remove the vertex property named n
 
template<class T >
bool remove_edge_property (EdgeProperty< T > &p)
 remove the edge property p
 
bool remove_edge_property (const std::string &n)
 remove the edge property named n
 
template<class T >
bool remove_halfface_property (HalfFaceProperty< T > &p)
 remove the halfface property p
 
bool remove_halfface_property (const std::string &n)
 remove the halfface property named n
 
template<class T >
bool remove_face_property (FaceProperty< T > &p)
 remove the face property p
 
bool remove_face_property (const std::string &n)
 remove the face property named n
 
template<class T >
bool remove_cell_property (CellProperty< T > &p)
 remove the cell property p
 
bool remove_cell_property (const std::string &n)
 remove the cell property named n
 
template<class T >
bool remove_model_property (ModelProperty< T > &p)
 remove the model property p
 
bool remove_model_property (const std::string &n)
 remove the model property named n
 
bool rename_vertex_property (const std::string &old_name, const std::string &new_name)
 rename a vertex property given its name
 
bool rename_halfface_property (const std::string &old_name, const std::string &new_name)
 rename a halfface property given its name
 
bool rename_face_property (const std::string &old_name, const std::string &new_name)
 rename a face property given its name
 
bool rename_edge_property (const std::string &old_name, const std::string &new_name)
 rename an edge property given its name
 
bool rename_cell_property (const std::string &old_name, const std::string &new_name)
 rename a cell property given its name
 
bool rename_model_property (const std::string &old_name, const std::string &new_name)
 rename a model property given its name
 
const std::type_info & get_vertex_property_type (const std::string &name) const
 
const std::type_info & get_edge_property_type (const std::string &name) const
 
const std::type_info & get_halfface_property_type (const std::string &name) const
 
const std::type_info & get_face_property_type (const std::string &name) const
 
const std::type_info & get_cell_property_type (const std::string &name) const
 
const std::type_info & get_model_property_type (const std::string &name) const
 
std::vector< std::string > vertex_properties () const
 returns the names of all vertex properties
 
std::vector< std::string > edge_properties () const
 returns the names of all edge properties
 
std::vector< std::string > halfface_properties () const
 returns the names of all halfface properties
 
std::vector< std::string > face_properties () const
 returns the names of all face properties
 
std::vector< std::string > cell_properties () const
 returns the names of all cell properties
 
std::vector< std::string > model_properties () const
 returns the names of all model properties
 
void property_stats (std::ostream &output) const override
 prints the names of all properties to an output stream (e.g., std::cout). More...
 
Iterators & Circulators
VertexIterator vertices_begin () const
 returns start iterator for vertices
 
VertexIterator vertices_end () const
 returns end iterator for vertices
 
VertexContainer vertices () const
 returns vertex container for C++11 range-based for-loops
 
EdgeIterator edges_begin () const
 returns start iterator for edges
 
EdgeIterator edges_end () const
 returns end iterator for edges
 
EdgeContainer edges () const
 returns edge container for C++11 range-based for-loops
 
HalfFaceIterator halffaces_begin () const
 returns start iterator for halffaces
 
HalfFaceIterator halffaces_end () const
 returns end iterator for halffaces
 
HalffaceContainer halffaces () const
 returns halfface container for C++11 range-based for-loops
 
FaceIterator faces_begin () const
 returns start iterator for faces
 
FaceIterator faces_end () const
 returns end iterator for faces
 
FaceContainer faces () const
 returns face container for C++11 range-based for-loops
 
CellIterator cells_begin () const
 returns start iterator for cells
 
CellIterator cells_end () const
 returns end iterator for cells
 
CellContainer cells () const
 returns cell container for C++11 range-based for-loops
 
Adjacency access
const std::set< Vertex > & vertices (Vertex v) const
 returns the vertices around vertex v
 
HalfFace halfface (Face f, unsigned int i) const
 returns the i'th halfface of face f. i has to be 0 or 1.
 
Face face (HalfFace h) const
 returns the face of HalfFace h.
 
HalfFace opposite (HalfFace h) const
 returns the twin halfface of halfface h.
 
Vertex vertex (Edge e, unsigned int i) const
 returns the i'th vertex of edge e. i has to be 0 or 1.
 
const std::vector< Vertex > & vertices (HalfFace h) const
 
const std::vector< Vertex > & vertices (Face f) const
 returns the set of vertices around face f
 
const std::set< Vertex > & vertices (Cell c) const
 returns the set of vertices around cell c
 
const std::set< Edge > & edges (Vertex v) const
 returns the set of edges around vertex v
 
const std::set< Edge > & edges (HalfFace h) const
 returns the set of edges around halfface h
 
const std::set< Edge > & edges (Cell c) const
 returns the set of edges around cell c
 
const std::set< HalfFace > & halffaces (Vertex v) const
 returns the set of halffaces around vertex v
 
const std::set< HalfFace > & halffaces (Edge e) const
 returns the set of halffaces around edge e
 
const std::vector< HalfFace > & halffaces (Cell c) const
 returns the set of halffaces around cell c
 
const std::set< Cell > & cells (Vertex v) const
 returns the set of cells around vertex v
 
const std::set< Cell > & cells (Edge e) const
 returns the set of cells around edge e
 
Cell cell (HalfFace h) const
 returns the cell associated with halfface h
 
Higher-level Topological Operations
bool is_tetraheral_mesh () const
 returns whether the mesh a tetrahedral mesh, i.e., every cell is a tetrahedron.
 
bool is_border (Vertex v) const
 
bool is_border (Edge e) const
 
bool is_border (HalfFace h) const
 returns whether f is a boundary face, i.e., it is not associated with a cell.
 
bool is_border (Face f) const
 returns whether f is a boundary face, i.e., it is incident to only one cell.
 
Edge find_edge (Vertex a, Vertex b) const
 find the edge (a,b)
 
HalfFace find_half_face (const std::vector< Vertex > &vertices) const
 find the halfface defined by a sequence of vertices (orientation sensitive)
 
bool is_degenerate (Face f) const
 returns whether face f is degenerate
 
void extract_boundary (std::vector< std::vector< Vertex > > &faces) const
 extracts the boundary surface and return its faces
 
- Public Member Functions inherited from Model
 Model (const std::string &name="unknown")
 Default constructor. The parameter name is optional, but it is useful for handling multiple models with the same viewer.
 
void set_name (const std::string &n)
 Sets/Changes the name of a model. Assigning a name to a model is optional, but it is useful for handling multiple models with the same viewer.
 
const std::string & name () const
 The name of a model.
 
const Box3bounding_box (bool recompute=false) const
 The bounding box of the model. More...
 
void invalidate_bounding_box ()
 Invalidates the bounding box of the model. So when bounding_box() is called, the bounding box will be re-computed. This function is typically called when the geometry of a model is changed.
 
virtual std::vector< vec3 > & points ()=0
 The vertices of the model. More...
 
virtual const std::vector< vec3 > & points () const =0
 The vertices of the model. More...
 
bool empty () const
 Tests if the model is empty.
 
virtual void property_stats (std::ostream &output) const
 Prints the names of all properties to an output stream (e.g., std::cout). More...
 
void set_renderer (Renderer *r)
 Sets the renderer of this model. More...
 
Rendererrenderer ()
 Gets the renderer of this model.
 
const Rendererrenderer () const
 Gets the constant renderer of this model.
 
void set_manipulator (Manipulator *manip)
 Attaches a manipulator to this model. More...
 
Manipulatormanipulator ()
 Gets the manipulator attached to this model.
 
const Manipulatormanipulator () const
 Gets the manipulator attached to this model.
 

Geometry-related Functions

const vec3position (Vertex v) const
 position of a vertex (read only)
 
const std::vector< vec3 > & points () const override
 vector of vertex positions (read only) More...
 
std::vector< vec3 > & points () override
 vector of vertex positions More...
 
void update_face_normals ()
 compute face normals by calling compute_face_normal(HalfFace) for each face.
 
vec3 compute_face_normal (Face f) const
 compute normal vector of face f.
 
void update_vertex_normals ()
 
float edge_length (Edge e) const
 compute the length of edge e.
 

Detailed Description

Data structure representing a polyhedral mesh.

Note
PolyMesh assumes the half-face normals pointing outside the cells.

This implementation is inspired by Surface_mesh https://opensource.cit-ec.de/projects/surface_mesh

Examples
Tutorial_112_PolyMesh, Tutorial_113_PolyMesh_Connectivity, Tutorial_114_PolyMesh_Property, and Tutorial_115_PolyMesh_IO.

Member Function Documentation

◆ add_cell()

PolyMesh::Cell add_cell ( const std::vector< HalfFace > &  faces)

add a new cell defined by faces.

Parameters
facesThe input faces created by add_face(), add_triangle(), or add_quad().
See also
add_face(), add_triangle(), add_quad(), add_tetra(), add_hexa()

◆ add_cell_property()

CellProperty< T > add_cell_property ( const std::string &  name,
const T  t = T() 
)
inline

add a cell property of type T with name name and default value t. fails if a property named name exists already, since the name has to be unique. in this case it returns an invalid property

◆ add_edge_property()

EdgeProperty< T > add_edge_property ( const std::string &  name,
const T  t = T() 
)
inline

add a edge property of type T with name name and default value t. fails if a property named name exists already, since the name has to be unique. in this case it returns an invalid property

◆ add_face()

PolyMesh::HalfFace add_face ( const std::vector< Vertex > &  vertices)

add a new face connecting vertices

Parameters
verticesThe input vertices created by add_vertex().
See also
add_triangle(), add_quad()

◆ add_face_property()

FaceProperty< T > add_face_property ( const std::string &  name,
const T  t = T() 
)
inline

add a face property of type T with name name and default value t. fails if a property named name exists already, since the name has to be unique. in this case it returns an invalid property

Examples
Tutorial_114_PolyMesh_Property.

◆ add_halfface_property()

HalfFaceProperty< T > add_halfface_property ( const std::string &  name,
const T  t = T() 
)
inline

add a halfface property of type T with name name and default value t. fails if a property named name exists already, since the name has to be unique. in this case it returns an invalid property

◆ add_hexa()

PolyMesh::Cell add_hexa ( Vertex  v0,
Vertex  v1,
Vertex  v2,
Vertex  v3,
Vertex  v4,
Vertex  v5,
Vertex  v6,
Vertex  v7 
)

add a new hexahedron connecting vertices v0, v1, v2, v3, v4, v5, v6, v7.

Parameters
{v0,v1,v2,v3,v4,v5,v6,v7}The input vertices created by add_vertex(). The vertices must be ordered as bellow: 3-----------------—2 |\ |\ | \ | \ | \ | \ | 7-------------—+—6 | | | | 0—+-------------—1 | \ | \ | \ | \ | | | 4-----------------—5

It creates all the faces and the cell, and adds them to the mesh.

See also
add_vertex()

◆ add_model_property()

ModelProperty< T > add_model_property ( const std::string &  name,
const T  t = T() 
)
inline

Adds a model property of type T with name name and default value t.

Fails if a property named name exists already, since the name has to be unique. In this case it returns an invalid property. Example:

auto trans = cloud->add_model_property<mat4>("transformation", mat4::identity());
trans[0] = mat4::translation(-x0, -y0, -z0);
static Mat4< float > translation(const Vec< 3, float > &t)
Static constructor return a 3D translation matrix (as a 4D affine transformation).
Definition: mat.h:2280
static Mat< N, M, float > identity()
Static constructor return an N x M identity matrix. see also load_identity()
Definition: mat.h:483
Mat4< float > mat4
A 4 by 4 matrix of float type.
Definition: types.h:68

◆ add_quad()

HalfFace add_quad ( Vertex  v0,
Vertex  v1,
Vertex  v2,
Vertex  v3 
)
inline

add a new quad face connecting vertices v0, v1, v2, v3.

Parameters
{v0,v1,v2,v3}The input vertices created by add_vertex().
See also
add_face(), add_triangle()

◆ add_tetra() [1/2]

Cell add_tetra ( HalfFace  f0,
HalfFace  f1,
HalfFace  f2,
HalfFace  f3 
)
inline

add a new tetrahedron defined by its faces.

Parameters
{f0,f1,f2,f3}The input faces created by add_face() or add_triangle().
See also
add_cell(), add_tetra(), add_face(), add_triangle().
Examples
Tutorial_112_PolyMesh.

◆ add_tetra() [2/2]

PolyMesh::Cell add_tetra ( Vertex  v0,
Vertex  v1,
Vertex  v2,
Vertex  v3 
)

add a new tetrahedron connecting vertices v0, v1, v2, v3.

Parameters
{v0,v1,v2,v3}The input vertices created by add_vertex().

It creates all the faces and the cell, and adds them to the mesh.

See also
add_vertex()

◆ add_triangle()

HalfFace add_triangle ( Vertex  v0,
Vertex  v1,
Vertex  v2 
)
inline

add a new triangle face connecting vertices v0, v1, v2.

Parameters
{v0,v1,v2}The input vertices created by add_vertex().
See also
add_face(), add_quad()

◆ add_vertex_property()

VertexProperty< T > add_vertex_property ( const std::string &  name,
const T  t = T() 
)
inline

add a vertex property of type T with name name and default value t. fails if a property named name exists already, since the name has to be unique. in this case it returns an invalid property

◆ cell_property()

CellProperty< T > cell_property ( const std::string &  name,
const T  t = T() 
)
inline

if a cell property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ clear()

void clear ( )

Removes all vertices, edges, halffaces, faces, cells and properties.

After calling this method, the mesh is the same as newly constructed. The additional properties (such as normal vectors) are also removed and must thus be re-added if needed.

◆ edge_property()

EdgeProperty< T > edge_property ( const std::string &  name,
const T  t = T() 
)
inline

if an edge property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ face_property()

FaceProperty< T > face_property ( const std::string &  name,
const T  t = T() 
)
inline

if a face property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ get_cell_property()

CellProperty< T > get_cell_property ( const std::string &  name) const
inline

get the cell property named name of type T. returns an invalid CellProperty if the property does not exist or if the type does not match.

◆ get_cell_property_type()

const std::type_info & get_cell_property_type ( const std::string &  name) const
inline

get the type_info T of cell property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ get_edge_property()

EdgeProperty< T > get_edge_property ( const std::string &  name) const
inline

get the edge property named name of type T. returns an invalid EdgeProperty if the property does not exist or if the type does not match.

◆ get_edge_property_type()

const std::type_info & get_edge_property_type ( const std::string &  name) const
inline

get the type_info T of edge property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ get_face_property()

FaceProperty< T > get_face_property ( const std::string &  name) const
inline

get the face property named name of type T. returns an invalid FaceProperty if the property does not exist or if the type does not match.

◆ get_face_property_type()

const std::type_info & get_face_property_type ( const std::string &  name) const
inline

get the type_info T of face property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ get_halfface_property()

HalfFaceProperty< T > get_halfface_property ( const std::string &  name) const
inline

get the halfface property named name of type T. returns an invalid HalfFaceProperty if the property does not exist or if the type does not match.

◆ get_halfface_property_type()

const std::type_info & get_halfface_property_type ( const std::string &  name) const
inline

get the type_info T of halfface property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ get_model_property()

ModelProperty< T > get_model_property ( const std::string &  name) const
inline

Gets the model property named name of type T.

Returns
The model property. An invalid ModelProperty will be returned if the property does not exist or if the type does not match. Example:
auto T = cloud->get_model_property<mat4>("transformation");
T[0] = mat4::translation(-x0, -y0, -z0);

◆ get_model_property_type()

const std::type_info & get_model_property_type ( const std::string &  name) const
inline

get the type_info T of model property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ get_vertex_property()

VertexProperty< T > get_vertex_property ( const std::string &  name) const
inline

get the vertex property named name of type T. returns an invalid VertexProperty if the property does not exist or if the type does not match.

◆ get_vertex_property_type()

const std::type_info & get_vertex_property_type ( const std::string &  name) const
inline

get the type_info T of vertex property name. returns an typeid(void) if the property does not exist or if the type does not match.

◆ halfface_property()

HalfFaceProperty< T > halfface_property ( const std::string &  name,
const T  t = T() 
)
inline

if a halfface property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ is_border() [1/2]

bool is_border ( Edge  e) const
inline

returns whether e is a boundary edge, i.e., at least one of its incident halfface is not associated with a cell.

◆ is_border() [2/2]

bool is_border ( Vertex  v) const
inline

returns whether v is a boundary vertex, i.e., at least one of its incident halfface is not associated with a cell.

◆ model_property()

ModelProperty< T > model_property ( const std::string &  name,
const T  t = T() 
)
inline

if a model property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ points() [1/2]

const std::vector< vec3 > & points ( ) const
inlineoverridevirtual

vector of vertex positions (read only)

Implements Model.

◆ points() [2/2]

std::vector< vec3 > & points ( )
inlineoverridevirtual

vector of vertex positions

Implements Model.

◆ property_stats()

void property_stats ( std::ostream &  output) const
overridevirtual

prints the names of all properties to an output stream (e.g., std::cout).

Reimplemented from Model.

◆ read()

bool read ( const std::string &  filename)

Read mesh from a PM file filename. Mainly for quick debug purposes. Client code should use PolyMeshIO.

See also
PolyMeshIO.

◆ resize()

void resize ( unsigned int  nv,
unsigned int  ne,
unsigned int  nf,
unsigned int  nc 
)
inline

resizes space for vertices, edges, halffaces, and their currently associated properties. Note: nf is the number of faces. for halffaces, nh = 2 * nf. *‍/

◆ update_vertex_normals()

void update_vertex_normals ( )

Computes vertex normals for each vertex.

Attention
For vertices on the border of the polyhedral mesh, the normals point outside. For interior vertices, vertex normals are not defined. This method is not stable for concave vertices or vertices with spanning angles close to 0 or 180 degrees (but these are very rare cases for polyhedral meshes).

◆ vertex_property()

VertexProperty< T > vertex_property ( const std::string &  name,
const T  t = T() 
)
inline

if a vertex property of type T with name name exists, it is returned. otherwise this property is added (with default value t)

◆ vertices()

const std::vector< Vertex > & vertices ( HalfFace  h) const
inline

returns the set of vertices around halfface h. The vertices are ordered in a way such that its normal points outside of the cell associated with h.

◆ write()

bool write ( const std::string &  filename) const

Write mesh to a PM file filename. Mainly for quick debug purposes. Client code should use PolyMeshIO.

See also
PolyMeshIO.

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