Blender  V3.3
node_geo_input_mesh_vertex_neighbors.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "DNA_mesh_types.h"
4 #include "DNA_meshdata_types.h"
5 
6 #include "BKE_mesh.h"
7 
8 #include "node_geometry_util.hh"
9 
11 
13 {
14  b.add_output<decl::Int>(N_("Vertex Count"))
15  .field_source()
16  .description(N_("The number of vertices connected to this vertex with an edge, "
17  "equal to the number of connected edges"));
18  b.add_output<decl::Int>(N_("Face Count"))
19  .field_source()
20  .description(N_("Number of faces that contain the vertex"));
21 }
22 
24  const eAttrDomain domain)
25 {
26  const Mesh *mesh = component.get_for_read();
27  if (mesh == nullptr) {
28  return {};
29  }
30 
31  if (domain == ATTR_DOMAIN_POINT) {
32  Array<int> vertices(mesh->totvert, 0);
33  for (const int i : IndexRange(mesh->totedge)) {
34  vertices[mesh->medge[i].v1]++;
35  vertices[mesh->medge[i].v2]++;
36  }
37  return VArray<int>::ForContainer(std::move(vertices));
38  }
39  return {};
40 }
41 
43  public:
44  VertexCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Count Field")
45  {
47  }
48 
50  const eAttrDomain domain,
51  IndexMask UNUSED(mask)) const final
52  {
53  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
54  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
55  return construct_vertex_count_gvarray(mesh_component, domain);
56  }
57  return {};
58  }
59 
60  uint64_t hash() const override
61  {
62  /* Some random constant hash. */
63  return 23574528465;
64  }
65 
66  bool is_equal_to(const fn::FieldNode &other) const override
67  {
68  return dynamic_cast<const VertexCountFieldInput *>(&other) != nullptr;
69  }
70 };
71 
73  const eAttrDomain domain)
74 {
75  const Mesh *mesh = component.get_for_read();
76  if (mesh == nullptr) {
77  return {};
78  }
79 
80  if (domain == ATTR_DOMAIN_POINT) {
81  Array<int> vertices(mesh->totvert, 0);
82  for (const int i : IndexRange(mesh->totloop)) {
83  int vertex = mesh->mloop[i].v;
84  vertices[vertex]++;
85  }
86  return VArray<int>::ForContainer(std::move(vertices));
87  }
88  return {};
89 }
90 
92  public:
93  VertexFaceCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Face Count Field")
94  {
96  }
97 
99  const eAttrDomain domain,
100  IndexMask UNUSED(mask)) const final
101  {
102  if (component.type() == GEO_COMPONENT_TYPE_MESH) {
103  const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
104  return construct_face_count_gvarray(mesh_component, domain);
105  }
106  return {};
107  }
108 
109  uint64_t hash() const override
110  {
111  /* Some random constant hash. */
112  return 3462374322;
113  }
114 
115  bool is_equal_to(const fn::FieldNode &other) const override
116  {
117  return dynamic_cast<const VertexFaceCountFieldInput *>(&other) != nullptr;
118  }
119 };
120 
122 {
123  Field<int> vertex_field{std::make_shared<VertexCountFieldInput>()};
124  Field<int> face_field{std::make_shared<VertexFaceCountFieldInput>()};
125 
126  params.set_output("Vertex Count", std::move(vertex_field));
127  params.set_output("Face Count", std::move(face_field));
128 }
129 
130 } // namespace blender::nodes::node_geo_input_mesh_vertex_neighbors_cc
131 
133 {
135 
136  static bNodeType ntype;
138  &ntype, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS, "Vertex Neighbors", NODE_CLASS_INPUT);
141  nodeRegisterType(&ntype);
142 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
@ GEO_COMPONENT_TYPE_MESH
#define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS
Definition: BKE_node.h:1482
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define final(a, b, c)
Definition: BLI_hash.h:21
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
static VArray ForContainer(ContainerT container)
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static VArray< int > construct_face_count_gvarray(const MeshComponent &component, const eAttrDomain domain)
static VArray< int > construct_vertex_count_gvarray(const MeshComponent &component, const eAttrDomain domain)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_input_mesh_vertex_neighbors()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition: stdint.h:90
unsigned int v1
unsigned int v2
unsigned int v
struct MEdge * medge
int totedge
int totvert
struct MLoop * mloop
int totloop
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)