This example shows how to add per-vertex/per-edge properties to a graph, and how to access existing properties.
27#include <easy3d/core/graph.h>
28#include <easy3d/util/initializer.h>
39Graph* old_graph_from_previous_example() {
41 auto graph =
new Graph;
50 graph->add_edge(v0, v1);
51 graph->add_edge(v1, v2);
52 graph->add_edge(v2, v3);
53 graph->add_edge(v3, v0);
54 graph->add_edge(v1, v3);
60int main(
int argc,
char** argv) {
64 Graph* graph = old_graph_from_previous_example();
70 for (
auto v : graph->vertices()) {
73 colors[v] = points[v];
74 std::cout <<
"vertex: " << v <<
", position: " << points[v] <<
", color: " << colors[v] << std::endl;
79 for (
auto e : graph->edges()) {
81 std::cout <<
"edge: " << e <<
", length: " << lengths[e] << std::endl;
A Graph data structure with easy property management.
Definition graph.h:50
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
Gets or adds a vertex property.
Definition graph.h:978
VertexProperty< T > add_vertex_property(const std::string &name, const T t=T())
Adds a vertex property.
Definition graph.h:908
float edge_length(Edge e) const
Computes the length of an edge.
Definition graph.cpp:256
EdgeProperty< T > add_edge_property(const std::string &name, const T t=T())
Adds an edge property.
Definition graph.h:920
Definition collider.cpp:182
This type represents a vertex (internally it is basically an index).
Definition graph.h:132