52 const auto comparator = [&](
const int index_a,
const int index_b) {
53 const float weight_a = weights[index_a];
54 const float weight_b = weights[index_b];
55 if (
UNLIKELY(weight_a == weight_b)) {
57 return index_a < index_b;
59 return weight_a < weight_b;
63 for (const int group_index : range) {
64 MutableSpan<int> group = indices.slice(offsets[group_index]);
65 parallel_sort(group.begin(), group.end(), comparator);
74 offset_indices::build_reverse_offsets(indices, r_offsets);
77 for (
const int64_t index : indices.index_range()) {
78 const int curve_index = indices[index];
79 r_indices[r_offsets[curve_index] + counts[curve_index]] =
int(index);
80 counts[curve_index]++;
84template<
typename T,
typename Func>
87 threading::parallel_for(values.index_range(), grain_size, [&](
const IndexRange range) {
88 MutableSpan<T> values_range = values.slice(range);
89 std::transform(values_range.begin(), values_range.end(), values_range.begin(), func);
97 for (const int64_t i : range) {
98 data[permutation[i]] = i;
106 const VectorSet<int> deduplicated_identifiers(r_identifiers_to_indices);
108 return deduplicated_identifiers.
index_of(identifier);
112 array_utils::fill_index_range<int>(indices);
113 parallel_sort(indices.begin(), indices.end(), [&](
const int index_a,
const int index_b) {
114 return deduplicated_identifiers[index_a] < deduplicated_identifiers[index_b];
118 r_identifiers_to_indices, 4096, [&](
const int index) {
return permutation[index]; });
119 return deduplicated_identifiers.
size();
123 const int domain_size,
128 if (domain_size == 0) {
134 evaluator.
add(group_id_field);
135 evaluator.
add(weight_field);
141 if (group_id.
is_single() && weight.is_single()) {
144 if (mask.is_empty()) {
151 mask.to_indices<
int>(gathered_indices);
153 array_utils::copy(weight, mask, weight_span.as_mutable_span());
158 array_utils::gather(group_id, mask, gathered_group_id.
as_mutable_span());
160 Array<int> offsets_to_sort(total_groups + 1, 0);
162 if (!weight.is_single()) {
167 parallel_transform<int>(gathered_indices, 2048, [&](
const int pos) {
return mask[
pos]; });
170 if (array_utils::indices_are_range(gathered_indices,
IndexRange(domain_size))) {
174 if (mask.size() == domain_size) {
175 return gathered_indices;
183 array_utils::scatter<int>(gathered_indices, mask, indices);
185 [&](
const int index) { indices[index] = index; });
187 if (array_utils::indices_are_range(indices, indices.index_range())) {
204 GeometryComponentEditData::remember_deformed_positions_if_necessary(geometry_set);
206 std::atomic<bool> has_reorder =
false;
207 std::atomic<bool> has_unsupported =
false;
208 if (domain == bke::AttrDomain::Instance) {
212 instances->instances_num(),
218 *instances, *indices, attribute_filter);
226 for (
const auto [type, domains] : geometry::components_supported_reordering().items()) {
228 if (src_component ==
nullptr || src_component->
is_empty()) {
231 if (!domains.contains(domain)) {
232 has_unsupported =
true;
242 if (!indices.has_value()) {
246 *src_component, *indices, domain, attribute_filter);
247 geometry_set.
remove(type);
248 geometry_set.
add(*dst_component.
get());
253 if (has_unsupported && !has_reorder) {
254 params.error_message_add(NodeWarningType::Info,
255 TIP_(
"Domain and geometry type combination is unsupported"));
258 params.set_output(
"Geometry", std::move(geometry_set));
267 if (values.contains(T(item->value))) {
271 items.
append({0,
nullptr, 0,
nullptr,
nullptr});
278 {bke::AttrDomain::Point,
279 bke::AttrDomain::Edge,
280 bke::AttrDomain::Face,
281 bke::AttrDomain::Curve,
282 bke::AttrDomain::Instance},
289 supported_items.
data(),
291 int(bke::AttrDomain::Point));
#define NODE_CLASS_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
constexpr int64_t size() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
int64_t index_of(const Key &key) const
void append(const T &value)
int attribute_domain_size(AttrDomain domain) const
virtual bool is_empty() const
void set_selection(Field< bool > selection)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_selection_as_mask() const
const GVArray & get_evaluated(const int field_index) const
void foreach_index_optimized(Fn &&fn) const
IndexMask complement(const IndexMask &universe, IndexMaskMemory &memory) const
IndexRange index_range() const
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void node_register_type(bNodeType *ntype)
static void node_declare(NodeDeclarationBuilder &b)
static int identifiers_to_indices(MutableSpan< int > r_identifiers_to_indices)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void parallel_transform(MutableSpan< T > values, const int64_t grain_size, const Func &func)
static void node_geo_exec(GeoNodeExecParams params)
static void node_register()
static void node_rna(StructRNA *srna)
static Vector< EnumPropertyItem > items_value_in(const Span< T > values, const EnumPropertyItem *src_items)
static Array< int > invert_permutation(const Span< int > permutation)
static std::optional< Array< int > > sorted_indices(const fn::FieldContext &field_context, const int domain_size, const Field< bool > selection_field, const Field< int > group_id_field, const Field< float > weight_field)
static void grouped_sort(const OffsetIndices< int > offsets, const Span< float > weights, MutableSpan< int > indices)
static void find_points_by_group_index(const Span< int > indices, MutableSpan< int > r_offsets, MutableSpan< int > r_indices)
static void node_init(bNodeTree *, bNode *node)
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)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void parallel_sort(RandomAccessIterator begin, RandomAccessIterator end)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
const EnumPropertyItem rna_enum_attribute_domain_items[]
void replace_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
const Instances * get_instances() const
void remove(const GeometryComponent::Type component_type)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
void add(const GeometryComponent &component)
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare