Easy3D 2.6.1
|
A Graph data structure with easy property management. More...
#include <easy3d/core/graph.h>
Classes | |
class | BaseHandle |
Base class for all topology types (internally it is basically an index). More... | |
struct | Edge |
This type represents an edge (internally it is basically an index). More... | |
class | EdgeAroundVertexCirculator |
This class circulates through all edges connected with a vertex. It also acts as a container-concept for C++11 range-based for loops. More... | |
struct | EdgeConnectivity |
This type stores the edge connectivity. More... | |
class | EdgeContainer |
This helper class is a container for iterating through all edges using C++11 range-based for-loops. More... | |
class | EdgeIterator |
This class iterates linearly over all edges. More... | |
class | EdgeProperty |
Edge property of type T. More... | |
class | ModelProperty |
Graph property of type T. More... | |
struct | Vertex |
This type represents a vertex (internally it is basically an index). More... | |
class | VertexAroundVertexCirculator |
This class circulates through all one-ring neighbors of a vertex. It also acts as a container-concept for C++11 range-based for loops. More... | |
struct | VertexConnectivity |
This type stores the vertex connectivity. More... | |
class | VertexContainer |
This helper class is a container for iterating through all vertices using C++11 range-based for-loops. More... | |
class | VertexIterator |
This class iterates linearly over all vertices. More... | |
class | VertexProperty |
Vertex property of type T. More... | |
Public Member Functions | |
Construct, destruct, assignment | |
Graph () | |
default constructor | |
~Graph () override=default | |
destructor | |
Graph (const Graph &rhs) | |
Copy constructor: copies rhs to *this . Performs a deep copy of all properties. | |
Graph & | operator= (const Graph &rhs) |
Assign rhs to *this . Performs a deep copy of all properties. | |
Graph & | assign (const Graph &rhs) |
Assign rhs to *this . Does not copy custom properties. | |
Add new elements by hand | |
Vertex | add_vertex (const vec3 &p) |
Add a new vertex with position p . | |
Edge | add_edge (const Vertex &v1, const Vertex &v2) |
Add a new edge connecting vertices v1 and v2 . | |
Memory Management | |
unsigned int | vertices_size () const |
Returns number of (deleted and valid) vertices in the graph. | |
unsigned int | edges_size () const |
Returns number of (deleted and valid) edges in the graph. | |
unsigned int | n_vertices () const |
Returns number of vertices in the graph. | |
unsigned int | n_edges () const |
Returns number of edges in the graph. | |
void | clear () |
Removes all vertices, edges, and properties, and resets the garbage state. | |
void | reserve (unsigned int nvertices, unsigned int nedges) |
Reserves memory for vertices and edges (mainly used in file readers) | |
void | resize (unsigned int nv, unsigned int ne) |
Resizes the space for vertices, edges, and their currently associated properties. | |
bool | has_garbage () const |
Checks if there are deleted vertices or edges. | |
void | collect_garbage () |
Removes deleted vertices and edges. | |
bool | is_deleted (Vertex v) const |
Checks if a vertex is deleted. | |
bool | is_deleted (Edge e) const |
Checks if an edge is deleted. | |
bool | is_valid (Vertex v) const |
Checks if a vertex is valid, i.e. the index is within the array bounds. | |
bool | is_valid (Edge e) const |
Checks if an edge is valid, i.e. the index is within the array bounds. | |
Low-level connectivity | |
bool | is_isolated (Vertex v) const |
Checks if a vertex is isolated (not incident to any edge). | |
Vertex | vertex (Edge e, unsigned int i) const |
Returns the i-th vertex of an edge. | |
Vertex | source (Edge e) const |
Returns the starting vertex of an edge, which is equal to vertex(e, 0). | |
Vertex | target (Edge e) const |
Returns the ending vertex of an edge, which is equal to vertex(e, 1). | |
Property handling | |
template<class T> | |
VertexProperty< T > | add_vertex_property (const std::string &name, const T t=T()) |
Adds a vertex property. | |
template<class T> | |
EdgeProperty< T > | add_edge_property (const std::string &name, const T t=T()) |
Adds an edge property. | |
template<class T> | |
ModelProperty< T > | add_model_property (const std::string &name, const T t=T()) |
Adds a model property. | |
template<class T> | |
VertexProperty< T > | get_vertex_property (const std::string &name) const |
Gets the vertex property of the specified type and name. | |
template<class T> | |
EdgeProperty< T > | get_edge_property (const std::string &name) const |
Gets the edge property of the specified type and name. | |
template<class T> | |
ModelProperty< T > | get_model_property (const std::string &name) const |
Gets the model property of the specified type and name. | |
template<class T> | |
VertexProperty< T > | vertex_property (const std::string &name, const T t=T()) |
Gets or adds a vertex property. | |
template<class T> | |
EdgeProperty< T > | edge_property (const std::string &name, const T t=T()) |
Gets or adds an edge property. | |
template<class T> | |
ModelProperty< T > | model_property (const std::string &name, const T t=T()) |
Gets or adds a model property. | |
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_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_edge_property (const std::string &old_name, const std::string &new_name) |
rename an edge 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 |
Gets the type information of a vertex property. | |
const std::type_info & | get_edge_property_type (const std::string &name) const |
Gets the type information of an edge property. | |
const std::type_info & | get_model_property_type (const std::string &name) const |
Gets the type information of a model property. | |
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 > | 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. | |
Iterators & Circulators | |
VertexIterator | vertices_begin () const |
Returns the start iterator for vertices. | |
VertexIterator | vertices_end () const |
Returns the end iterator for vertices. | |
VertexContainer | vertices () const |
Returns the vertex container for range-based for-loops. | |
EdgeIterator | edges_begin () const |
Returns the start iterator for edges. | |
EdgeIterator | edges_end () const |
Returns the end iterator for edges. | |
EdgeContainer | edges () const |
Returns the edge container for range-based for-loops. | |
VertexAroundVertexCirculator | vertices (Vertex v) const |
Returns the circulator for vertices around a vertex. | |
EdgeAroundVertexCirculator | edges (Vertex v) const |
Returns the circulator for edges around a vertex. | |
Higher-level Topological Operations | |
unsigned int | valence (Vertex v) const |
Returns the valence (number of incident edges or neighboring vertices) of a vertex. | |
Edge | find_edge (Vertex a, Vertex b) const |
Finds the edge connecting two vertices. | |
void | delete_vertex (Vertex v) |
Deletes a vertex from the graph. | |
void | delete_edge (Edge e) |
Deletes an edge from the graph. | |
![]() | |
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 Box3 & | bounding_box (bool recompute=false) const |
The bounding box of the model. | |
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. | |
bool | empty () const |
Tests if the model is empty. | |
void | set_renderer (std::shared_ptr< Renderer > r) |
Sets the renderer of this model. | |
Renderer * | renderer () |
Gets the renderer of this model. | |
const Renderer * | renderer () const |
Gets the constant renderer of this model. | |
void | set_manipulator (std::shared_ptr< Manipulator > manip) |
Attaches a manipulator to this model. | |
Manipulator * | manipulator () |
Gets the manipulator attached to this model. | |
const Manipulator * | manipulator () const |
Gets the manipulator attached to this model. | |
Geometry-related Functions | |
const vec3 & | position (Vertex v) const |
Returns the position of a vertex (read-only). | |
vec3 & | position (Vertex v) |
Returns the position of a vertex. | |
const std::vector< vec3 > & | points () const override |
Returns the vector of vertex positions (read-only). | |
std::vector< vec3 > & | points () override |
Returns the vector of vertex positions. | |
float | edge_length (Edge e) const |
Computes the length of an edge. | |
A Graph data structure with easy property management.
This implementation is inspired by Surface_mesh https://opensource.cit-ec.de/projects/surface_mesh
Copy constructor: copies rhs
to *this
. Performs a deep copy of all properties.
rhs | The graph to copy from. |
Graph::Edge add_edge | ( | const Vertex & | v1, |
const Vertex & | v2 ) |
Add a new edge connecting vertices v1
and v2
.
v1 | The first vertex. |
v2 | The second vertex. |
|
inline |
Adds an edge property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
|
inline |
Adds a model property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
Graph::Vertex add_vertex | ( | const vec3 & | p | ) |
Add a new vertex with position p
.
p | The position of the vertex. |
|
inline |
Adds a vertex property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
Assign rhs
to *this
. Does not copy custom properties.
rhs | The graph to assign from. |
void clear | ( | ) |
Removes all vertices, edges, and properties, and resets the garbage state.
After calling this method, the graph is the same as newly constructed.
void delete_edge | ( | Edge | e | ) |
Deletes an edge from the graph.
e | The edge to delete. |
void delete_vertex | ( | Vertex | v | ) |
Deletes a vertex from the graph.
v | The vertex to delete. |
float edge_length | ( | Edge | e | ) | const |
Computes the length of an edge.
e | The edge. |
|
inline |
Gets or adds an edge property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
|
inline |
Returns the edge container for range-based for-loops.
|
inline |
Returns the circulator for edges around a vertex.
v | The vertex. |
|
inline |
Returns the start iterator for edges.
|
inline |
Returns the end iterator for edges.
|
inline |
Returns number of (deleted and valid) edges in the graph.
Graph::Edge find_edge | ( | Vertex | a, |
Vertex | b ) const |
Finds the edge connecting two vertices.
a | The first vertex. |
b | The second vertex. |
|
inline |
Gets the edge property of the specified type and name.
T | The type of the property. |
name | The name of the property. |
|
inline |
Gets the type information of an edge property.
name | The name of the property. |
|
inline |
Gets the model property of the specified type and name.
T | The type of the property. |
name | The name of the property. |
|
inline |
Gets the type information of a model property.
name | The name of the property. |
|
inline |
Gets the vertex property of the specified type and name.
T | The type of the property. |
name | The name of the property. |
|
inline |
Gets the type information of a vertex property.
name | The name of the property. |
|
inline |
Checks if there are deleted vertices or edges.
|
inline |
Checks if an edge is deleted.
e | The edge to check. |
|
inline |
Checks if a vertex is deleted.
v | The vertex to check. |
|
inline |
Checks if a vertex is isolated (not incident to any edge).
v | The vertex to check. |
|
inline |
Checks if an edge is valid, i.e. the index is within the array bounds.
e | The edge to check. |
|
inline |
Checks if a vertex is valid, i.e. the index is within the array bounds.
v | The vertex to check. |
|
inline |
Gets or adds a model property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
|
inline |
Returns number of edges in the graph.
|
inline |
Returns number of vertices in the graph.
Assign rhs
to *this
. Performs a deep copy of all properties.
rhs | The graph to assign from. |
|
inlineoverridevirtual |
Returns the vector of vertex positions (read-only).
Implements Model.
|
inlineoverridevirtual |
Returns the position of a vertex.
v | The vertex. |
Returns the position of a vertex (read-only).
v | The vertex. |
|
overridevirtual |
Prints the names of all properties to an output stream.
output | The output stream. |
Reimplemented from Model.
void reserve | ( | unsigned int | nvertices, |
unsigned int | nedges ) |
Reserves memory for vertices and edges (mainly used in file readers)
nvertices | The number of vertices to reserve. |
nedges | The number of edges to reserve. |
|
inline |
Resizes the space for vertices, edges, and their currently associated properties.
nv | The number of vertices. |
ne | The number of edges. |
Returns the starting vertex of an edge, which is equal to vertex(e, 0).
e | The edge. |
Returns the ending vertex of an edge, which is equal to vertex(e, 1).
e | The edge. |
unsigned int valence | ( | Vertex | v | ) | const |
Returns the valence (number of incident edges or neighboring vertices) of a vertex.
v | The vertex. |
Returns the i-th vertex of an edge.
e | The edge. |
i | The index (0 or 1). |
|
inline |
Gets or adds a vertex property.
T | The type of the property. |
name | The name of the property. |
t | The default value of the property. |
|
inline |
Returns the vertex container for range-based for-loops.
|
inline |
Returns the circulator for vertices around a vertex.
v | The vertex. |
|
inline |
Returns the start iterator for vertices.
|
inline |
Returns the end iterator for vertices.
|
inline |
Returns number of (deleted and valid) vertices in the graph.