30 if (
node !=
nullptr) {
32 b.add_input(data_type,
"Value"_ustr)
33 .structure_type(StructureType::Field)
34 .description(
"The values the mean and median will be calculated from");
37 b.add_input<
decl::Int>(
"Group ID"_ustr,
"Group Index"_ustr)
38 .structure_type(StructureType::Field)
40 .description(
"An index used to group values together for multiple separate operations");
42 if (
node !=
nullptr) {
44 b.add_output(data_type,
"Mean"_ustr)
45 .structure_type(StructureType::Field)
46 .propagate_references()
47 .description(
"The sum of all values in each group divided by the size of said group");
48 b.add_output(data_type,
"Median"_ustr)
50 .structure_type(StructureType::Field)
51 .propagate_references()
53 "The middle value in each group when all values are sorted from lowest to highest");
73 switch (socket.
type) {
100 node.custom1 = *type;
108 node.custom1 = *type;
118 node.custom1 = *type;
127 if constexpr (std::is_same<T, float3>::value) {
142 const auto middle_itr = values.
begin() + values.
size() / 2;
143 std::nth_element(values.
begin(), middle_itr, values.
end());
144 if (values.
size() % 2 == 0) {
145 auto *
const left_middle_itr = std::max_element(values.
begin(), middle_itr);
165 input_(std::move(input)),
166 group_index_(std::move(group_index)),
167 source_domain_(source_domain),
168 operation_(operation)
177 if (domain_size == 0) {
183 evaluator.
add(input_);
184 evaluator.
add(group_index_);
202 auto &pair = sum_and_counts.
lookup_or_add(group_indices[i], std::make_pair(
T(), 0));
203 pair.first = pair.first + values[i];
204 pair.second = pair.second + 1;
209 const auto &pair = sum_and_counts.
lookup(group_indices[i]);
210 outputs[i] = pair.
first / pair.second;
234 outputs[i] = medians.
lookup(group_indices[i]);
241 return attributes.
adapt_domain(std::move(g_outputs), source_domain_, context.domain());
252 static constexpr int8_t id = 0;
255 hash.add(deep_hash_cache.
ensure(group_index_));
256 hash.add(source_domain_);
257 hash.add(operation_);
263 return source_domain_;
289 {
CD_PROP_FLOAT,
"FLOAT", ICON_NODE_SOCKET_FLOAT,
"Float",
"Floating-point value"},
292 ICON_NODE_SOCKET_VECTOR,
294 "3D vector with floating-point values"},
295 {0,
nullptr, 0,
nullptr,
nullptr},
301 "Type of data the outputs are calculated from",
312 int(AttrDomain::Point),
322 ntype.
ui_name =
"Field Average";
323 ntype.
ui_description =
"Calculate the mean and median of a given field";
#define NODE_CLASS_CONVERTER
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void to_static_type(Fn &&fn) const
const CPPType & type() const
VArray< T > typed() const
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
ItemIterator items() const &
Value & lookup_or_add(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr T * end() const
constexpr T * begin() const
constexpr IndexRange index_range() const
static VArray from_single(T value, const int64_t size)
static VArray from_container(ContainerT container)
GVArray adapt_domain(const GVArray &varray, const AttrDomain from_domain, const AttrDomain to_domain) const
int domain_size(const AttrDomain domain) const
constexpr IndexRange index_range() const
int add(GField field, GVArray *varray_ptr)
const GVArray & get_evaluated(const int field_index) const
static GField from_input(Args &&...args)
const bke::bNodeType & node_type() const
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
T extract_input(const UString identifier)
bool output_is_required(const UString identifier) const
const bNode & node() const
void set_output(const UString identifier, T &&value)
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
Vector< SocketDeclaration * > inputs
T compute_sum(const Span< T > data)
void node_register_type(bNodeType &ntype)
T midpoint(const T &a, const T &b)
static void node_init(bNodeTree *, bNode *node)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static std::optional< eCustomDataType > node_type_from_other_socket(const bNodeSocket &socket)
static void node_rna(StructRNA *srna)
static void node_declare(NodeDeclarationBuilder &b)
static T calculate_median(MutableSpan< T > values)
void search_link_ops_for_declarations(GatherLinkSearchOpParams ¶ms, Span< SocketDeclaration * > declarations)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
VecBase< float, 3 > float3
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_attribute_domain_items[]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
void(*) initfunc(bNodeTree *ntree, bNode *node)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
nodes::NodeDeclaration * static_declaration
UniqueHash ensure(const GFieldRef &field)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)