[Bf-blender-cvs] [c30b64c] depsgraph_refactor: Depsgraph WIP: Start of OGDF graph export

Joshua Leung noreply at git.blender.org
Thu Jan 29 14:13:00 CET 2015


Commit: c30b64c7c3b31e600f01c7ccacee1495cf9dbb78
Author: Joshua Leung
Date:   Fri Jan 30 00:22:38 2015 +1300
Branches: depsgraph_refactor
https://developer.blender.org/rBc30b64c7c3b31e600f01c7ccacee1495cf9dbb78

Depsgraph WIP: Start of OGDF graph export

Useful Notes:
* The OGDF headers have to come before the Blender ones, or else the code will
  NOT compile under mingw64 (and potentially a few others). In particular, this
  results in many non-sensical errors in windef.h, windows.h, and winreg.h, potentially
  arising from redefined or already defined constants.

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

M	source/blender/depsgraph/SConscript
A	source/blender/depsgraph/intern/depsgraph_debug_ogdf.cpp

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

diff --git a/source/blender/depsgraph/SConscript b/source/blender/depsgraph/SConscript
index 904d54e..54d5d17 100644
--- a/source/blender/depsgraph/SConscript
+++ b/source/blender/depsgraph/SConscript
@@ -67,6 +67,9 @@ else:
 if env['WITH_BF_LEGACY_DEPSGRAPH']:
     defs.append('WITH_LEGACY_DEPSGRAPH')
 
+if env['WITH_BF_OGDF']:
+	incs.append('#/extern/ogdf')
+
 env.BlenderLib(libname='bf_depsgraph', sources=sources,
                includes=incs, defines=defs,
                libtype=['core', 'player'], priority=[200, 40])
