Easy3D 2.6.1
Loading...
Searching...
No Matches
Graph Class Reference

A Graph data structure with easy property management. More...

#include <easy3d/core/graph.h>

Inheritance diagram for Graph:
Model

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.
 
Graphoperator= (const Graph &rhs)
 Assign rhs to *this. Performs a deep copy of all properties.
 
Graphassign (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.
 
- 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.
 
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.
 
Rendererrenderer ()
 Gets the renderer of this model.
 
const Rendererrenderer () const
 Gets the constant renderer of this model.
 
void set_manipulator (std::shared_ptr< Manipulator > manip)
 Attaches a manipulator to this model.
 
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
 Returns the position of a vertex (read-only).
 
vec3position (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.
 

Detailed Description

Constructor & Destructor Documentation

◆ Graph()

Graph ( const Graph & rhs)
inline

Copy constructor: copies rhs to *this. Performs a deep copy of all properties.

Parameters
rhsThe graph to copy from.

Member Function Documentation

◆ add_edge()

Graph::Edge add_edge ( const Vertex & v1,
const Vertex & v2 )

Add a new edge connecting vertices v1 and v2.

Parameters
v1The first vertex.
v2The second vertex.
Returns
The added edge.

◆ add_edge_property()

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

Adds an edge property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The added edge property. The operation fails if a property with the same name already exists, since the name has to be unique. In this case, it returns an invalid property.
Examples
Tutorial_110_Graph_Property/main.cpp.

◆ add_model_property()

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

Adds a model property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The added model property. The operation fails if a property with the same name already exists, since the name has to be unique. In this case, it returns an invalid property.

◆ add_vertex()

Graph::Vertex add_vertex ( const vec3 & p)

Add a new vertex with position p.

Parameters
pThe position of the vertex.
Returns
The added vertex.

◆ add_vertex_property()

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

Adds a vertex property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The added vertex property. The operation fails if a property with the same name already exists, since the name has to be unique. In this case, it returns an invalid property.
Examples
Tutorial_110_Graph_Property/main.cpp.

◆ assign()

Graph & assign ( const Graph & rhs)

Assign rhs to *this. Does not copy custom properties.

Parameters
rhsThe graph to assign from.
Returns
A reference to this graph.

◆ clear()

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.

◆ delete_edge()

void delete_edge ( Edge e)

Deletes an edge from the graph.

Parameters
eThe edge to delete.

◆ delete_vertex()

void delete_vertex ( Vertex v)

Deletes a vertex from the graph.

Parameters
vThe vertex to delete.

◆ edge_length()

float edge_length ( Edge e) const

Computes the length of an edge.

Parameters
eThe edge.
Returns
The length of the edge.
Examples
Tutorial_110_Graph_Property/main.cpp.

◆ edge_property()

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

Gets or adds an edge property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The edge property.

◆ edges() [1/2]

EdgeContainer edges ( ) const
inline

Returns the edge container for range-based for-loops.

Returns
The edge container.
Examples
Tutorial_109_Graph_Connectivity/main.cpp, and Tutorial_110_Graph_Property/main.cpp.

◆ edges() [2/2]

EdgeAroundVertexCirculator edges ( Vertex v) const
inline

Returns the circulator for edges around a vertex.

Parameters
vThe vertex.
Returns
The circulator for edges around the vertex.

◆ edges_begin()

EdgeIterator edges_begin ( ) const
inline

Returns the start iterator for edges.

Returns
The start iterator for edges.

◆ edges_end()

EdgeIterator edges_end ( ) const
inline

Returns the end iterator for edges.

Returns
The end iterator for edges.

◆ edges_size()

unsigned int edges_size ( ) const
inline

Returns number of (deleted and valid) edges in the graph.

Returns
The number of edges.

◆ find_edge()

Graph::Edge find_edge ( Vertex a,
Vertex b ) const

Finds the edge connecting two vertices.

Parameters
aThe first vertex.
bThe second vertex.
Returns
The edge connecting the vertices.

◆ get_edge_property()

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

Gets the edge property of the specified type and name.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
Returns
The edge property. If the property does not exist or the type does not match, it returns an invalid property.

◆ get_edge_property_type()

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

Gets the type information of an edge property.

Parameters
nameThe name of the property.
Returns
The type information of the property. Returns a typeid(void) if the property does not exist or if the type does not match.

◆ get_model_property()

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

Gets the model property of the specified type and name.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
Returns
The model property. If the property does not exist or the type does not match, it returns an invalid property.

◆ get_model_property_type()

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

Gets the type information of a model property.

Parameters
nameThe name of the property.
Returns
The type information of the property. Returns a typeid(void) if the property does not exist or if the type does not match.

◆ get_vertex_property()

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

Gets the vertex property of the specified type and name.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
Returns
The vertex property. If the property does not exist or the type does not match, it returns an invalid property.

◆ get_vertex_property_type()

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

Gets the type information of a vertex property.

Parameters
nameThe name of the property.
Returns
The type information of the property. Returns a typeid(void) if the property does not exist or if the type does not match.

◆ has_garbage()

bool has_garbage ( ) const
inline

Checks if there are deleted vertices or edges.

Returns
True if there are deleted vertices or edges, false otherwise.

◆ is_deleted() [1/2]

bool is_deleted ( Edge e) const
inline

Checks if an edge is deleted.

Parameters
eThe edge to check.
Returns
True if the edge is deleted, false otherwise.
See also
collect_garbage()

◆ is_deleted() [2/2]

bool is_deleted ( Vertex v) const
inline

Checks if a vertex is deleted.

Parameters
vThe vertex to check.
Returns
True if the vertex is deleted, false otherwise.
See also
collect_garbage()

◆ is_isolated()

bool is_isolated ( Vertex v) const
inline

Checks if a vertex is isolated (not incident to any edge).

Parameters
vThe vertex to check.
Returns
True if the vertex is isolated, false otherwise.

◆ is_valid() [1/2]

bool is_valid ( Edge e) const
inline

Checks if an edge is valid, i.e. the index is within the array bounds.

Parameters
eThe edge to check.
Returns
True if the edge is valid, false otherwise.

◆ is_valid() [2/2]

bool is_valid ( Vertex v) const
inline

Checks if a vertex is valid, i.e. the index is within the array bounds.

Parameters
vThe vertex to check.
Returns
True if the vertex is valid, false otherwise.

◆ model_property()

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

Gets or adds a model property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The model property.

◆ n_edges()

unsigned int n_edges ( ) const
inline

Returns number of edges in the graph.

Returns
The number of edges.
Examples
Tutorial_111_Graph_IO/main.cpp.

◆ n_vertices()

unsigned int n_vertices ( ) const
inline

Returns number of vertices in the graph.

Returns
The number of vertices.
Examples
Tutorial_111_Graph_IO/main.cpp.

◆ operator=()

Graph & operator= ( const Graph & rhs)

Assign rhs to *this. Performs a deep copy of all properties.

Parameters
rhsThe graph to assign from.
Returns
A reference to this graph.

◆ points() [1/2]

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

Returns the vector of vertex positions (read-only).

Returns
The vector of vertex positions.

Implements Model.

◆ points() [2/2]

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

Returns the vector of vertex positions.

Returns
The vector of vertex positions.

Implements Model.

◆ position() [1/2]

vec3 & position ( Vertex v)
inline

Returns the position of a vertex.

Parameters
vThe vertex.
Returns
The position of the vertex.

◆ position() [2/2]

const vec3 & position ( Vertex v) const
inline

Returns the position of a vertex (read-only).

Parameters
vThe vertex.
Returns
The position of the vertex.

◆ property_stats()

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

Prints the names of all properties to an output stream.

Parameters
outputThe output stream.

Reimplemented from Model.

◆ reserve()

void reserve ( unsigned int nvertices,
unsigned int nedges )

Reserves memory for vertices and edges (mainly used in file readers)

Parameters
nverticesThe number of vertices to reserve.
nedgesThe number of edges to reserve.

◆ resize()

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

Resizes the space for vertices, edges, and their currently associated properties.

Parameters
nvThe number of vertices.
neThe number of edges.

◆ source()

Vertex source ( Edge e) const
inline

Returns the starting vertex of an edge, which is equal to vertex(e, 0).

Parameters
eThe edge.

◆ target()

Vertex target ( Edge e) const
inline

Returns the ending vertex of an edge, which is equal to vertex(e, 1).

Parameters
eThe edge.

◆ valence()

unsigned int valence ( Vertex v) const

Returns the valence (number of incident edges or neighboring vertices) of a vertex.

Parameters
vThe vertex.
Returns
The valence of the vertex.

◆ vertex()

Vertex vertex ( Edge e,
unsigned int i ) const
inline

Returns the i-th vertex of an edge.

Parameters
eThe edge.
iThe index (0 or 1).
Returns
The i-th vertex of the edge.
Examples
Tutorial_109_Graph_Connectivity/main.cpp.

◆ vertex_property()

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

Gets or adds a vertex property.

Template Parameters
TThe type of the property.
Parameters
nameThe name of the property.
tThe default value of the property.
Returns
The vertex property.
Examples
Tutorial_110_Graph_Property/main.cpp.

◆ vertices() [1/2]

VertexContainer vertices ( ) const
inline

Returns the vertex container for range-based for-loops.

Returns
The vertex container.
Examples
Tutorial_109_Graph_Connectivity/main.cpp, and Tutorial_110_Graph_Property/main.cpp.

◆ vertices() [2/2]

VertexAroundVertexCirculator vertices ( Vertex v) const
inline

Returns the circulator for vertices around a vertex.

Parameters
vThe vertex.
Returns
The circulator for vertices around the vertex.

◆ vertices_begin()

VertexIterator vertices_begin ( ) const
inline

Returns the start iterator for vertices.

Returns
The start iterator for vertices.

◆ vertices_end()

VertexIterator vertices_end ( ) const
inline

Returns the end iterator for vertices.

Returns
The end iterator for vertices.

◆ vertices_size()

unsigned int vertices_size ( ) const
inline

Returns number of (deleted and valid) vertices in the graph.

Returns
The number of vertices.

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