[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42580] branches/tile/source/blender/ compositor: Generalization of group node conversion in the new compositor.

Lukas Toenne lukas.toenne at googlemail.com
Mon Dec 12 11:22:41 CET 2011


Revision: 42580
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42580
Author:   lukastoenne
Date:     2011-12-12 10:22:34 +0000 (Mon, 12 Dec 2011)
Log Message:
-----------
Generalization of group node conversion in the new compositor.

This allows groups inside groups to work and also simplifies the code a lot.

* Ungrouping of group nodes ("expanding" might be a better name?) is
done as part of the general addNodeTree function now. This way the
ungrouping happens recursively on all levels of group nodes.
* The adding of a node tree works in three basic steps:
 1) Add all nodes, including group nodes (ignoring internals of the
group at this point)
 2) Add links between nodes (again, no group internals here)
 3) Expand all newly added group nodes from this tree, which replaces
them with internal nodes and proxy nodes for inputs and outputs.
* Expanding the node tree works different now:
 1) First add proxy nodes for all input/output sockets. The group
node sockets are then reconnected to the "outer" proxy sockets, while
the internal group sockets (sock->groupsock) are assigned to the
"inner" proxy sockets.
 2) Then the actual inner node tree is added, which connects internal
nodes to the proxies
 An important change is that the list of nodes, which is used to look
up link targets by their bNode/bNodeSocket pairs, is now limited to
the nodes added from the current tree (including proxies from the
group). This is necessary to avoid ambiguous assignments from other
instances of the same group node type!
 An advantage is also that now no more special group socket pointers
and "insideGroup" flags are needed for the Socket class, making the
code a bit simpler.
* Currently the "actual data type" is not converted on proxy
nodes (XXX TODO in the patch), this should be revisited.

Modified Paths:
--------------
    branches/tile/source/blender/compositor/intern/COM_ExecutionSystem.cpp
    branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
    branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.h
    branches/tile/source/blender/compositor/intern/COM_InputSocket.cpp
    branches/tile/source/blender/compositor/intern/COM_InputSocket.h
    branches/tile/source/blender/compositor/intern/COM_Node.cpp
    branches/tile/source/blender/compositor/intern/COM_Node.h
    branches/tile/source/blender/compositor/intern/COM_OutputSocket.cpp
    branches/tile/source/blender/compositor/intern/COM_OutputSocket.h
    branches/tile/source/blender/compositor/intern/COM_Socket.cpp
    branches/tile/source/blender/compositor/intern/COM_Socket.h
    branches/tile/source/blender/compositor/nodes/COM_GroupNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_GroupNode.h
    branches/tile/source/blender/compositor/nodes/COM_SocketProxyNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_SocketProxyNode.h

Modified: branches/tile/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2011-12-12 09:28:46 UTC (rev 42579)
+++ branches/tile/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2011-12-12 10:22:34 UTC (rev 42580)
@@ -52,11 +52,10 @@
 
 	Node* mainOutputNode=NULL;
 
-	mainOutputNode = ExecutionSystemHelper::addbNodeTree(this->getNodes(), this->getConnections(), editingtree);
+	mainOutputNode = ExecutionSystemHelper::addbNodeTree(*this, 0, editingtree);
 
 	if (mainOutputNode) {
 		context.setScene((Scene*)mainOutputNode->getbNode()->id);
-		ExecutionSystemHelper::ungroup(*this); /* copy subtrees of GroupNode in main tree, so only the main tree needs to be evaluated (reduces complexity) */
 		this->convertToOperations();
 		this->groupOperations(); /* group operations in ExecutionGroups */
 		vector<ExecutionGroup*> executionGroups;

Modified: branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2011-12-12 09:28:46 UTC (rev 42579)
+++ branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp	2011-12-12 10:22:34 UTC (rev 42580)
@@ -37,25 +37,39 @@
 #include "COM_WriteBufferOperation.h"
 #include "COM_ReadBufferOperation.h"
 
-Node* ExecutionSystemHelper::addbNodeTree(vector<Node*>& nodes, vector<SocketConnection*>& links, bNodeTree *tree) {
-    Node* mainnode = NULL;
+Node* ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_start, bNodeTree *tree) {
+	vector<Node*>& nodes = system.getNodes();
+	vector<SocketConnection*>& links = system.getConnections();
+	Node* mainnode = NULL;
 	/* add all nodes of the tree to the node list */
-    bNode* node = (bNode*)tree->nodes.first;
-    while (node != NULL) {
+	bNode* node = (bNode*)tree->nodes.first;
+	while (node != NULL) {
 		Node* execnode = addNode(nodes, node);
-        if (node->type == CMP_NODE_COMPOSITE) {
-            mainnode = execnode;
-        }
-        node = (bNode*)node->next;
-    }
+		if (node->type == CMP_NODE_COMPOSITE) {
+			mainnode = execnode;
+		}
+		node = (bNode*)node->next;
+	}
 
+	NodeRange node_range(nodes.begin()+nodes_start, nodes.end());
+
 	/* add all nodelinks of the tree to the link list */
 	bNodeLink* nodelink = (bNodeLink*)tree->links.first;
-    while (nodelink != NULL) {
-			addNodeLink(nodes, links, nodelink);
-			nodelink = (bNodeLink*)nodelink->next;
-    }
-    return mainnode;
+	while (nodelink != NULL) {
+		addNodeLink(node_range, links, nodelink);
+		nodelink = (bNodeLink*)nodelink->next;
+	}
+
+	/* Expand group nodes */
+	for (int i=nodes_start; i < nodes.size(); ++i) {
+		Node *execnode = nodes[i];
+		if (execnode->isGroupNode()) {
+			GroupNode * groupNode = (GroupNode*)execnode;
+			groupNode->ungroup(system);
+		}
+	}
+
+	return mainnode;
 }
 
 void ExecutionSystemHelper::addNode(vector<Node*>& nodes, Node *node) {
@@ -91,8 +105,45 @@
 	}
 }
 
