[Bf-blender-cvs] [1a6a80270da] blender2.7: Cycles: Add utility to dump BVH tree as graphviz file

Sergey Sharybin noreply at git.blender.org
Wed Jan 9 12:56:36 CET 2019


Commit: 1a6a80270dae82d5ce9bf1266476f7bf0fe1d714
Author: Sergey Sharybin
Date:   Tue Jan 8 18:17:21 2019 +0100
Branches: blender2.7
https://developer.blender.org/rB1a6a80270dae82d5ce9bf1266476f7bf0fe1d714

Cycles: Add utility to dump BVH tree as graphviz file

===================================================================

M	intern/cycles/bvh/bvh_node.cpp
M	intern/cycles/bvh/bvh_node.h

===================================================================

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;



More information about the Bf-blender-cvs mailing list