19# include "openvdb/tools/Morphology.h"
38 b.use_custom_socket_order();
39 b.allow_any_socket_order();
40 b.add_default_layout();
46 b.add_input(data_type,
"Grid"_ustr).hide_value().structure_type(StructureType::Grid);
47 b.add_output(data_type,
"Grid"_ustr).structure_type(StructureType::Grid).align_with_previous();
54 N_(
"6-connectivity: affect voxels connected by faces only")},
59 N_(
"18-connectivity: affect voxels connected by faces or edges only")},
64 N_(
"26-connectivity: affect voxels connected by faces, edges, or vertices")},
65 {0,
nullptr, 0,
nullptr,
nullptr},
73 N_(
"Ignore active tiles; they are neither dilated/eroded nor contribute to the operation")},
78 N_(
"Voxelize active tiles, apply operation, and leave in voxelized state")},
83 N_(
"Keep tiles unchanged when possible, only voxelizing if necessary. More memory "
85 {0,
nullptr, 0,
nullptr,
nullptr},
89 .static_items(connectivity_items)
91 .structure_type(StructureType::Single)
95 .static_items(tile_policy_items)
97 .structure_type(StructureType::Single)
105 .description(
"Number of times to dilate or erode the active voxels");
115 switch (socket.
type) {
134 const bool supports_grid =
ELEM(structure_type, StructureType::Grid, StructureType::Dynamic);
142 ELEM(structure_type, StructureType::Dynamic, StructureType::Single) &&
154 node.custom1 = *data_type;
161 node.custom1 = *data_type;
169static openvdb::tools::NearestNeighbors connectivity_to_openvdb(
const Connectivity connectivity)
171 switch (connectivity) {
173 return openvdb::tools::NN_FACE;
175 return openvdb::tools::NN_FACE_EDGE;
177 return openvdb::tools::NN_FACE_EDGE_VERTEX;
180 return openvdb::tools::NN_FACE;
183static openvdb::tools::TilePolicy tile_policy_to_openvdb(
const TilePolicy policy)
187 return openvdb::tools::IGNORE_TILES;
189 return openvdb::tools::EXPAND_TILES;
191 return openvdb::tools::PRESERVE_TILES;
194 return openvdb::tools::PRESERVE_TILES;
201 bke::GVolumeGrid grid = params.
extract_input<bke::GVolumeGrid>(
"Grid"_ustr);
211 params.
set_output(
"Grid"_ustr, std::move(grid));
215 const openvdb::tools::NearestNeighbors nn = connectivity_to_openvdb(connectivity);
216 const openvdb::tools::TilePolicy policy = tile_policy_to_openvdb(tile_policy);
218 bke::VolumeTreeAccessToken tree_token;
219 openvdb::GridBase &grid_base = grid.get_for_write().grid_for_write(tree_token);
220 bke::volume_grid::to_typed_grid(grid_base, [&](
auto &grid) {
222 openvdb::tools::dilateActiveValues(grid.tree(), steps, nn, policy);
225 openvdb::tools::erodeActiveValues(grid.tree(), -steps, nn, policy);
229 params.
set_output(
"Grid"_ustr, std::move(grid));
245 "Node socket data type",
257 ntype.
ui_name =
"Grid Dilate & Erode";
259 "Dilate or erode the active regions of a grid. This changes which voxels are "
260 "active but does not change their values.";
#define NODE_CLASS_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define BLI_assert_unreachable()
nodes::StructureType inferred_structure_type
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
T extract_input(const UString identifier)
void set_default_remaining_outputs()
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)
StructureType structure_type
void node_register_type(bNodeType &ntype)
static void node_rna(StructRNA *srna)
static void node_gather_link_search_ops(GatherLinkSearchOpParams ¶ms)
static std::optional< eNodeSocketDatatype > node_type_for_socket_type(const bNodeSocket &socket)
static void node_register()
static void node_init(bNodeTree *, bNode *node)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
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)
const EnumPropertyItem * grid_socket_type_items_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
bke::bNodeSocketRuntime * runtime
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
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
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)