Blender V5.0
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").hide_value().structure_type(StructureType::Grid);
20 b.add_output<decl::Float>("Grid").structure_type(StructureType::Grid).align_with_previous();
21 b.add_input<decl::Int>("Iterations")
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");
31 if (!grid) {
32 params.set_default_remaining_outputs();
33 return;
34 }
35
36 const int iterations = params.extract_input<int>("Iterations");
37 if (iterations <= 0) {
38 params.set_output("Grid", 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", std::move(grid));
57#else
59#endif
60}
61
62static void node_register()
63{
64 static blender::bke::bNodeType ntype;
65 geo_node_type_base(&ntype, "GeometryNodeSDFGridLaplacian");
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:461
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define filter
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
NodeDeclareFunction declare
Definition BKE_node.hh:362
i
Definition text_draw.cc:230