diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-08 20:17:21 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-09 14:14:20 +0300 |
commit | 1a6a80270dae82d5ce9bf1266476f7bf0fe1d714 (patch) | |
tree | 937ee852808bc03c710ce1edf457f04e402ffa3f | |
parent | 8044e5f2d771a1c3ee1a116132ddc09ce3452cbb (diff) |
Cycles: Add utility to dump BVH tree as graphviz file
-rw-r--r-- | intern/cycles/bvh/bvh_node.cpp | 50 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_node.h | 3 |
2 files changed, 53 insertions, 0 deletions
diff --git a/intern/cycles/bvh/bvh_node.cpp b/intern/cycles/bvh/bvh_node.cpp index dc0255c4039..614fb6be88a 100644 --- a/intern/cycles/bvh/bvh_node.cpp +++ b/intern/cycles/bvh/bvh_node.cpp @@ -150,6 +150,56 @@ void BVHNode::update_time() } } +namespace { + +struct DumpTraversalContext { + /* Descriptor of wile where writing is happening. */ + FILE *stream; + /* Unique identifier of the node current. */ + int id; +}; + +void dump_subtree(DumpTraversalContext *context, + const BVHNode *node, + const BVHNode *parent = NULL) +{ + if(node->is_leaf()) { + fprintf(context->stream, + " node_%p [label=\"%d\",fillcolor=\"#ccccee\",style=filled]\n", + node, + context->id); + } + else { + fprintf(context->stream, + " node_%p [label=\"%d\",fillcolor=\"#cceecc\",style=filled]\n", + node, + context->id); + } + if(parent != NULL) { + fprintf(context->stream, " node_%p -> node_%p;\n", parent, node); + } + context->id += 1; + for(int i = 0; i < node->num_children(); ++i) { + dump_subtree(context, node->get_child(i), node); + } +} + +} // namespace + +void BVHNode::dump_graph(const char *filename) +{ + DumpTraversalContext context; + context.stream = fopen(filename, "w"); + if(context.stream == NULL) { + return; + } + context.id = 0; + fprintf(context.stream, "digraph BVH {\n"); + dump_subtree(&context, this); + fprintf(context.stream, "}\n"); + fclose(context.stream); +} + /* Inner Node */ void InnerNode::print(int depth) const diff --git a/intern/cycles/bvh/bvh_node.h b/intern/cycles/bvh/bvh_node.h index 8a2cffeb056..d9105d69739 100644 --- a/intern/cycles/bvh/bvh_node.h +++ b/intern/cycles/bvh/bvh_node.h @@ -94,6 +94,9 @@ public: uint update_visibility(); void update_time(); + /* Dump the content of the tree as a graphviz file. */ + void dump_graph(const char *filename); + // Properties. BoundBox bounds; uint visibility; |