This example gives a minimalistic approach of importing a graph and displaying it with Tulip OpenGL rendering engine.
This example gives a minimalistic approach of importing a graph and displaying it with Tulip OpenGL rendering engine
In this example, we are making a standalone program that will load a graph file passed as argument to the program and display it into a new window.
The code contains a step-by-step explanation of the process, please refer to classes documentation for more information about their usage.
#include <tulip/PluginLoaderTxt.h>
#include <tulip/PluginLibraryLoader.h>
#include <tulip/GlMainWidget.h>
#include <tulip/MouseInteractors.h>
#include <tulip/TlpQtTools.h>
#include <tulip/LayoutProperty.h>
#include <tulip/SizeProperty.h>
#include <tulip/StringProperty.h>
#include <tulip/DoubleProperty.h>
#include <tulip/IntegerProperty.h>
#include <tulip/TulipViewSettings.h>
#include <tulip/GlGraphComposite.h>
#include <tulip/GlGraphRenderingParameters.h>
#include <QApplication>
#include <QString>
#include <iostream>
using namespace std;
void addChildren(
Graph *graph,
node root,
int depth,
int degree) {
if (depth > 0) {
for (int i = 0; i < degree; ++i) {
addChildren(graph, child, depth - 1, degree);
}
}
}
Graph *createCompleteTree(
int depth,
int degree) {
Graph *graph = newGraph();
addChildren(graph, root, depth, degree);
return graph;
}
void setTreeVisualProperties(
Graph *tree) {
std::string errMsg;
for (
auto n : tree->
nodes()) {
}
viewBorderWidth->
setAllNodeValue(1);
std::vector<int> glyphsMap;
glyphsMap.push_back(tlp::NodeShape::Square);
glyphsMap.push_back(tlp::NodeShape::Circle);
glyphsMap.push_back(tlp::NodeShape::RoundedBox);
glyphsMap.push_back(tlp::NodeShape::Hexagon);
glyphsMap.push_back(tlp::NodeShape::Star);
glyphsMap.push_back(tlp::NodeShape::Ring);
std::vector<Color> colorsMap;
colorsMap.push_back(Color::Red);
colorsMap.push_back(Color::Azure);
colorsMap.push_back(Color::Lemon);
colorsMap.push_back(Color::SpringGreen);
colorsMap.push_back(Color::Apricot);
colorsMap.push_back(Color::Magenta);
for (
auto n : tree->
nodes()) {
viewShape->
setNodeValue(n, glyphsMap[
int(dagLevel.getNodeValue(n))]);
viewColor->setNodeValue(n, colorsMap[int(dagLevel.getNodeValue(n))]);
}
}
}
int main(int argc, char **argv) {
QApplication app(argc, argv);
if (QApplication::arguments().size() == 2) {
QString filename = QApplication::arguments()[1];
if (!((filename.endsWith(".tlp")) || (filename.endsWith(".tlp.gz")))) {
<< " not compatible. Use a tlp file or a tlp.gz file" << endl;
exit(EXIT_FAILURE);
}
} else {
g = createCompleteTree(5, 2);
setTreeVisualProperties(g);
}
mainWidget->show();
QApplication::processEvents();
mainWidget->installEventFilter(new MouseNKeysNavigator);
return app.exec();
}
virtual void setNodeValue(const node n, typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of a node and notify the observers of a modification.
A graph property that maps a tlp::Color value to graph elements.
A graph property that maps a double value to graph elements.
Class use to visualize graph in OpenGL Tulip engine.
GlGraphRenderingParameters * getRenderingParametersPointer()
Return a pointer on rendering parameters used for rendering.
That class defines all the parameters used by GlGraphComposite to render a graph.
void setViewArrow(const bool state)
Activate or deactivate displaying of arrows along the graph's edges.
void setLabelScaled(bool state)
void setEdgeColorInterpolate(const bool state)
Activate or deactivate interpolation of nodes colors along edge.
void setEdgeSizeInterpolate(const bool state)
Activate or deactivate interpolation of nodes colors along edge.
A GlLayer is like an 2D drawing software layer system.
void addGraph(tlp::Graph *graph, const std::string &name)
A convenient function that adds a graph to the layer.
This widget provide a simple system to visualize data/graph with OpenGL 3D engine.
tlp::GlScene * getScene()
Get the GlScene of this GlMainWidget You have to add yours GlLayer and GlEntity to this GlScene At th...
void draw(bool graphChanged=true)
void centerScene(bool graphChanged=false, float zoomFactor=1.0)
Convenience function that calls center function on the current scene, applies a zoom (if needed) and ...
GlLayer * createLayer(const std::string &name)
Create a layer with the given name in the scene This layer is added to the layers list Now the scene ...
GlGraphComposite * getGlGraphComposite()
Return the current GlGraphComposite used by the scene.
virtual const std::vector< node > & nodes() const =0
Return a const reference on the vector of nodes of the graph It is the fastest way to access to nodes...
virtual PropertyInterface * getProperty(const std::string &name) const =0
Gets an existing property. In DEBUG mode an assertion checks the existence of the property.
virtual edge addEdge(const node source, const node target)=0
Adds a new edge in the graph This edge is also added in all the super-graph of the graph.
virtual node addNode()=0
Adds a new node in the graph and returns it. This node is also added in all the ancestor graphs.
bool applyPropertyAlgorithm(const std::string &algorithm, PropertyInterface *result, std::string &errorMessage, DataSet *parameters=nullptr, PluginProgress *progress=nullptr)
Runs a plugin on the graph, whose result is a property.
A graph property that maps an integer value to graph elements.
A graph property that maps a tlp::Coord value to graph nodes and std::vector<tlp::Coord> for edges.
A graph property that maps a tlp::Size value to graph elements.
A graph property that maps a std::string value to graph elements.
Graph * loadGraph(const std::string &filename, tlp::PluginProgress *progress=nullptr)
Loads a graph from a file (extension can be any of the Tulip supported input graph file format).
std::string QStringToTlpString(const QString &toConvert)
Convert a QString to a Tulip UTF-8 encoded std::string.
void initTulipSoftware(PluginLoader *loader=nullptr, bool removeDiscardedPlugins=false)
Sets up environment when creating an executable using Tulip libraries This method performs basic oper...
The node struct represents a node in a Graph object.