Blender  V2.93
COM_DilateErodeNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_DilateErodeNode.h"
20 #include "BLI_math.h"
21 #include "COM_AntiAliasOperation.h"
23 #include "COM_ExecutionSystem.h"
26 
27 namespace blender::compositor {
28 
29 DilateErodeNode::DilateErodeNode(bNode *editorNode) : Node(editorNode)
30 {
31  /* initialize node data */
32  NodeBlurData *data = &m_alpha_blur;
33  memset(data, 0, sizeof(NodeBlurData));
34  data->filtertype = R_FILTER_GAUSS;
35 
36  if (editorNode->custom2 > 0) {
37  data->sizex = data->sizey = editorNode->custom2;
38  }
39  else {
40  data->sizex = data->sizey = -editorNode->custom2;
41  }
42 }
43 
45  const CompositorContext &context) const
46 {
47 
48  bNode *editorNode = this->getbNode();
49  if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_THRESH) {
51  operation->setDistance(editorNode->custom2);
52  operation->setInset(editorNode->custom3);
53  converter.addOperation(operation);
54 
55  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
56 
57  if (editorNode->custom3 < 2.0f) {
58  AntiAliasOperation *antiAlias = new AntiAliasOperation();
59  converter.addOperation(antiAlias);
60 
61  converter.addLink(operation->getOutputSocket(), antiAlias->getInputSocket(0));
62  converter.mapOutputSocket(getOutputSocket(0), antiAlias->getOutputSocket(0));
63  }
64  else {
65  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
66  }
67  }
68  else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) {
69  if (editorNode->custom2 > 0) {
71  operation->setDistance(editorNode->custom2);
72  converter.addOperation(operation);
73 
74  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
75  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
76  }
77  else {
79  operation->setDistance(-editorNode->custom2);
80  converter.addOperation(operation);
81 
82  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
83  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
84  }
85  }
86  else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_FEATHER) {
87  /* this uses a modified gaussian blur function otherwise its far too slow */
88  eCompositorQuality quality = context.getQuality();
89 
91  operationx->setData(&m_alpha_blur);
92  operationx->setQuality(quality);
93  operationx->setFalloff(PROP_SMOOTH);
94  converter.addOperation(operationx);
95 
96  converter.mapInputSocket(getInputSocket(0), operationx->getInputSocket(0));
97  // converter.mapInputSocket(getInputSocket(1), operationx->getInputSocket(1)); // no size input
98  // yet
99 
101  operationy->setData(&m_alpha_blur);
102  operationy->setQuality(quality);
103  operationy->setFalloff(PROP_SMOOTH);
104  converter.addOperation(operationy);
105 
106  converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0));
107  // converter.mapInputSocket(getInputSocket(1), operationy->getInputSocket(1)); // no size input
108  // yet
109  converter.mapOutputSocket(getOutputSocket(0), operationy->getOutputSocket());
110 
111  converter.addPreview(operationy->getOutputSocket());
112 
113  /* TODO? */
114  /* see gaussian blue node for original usage */
115 #if 0
116  if (!connectedSizeSocket) {
117  operationx->setSize(size);
118  operationy->setSize(size);
119  }
120 #else
121  operationx->setSize(1.0f);
122  operationy->setSize(1.0f);
123 #endif
124  operationx->setSubtract(editorNode->custom2 < 0);
125  operationy->setSubtract(editorNode->custom2 < 0);
126 
127  if (editorNode->storage) {
128  NodeDilateErode *data_storage = (NodeDilateErode *)editorNode->storage;
129  operationx->setFalloff(data_storage->falloff);
130  operationy->setFalloff(data_storage->falloff);
131  }
132  }
133  else {
134  if (editorNode->custom2 > 0) {
135  DilateStepOperation *operation = new DilateStepOperation();
136  operation->setIterations(editorNode->custom2);
137  converter.addOperation(operation);
138 
139  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
140  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
141  }
142  else {
143  ErodeStepOperation *operation = new ErodeStepOperation();
144  operation->setIterations(-editorNode->custom2);
145  converter.addOperation(operation);
146 
147  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
148  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
149  }
150  }
151 }
152 
153 } // namespace blender::compositor
@ CMP_NODE_DILATEERODE_DISTANCE_THRESH
@ CMP_NODE_DILATEERODE_DISTANCE_FEATHER
@ CMP_NODE_DILATEERODE_DISTANCE
#define R_FILTER_GAUSS
#define PROP_SMOOTH
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
AntiAlias operations it only supports anti aliasing on BW buffers.
void setData(const NodeBlurData *data)
Overall context of the compositor.
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
void setQuality(eCompositorQuality quality)
eCompositorQuality
Possible quality settings.
Definition: COM_Enums.h:32
short custom1
void * storage
short custom2
float custom3