Blender V5.3
node_geo_sdf_grid_laplacian.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_volume_grid.hh"
6
8
9#ifdef WITH_OPENVDB
10# include "openvdb/tools/LevelSetFilter.h"
11#endif
12
14
16{
17 b.use_custom_socket_order();
18 b.allow_any_socket_order();
19 b.add_input<decl::Float>("Grid"_ustr).hide_value().structure_type(StructureType::Grid);
20 b.add_output<decl::Float>("Grid"_ustr).structure_type(StructureType::Grid).align_with_previous();
21 b.add_input<decl::Int>("Iterations"_ustr)
22 .default_value(1)
23 .min(0)
24 .description("Number of iterations to apply the filter");
25}
26
28{
29#ifdef WITH_OPENVDB
30 auto grid = params.extract_input<bke::VolumeGrid<float>>("Grid"_ustr);
31 if (!grid) {
33 return;
34 }
35
36 const int iterations = params.extract_input<int>("Iterations"_ustr);
37 if (iterations <= 0) {
38 params.set_output("Grid"_ustr, std::move(grid));
39 return;
40 }
41
42 bke::VolumeTreeAccessToken tree_token;
43 openvdb::FloatGrid &vdb_grid = grid.grid_for_write(tree_token);
44
45 try {
46 openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(vdb_grid);
47 for (int i = 0; i < iterations; i++) {
48 filter.laplacian();
49 }
50 }
51 catch (const openvdb::RuntimeError & /*e*/) {
53 return;
54 }
55
56 params.set_output("Grid"_ustr, std::move(grid));
57#else
59#endif
60}
61
62static void node_register()
63{
64 static bke::bNodeType ntype;
65 geo_node_type_base(&ntype, "GeometryNodeSDFGridLaplacian"_ustr);
66 ntype.ui_name = "SDF Grid Laplacian";
67 ntype.ui_description =
68 "Apply Laplacian flow smoothing to a signed distance field. Computationally efficient "
69 "alternative to mean curvature flow, ideal when combined with SDF normalization";
71 ntype.declare = node_declare;
74}
76
77} // namespace blender::nodes::node_geo_sdf_grid_laplacian_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define NOD_REGISTER_NODE(REGISTER_FUNC)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
void node_geo_sdf_grid_error_not_levelset(GeoNodeExecParams &params)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams &params)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
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
NodeDeclareFunction declare
Definition BKE_node.hh:393