This example gives a minimalistic approach of importing a graph and displaying it with Tulip OpenGL rendering engineIn 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 <tulip/ForEach.h>
#include <QApplication>
#include <QString>
#include <iostream>
using namespace tlp;
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) {
addChildren(graph, root, depth, degree);
return graph;
}
void setTreeVisualProperties(
Graph *tree) {
std::string errMsg;
viewLabel->
setNodeValue(n, QString::number(n.id).toStdString());
}
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);
IntegerProperty *viewShape = tree->
getProperty<IntegerProperty>(
"viewShape");
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")))) {
cout << "File " << filename.toStdString() << " 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();
}