Page MenuHome

BLI: library to export graphs in dot format
Needs ReviewPublic

Authored by Jacques Lucke (JacquesLucke) on Mon, Feb 10, 3:54 PM.

Details

Summary

This implements a new C++ library that helps writing dot exporters for different graphs in Blender.

Motivation:

During the last year, I had to implement a couple of graph data structures and algorithms on those graphs. For debugging it is very helpful to visualize the graphs. However, writing a dot exporter can be a bit annoying (even if it is not complicated). Especially, when you have to do it multiple times. At some point I extracted this small library which greatly simplified the process of writing these exporters.

I'm submitting this as separate patch, so that it can be reviewed separately from the particle nodes.

Usage:

This code snippet defines three graphs which are shown below:

using namespace BLI::DotExport;

{
  DirectedGraph digraph;
  Node &node_a = digraph.new_node("A");
  Node &node_b = digraph.new_node("B");
  digraph.new_edge(node_a, node_b);
  std::cout << digraph.to_dot_string() << '\n';
}
{
  UndirectedGraph graph;
  Node &node_a = graph.new_node("A");
  Node &node_b = graph.new_node("B");
  Node &node_c = graph.new_node("C");

  Cluster &cluster = graph.new_cluster("My Cluster");
  node_a.set_parent_cluster(cluster);
  node_b.set_parent_cluster(cluster);

  UndirectedEdge &edge = graph.new_edge(node_a, node_b);
  graph.new_edge(node_c, node_b);

  graph.set_rankdir(Attr_rankdir::LeftToRight);
  node_b.set_shape(Attr_shape::Diamond);
  node_c.set_background_color("#EE5544");
  edge.set_attribute("color", "#0000FF");

  std::cout << graph.to_dot_string() << '\n';
}
{
  DirectedGraph digraph;
  digraph.set_rankdir(Attr_rankdir::LeftToRight);

  Node &node_a = digraph.new_node("");
  Node &node_b = digraph.new_node("");

  NodeWithSocketsRef node_with_sockets_a(node_a, "Node A", {"A", "B"}, {"C", "D"});
  NodeWithSocketsRef node_with_sockets_b(node_b, "Node B", {"A", "B"}, {"C", "D"});

  digraph.new_edge(node_with_sockets_a.output(0), node_with_sockets_b.input(1));

  std::cout << digraph.to_dot_string() << '\n';
}



It works great with more complex graphs as well:

Diff Detail

Repository
rB Blender