29 if (
node !=
nullptr) {
31 b.add_input(data_type,
"Value"_ustr)
32 .structure_type(StructureType::Field)
33 .description(
"The values the standard deviation and variance will be calculated from");
36 b.add_input<
decl::Int>(
"Group ID"_ustr,
"Group Index"_ustr)
37 .structure_type(StructureType::Field)
39 .description(
"An index used to group values together for multiple separate operations");
41 if (
node !=
nullptr) {
43 b.add_output(data_type,
"Standard Deviation"_ustr)
44 .structure_type(StructureType::Field)
45 .propagate_references()
46 .description(
"The square root of the variance for each group");
47 b.add_output(data_type,
"Variance"_ustr)
48 .structure_type(StructureType::Field)
49 .propagate_references()
50 .description(
"The expected squared deviation from the mean for each group");
70 switch (socket.
type) {
94 IFACE_(
"Standard Deviation"),
105 node.custom1 = *type;
115 node.custom1 = *type;
135 input_(std::move(input)),
136 group_index_(std::move(group_index)),
137 source_domain_(source_domain),
138 operation_(operation)
147 if (domain_size == 0) {
153 evaluator.
add(input_);
154 evaluator.
add(group_index_);
166 const T mean = std::reduce(values.
begin(), values.
end(),
T()) / domain_size;
167 const T sum_of_squared_diffs = std::accumulate(
168 values.
begin(), values.
end(),
T(), [mean](
T accumulator,
const T &value) {
169 T difference = mean - value;
170 return accumulator + difference * difference;
180 auto &pair = sum_and_counts.
lookup_or_add(group_indices[i], std::make_pair(
T(), 0));
181 pair.first = pair.first + values[i];
182 pair.second = pair.second + 1;
186 const auto &pair = sum_and_counts.
lookup(group_indices[i]);
187 T mean = pair.first / pair.second;
188 T deviation = (mean - values[i]);
189 deviation = deviation * deviation;
192 dev_sum = dev_sum + deviation;
197 const auto &pair = sum_and_counts.
lookup(group_indices[i]);
205 const T mean = std::reduce(values.
begin(), values.
end(),
T()) / domain_size;
206 const T sum_of_squared_diffs = std::accumulate(
207 values.
begin(), values.
end(),
T(), [mean](
T accumulator,
const T &value) {
208 T difference = mean - value;
209 return accumulator + difference * difference;
218 auto &pair = sum_and_counts.
lookup_or_add(group_indices[i], std::make_pair(
T(), 0));
219 pair.first = pair.first + values[i];
220 pair.second = pair.second + 1;
224 const auto &pair = sum_and_counts.
lookup(group_indices[i]);
225 T mean = pair.first / pair.second;
226 T deviation = (mean - values[i]);
227 deviation = deviation * deviation;
230 dev_sum = dev_sum + deviation;
235 const auto &pair = sum_and_counts.
lookup(group_indices[i]);
236 outputs[i] = deviations.
lookup(group_indices[i]) / pair.second;
243 return attributes.
adapt_domain(std::move(g_outputs), source_domain_, context.domain());
254 static constexpr int8_t id = 0;
257 hash.add(deep_hash_cache.
ensure(group_index_));
258 hash.add(source_domain_);
259 hash.add(operation_);
265 return source_domain_;
277 "Standard Deviation"_ustr,
292 {
CD_PROP_FLOAT,
"FLOAT", ICON_NODE_SOCKET_FLOAT,
"Float",
"Floating-point value"},
295 ICON_NODE_SOCKET_VECTOR,
297 "3D vector with floating-point values"},
298 {0,
nullptr, 0,
nullptr,
nullptr},
304 "Type of data the outputs are calculated from",
315 int(AttrDomain::Point),
325 ntype.
ui_name =
"Field Variance";
326 ntype.
ui_description =
"Calculate the standard deviation and variance of a given field";
#define NODE_CLASS_CONVERTER
#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
const Value & lookup(const Key &key) const
Value & lookup_or_add(const Key &key, const Value &value)
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 const T * begin() const
constexpr IndexRange index_range() const
constexpr const T * end() 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
void node_register_type(bNodeType &ntype)
static void node_init(bNodeTree *, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_rna(StructRNA *srna)
static void node_geo_exec(GeoNodeExecParams params)
static void node_register()
static std::optional< eCustomDataType > node_type_from_other_socket(const bNodeSocket &socket)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
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)