I have a string in a C++ Qt application (on Ubuntu) which contains valid GraphViz/dot graph syntax. I want to generate an image file/object from this text, similar to the images that various online tools (like this one: http://www.webgraphviz.com/) spit out. Maybe I'm using wrong search terms, but I can't seem to find relevant help with this.
What I basically want is something like this:
generate_dot_graph_image(std::string dot_text, std::string image_file_path)
Additional details: I have a Dijkstra solver whose solution (basically the original graph after removing non-used edges) I want to visualize inside my application. The solver already includes an option to convert the solution to a string that can be parsed as a dot graph using a utility such as the one I linked above. But what I want is to be able to do this from inside C++.
So I was able to do exactly what I wanted using the GraphViz libraries. You can install them on Ubuntu using
sudo apt-get install graphviz-lib
andsudo apt-get install libgraphviz-dev
. Once that's done:gvc is a C library, and the functions take non-const C strings as arguments, hence the const_casts in the beginning. You can also edit the image size by altering the
-Gsize=8,4
and-Gdpi=100
args. With the current configuration you'll get an 8*100 x 4*100 = 800x400 image file. Anyway, these arguments are the same as you would apply when running thedot
command from bash.Other than that, this code is basically copied from one of the examples in the graphViz as a library manual: http://www.graphviz.org/pdf/libguide.pdf
I found a way, I used the following function and it works: