Blender V4.3
COM_DilateErodeNode.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#include "COM_SMAAOperation.h"
9
10namespace blender::compositor {
11
12DilateErodeNode::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 const bNode *editor_node = this->get_bnode();
33 operation->set_distance(editor_node->custom2);
34 operation->set_inset(editor_node->custom3);
35 converter.add_operation(operation);
36
37 converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
38
39 if (editor_node->custom3 < 2.0f) {
40 SMAAOperation *smaa_operation = new SMAAOperation();
41 converter.add_operation(smaa_operation);
42 converter.add_link(operation->get_output_socket(), smaa_operation->get_input_socket(0));
43 converter.map_output_socket(get_output_socket(0), smaa_operation->get_output_socket());
44 }
45 else {
46 converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
47 }
48 }
49 else if (editor_node->custom1 == CMP_NODE_DILATE_ERODE_DISTANCE) {
50 if (editor_node->custom2 > 0) {
52 operation->set_distance(editor_node->custom2);
53 converter.add_operation(operation);
54
55 converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
56 converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
57 }
58 else {
60 operation->set_distance(-editor_node->custom2);
61 converter.add_operation(operation);
62
63 converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
64 converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
65 }
66 }
67 else if (editor_node->custom1 == CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER) {
69 operationx->set_data(&alpha_blur_);
70 operationx->set_falloff(PROP_SMOOTH);
71 converter.add_operation(operationx);
72
73 converter.map_input_socket(get_input_socket(0), operationx->get_input_socket(0));
74 // converter.map_input_socket(get_input_socket(1), operationx->get_input_socket(1)); // no size
75 // input yet
76
78 operationy->set_data(&alpha_blur_);
79 operationy->set_falloff(PROP_SMOOTH);
80 converter.add_operation(operationy);
81
82 converter.add_link(operationx->get_output_socket(), operationy->get_input_socket(0));
83 // converter.map_input_socket(get_input_socket(1), operationy->get_input_socket(1)); // no size
84 // input yet
85 converter.map_output_socket(get_output_socket(0), operationy->get_output_socket());
86
87 converter.add_preview(operationy->get_output_socket());
88
89 /* TODO? */
90 /* see gaussian blue node for original usage */
91#if 0
92 if (!connected_size_socket) {
93 operationx->set_size(size);
94 operationy->set_size(size);
95 }
96#else
97 operationx->set_size(1.0f);
98 operationy->set_size(1.0f);
99#endif
100 operationx->set_subtract(editor_node->custom2 < 0);
101 operationy->set_subtract(editor_node->custom2 < 0);
102
103 if (editor_node->storage) {
104 NodeDilateErode *data_storage = (NodeDilateErode *)editor_node->storage;
105 operationx->set_falloff(data_storage->falloff);
106 operationy->set_falloff(data_storage->falloff);
107 }
108 }
109 else {
110 if (editor_node->custom2 > 0) {
111 DilateStepOperation *operation = new DilateStepOperation();
112 operation->set_iterations(editor_node->custom2);
113 converter.add_operation(operation);
114
115 converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
116 converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
117 }
118 else {
119 ErodeStepOperation *operation = new ErodeStepOperation();
120 operation->set_iterations(-editor_node->custom2);
121 converter.add_operation(operation);
122
123 converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
124 converter.map_output_socket(get_output_socket(0), operation->get_output_socket(0));
125 }
126 }
127}
128
129} // namespace blender::compositor
@ CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER
@ CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD
@ CMP_NODE_DILATE_ERODE_DISTANCE
@ R_FILTER_GAUSS
@ PROP_SMOOTH
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:85
NodeInput * get_input_socket(unsigned int index) const
Definition COM_Node.cc:90
const bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition COM_Node.h:65
int16_t custom1
void * storage
float custom3
int16_t custom2