diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-04-15 18:06:12 +0400 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2014-04-15 18:28:10 +0400 |
commit | 09874df135888b89f51d7becaa369ebb1d1623c6 (patch) | |
tree | bccf5950d42963992adff95dbc3f00ed7db1cf16 /source/blender/compositor/nodes/COM_DistanceMatteNode.cpp | |
parent | 28a829893c702918afc5ac1945a06eaefa611594 (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/nodes/COM_DistanceMatteNode.cpp')
-rw-r--r-- | source/blender/compositor/nodes/COM_DistanceMatteNode.cpp | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp index 3c532fe0b1d..704c704c500 100644 --- a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp @@ -31,55 +31,58 @@ DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode) /* pass */ } -void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) +void DistanceMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { - InputSocket *inputSocketImage = this->getInputSocket(0); - InputSocket *inputSocketKey = this->getInputSocket(1); - OutputSocket *outputSocketImage = this->getOutputSocket(0); - OutputSocket *outputSocketMatte = this->getOutputSocket(1); - - NodeOperation *operation; bNode *editorsnode = getbNode(); NodeChroma *storage = (NodeChroma *)editorsnode->storage; - + + NodeInput *inputSocketImage = this->getInputSocket(0); + NodeInput *inputSocketKey = this->getInputSocket(1); + NodeOutput *outputSocketImage = this->getOutputSocket(0); + NodeOutput *outputSocketMatte = this->getOutputSocket(1); + + SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + converter.addOperation(operationAlpha); + /* work in RGB color space */ + NodeOperation *operation; if (storage->channel == 1) { - operation = new DistanceRGBMatteOperation(); - ((DistanceRGBMatteOperation *) operation)->setSettings(storage); - - inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph); - inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph); + DistanceRGBMatteOperation *matte = new DistanceRGBMatteOperation(); + matte->setSettings(storage); + converter.addOperation(matte); + + converter.mapInputSocket(inputSocketImage, matte->getInputSocket(0)); + converter.mapInputSocket(inputSocketImage, operationAlpha->getInputSocket(0)); + + converter.mapInputSocket(inputSocketKey, matte->getInputSocket(1)); + + operation = matte; } /* work in YCbCr color space */ else { - operation = new DistanceYCCMatteOperation(); - ((DistanceYCCMatteOperation *) operation)->setSettings(storage); - + DistanceYCCMatteOperation *matte = new DistanceYCCMatteOperation(); + matte->setSettings(storage); + converter.addOperation(matte); + ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation(); - inputSocketImage->relinkConnections(operationYCCImage->getInputSocket(0), 0, graph); - addLink(graph, operationYCCImage->getOutputSocket(), operation->getInputSocket(0)); - graph->addOperation(operationYCCImage); - ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation(); - inputSocketKey->relinkConnections(operationYCCMatte->getInputSocket(0), 1, graph); - addLink(graph, operationYCCMatte->getOutputSocket(), operation->getInputSocket(1)); - graph->addOperation(operationYCCMatte); - } - - if (outputSocketMatte->isConnected()) { - outputSocketMatte->relinkConnections(operation->getOutputSocket()); - } - - graph->addOperation(operation); - - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); - addLink(graph, operation->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0)); - addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1)); - - graph->addOperation(operationAlpha); - addPreviewOperation(graph, context, operationAlpha->getOutputSocket()); - - if (outputSocketImage->isConnected()) { - outputSocketImage->relinkConnections(operationAlpha->getOutputSocket()); + converter.addOperation(operationYCCImage); + converter.addOperation(operationYCCMatte); + + converter.mapInputSocket(inputSocketImage, operationYCCImage->getInputSocket(0)); + converter.addLink(operationYCCImage->getOutputSocket(), matte->getInputSocket(0)); + converter.addLink(operationYCCImage->getOutputSocket(), operationAlpha->getInputSocket(0)); + + converter.mapInputSocket(inputSocketKey, operationYCCMatte->getInputSocket(0)); + converter.addLink(operationYCCMatte->getOutputSocket(), matte->getInputSocket(1)); + + operation = matte; } + + converter.addLink(operation->getOutputSocket(), operationAlpha->getInputSocket(1)); + + converter.mapOutputSocket(outputSocketMatte, operation->getOutputSocket()); + converter.mapOutputSocket(outputSocketImage, operationAlpha->getOutputSocket()); + + converter.addPreview(operationAlpha->getOutputSocket()); } |