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.cpp
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.cpp')
-rw-r--r--source/blender/compositor/intern/COM_Node.cpp235
1 files changed, 117 insertions, 118 deletions
diff --git a/source/blender/compositor/intern/COM_Node.cpp b/source/blender/compositor/intern/COM_Node.cpp
index b62e2d08d9a..67f4d2523f3 100644
--- a/source/blender/compositor/intern/COM_Node.cpp
+++ b/source/blender/compositor/intern/COM_Node.cpp
@@ -22,27 +22,32 @@
#include <string.h>
+extern "C" {
#include "BKE_node.h"
-#include "COM_Node.h"
-#include "COM_NodeOperation.h"
-#include "COM_SetValueOperation.h"
-#include "COM_SetVectorOperation.h"
-#include "COM_SetColorOperation.h"
-#include "COM_SocketConnection.h"
+#include "RNA_access.h"
+}
+
#include "COM_ExecutionSystem.h"
-#include "COM_PreviewOperation.h"
+#include "COM_NodeOperation.h"
#include "COM_TranslateOperation.h"
#include "COM_SocketProxyNode.h"
-//#include <stdio.h>
#include "COM_defines.h"
-Node::Node(bNode *editorNode, bool create_sockets) : NodeBase()
+#include "COM_Node.h" /* own include */
+
+/**************
+ **** Node ****
+ **************/
+
+Node::Node(bNode *editorNode, bool create_sockets) :
+ m_editorNodeTree(NULL),
+ m_editorNode(editorNode),
+ m_inActiveGroup(false),
+ m_instanceKey(NODE_INSTANCE_KEY_NONE)
{
- setbNode(editorNode);
-
if (create_sockets) {
bNodeSocket *input = (bNodeSocket *)editorNode->inputs.first;
while (input != NULL) {
@@ -50,7 +55,7 @@ Node::Node(bNode *editorNode, bool create_sockets) : NodeBase()
if (input->type == SOCK_RGBA) dt = COM_DT_COLOR;
if (input->type == SOCK_VECTOR) dt = COM_DT_VECTOR;
- this->addInputSocket(dt, (InputSocketResizeMode)input->resizemode, input);
+ this->addInputSocket(dt, input);
input = input->next;
}
bNodeSocket *output = (bNodeSocket *)editorNode->outputs.first;
@@ -65,102 +70,50 @@ Node::Node(bNode *editorNode, bool create_sockets) : NodeBase()
}
}
-void Node::addSetValueOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex)
+Node::~Node()
{
- InputSocket *input = getInputSocket(editorNodeInputSocketIndex);
- SetValueOperation *operation = new SetValueOperation();
- operation->setValue(input->getEditorValueFloat());
- this->addLink(graph, operation->getOutputSocket(), inputsocket);
- graph->addOperation(operation);
+ while (!this->m_outputsockets.empty()) {
+ delete (this->m_outputsockets.back());
+ this->m_outputsockets.pop_back();
+ }
+ while (!this->m_inputsockets.empty()) {
+ delete (this->m_inputsockets.back());
+ this->m_inputsockets.pop_back();
+ }
}
-void Node::addPreviewOperation(ExecutionSystem *system, CompositorContext *context, OutputSocket *outputSocket)
+void Node::addInputSocket(DataType datatype)
{
- if (this->isInActiveGroup()) {
- if (!(this->getbNode()->flag & NODE_HIDDEN)) { // do not calculate previews of hidden nodes.
- bNodeInstanceHash *previews = context->getPreviewHash();
- if (previews && (this->getbNode()->flag & NODE_PREVIEW)) {
- PreviewOperation *operation = new PreviewOperation(context->getViewSettings(), context->getDisplaySettings());
- system->addOperation(operation);
- operation->setbNode(this->getbNode());
- operation->setbNodeTree(system->getContext().getbNodeTree());
- operation->verifyPreview(previews, this->getInstanceKey());
- this->addLink(system, outputSocket, operation->getInputSocket(0));
- }
- }
- }
+ this->addInputSocket(datatype, NULL);
}
-void Node::addPreviewOperation(ExecutionSystem *system, CompositorContext *context, InputSocket *inputSocket)
+void Node::addInputSocket(DataType datatype, bNodeSocket *bSocket)
{
- if (inputSocket->isConnected() && this->isInActiveGroup()) {
- OutputSocket *outputsocket = inputSocket->getConnection()->getFromSocket();
- this->addPreviewOperation(system, context, outputsocket);
- }
+ NodeInput *socket = new NodeInput(this, bSocket, datatype);
+ this->m_inputsockets.push_back(socket);
}
-SocketConnection *Node::addLink(ExecutionSystem *graph, OutputSocket *outputSocket, InputSocket *inputsocket)
+void Node::addOutputSocket(DataType datatype)
{
- if (inputsocket->isConnected()) {
- return NULL;
- }
- SocketConnection *connection = new SocketConnection();
- connection->setFromSocket(outputSocket);
- outputSocket->addConnection(connection);
- connection->setToSocket(inputsocket);
- inputsocket->setConnection(connection);
- graph->addSocketConnection(connection);
- return connection;
-}
-
-void Node::addSetColorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex)
-{
- InputSocket *input = getInputSocket(editorNodeInputSocketIndex);
- SetColorOperation *operation = new SetColorOperation();
- float col[4];
- input->getEditorValueColor(col);
- operation->setChannel1(col[0]);
- operation->setChannel2(col[1]);
- operation->setChannel3(col[2]);
- operation->setChannel4(col[3]);
- this->addLink(graph, operation->getOutputSocket(), inputsocket);
- graph->addOperation(operation);
-}
-
-void Node::addSetVectorOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex)
-{
- InputSocket *input = getInputSocket(editorNodeInputSocketIndex);
- SetVectorOperation *operation = new SetVectorOperation();
- float vec[3];
- input->getEditorValueVector(vec);
- operation->setX(vec[0]);
- operation->setY(vec[1]);
- operation->setZ(vec[2]);
- this->addLink(graph, operation->getOutputSocket(), inputsocket);
- graph->addOperation(operation);
-}
-
-NodeOperation *Node::convertToOperations_invalid_index(ExecutionSystem *graph, int index)
-{
- const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
- SetColorOperation *operation = new SetColorOperation();
- operation->setChannels(warning_color);
-
- /* link the operation */
- this->getOutputSocket(index)->relinkConnections(operation->getOutputSocket());
- graph->addOperation(operation);
- return operation;
-}
-
-/* when a node has no valid data (missing image / group pointer, or missing renderlayer from EXR) */
-void Node::convertToOperations_invalid(ExecutionSystem *graph, CompositorContext *context)
-{
- /* this is a really bad situation - bring on the pink! - so artists know this is bad */
- int index;
- vector<OutputSocket *> &outputsockets = this->getOutputSockets();
- for (index = 0; index < outputsockets.size(); index++) {
- convertToOperations_invalid_index(graph, index);
- }
+ this->addOutputSocket(datatype, NULL);
+
+}
+void Node::addOutputSocket(DataType datatype, bNodeSocket *bSocket)
+{
+ NodeOutput *socket = new NodeOutput(this, bSocket, datatype);
+ this->m_outputsockets.push_back(socket);
+}
+
+NodeOutput *Node::getOutputSocket(unsigned int index) const
+{
+ BLI_assert(index < this->m_outputsockets.size());
+ return this->m_outputsockets[index];
+}
+
+NodeInput *Node::getInputSocket(unsigned int index) const
+{
+ BLI_assert(index < this->m_inputsockets.size());
+ return this->m_inputsockets[index];
}
bNodeSocket *Node::getEditorInputSocket(int editorNodeInputSocketIndex)
@@ -190,28 +143,74 @@ bNodeSocket *Node::getEditorOutputSocket(int editorNodeInputSocketIndex)
return NULL;
}
-InputSocket *Node::findInputSocketBybNodeSocket(bNodeSocket *socket)
+
+/*******************
+ **** NodeInput ****
+ *******************/
+
+NodeInput::NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype) :
+ m_node(node),
+ m_editorSocket(b_socket),
+ m_datatype(datatype),
+ m_link(NULL)
{
- vector<InputSocket *> &inputsockets = this->getInputSockets();
- unsigned int index;
- for (index = 0; index < inputsockets.size(); index++) {
- InputSocket *input = inputsockets[index];
- if (input->getbNodeSocket() == socket) {
- return input;
- }
- }
- return NULL;
}
-OutputSocket *Node::findOutputSocketBybNodeSocket(bNodeSocket *socket)
+void NodeInput::setLink(NodeOutput *link)
{
- vector<OutputSocket *> &outputsockets = this->getOutputSockets();
- unsigned int index;
- for (index = 0; index < outputsockets.size(); index++) {
- OutputSocket *output = outputsockets[index];
- if (output->getbNodeSocket() == socket) {
- return output;
- }
- }
- return NULL;
+ m_link = link;
+}
+
+float NodeInput::getEditorValueFloat()
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get(&ptr, "default_value");
+}
+
+void NodeInput::getEditorValueColor(float *value)
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get_array(&ptr, "default_value", value);
+}
+
+void NodeInput::getEditorValueVector(float *value)
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get_array(&ptr, "default_value", value);
+}
+
+
+/********************
+ **** NodeOutput ****
+ ********************/
+
+NodeOutput::NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype) :
+ m_node(node),
+ m_editorSocket(b_socket),
+ m_datatype(datatype)
+{
+}
+
+float NodeOutput::getEditorValueFloat()
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get(&ptr, "default_value");
+}
+
+void NodeOutput::getEditorValueColor(float *value)
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get_array(&ptr, "default_value", value);
+}
+
+void NodeOutput::getEditorValueVector(float *value)
+{
+ PointerRNA ptr;
+ RNA_pointer_create((ID *)getNode()->getbNodeTree(), &RNA_NodeSocket, getbNodeSocket(), &ptr);
+ return RNA_float_get_array(&ptr, "default_value", value);
}