diff --git a/source/blender/depsgraph/intern/depsgraph_debug_ogdf.cpp b/source/blender/depsgraph/intern/depsgraph_debug_ogdf.cpp
new file mode 100644
index 0000000..66040f4
--- /dev/null
+++ b/source/blender/depsgraph/intern/depsgraph_debug_ogdf.cpp
@@ -0,0 +1,322 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Joshua Leung
+ * Contributor(s): None Yet
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * Implementation of tools for debugging the depsgraph using OGDF
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <ogdf/basic/Graph.h>
+#include <ogdf/layered/OptimalHierarchyLayout.h>
+
+extern "C" {
+#include "BLI_listbase.h"
+#include "BLI_ghash.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
+
+#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_build.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+}  /* extern "C" */
+
+#include "depsgraph_debug.h"
+#include "depsnode.h"
+#include "depsnode_component.h"
+#include "depsnode_operation.h"
+#include "depsgraph_types.h"
+#include "depsgraph_intern.h"
+
+using namespace ogdf;
+
+/* ****************** */
+/* OGDF Debugging */
+
+struct DebugContext {
+	FILE *file;
+
+	Graph *outgraph;
+
+	bool show_tags;
+	bool show_eval_priority;
+
+	bool show_owner_links;
+	bool show_rel_labels;
+};
+
+static void deg_debug_ogdf_graph_nodes(const DebugContext &ctx, const Depsgraph *graph);
+static void deg_debug_ogdf_graph_relations(const DebugContext &ctx, const Depsgraph *graph);
+
+/* -------------------------------- */
+
+static void deg_debug_ogdf_node_single(const DebugContext &ctx, const DepsNode *node)
+{
+	const char *shape = "box";
+	string name = node->identifier();
+	float priority = -1.0f;
+	if (node->type == DEPSNODE_TYPE_ID_REF) {
+		IDDepsNode *id_node = (IDDepsNode *)node;
+		char buf[256];
+		BLI_snprintf(buf, sizeof(buf), " (Layers: %d)", id_node->layers);
+		name += buf;
+	}
+	if (ctx.show_eval_priority && node->tclass == DEPSNODE_CLASS_OPERATION) {
+		priority = ((OperationDepsNode *)node)->eval_priority;
+	}
+
+#if 0
+	deg_debug_fprintf(ctx, "// %s\n", name.c_str());
+	deg_debug_fprintf(ctx, "\"node_%p\"", node);
+	deg_debug_fprintf(ctx, "[");
+	//	deg_debug_fprintf(ctx, "label=<<B>%s</B>>", name);
+	if (priority >= 0.0f) {
+		deg_debug_fprintf(ctx, "label=<%s<BR/>(<I>%.2f</I>)>",
+			name.c_str(),
+			priority);
+	}
+	else {
+		deg_debug_fprintf(ctx, "label=<%s>", name.c_str());
+	}
+	deg_debug_fprintf(ctx, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
+	deg_debug_fprintf(ctx, ",fontsize=%f", deg_debug_graphviz_node_label_size);
+	deg_debug_fprintf(ctx, ",shape=%s", shape);
+	deg_debug_fprintf(ctx, ",style="); deg_debug_graphviz_node_style(ctx, node);
+	deg_debug_fprintf(ctx, ",color="); deg_debug_graphviz_node_color(ctx, node);
+	deg_debug_fprintf(ctx, ",fillcolor="); deg_debug_graphviz_node_fillcolor(ctx, node);
+	deg_debug_fprintf(ctx, ",penwidth="); deg_debug_graphviz_node_penwidth(ctx, node);
+	deg_debug_fprintf(ctx, "];" NL);
+	deg_debug_fprintf(ctx, NL);
+#endif
+}
+
+static void deg_debug_ogdf_node(const DebugContext &ctx, const DepsNode *node)
+{
+	switch (node->type) {
+		case DEPSNODE_TYPE_ID_REF:
+		{
+			const IDDepsNode *id_node = (const IDDepsNode *)node;
+			if (id_node->components.empty()) {
+				deg_debug_ogdf_node_single(ctx, node);
+			}
+			else {
+				for (IDDepsNode::ComponentMap::const_iterator it = id_node->components.begin();
+					it != id_node->components.end();
+					++it)
+				{
+					const ComponentDepsNode *comp = it->second;
+					deg_debug_ogdf_node(ctx, comp);
+				}
+			}
+			break;
+		}
+		case DEPSNODE_TYPE_SUBGRAPH:
+		{
+			SubgraphDepsNode *sub_node = (SubgraphDepsNode *)node;
+			if (sub_node->graph) {
+				//deg_debug_graphviz_node_cluster_begin(ctx, node);
+				deg_debug_ogdf_graph_nodes(ctx, sub_node->graph);
+				//deg_debug_graphviz_node_cluster_end(ctx);
+			}
+			else {
+				deg_debug_ogdf_node_single(ctx, node);
+			}
+			break;
+		}
+		case DEPSNODE_TYPE_PARAMETERS:
+		case DEPSNODE_TYPE_ANIMATION:
+		case DEPSNODE_TYPE_TRANSFORM:
+		case DEPSNODE_TYPE_PROXY:
+		case DEPSNODE_TYPE_GEOMETRY:
+		case DEPSNODE_TYPE_SEQUENCER:
+		case DEPSNODE_TYPE_EVAL_POSE:
+		case DEPSNODE_TYPE_BONE:
+		case DEPSNODE_TYPE_SHADING:
+		{
+			ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
+			if (!comp_node->operations.empty()) {
+				for (ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
+					it != comp_node->operations.end();
+					++it)
+				{
+					const DepsNode *op_node = it->second;
+					deg_debug_ogdf_node(ctx, op_node);
+				}
+			}
+			else {
+				deg_debug_ogdf_node_single(ctx, node);
+			}
+			break;
+		}
+		default:
+			deg_debug_ogdf_node_single(ctx, node);
+			break;
+	}
+}
+
+static void deg_debug_ogdf_graph_nodes(const DebugContext &ctx, const Depsgraph *graph)
+{
+	if (graph->root_node) {
+		deg_debug_ogdf_node(ctx, graph->root_node);
+	}
+	for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
+		it != graph->id_hash.end();
+		++it)
+	{
+		DepsNode *node = it->second;
+		deg_debug_ogdf_node(ctx, node);
+	}
+	TimeSourceDepsNode *time_source = graph->find_time_source(NULL);
+	if (time_source != NULL) {
+		deg_debug_ogdf_node(ctx, time_source);
+	}
+}
+
+/* -------------------------------- */
+
+static void deg_debug_ogdf_node_relations(const DebugContext &ctx, const DepsNode *node)
+{
+	DEPSNODE_RELATIONS_ITER_BEGIN(node->inlinks, rel)
+	{
+		const DepsNode *tail = rel->to; /* same as node */
+		const DepsNode *head = rel->from;
+
+		// XXX: IMPLEMENT ME!
+		(void)tail;
+		(void)head;
+	}
+	DEPSNODE_RELATIONS_ITER_END;
+
+#if 0
+	if (node->tclass == DEPSNODE_CLASS_COMPONENT) {
+		const ComponentDepsNode *comp_node = (const ComponentDepsNode *)node;
+		for (ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
+			 it != comp_node->operations.end();
+			 ++it)
+		{
+			OperationDepsNode *op_node = it->second;
+			deg_debug_ogdf_node_relations(ctx, op_node);
+		}
+	}
+	else if (node->type == DEPSNODE_TYPE_ID_REF) {
+		const IDDepsNode *id_node = (const IDDepsNode *)node;
+		for (IDDepsNode::ComponentMap::const_iterator it = id_node->components.begin();
+			 it != id_node->components.end();
+			 ++it)
+		{
+			const ComponentDepsNode *comp = it->second;
+			deg_debug_ogdf_node_relations(ctx, comp);
+		}
+	}
+	else if (node->type == DEPSNODE_TYPE_SUBGRAPH) {
+		SubgraphDepsNode *sub_node = (SubgraphDepsNode *)node;
+		if (sub_node->graph) {
+			deg_debug_ogdf_graph_relations(ctx, sub_node->graph);
+		}
+	}
+#endif
+}
+
+static void deg_debug_ogdf_graph_relations(const DebugContext &ctx, const Depsgraph *graph)
+{
+#if 0
+	if (graph->root_node) {
+		deg_debug_ogdf_node_relations(ctx, graph->root_node);
+	}
+	for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
+		it != graph->id_hash.end();
+		++it)
+	{
+		DepsNode *id_node = it->second;
+		deg_debug_ogdf_node_relations(ctx, id_node);
+	}
+#else
+	for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
+		it != graph->id_hash.end();
+		++it)
+	{
+		IDDepsNode *id_node = it->second;
+		for (IDDepsNode::ComponentMap::const_iterator it = id_node->components.begin();
+			it != id_node->components.end();
+			++it)
+		{
+			ComponentDepsNode *comp_node = it->second;
+			for (ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
+				it != comp_node->operations.end();
+				++it)
+			{
+				OperationDepsNode *op_node = it->second;
+				deg_debug_ogdf_node_relations(ctx, op_node);
+			}
+		}
+	}
+
+	TimeSourceDepsNode *time_source = graph->find_time_source(NULL);
+	if (time_source != NULL) {
+		deg_debug_ogdf_node_relations(ctx, time_source);
+	}
+#endif
+}
+
+/* -------------------------------- */
+
+void DEG_debug_ogdf(const Depsgraph *graph, FILE *f, const char *label)
+{
+	if (!graph) {
+		return;
+	}
+
+	/* create OGDF graph */
+	Graph outgraph;
+
+	GraphAttributes GA(outgraph, GraphAttributes::nodeGraphics |
+					   GraphAttributes::edgeGraphics |
+					   GraphAttributes::nodeLabel |
+					   GraphAttributes::nodeStyle |
+					   GraphAttributes::edgeType |
+					   GraphAttributes::edgeArrow |
+					   GraphAttributes::edgeStyle);
+
+	/* build OGDF graph from depsgraph */
+	DebugContext ctx;
+
+	ctx.outgraph = &outgraph;
+	ctx.file = f;
+	ctx.show_eval_priority = false;
+
+	
+	deg_debug_ogdf_graph_nodes(ctx, graph);
+	deg_debug_ogdf_graph_relations(ctx, graph);
+
+	/* export it */
+
+}
+
+/* ****************** */
+




More information about the Bf-blender-cvs mailing list