diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-30 13:27:53 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-30 17:03:43 +0300 |
commit | 04a92297ddfb86b1766733461f01104bcbd5b38e (patch) | |
tree | de724e43767f0bd01b51517c9a4684a2b9c5271c /source/blender/compositor | |
parent | d4e76712d4fdf55815cf59df52ffa35df84ed09a (diff) |
Cleanup: Replace std::vector with blender::Vector.
Diffstat (limited to 'source/blender/compositor')
12 files changed, 58 insertions, 128 deletions
diff --git a/source/blender/compositor/intern/COM_Node.cc b/source/blender/compositor/intern/COM_Node.cc index 517f23f13cd..6ac48e3646c 100644 --- a/source/blender/compositor/intern/COM_Node.cc +++ b/source/blender/compositor/intern/COM_Node.cc @@ -76,13 +76,11 @@ Node::Node(bNode *editorNode, bool create_sockets) Node::~Node() { - while (!this->m_outputsockets.empty()) { - delete (this->m_outputsockets.back()); - this->m_outputsockets.pop_back(); + while (!this->outputs.is_empty()) { + delete (this->outputs.pop_last()); } - while (!this->m_inputsockets.empty()) { - delete (this->m_inputsockets.back()); - this->m_inputsockets.pop_back(); + while (!this->inputs.is_empty()) { + delete (this->inputs.pop_last()); } } @@ -94,7 +92,7 @@ void Node::addInputSocket(DataType datatype) void Node::addInputSocket(DataType datatype, bNodeSocket *bSocket) { NodeInput *socket = new NodeInput(this, bSocket, datatype); - this->m_inputsockets.push_back(socket); + this->inputs.append(socket); } void Node::addOutputSocket(DataType datatype) @@ -104,19 +102,17 @@ void Node::addOutputSocket(DataType datatype) void Node::addOutputSocket(DataType datatype, bNodeSocket *bSocket) { NodeOutput *socket = new NodeOutput(this, bSocket, datatype); - this->m_outputsockets.push_back(socket); + outputs.append(socket); } NodeOutput *Node::getOutputSocket(unsigned int index) const { - BLI_assert(index < this->m_outputsockets.size()); - return this->m_outputsockets[index]; + return outputs[index]; } NodeInput *Node::getInputSocket(unsigned int index) const { - BLI_assert(index < this->m_inputsockets.size()); - return this->m_inputsockets[index]; + return inputs[index]; } bNodeSocket *Node::getEditorInputSocket(int editorNodeInputSocketIndex) diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index 5b168ef87fd..9aca1a8ff44 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -18,10 +18,12 @@ #pragma once +#include "BLI_vector.hh" + #include "DNA_node_types.h" + #include <algorithm> #include <string> -#include <vector> /* common node includes * added here so node files don't have to include themselves @@ -38,10 +40,6 @@ class NodeConverter; * My node documentation. */ class Node { - public: - typedef std::vector<NodeInput *> Inputs; - typedef std::vector<NodeOutput *> Outputs; - private: /** * \brief stores the reference to the SDNA bNode struct @@ -54,16 +52,6 @@ class Node { 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 */ bool m_inActiveGroup; @@ -75,20 +63,14 @@ class Node { protected: /** - * \brief get access to the vector of input sockets + * \brief the list of actual inputsockets \see NodeInput */ - const Inputs &getInputSockets() const - { - return this->m_inputsockets; - } + blender::Vector<NodeInput *> inputs; /** - * \brief get access to the vector of input sockets + * \brief the list of actual outputsockets \see NodeOutput */ - const Outputs &getOutputSockets() const - { - return this->m_outputsockets; - } + blender::Vector<NodeOutput *> outputs; public: Node(bNode *editorNode, bool create_sockets = true); @@ -131,19 +113,19 @@ class Node { } /** - * \brief Return the number of input sockets of this node. + * \brief get access to the vector of input sockets */ - unsigned int getNumberOfInputSockets() const + const blender::Vector<NodeInput *> &getInputSockets() const { - return this->m_inputsockets.size(); + return this->inputs; } /** - * \brief Return the number of output sockets of this node. + * \brief get access to the vector of input sockets */ - unsigned int getNumberOfOutputSockets() const + const blender::Vector<NodeOutput *> &getOutputSockets() const { - return this->m_outputsockets.size(); + return this->outputs; } /** @@ -151,17 +133,7 @@ class Node { * \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); - } + NodeOutput *getOutputSocket(const unsigned int index = 0) const; /** * get the reference to a certain inputsocket @@ -170,14 +142,6 @@ class Node { */ 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: diff --git a/source/blender/compositor/intern/COM_NodeGraph.cc b/source/blender/compositor/intern/COM_NodeGraph.cc index 53b912fe5e4..7e05bf637b7 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.cc +++ b/source/blender/compositor/intern/COM_NodeGraph.cc @@ -45,9 +45,8 @@ NodeGraph::NodeGraph() NodeGraph::~NodeGraph() { - for (int index = 0; index < this->m_nodes.size(); index++) { - Node *node = this->m_nodes[index]; - delete node; + while (m_nodes.size()) { + delete m_nodes.pop_last(); } } @@ -155,27 +154,11 @@ void NodeGraph::add_bNode(const CompositorContext &context, } } -NodeGraph::NodeInputs NodeGraph::find_inputs(const NodeRange &node_range, bNodeSocket *b_socket) -{ - NodeInputs result; - for (blender::Vector<Node *>::iterator it = node_range.first; it != node_range.second; ++it) { - Node *node = *it; - for (int index = 0; index < node->getNumberOfInputSockets(); index++) { - NodeInput *input = node->getInputSocket(index); - if (input->getbNodeSocket() == b_socket) { - result.push_back(input); - } - } - } - return result; -} - NodeOutput *NodeGraph::find_output(const NodeRange &node_range, bNodeSocket *b_socket) { for (blender::Vector<Node *>::iterator it = node_range.first; it != node_range.second; ++it) { Node *node = *it; - for (int index = 0; index < node->getNumberOfOutputSockets(); index++) { - NodeOutput *output = node->getOutputSocket(index); + for (NodeOutput *output : node->getOutputSockets()) { if (output->getbNodeSocket() == b_socket) { return output; } @@ -204,12 +187,13 @@ void NodeGraph::add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink return; } - NodeInputs inputs = find_inputs(node_range, b_nodelink->tosock); - for (NodeInput *input : inputs) { - if (input->isLinked()) { - continue; + for (blender::Vector<Node *>::iterator it = node_range.first; it != node_range.second; ++it) { + Node *node = *it; + for (NodeInput *input : node->getInputSockets()) { + if (input->getbNodeSocket() == b_nodelink->tosock && !input->isLinked()) { + add_link(output, input); + } } - add_link(output, input); } } diff --git a/source/blender/compositor/intern/COM_NodeGraph.h b/source/blender/compositor/intern/COM_NodeGraph.h index 156a315933c..9347df5d9e2 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.h +++ b/source/blender/compositor/intern/COM_NodeGraph.h @@ -73,7 +73,6 @@ class NodeGraph { protected: typedef std::pair<blender::Vector<Node *>::iterator, blender::Vector<Node *>::iterator> NodeRange; - typedef std::vector<NodeInput *> NodeInputs; static bNodeSocket *find_b_node_input(bNode *b_node, const char *identifier); static bNodeSocket *find_b_node_output(bNode *b_node, const char *identifier); @@ -92,7 +91,6 @@ class NodeGraph { bNodeInstanceKey key, bool is_active_group); - NodeInputs find_inputs(const NodeRange &node_range, bNodeSocket *b_socket); NodeOutput *find_output(const NodeRange &node_range, bNodeSocket *b_socket); void add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink); diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cc b/source/blender/compositor/nodes/COM_CryptomatteNode.cc index 89caff047b4..23305fa06f8 100644 --- a/source/blender/compositor/nodes/COM_CryptomatteNode.cc +++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cc @@ -254,7 +254,7 @@ CryptomatteOperation *CryptomatteLegacyNode::create_cryptomatte_operation( const bNode &UNUSED(node), const NodeCryptomatte *cryptomatte_settings) const { - const int num_inputs = getNumberOfInputSockets() - 1; + const int num_inputs = inputs.size() - 1; CryptomatteOperation *operation = new CryptomatteOperation(num_inputs); if (cryptomatte_settings) { LISTBASE_FOREACH (CryptomatteEntry *, cryptomatte_entry, &cryptomatte_settings->entries) { diff --git a/source/blender/compositor/nodes/COM_ImageNode.cc b/source/blender/compositor/nodes/COM_ImageNode.cc index 380773eca64..092cf836a41 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cc +++ b/source/blender/compositor/nodes/COM_ImageNode.cc @@ -79,7 +79,6 @@ void ImageNode::convertToOperations(NodeConverter &converter, Image *image = (Image *)editorNode->id; ImageUser *imageuser = (ImageUser *)editorNode->storage; int framenumber = context.getFramenumber(); - int numberOfOutputs = this->getNumberOfOutputSockets(); bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0; BKE_image_user_frame_calc(image, imageuser, context.getFramenumber()); /* force a load, we assume iuser index will be set OK anyway */ @@ -89,14 +88,12 @@ void ImageNode::convertToOperations(NodeConverter &converter, if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { - NodeOutput *socket; int index; is_multilayer_ok = true; - for (index = 0; index < numberOfOutputs; index++) { + for (NodeOutput *socket : getOutputSockets()) { NodeOperation *operation = nullptr; - socket = this->getOutputSocket(index); bNodeSocket *bnodeSocket = socket->getbNodeSocket(); NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage; RenderPass *rpass = (RenderPass *)BLI_findstring( @@ -173,8 +170,7 @@ void ImageNode::convertToOperations(NodeConverter &converter, converter.addPreview(operation->getOutputSocket()); } if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) { - for (int alphaIndex = 0; alphaIndex < numberOfOutputs; alphaIndex++) { - NodeOutput *alphaSocket = this->getOutputSocket(alphaIndex); + for (NodeOutput *alphaSocket : getOutputSockets()) { bNodeSocket *bnodeAlphaSocket = alphaSocket->getbNodeSocket(); if (!STREQ(bnodeAlphaSocket->name, "Alpha")) { continue; @@ -206,12 +202,13 @@ void ImageNode::convertToOperations(NodeConverter &converter, /* without this, multilayer that fail to load will crash blender T32490. */ if (is_multilayer_ok == false) { - for (int i = 0; i < getNumberOfOutputSockets(); i++) { - converter.setInvalidOutput(getOutputSocket(i)); + for (NodeOutput *output : getOutputSockets()) { + converter.setInvalidOutput(output); } } } else { + const int64_t numberOfOutputs = getOutputSockets().size(); if (numberOfOutputs > 0) { ImageOperation *operation = new ImageOperation(); operation->setImage(image); @@ -298,6 +295,6 @@ void ImageNode::convertToOperations(NodeConverter &converter, } } } -} +} // namespace blender::compositor } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cc b/source/blender/compositor/nodes/COM_OutputFileNode.cc index e6b1aedde07..10f176d71f5 100644 --- a/source/blender/compositor/nodes/COM_OutputFileNode.cc +++ b/source/blender/compositor/nodes/COM_OutputFileNode.cc @@ -71,17 +71,16 @@ void OutputFileNode::convertToOperations(NodeConverter &converter, } converter.addOperation(outputOperation); - int num_inputs = getNumberOfInputSockets(); bool previewAdded = false; - for (int i = 0; i < num_inputs; i++) { - NodeInput *input = getInputSocket(i); + int index = 0; + for (NodeInput *input : inputs) { NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage; /* note: layer becomes an empty placeholder if the input is not linked */ outputOperation->add_layer(sockdata->layer, input->getDataType(), input->isLinked()); - converter.mapInputSocket(input, outputOperation->getInputSocket(i)); + converter.mapInputSocket(input, outputOperation->getInputSocket(index++)); if (!previewAdded) { converter.addNodeInputPreview(input); @@ -90,10 +89,8 @@ void OutputFileNode::convertToOperations(NodeConverter &converter, } } else { /* single layer format */ - int num_inputs = getNumberOfInputSockets(); bool previewAdded = false; - for (int i = 0; i < num_inputs; i++) { - NodeInput *input = getInputSocket(i); + for (NodeInput *input : inputs) { if (input->isLinked()) { NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage; diff --git a/source/blender/compositor/nodes/COM_RenderLayersNode.cc b/source/blender/compositor/nodes/COM_RenderLayersNode.cc index eead775b192..851d0366546 100644 --- a/source/blender/compositor/nodes/COM_RenderLayersNode.cc +++ b/source/blender/compositor/nodes/COM_RenderLayersNode.cc @@ -74,9 +74,8 @@ void RenderLayersNode::testRenderLink(NodeConverter &converter, missingRenderLink(converter); return; } - const int num_outputs = this->getNumberOfOutputSockets(); - for (int i = 0; i < num_outputs; i++) { - NodeOutput *output = this->getOutputSocket(i); + + for (NodeOutput *output : getOutputSockets()) { NodeImageLayer *storage = (NodeImageLayer *)output->getbNodeSocket()->storage; RenderPass *rpass = (RenderPass *)BLI_findstring( &rl->passes, storage->pass_name, offsetof(RenderPass, name)); @@ -155,9 +154,7 @@ void RenderLayersNode::missingSocketLink(NodeConverter &converter, NodeOutput *o void RenderLayersNode::missingRenderLink(NodeConverter &converter) const { - const int num_outputs = this->getNumberOfOutputSockets(); - for (int i = 0; i < num_outputs; i++) { - NodeOutput *output = this->getOutputSocket(i); + for (NodeOutput *output : outputs) { missingSocketLink(converter, output); } } diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.cc b/source/blender/compositor/operations/COM_CryptomatteOperation.cc index 63bbca66296..52ae1d6d5b5 100644 --- a/source/blender/compositor/operations/COM_CryptomatteOperation.cc +++ b/source/blender/compositor/operations/COM_CryptomatteOperation.cc @@ -22,10 +22,10 @@ namespace blender::compositor { CryptomatteOperation::CryptomatteOperation(size_t num_inputs) { + inputs.resize(num_inputs); for (size_t i = 0; i < num_inputs; i++) { this->addInputSocket(DataType::Color); } - inputs.resize(num_inputs); this->addOutputSocket(DataType::Color); this->flags.complex = true; } @@ -40,7 +40,7 @@ void CryptomatteOperation::initExecution() void CryptomatteOperation::addObjectIndex(float objectIndex) { if (objectIndex != 0.0f) { - m_objectIndex.push_back(objectIndex); + m_objectIndex.append(objectIndex); } } @@ -60,11 +60,11 @@ void CryptomatteOperation::executePixel(float output[4], int x, int y, void *dat output[1] = ((float)((m3hash << 8)) / (float)UINT32_MAX); output[2] = ((float)((m3hash << 16)) / (float)UINT32_MAX); } - for (size_t i = 0; i < m_objectIndex.size(); i++) { - if (m_objectIndex[i] == input[0]) { + for (float hash : m_objectIndex) { + if (input[0] == hash) { output[3] += input[1]; } - if (m_objectIndex[i] == input[2]) { + if (input[2] == hash) { output[3] += input[3]; } } diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.h b/source/blender/compositor/operations/COM_CryptomatteOperation.h index 176a1184491..40a1fbf5a80 100644 --- a/source/blender/compositor/operations/COM_CryptomatteOperation.h +++ b/source/blender/compositor/operations/COM_CryptomatteOperation.h @@ -24,10 +24,10 @@ namespace blender::compositor { class CryptomatteOperation : public NodeOperation { private: - std::vector<float> m_objectIndex; + blender::Vector<float> m_objectIndex; public: - std::vector<SocketReader *> inputs; + blender::Vector<SocketReader *> inputs; CryptomatteOperation(size_t num_inputs = 6); diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cc b/source/blender/compositor/operations/COM_OutputFileOperation.cc index cb9c2e4a16b..5184cd42b9e 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cc +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cc @@ -330,7 +330,7 @@ void OutputOpenExrMultiLayerOperation::add_layer(const char *name, bool use_layer) { this->addInputSocket(datatype); - this->m_layers.push_back(OutputOpenExrLayer(name, datatype, use_layer)); + this->m_layers.append(OutputOpenExrLayer(name, datatype, use_layer)); } StampData *OutputOpenExrMultiLayerOperation::createStampData() const @@ -340,17 +340,16 @@ StampData *OutputOpenExrMultiLayerOperation::createStampData() const RenderResult render_result; StampData *stamp_data = BKE_stamp_info_from_scene_static(m_scene); render_result.stamp_data = stamp_data; - for (int i = 0; i < this->m_layers.size(); i++) { - const OutputOpenExrLayer *layer = &this->m_layers[i]; + for (const OutputOpenExrLayer &layer : m_layers) { /* Skip unconnected sockets. */ - if (layer->imageInput == nullptr) { + if (layer.imageInput == nullptr) { continue; } - std::unique_ptr<MetaData> meta_data = layer->imageInput->getMetaData(); + std::unique_ptr<MetaData> meta_data = layer.imageInput->getMetaData(); if (meta_data) { blender::StringRef layer_name = blender::bke::cryptomatte::BKE_cryptomatte_extract_layer_name( - blender::StringRef(layer->name, BLI_strnlen(layer->name, sizeof(layer->name)))); + blender::StringRef(layer.name, BLI_strnlen(layer.name, sizeof(layer.name)))); meta_data->replaceHashNeutralCryptomatteKeys(layer_name); meta_data->addToRenderResult(&render_result); } diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 81277ab1ef3..6415891032a 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -88,8 +88,6 @@ struct OutputOpenExrLayer { /* Writes inputs into OpenEXR multilayer channels. */ class OutputOpenExrMultiLayerOperation : public NodeOperation { protected: - typedef std::vector<OutputOpenExrLayer> LayerList; - const Scene *m_scene; const RenderData *m_rd; const bNodeTree *m_tree; @@ -97,7 +95,7 @@ class OutputOpenExrMultiLayerOperation : public NodeOperation { char m_path[FILE_MAX]; char m_exr_codec; bool m_exr_half_float; - LayerList m_layers; + blender::Vector<OutputOpenExrLayer> m_layers; const char *m_viewName; StampData *createStampData() const; |