Blender  V2.93
multi_function_builder.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 
18 
19 #include "BLI_hash.hh"
20 
21 namespace blender::fn {
22 
24  : type_(type), value_(value)
25 {
26  MFSignatureBuilder signature{"Constant " + type.name()};
27  std::stringstream ss;
28  type.debug_print(value, ss);
29  signature.single_output(ss.str(), type);
30  signature_ = signature.build();
31  this->set_signature(&signature_);
32 }
33 
36  MFContext UNUSED(context)) const
37 {
38  GMutableSpan output = params.uninitialized_single_output(0);
39  type_.fill_uninitialized_indices(value_, output.data(), mask);
40 }
41 
43 {
44  return type_.hash(value_);
45 }
46 
48 {
49  const CustomMF_GenericConstant *_other = dynamic_cast<const CustomMF_GenericConstant *>(&other);
50  if (_other == nullptr) {
51  return false;
52  }
53  if (type_ != _other->type_) {
54  return false;
55  }
56  return type_.is_equal(value_, _other->value_);
57 }
58 
59 static std::string gspan_to_string(GSpan array)
60 {
61  std::stringstream ss;
62  ss << "[";
63  const int64_t max_amount = 5;
64  for (int64_t i : IndexRange(std::min(max_amount, array.size()))) {
65  array.type().debug_print(array[i], ss);
66  ss << ", ";
67  }
68  if (max_amount < array.size()) {
69  ss << "...";
70  }
71  ss << "]";
72  return ss.str();
73 }
74 
76 {
77  const CPPType &type = array.type();
78  MFSignatureBuilder signature{"Constant " + type.name() + " Vector"};
79  signature.vector_output(gspan_to_string(array), type);
80  signature_ = signature.build();
81  this->set_signature(&signature_);
82 }
83 
86  MFContext UNUSED(context)) const
87 {
88  GVectorArray &vectors = params.vector_output(0);
89  for (int64_t i : mask) {
90  vectors.extend(i, array_);
91  }
92 }
93 
95  Span<MFDataType> input_types,
96  Span<MFDataType> output_types)
97  : output_amount_(output_types.size())
98 {
100  for (MFDataType data_type : input_types) {
101  signature.input("Input", data_type);
102  }
103  for (MFDataType data_type : output_types) {
104  signature.output("Output", data_type);
105  }
106  signature_ = signature.build();
107  this->set_signature(&signature_);
108 }
110 {
111  for (int param_index : this->param_indices()) {
112  MFParamType param_type = this->param_type(param_index);
113  if (!param_type.is_output()) {
114  continue;
115  }
116 
117  if (param_type.data_type().is_single()) {
118  GMutableSpan span = params.uninitialized_single_output(param_index);
119  const CPPType &type = span.type();
120  type.fill_uninitialized_indices(type.default_value(), span.data(), mask);
121  }
122  }
123 }
124 
125 } // namespace blender::fn
#define UNUSED(x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define output
size_t size() const
Definition: util_array.h:203
uint64_t hash(const void *value) const
Definition: FN_cpp_type.hh:647
void fill_uninitialized_indices(const void *value, void *dst, IndexMask mask) const
Definition: FN_cpp_type.hh:626
bool is_equal(const void *a, const void *b) const
Definition: FN_cpp_type.hh:640
CustomMF_DefaultOutput(StringRef name, Span< MFDataType > input_types, Span< MFDataType > output_types)
void call(IndexMask mask, MFParams params, MFContext context) const override
void call(IndexMask mask, MFParams params, MFContext context) const override
CustomMF_GenericConstant(const CPPType &type, const void *value)
void call(IndexMask mask, MFParams params, MFContext context) const override
bool equals(const MultiFunction &other) const override
const CPPType & type() const
void extend(int64_t index, const GVArray &values)
StringRefNull name() const
MFParamType param_type(int param_index) const
IndexRange param_indices() const
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static std::string gspan_to_string(GSpan array)
struct SELECTID_Context context
Definition: select_engine.c:47
#define min(a, b)
Definition: sort.c:51
__int64 int64_t
Definition: stdint.h:92
unsigned __int64 uint64_t
Definition: stdint.h:93
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)