Blender V5.3
node_geo_edges_to_face_groups.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 "DNA_mesh_types.h"
6
7#include "BKE_mesh_mapping.hh"
8
10
11#include "node_geometry_util.hh"
12
14
16{
17 b.add_input<decl::Bool>("Boundary Edges"_ustr)
18 .default_value(true)
19 .hide_value()
20 .structure_type(StructureType::Field)
21 .description("Edges used to split faces into separate groups");
22 b.add_output<decl::Int>("Face Group ID"_ustr)
23 .structure_type(StructureType::Field)
24 .propagate_references()
25 .description("Index of the face group inside each boundary edge region");
26}
27
29static void join_indices(AtomicDisjointSet &set, const Span<int> indices)
30{
31 for (const int i : indices.index_range().drop_back(1)) {
32 set.join(indices[i], indices[i + 1]);
33 }
34}
35
37 private:
38 Field<bool> non_boundary_edge_field_;
39
40 public:
42 : bke::MeshFieldInput(CPPType::get<int>(), "Edges to Face Groups"),
43 non_boundary_edge_field_(std::move(selection))
44 {
45 }
46
48 const AttrDomain domain,
49 const IndexMask & /*mask*/) const final
50 {
51 const bke::MeshFieldContext context{mesh, AttrDomain::Edge};
52 fn::FieldEvaluator evaluator{context, mesh.edges_num};
53 evaluator.add(non_boundary_edge_field_);
54 evaluator.evaluate();
55 const IndexMask non_boundary_edges = evaluator.get_evaluated_as_mask(0);
56
57 const OffsetIndices faces = mesh.faces();
58
59 Array<int> edge_to_face_offsets;
60 Array<int> edge_to_face_indices;
62 faces, mesh.corner_edges(), mesh.edges_num, edge_to_face_offsets, edge_to_face_indices);
63
65 non_boundary_edges.foreach_index(
66 [&](const int edge) { join_indices(islands, edge_to_face_map[edge]); },
68
69 Array<int> output(faces.size());
70 islands.calc_reduced_ids(output);
71
72 return mesh.attributes().adapt_domain(
73 VArray<int>::from_container(std::move(output)), AttrDomain::Face, domain);
74 }
75
76 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
77 {
78 static constexpr int8_t id = 0;
79 hash.add(&id);
80 hash.add(deep_hash_cache.ensure(non_boundary_edge_field_));
81 }
82
83 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
84 {
85 return AttrDomain::Face;
86 }
87};
88
90{
91 Field<bool> boundary_edges = params.extract_input<Field<bool>>("Boundary Edges"_ustr);
92 Field<bool> non_boundary_edges = fn::invert_boolean_field(std::move(boundary_edges));
93 params.set_output(
94 "Face Group ID"_ustr,
95 Field<int>::from_input<FaceSetFromBoundariesInput>(std::move(non_boundary_edges)));
96}
97
98static void node_register()
99{
100 static bke::bNodeType ntype;
101
102 geo_node_type_base(&ntype, "GeometryNodeEdgesToFaceGroups"_ustr, GEO_NODE_EDGES_TO_FACE_GROUPS);
103 ntype.ui_name = "Edges to Face Groups";
104 ntype.ui_description = "Group faces into regions surrounded by the selected boundary edges";
105 ntype.enum_name_legacy = "EDGES_TO_FACE_GROUPS";
106 ntype.nclass = NODE_CLASS_INPUT;
108 ntype.declare = node_declare;
110
112}
114
115} // namespace blender::nodes::node_geo_edges_to_face_groups_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_EDGES_TO_FACE_GROUPS
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define output
constexpr IndexRange drop_back(int64_t n) const
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
static VArray from_container(ContainerT container)
int add(GField field, GVArray *varray_ptr)
IndexMask get_evaluated_as_mask(int field_index)
uint64_t hash() const
Definition field.cc:185
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
static Field from_input(Args &&...args)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const override
GroupedSpan< int > build_edge_to_face_map(OffsetIndices< int > faces, Span< int > corner_edges, int edges_num, Array< int > &r_offsets, Array< int > &r_indices)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
constexpr ParallelGrainSize grain_size(int grain_size)
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition field.cc:564
static void join_indices(AtomicDisjointSet &set, const Span< int > indices)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
signed char int8_t
Definition BKE_text.h:76
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
UniqueHash ensure(const GFieldRef &field)
Definition field.cc:113