Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2014-04-15 18:06:12 +0400
committerLukas Tönne <lukas.toenne@gmail.com>2014-04-15 18:28:10 +0400
commit09874df135888b89f51d7becaa369ebb1d1623c6 (patch)
treebccf5950d42963992adff95dbc3f00ed7db1cf16 /source/blender/compositor/intern/COM_Node.h
parent28a829893c702918afc5ac1945a06eaefa611594 (diff)
Structural cleanup and improvements for the compositor.
Many parts of the compositor are unnecessarily complicated. This patch aims at reducing the complexity of writing nodes and making the code more transparent. == Separating Nodes and Operations == Currently these are both mixed in the same graph, even though they have very different purposes and are used at distinct stages in the compositing process. The patch introduces dedicated graph classes for nodes and for operations. This removes the need for a lot of special case checks (isOperation etc.) and explicit type casts. It simplifies the code since it becomes clear at every stage what type of node we are dealing with. The compiler can use static typing to avoid common bugs from mixing up these types and fewer runtime sanity checks are needed. == Simplified Node Conversion == Converting nodes to operations was previously based on "relinking", i.e. nodes would start with by mirroring links in the Blender DNA node trees, then add operations and redirect these links to them. This was very hard to follow in many cases and required a lot of attention to avoid invalid states. Now there is a helper class called the NodeConverter, which is passed to nodes and implements a much simpler API for this process. Nodes can add operations and explicit connections as before, but defining "external" links to the inputs/outputs of the original node now uses mapping instead of directly modifying link data. Input data (node graph) and result (operations graph) are cleanly separated. == Removed Redundant Data Structures == A few redundant data structures have been removed, notably the SocketConnection. These are only needed temporarily during graph construction. For executing the compositor operations it is perfectly sufficient to store only the direct input link pointers. A common pointer indirection is avoided this way (which might also give a little performance improvement). == Avoid virtual recursive functions == Recursive virtual functions are evil. They are very hard to follow during debugging. At least in the parts this patch is concerned with these functions have been replaced by a non-virtual recursive core function (which might then call virtual non-recursive functions if needed). See for example NodeOperationBuilder::group_operations.
Diffstat (limited to 'source/blender/compositor/intern/COM_Node.h')
-rw-r--r--source/blender/compositor/intern/COM_Node.h234
1 files changed, 173 insertions, 61 deletions
diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h
index c14a1973da5..6046af24c55 100644
--- a/source/blender/compositor/intern/COM_Node.h
+++ b/source/blender/compositor/intern/COM_Node.h
@@ -23,32 +23,50 @@
#ifndef __COM_NODE_H__
#define __COM_NODE_H__
-#include "COM_NodeBase.h"
-#include "COM_InputSocket.h"
-#include "COM_OutputSocket.h"
-#include "COM_CompositorContext.h"
#include "DNA_node_types.h"
#include "BKE_text.h"
-#include "COM_ExecutionSystem.h"
#include <vector>
#include <string>
#include <algorithm>
-using namespace std;
+/* common node includes
+ * added here so node files don't have to include themselves
+ */
+#include "COM_CompositorContext.h"
+#include "COM_NodeConverter.h"
class Node;
class NodeOperation;
-class ExecutionSystem;
-
-typedef vector<Node *> NodeList;
-typedef NodeList::iterator NodeIterator;
-typedef pair<NodeIterator, NodeIterator> NodeRange;
+class NodeConverter;
/**
* My node documentation.
*/
-class Node : public NodeBase {
+class Node {
+public:
+ typedef std::vector<NodeInput *> Inputs;
+ typedef std::vector<NodeOutput *> Outputs;
+
private:
+ /**
+ * @brief stores the reference to the SDNA bNode struct
+ */
+ bNodeTree *m_editorNodeTree;
+
+ /**
+ * @brief stores the reference to the SDNA bNode struct
+ */
+ bNode *m_editorNode;
+
+ /**
+ * @brief the list of actual inputsockets @see NodeInput
+ */
+ Inputs m_inputsockets;
+
+ /**
+ * @brief the list of actual outputsockets @see NodeOutput
+ */
+ Outputs m_outputsockets;
/**
* @brief Is this node part of the active group
@@ -60,10 +78,81 @@ private:
*/
bNodeInstanceKey m_instanceKey;
+protected:
+ /**
+ * @brief get access to the vector of input sockets
+ */
+ const Inputs &getInputSockets() const { return this->m_inputsockets; }
+
+ /**
+ * @brief get access to the vector of input sockets
+ */
+ const Outputs &getOutputSockets() const { return this->m_outputsockets; }
+
public:
Node(bNode *editorNode, bool create_sockets = true);
+ virtual ~Node();
+
+ /**
+ * @brief get the reference to the SDNA bNode struct
+ */
+ bNode *getbNode() const {return m_editorNode;}
/**
+ * @brief get the reference to the SDNA bNodeTree struct
+ */
+ bNodeTree *getbNodeTree() const {return m_editorNodeTree;}
+
+ /**
+ * @brief set the reference to the bNode
+ * @note used in Node instances to receive the storage/settings and complex node for highlight during execution
+ * @param bNode
+ */
+ void setbNode(bNode *node) {this->m_editorNode = node;}
+
+ /**
+ * @brief set the reference to the bNodeTree
+ * @param bNodeTree
+ */
+ void setbNodeTree(bNodeTree *nodetree) {this->m_editorNodeTree = nodetree;}
+
+ /**
+ * @brief Return the number of input sockets of this node.
+ */
+ const unsigned int getNumberOfInputSockets() const { return this->m_inputsockets.size(); }
+
+ /**
+ * @brief Return the number of output sockets of this node.
+ */
+ const unsigned int getNumberOfOutputSockets() const { return this->m_outputsockets.size(); }
+
+ /**
+ * get the reference to a certain outputsocket
+ * @param index
+ * the index of the needed outputsocket
+ */
+ NodeOutput *getOutputSocket(const unsigned int index) const;
+
+ /**
+ * get the reference to the first outputsocket
+ * @param index
+ * the index of the needed outputsocket
+ */
+ inline NodeOutput *getOutputSocket() const { return getOutputSocket(0); }
+
+ /**
+ * get the reference to a certain inputsocket
+ * @param index
+ * the index of the needed inputsocket
+ */
+ NodeInput *getInputSocket(const unsigned int index) const;
+
+ /** Check if this is an input node
+ * An input node is a node that only has output sockets and no input sockets
+ */
+ bool isInputNode() const { return m_inputsockets.empty(); }
+
+ /**
* @brief Is this node in the active group (the group that is being edited)
* @param isInActiveGroup
*/
@@ -75,7 +164,7 @@ public:
* the active group will be the main tree (all nodes that are not part of a group will be active)
* @return bool [false:true]
*/
- inline bool isInActiveGroup() { return this->m_inActiveGroup; }
+ inline bool isInActiveGroup() const { return this->m_inActiveGroup; }
/**
* @brief convert node to operation
@@ -85,76 +174,99 @@ public:
* @param system the ExecutionSystem where the operations need to be added
* @param context reference to the CompositorContext
*/
- virtual void convertToOperations(ExecutionSystem *system, CompositorContext *context) = 0;
-
- /**
- * this method adds a SetValueOperation as input of the input socket.
- * This can only be used from the convertToOperation method. all other usages are not allowed
- */
- void addSetValueOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex);
-
- /**
- * this method adds a SetColorOperation as input of the input socket.
- * This can only be used from the convertToOperation method. all other usages are not allowed
- */
- void addSetColorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex);
-
- /**
- * this method adds a SetVectorOperation as input of the input socket.
- * This can only be used from the convertToOperation method. all other usages are not allowed
- */
- void addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex);
+ virtual void convertToOperations(NodeConverter &converter, const CompositorContext &context) const = 0;
/**
* Create dummy warning operation, use when we can't get the source data.
*/
- NodeOperation *convertToOperations_invalid_index(ExecutionSystem *graph, int index);
+ NodeOperation *convertToOperations_invalid_index(NodeConverter *compiler, int index) const;
/**
* when a node has no valid data (missing image or a group nodes ID pointer is NULL)
* call this function from #convertToOperations, this way the node sockets are converted
* into valid outputs, without this the compositor system gets confused and crashes, see [#32490]
*/
- void convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context);
-
- /**
- * Creates a new link between an outputSocket and inputSocket and registrates the link to the graph
- * @return the new created link
- */
- SocketConnection *addLink(ExecutionSystem *graph, OutputSocket *outputSocket, InputSocket *inputsocket);
+ void convertToOperations_invalid(NodeConverter *compiler) const;
+ void setInstanceKey(bNodeInstanceKey instance_key) { m_instanceKey = instance_key; }
+ bNodeInstanceKey getInstanceKey() const { return m_instanceKey; }
+
+protected:
/**
- * is this node a group node.
- */
- virtual bool isGroupNode() const { return false; }
- /**
- * is this node a proxy node.
+ * @brief add an NodeInput to the collection of inputsockets
+ * @note may only be called in an constructor
+ * @param socket the NodeInput to add
*/
- virtual bool isProxyNode() const { return false; }
+ void addInputSocket(DataType datatype);
+ void addInputSocket(DataType datatype, bNodeSocket *socket);
/**
- * @brief find the InputSocket by bNodeSocket
- *
- * @param socket
+ * @brief add an NodeOutput to the collection of outputsockets
+ * @note may only be called in an constructor
+ * @param socket the NodeOutput to add
*/
- InputSocket *findInputSocketBybNodeSocket(bNodeSocket *socket);
+ void addOutputSocket(DataType datatype);
+ void addOutputSocket(DataType datatype, bNodeSocket *socket);
+
+ bNodeSocket *getEditorInputSocket(int editorNodeInputSocketIndex);
+ bNodeSocket *getEditorOutputSocket(int editorNodeOutputSocketIndex);
+};
+
+
+/**
+ * @brief NodeInput are sockets that can receive data/input
+ * @ingroup Model
+ */
+class NodeInput {
+private:
+ Node *m_node;
+ bNodeSocket *m_editorSocket;
+
+ DataType m_datatype;
/**
- * @brief find the OutputSocket by bNodeSocket
- *
- * @param socket
+ * @brief link connected to this NodeInput.
+ * An input socket can only have a single link
*/
- OutputSocket *findOutputSocketBybNodeSocket(bNodeSocket *socket);
+ NodeOutput *m_link;
- void setInstanceKey(bNodeInstanceKey instance_key) { m_instanceKey = instance_key; }
- bNodeInstanceKey getInstanceKey() const { return m_instanceKey; }
+public:
+ NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype);
-protected:
- void addPreviewOperation(ExecutionSystem *system, CompositorContext *context, InputSocket *inputSocket);
- void addPreviewOperation(ExecutionSystem *system, CompositorContext *context, OutputSocket *outputSocket);
+ Node *getNode() const { return this->m_node; }
+ DataType getDataType() const { return m_datatype; }
+ bNodeSocket *getbNodeSocket() const { return this->m_editorSocket; }
- bNodeSocket *getEditorInputSocket(int editorNodeInputSocketIndex);
- bNodeSocket *getEditorOutputSocket(int editorNodeOutputSocketIndex);
+ void setLink(NodeOutput *link);
+ bool isLinked() const { return m_link; }
+ NodeOutput *getLink() { return m_link; }
+
+ float getEditorValueFloat();
+ void getEditorValueColor(float *value);
+ void getEditorValueVector(float *value);
+};
+
+
+/**
+ * @brief NodeOutput are sockets that can send data/input
+ * @ingroup Model
+ */
+class NodeOutput {
private:
+ Node *m_node;
+ bNodeSocket *m_editorSocket;
+
+ DataType m_datatype;
+
+public:
+ NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype);
+
+ Node *getNode() const { return this->m_node; }
+ DataType getDataType() const { return m_datatype; }
+ bNodeSocket *getbNodeSocket() const { return this->m_editorSocket; }
+
+ float getEditorValueFloat();
+ void getEditorValueColor(float *value);
+ void getEditorValueVector(float *value);
};
#endif /* __COM_NODE_H__ */