-
-SocketConnection* ExecutionSystemHelper::addNodeLink(vector<Node*>& nodes, vector<SocketConnection*>& links, bNodeLink *bNodeLink) {
+static InputSocket* find_input(NodeRange &node_range, bNode *bnode, bNodeSocket* bsocket) {
+	if (bnode != NULL) {
+		for(NodeIterator it=node_range.first; it!=node_range.second; ++it) {
+			Node* node = *it;
+			if (node->getbNode() == bnode)
+				return node->findInputSocketBybNodeSocket(bsocket);
+		}
+	} else {
+		for(NodeIterator it=node_range.first; it!=node_range.second; ++it) {
+			Node* node = *it;
+			if (node->isProxyNode()) {
+				InputSocket *proxySocket = node->getInputSocket(0);
+				if (proxySocket->getbNodeSocket()==bsocket)
+					return proxySocket;
+			}
+		}
+	}
+	return NULL;
+}
+static OutputSocket* find_output(NodeRange &node_range, bNode *bnode, bNodeSocket* bsocket) {
+	if (bnode != NULL) {
+		for(NodeIterator it=node_range.first; it!=node_range.second; ++it) {
+			Node* node = *it;
+			if (node->getbNode() == bnode)
+				return node->findOutputSocketBybNodeSocket(bsocket);
+		}
+	} else {
+		for(NodeIterator it=node_range.first; it!=node_range.second; ++it) {
+			Node* node = *it;
+			if (node->isProxyNode()) {
+				OutputSocket *proxySocket = node->getOutputSocket(0);
+				if (proxySocket->getbNodeSocket()==bsocket)
+					return proxySocket;
+			}
+		}
+	}
+	return NULL;
+}
+SocketConnection* ExecutionSystemHelper::addNodeLink(NodeRange &node_range, vector<SocketConnection*>& links, bNodeLink *bNodeLink) {
 	/// @note: cyclic lines will be ignored. This has been copied from node.c
 	if (bNodeLink->tonode != 0 && bNodeLink->fromnode != 0) {
 		if(!(bNodeLink->fromnode->level >= bNodeLink->tonode->level && bNodeLink->tonode->level!=0xFFF)) { // only add non cyclic lines! so execution will procede
@@ -100,11 +151,8 @@
 		}
 	}
 
-	Node* fromNode = findNodeBybNode(nodes, bNodeLink->fromnode, bNodeLink->fromsock);
-	Node* toNode = findNodeBybNode(nodes, bNodeLink->tonode, bNodeLink->tosock);
-
-	OutputSocket *outputSocket = fromNode->findOutputSocketBybNodeSocket(bNodeLink->fromsock);
-	InputSocket *inputSocket = toNode->findInputSocketBybNodeSocket(bNodeLink->tosock);
+	InputSocket *inputSocket = find_input(node_range, bNodeLink->tonode, bNodeLink->tosock);
+	OutputSocket *outputSocket = find_output(node_range, bNodeLink->fromnode, bNodeLink->fromsock);
 	if (inputSocket == NULL || outputSocket == NULL) {
 		return NULL;
 	}
@@ -124,60 +172,3 @@
 	links.push_back(newconnection);
 	return newconnection;
 }
-
-
-bool ExecutionSystemHelper::containsbNodeSocket(bNode *bnode, bNodeSocket* bsocket) {
-	bNodeSocket *socket = (bNodeSocket*)bnode->inputs.first;
-	while (socket != NULL) {
-		if (socket->groupsock == bsocket) {
-			return true;
-		}
-		socket = (bNodeSocket*)socket->next;
-	}
-	socket = (bNodeSocket*)bnode->outputs.first;
-	while (socket != NULL) {
-		if (socket->groupsock == bsocket) {
-			return true;
-		}
-		socket = (bNodeSocket*)socket->next;
-	}
-
-	return false;
-}
-
-
-Node* ExecutionSystemHelper::findNodeBybNode(vector<Node*>& nodes, bNode *bnode, bNodeSocket* bsocket) {
-	unsigned int index;
-	if (bnode != NULL) {
-		for(index = 0; index < nodes.size(); index++) {
-			Node* node = nodes[index];
-			if (node->getbNode() == bnode) {
-				return node;
-			}
-		}
-	} else {
-		// only look in the GroupNodes.
-		for(index = 0; index < nodes.size(); index++) {
-			Node* node = nodes[index];
-			if (node->isGroupNode()) {
-				bNode *bnode = node->getbNode();
-				if (containsbNodeSocket(bnode, bsocket)) {
-					return node;
-				}
-			}
-		}
-	}
-	return NULL;
-}
-
-void ExecutionSystemHelper::ungroup(ExecutionSystem &system) {
-	unsigned int index;
-	vector<Node*> &nodes = system.getNodes();
-	for(index = 0; index < nodes.size(); index++) {
-		Node* node = nodes[index];
-		if (node->isGroupNode()) {
-			GroupNode * groupNode = (GroupNode*)node;
-			groupNode->ungroup(system);
-		}
-	}
-}

Modified: branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.h
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.h	2011-12-12 09:28:46 UTC (rev 42579)
+++ branches/tile/source/blender/compositor/intern/COM_ExecutionSystemHelper.h	2011-12-12 10:22:34 UTC (rev 42580)
@@ -43,12 +43,12 @@
 
 	/**
 	  * @brief add an bNodeTree to the nodes list and connections
-	  * @param nodes vector of nodes
-	  * @param links vector of links
+	  * @param system Execution system
+	  * @param nodes_start Starting index in the system's nodes list for nodes in this tree.
 	  * @param tree bNodeTree to add
 	  * @return Node representing the "Compositor node" of the maintree. or NULL when a subtree is added
 	  */
-	static Node* addbNodeTree(vector<Node*>& nodes, vector<SocketConnection*>& links, bNodeTree * tree);
+	static Node* addbNodeTree(ExecutionSystem &system, int nodes_start, bNodeTree * tree);
 
 	/**
 	  * @brief add an editor node to the system.
@@ -89,15 +89,6 @@
 	static void addExecutionGroup(vector<ExecutionGroup*>& executionGroups, ExecutionGroup *executionGroup);
 
 	/**
-	  * @brief find the first node that contains the bNode
-	  *
-	  * @param nodes list of nodes where to look in
-	  * @param node bNode that needs to be found. Can be NULL for Group nodes
-	  * @param bsocket For Group nodes the socket is used to determine the Node.
-	  */
-	static Node* findNodeBybNode(vector<Node*>& nodes, bNode* node, bNodeSocket* bsocket);
-
-	/**
 	  * Find all Node Operations that needs to be executed.
 	  * @param rendering
 	  * the rendering parameter will tell what type of execution we are doing
@@ -111,34 +102,14 @@
 	  *
 	  * @note Cyclic links will be ignored
 	  *
-	  * @param nodes list of nodes
+	  * @param node_range list of possible nodes for lookup.
 	  * @param links list of links to add the bNodeLink to
 	  * @param bNodeLink the link to be added
 	  * @return the created SocketConnection or NULL
 	  */
-	static SocketConnection* addNodeLink(vector<Node*>& nodes, vector<SocketConnection*>& links, bNodeLink *bNodeLink);
+	static SocketConnection* addNodeLink(NodeRange &node_range, vector<SocketConnection*>& links, bNodeLink *bNodeLink);
 
 	/**
-	  * @brief check whether bnode contains bsocket
-	  *
-	  * @note only works for group nodes
-	  *
-	  * @param bnode node to look in
-	  * @param bsocket socket to look for
-	  */
-	static bool containsbNodeSocket(bNode *bnode, bNodeSocket* bsocket);
-
-	/**
-	  * @brief Ungroup NodeGroup.
-	  *
-	  * The user can create Group of nodes. These groups are complex during execution. To reduce this complexity
-	  * these groups are flattened and removed.
-	  *
-	  * Ungroup will modify the connections and nodes list.
-	  */
-	static void ungroup(ExecutionSystem& system);
-
-	/**
 	  * @brief create a new SocketConnection and add to a vector of links
 	  * @param links the vector of links
 	  * @param fromSocket the startpoint of the connection

Modified: branches/tile/source/blender/compositor/intern/COM_InputSocket.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_InputSocket.cpp	2011-12-12 09:28:46 UTC (rev 42579)
+++ branches/tile/source/blender/compositor/intern/COM_InputSocket.cpp	2011-12-12 10:22:34 UTC (rev 42580)
@@ -28,26 +28,19 @@
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list