Blender
V5.3
source
blender
compositor
intern
operation.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#include <limits>
6
#include <memory>
7
8
#include "
BLI_map.hh
"
9
#include "
BLI_string_ref.hh
"
10
11
#include "
COM_context.hh
"
12
#include "
COM_conversion_operation.hh
"
13
#include "
COM_domain.hh
"
14
#include "
COM_input_descriptor.hh
"
15
#include "
COM_operation.hh
"
16
#include "
COM_realize_on_domain_operation.hh
"
17
#include "
COM_result.hh
"
18
#include "
COM_simple_operation.hh
"
19
20
namespace
blender::compositor
{
21
22
Operation::Operation
(
Context
&
context
) : context_(
context
) {}
23
24
Operation::~Operation
() =
default
;
25
26
void
Operation::evaluate
()
27
{
28
this->
evaluate_input_processors
();
29
this->
execute
();
30
this->
log_data
();
31
this->release_inputs();
32
this->
context
().
evaluate_operation_post
();
33
}
34
35
Result
&
Operation::get_input
(
StringRef
identifier)
const
36
{
37
return
*results_mapped_to_inputs_.lookup(identifier);
38
}
39
40
Result
&
Operation::get_result
(
StringRef
identifier)
41
{
42
return
results_.lookup(identifier);
43
}
44
45
void
Operation::map_input_to_result
(
StringRef
identifier,
Result
*
result
)
46
{
47
results_mapped_to_inputs_.add_new(identifier,
result
);
48
}
49
50
void
Operation::free_results
()
51
{
52
for
(
Result
&
result
: results_.values()) {
53
result
.free();
54
}
55
}
56
57
Context
&
Operation::context
()
const
58
{
59
return
context_;
60
}
61
62
Domain
Operation::compute_domain
()
63
{
64
/* Default to an identity domain in case no domain input was found, most likely because all
65
* inputs are single values. */
66
Domain
operation_domain =
Domain::identity
();
67
int
current_domain_priority = std::numeric_limits<int>::max();
68
69
/* Go over the inputs and find the domain of the non single value input with the highest domain
70
* priority. */
71
for
(
StringRef
identifier : input_descriptors_.keys()) {
72
const
Result
&
result
=
get_input
(identifier);
73
const
InputDescriptor
&
descriptor
=
get_input_descriptor
(identifier);
74
75
/* A single value input can't be a domain input. */
76
if
(
result
.is_single_value() ||
descriptor
.expects_single_value) {
77
continue
;
78
}
79
80
/* An input that skips operation domain realization can't be a domain input. */
81
if
(
descriptor
.realization_mode !=
InputRealizationMode::OperationDomain
) {
82
continue
;
83
}
84
85
/* Notice that the lower the domain priority value is, the higher the priority is, hence the
86
* less than comparison. */
87
if
(
descriptor
.domain_priority < current_domain_priority) {
88
operation_domain =
result
.domain();
89
current_domain_priority =
descriptor
.domain_priority;
90
}
91
}
92
93
return
operation_domain;
94
}
95
96
void
Operation::evaluate_input_processors
()
97
{
98
/* Each input processor type is added to all inputs entirely before the next type. This is done
99
* because the construction of the input processors may depend on the result of previous input
100
* processors for all inputs. For instance, the realize on domain input processor considers the
101
* value of all inputs, so previous input processors for all inputs needs to be added and
102
* evaluated first. */
103
104
for
(
const
std::string &identifier : results_mapped_to_inputs_.keys()) {
105
SimpleOperation
*conversion =
ConversionOperation::construct_if_needed
(
106
this->
context
(), this->
get_input
(identifier), this->
get_input_descriptor
(identifier));
107
this->add_and_evaluate_input_processor(identifier, conversion);
108
}
109
110
for
(
const
std::string &identifier : results_mapped_to_inputs_.keys()) {
111
SimpleOperation
*realize_on_domain =
RealizeOnDomainOperation::construct_if_needed
(
112
this->
context
(),
113
this->
get_input
(identifier),
114
this->
get_input_descriptor
(identifier),
115
this->
compute_domain
());
116
this->add_and_evaluate_input_processor(identifier, realize_on_domain);
117
}
118
}
119
120
void
Operation::log_data
() {};
121
122
void
Operation::populate_result
(
StringRef
identifier,
const
ResultType
type)
123
{
124
results_.add_new(identifier, this->
context
().create_result(type));
125
}
126
127
void
Operation::declare_input_descriptor
(
StringRef
identifier,
InputDescriptor
descriptor
)
128
{
129
input_descriptors_.add_new(identifier,
descriptor
);
130
}
131
132
InputDescriptor
&
Operation::get_input_descriptor
(
StringRef
identifier)
133
{
134
return
input_descriptors_.lookup(identifier);
135
}
136
137
void
Operation::allocate_default_remaining_outputs
()
138
{
139
for
(
Result
&
result
: results_.values()) {
140
if
(
result
.should_compute() && !
result
.is_allocated()) {
141
result
.allocate_invalid();
142
}
143
}
144
}
145
146
void
Operation::add_and_evaluate_input_processor(
StringRef
identifier,
SimpleOperation
*processor)
147
{
148
/* Allow null inputs to facilitate construct_if_needed pattern of addition. For instance, see the
149
* implementation of the evaluate_input_processors method. */
150
if
(!processor) {
151
return
;
152
}
153
154
ProcessorsVector
&processors = input_processors_.lookup_or_add_default(identifier);
155
156
/* Get the result that should serve as the input for the processor. This is either the result
157
* mapped to the input or the result of the last processor depending on whether this is the first
158
* processor or not. */
159
Result &
result
= processors.is_empty() ? this->
get_input
(identifier) :
160
processors.last()->
get_result
();
161
162
/* Map the input result of the processor and add it to the processors vector. */
163
processor->
map_input_to_result
(&
result
);
164
processors.append(std::unique_ptr<SimpleOperation>(processor));
165
166
/* Switch the result mapped to the input to be the output result of the processor. */
167
results_mapped_to_inputs_.lookup(identifier) = &processor->
get_result
();
168
169
processor->
evaluate
();
170
}
171
172
void
Operation::release_inputs()
173
{
174
for
(Result *
result
: results_mapped_to_inputs_.values()) {
175
result
->release();
176
}
177
}
178
179
}
// namespace blender::compositor
BLI_map.hh
BLI_string_ref.hh
COM_context.hh
COM_conversion_operation.hh
COM_domain.hh
COM_input_descriptor.hh
COM_operation.hh
COM_realize_on_domain_operation.hh
COM_result.hh
COM_simple_operation.hh
blender::StringRef
Definition
BLI_string_ref.hh:165
blender::compositor::Context
Definition
COM_context.hh:53
blender::compositor::Context::evaluate_operation_post
virtual void evaluate_operation_post() const
Definition
compositor/intern/context.cc:63
blender::compositor::ConversionOperation::construct_if_needed
static SimpleOperation * construct_if_needed(Context &context, const Result &input_result, const InputDescriptor &input_descriptor)
Definition
conversion_operation.cc:81
blender::compositor::Domain
Definition
COM_domain.hh:158
blender::compositor::Domain::identity
static Domain identity()
Definition
domain.cc:47
blender::compositor::InputDescriptor
Definition
COM_input_descriptor.hh:45
blender::compositor::Operation::get_result
Result & get_result(StringRef identifier)
Definition
operation.cc:40
blender::compositor::Operation::~Operation
virtual ~Operation()
blender::compositor::Operation::Operation
Operation(Context &context)
Definition
operation.cc:22
blender::compositor::Operation::free_results
void free_results()
Definition
operation.cc:50
blender::compositor::Operation::populate_result
void populate_result(StringRef identifier, ResultType type)
Definition
operation.cc:122
blender::compositor::Operation::evaluate_input_processors
virtual void evaluate_input_processors()
Definition
operation.cc:96
blender::compositor::Operation::log_data
virtual void log_data()
Definition
operation.cc:120
blender::compositor::Operation::allocate_default_remaining_outputs
void allocate_default_remaining_outputs()
Definition
operation.cc:137
blender::compositor::Operation::execute
virtual void execute()=0
blender::compositor::Operation::context
Context & context() const
Definition
operation.cc:57
blender::compositor::Operation::evaluate
virtual void evaluate()
Definition
operation.cc:26
blender::compositor::Operation::get_input
Result & get_input(StringRef identifier) const
Definition
operation.cc:35
blender::compositor::Operation::map_input_to_result
void map_input_to_result(StringRef identifier, Result *result)
Definition
operation.cc:45
blender::compositor::Operation::compute_domain
virtual Domain compute_domain()
Definition
operation.cc:62
blender::compositor::Operation::get_input_descriptor
InputDescriptor & get_input_descriptor(StringRef identifier)
Definition
operation.cc:132
blender::compositor::Operation::declare_input_descriptor
void declare_input_descriptor(StringRef identifier, InputDescriptor descriptor)
Definition
operation.cc:127
blender::compositor::RealizeOnDomainOperation::construct_if_needed
static SimpleOperation * construct_if_needed(Context &context, const Result &input_result, const InputDescriptor &input_descriptor, const Domain &operation_domain)
Definition
realize_on_domain_operation.cc:321
blender::compositor::Result
Definition
COM_result.hh:125
blender::compositor::SimpleOperation
Definition
COM_simple_operation.hh:21
blender::compositor::SimpleOperation::map_input_to_result
void map_input_to_result(Result *result)
Definition
simple_operation.cc:20
blender::compositor::SimpleOperation::get_result
Result & get_result()
Definition
simple_operation.cc:15
blender::compositor
Definition
BKE_node.hh:77
blender::compositor::InputRealizationMode::OperationDomain
@ OperationDomain
Definition
COM_input_descriptor.hh:26
blender::compositor::ProcessorsVector
Vector< std::unique_ptr< SimpleOperation > > ProcessorsVector
Definition
COM_operation.hh:25
blender::compositor::ResultType
ResultType
Definition
COM_result.hh:53
blender::result
double result
Definition
BLI_expr_pylike_eval_test.cc:353
blender::descriptor
descriptor
Definition
logImageCore.h:77
Generated on
for Blender by
doxygen
1.18.0