Blender  V3.3
COM_DilateErodeNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_DilateErodeNode.h"
9 
10 namespace blender::compositor {
11 
12 DilateErodeNode::DilateErodeNode(bNode *editor_node) : Node(editor_node)
13 {
14  /* initialize node data */
15  NodeBlurData *data = &alpha_blur_;
16  memset(data, 0, sizeof(NodeBlurData));
17  data->filtertype = R_FILTER_GAUSS;
18 
19  if (editor_node->custom2 > 0) {
20  data->sizex = data->sizey = editor_node->custom2;
21  }
22  else {
23  data->sizex = data->sizey = -editor_node->custom2;
24  }
25 }
26 
28  const CompositorContext &context) const
29 {
30 
31  bNode *editor_node = this->get_bnode();
32  if (editor_node->custom1 == CMP_NODE_DILATEERODE_DISTANCE_THRESH) {
34  operation->set_distance(editor_node->custom2);
35  operation->set_inset(editor_node->custom3);
36  converter.add_operation(operation);
37 
38  converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
39 
40  if (editor_node->custom3 < 2.0f) {
41  AntiAliasOperation *anti_alias = new AntiAliasOperation();
42  converter.add_operation(anti_alias);
43 
44  converter.add_link(operation->get_output_socket(), anti_alias->get_input_socket(0));
45  converter.map_output_socket(get_output_socket(0), anti_alias->get_output_socket(0));
46  }
47  else {
48  converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
49  }
50  }
51  else if (editor_node->custom1 == CMP_NODE_DILATEERODE_DISTANCE) {
52  if (editor_node->custom2 > 0) {
54  operation->set_distance(editor_node->custom2);
55  converter.add_operation(operation);
56 
57  converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
58  converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
59  }
60  else {
62  operation->set_distance(-editor_node->custom2);
63  converter.add_operation(operation);
64 
65  converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
66  converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
67  }
68  }
69  else if (editor_node->custom1 == CMP_NODE_DILATEERODE_DISTANCE_FEATHER) {
70  /* this uses a modified gaussian blur function otherwise its far too slow */
71  eCompositorQuality quality = context.get_quality();
72 
74  operationx->set_data(&alpha_blur_);
75  operationx->set_quality(quality);
76  operationx->set_falloff(PROP_SMOOTH);
77  converter.add_operation(operationx);
78 
79  converter.map_input_socket(get_input_socket(0), operationx->get_input_socket(0));
80  // converter.map_input_socket(get_input_socket(1), operationx->get_input_socket(1)); // no size
81  // input yet
82 
84  operationy->set_data(&alpha_blur_);
85  operationy->set_quality(quality);
86  operationy->set_falloff(PROP_SMOOTH);
87  converter.add_operation(operationy);
88 
89  converter.add_link(operationx->get_output_socket(), operationy->get_input_socket(0));
90  // converter.map_input_socket(get_input_socket(1), operationy->get_input_socket(1)); // no size
91  // input yet
92  converter.map_output_socket(get_output_socket(0), operationy->get_output_socket());
93 
94  converter.add_preview(operationy->get_output_socket());
95 
96  /* TODO? */
97  /* see gaussian blue node for original usage */
98 #if 0
99  if (!connected_size_socket) {
100  operationx->set_size(size);
101  operationy->set_size(size);
102  }
103 #else
104  operationx->set_size(1.0f);
105  operationy->set_size(1.0f);
106 #endif
107  operationx->set_subtract(editor_node->custom2 < 0);
108  operationy->set_subtract(editor_node->custom2 < 0);
109 
110  if (editor_node->storage) {
111  NodeDilateErode *data_storage = (NodeDilateErode *)editor_node->storage;
112  operationx->set_falloff(data_storage->falloff);
113  operationy->set_falloff(data_storage->falloff);
114  }
115  }
116  else {
117  if (editor_node->custom2 > 0) {
118  DilateStepOperation *operation = new DilateStepOperation();
119  operation->set_iterations(editor_node->custom2);
120  converter.add_operation(operation);
121 
122  converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
123  converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
124  }
125  else {
126  ErodeStepOperation *operation = new ErodeStepOperation();
127  operation->set_iterations(-editor_node->custom2);
128  converter.add_operation(operation);
129 
130  converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
131  converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
132  }
133  }
134 }
135 
136 } // 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 set_data(const NodeBlurData *data)
Overall context of the compositor.
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void add_link(NodeOperationOutput *from, NodeOperationInput *to)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_preview(NodeOperationOutput *output)
void add_operation(NodeOperation *operation)
void map_input_socket(NodeInput *node_socket, NodeOperationInput *operation_socket)
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperationInput * get_input_socket(unsigned int index)
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89
void set_quality(eCompositorQuality quality)
eCompositorQuality
Possible quality settings.
Definition: COM_Enums.h:19
short custom1
void * storage
short custom2
float custom3