Submitted by Anonymous on Tue, 2011-05-17 16:14
Posted in
Creating a graph
All the required functions are declared in <tulip/Graph.h>
tlp::Graph* g = tlp::newGraph();
This is the only way to create a Tulip graph from scratch, you cannot create a new instance of tlp::Graph as it is an abstract class.
Other ways to get a tlp::Graph is to import it from a file.
To import a file in the Tulip format, simply use :
tlp::loadGraph("mygraph.tlp"); tlp::loadGraph("mygraph.tlp.gz");
Iterating over nodes/edges
Tulip has its own style of iterators, and provides a forEach macro, that can be found in <tulip/ForEach.h>
node n; Graph* graph; forEach(n, graph->getNodes()) { } forEach(n, graph->getEdges()) { }
Retrieving the value of a property for nodes/edges
node n;
edge e;
StringProperty* labels = graph->getProperty<StringProperty>("viewLabel");
string s = labels->getNodeValue(n);
string s = labels->getEdgeValue(e);
Setting the value of a property for nodes/edges
node n; edge e; StringProperty* labels = graph->getProperty<StringProperty>("viewLabel"); string s = labels->setNodeValue(n, "myvalue"); string s = labels->setEdgeValue(e, "myvalue");