Blender V5.3
BKE_volume_grid_process.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#ifdef WITH_OPENVDB
12
13# include <openvdb/openvdb.h>
14
15# include "BKE_volume_grid.hh"
16# include "BKE_volume_openvdb.hh"
17
18# include "BLI_function_ref.hh"
19# include "BLI_generic_pointer.hh"
20# include "BLI_generic_span.hh"
21# include "BLI_index_mask_fwd.hh"
22
23# include "FN_field.hh"
24
26
27using LeafNodeMask = openvdb::util::NodeMask<3u>;
28
29using GetVoxelsFn = FunctionRef<void(MutableSpan<openvdb::Coord> r_voxels)>;
34using ProcessLeafFn = FunctionRef<void(const LeafNodeMask &leaf_node_mask,
35 const openvdb::CoordBBox &leaf_bbox,
36 GetVoxelsFn get_voxels_fn)>;
40using ProcessTilesFn = FunctionRef<void(Span<openvdb::CoordBBox> tiles)>;
45using ProcessVoxelsFn = FunctionRef<void(Span<openvdb::Coord> voxels)>;
46
51void parallel_grid_topology_tasks(const openvdb::MaskTree &mask_tree,
52 ProcessLeafFn process_leaf_fn,
53 ProcessVoxelsFn process_voxels_fn,
54 ProcessTilesFn process_tiles_fn);
55
56template<typename GridT>
57constexpr bool is_supported_grid_type = is_same_any_v<GridT,
58 openvdb::FloatGrid,
59 openvdb::Vec3fGrid,
60 openvdb::BoolGrid,
61 openvdb::Int32Grid,
62 openvdb::Vec4fGrid>;
63
64template<typename Fn> inline void to_typed_grid(const openvdb::GridBase &grid_base, Fn &&fn)
65{
66 const VolumeGridType grid_type = get_type(grid_base);
67 BKE_volume_grid_type_to_static_type(grid_type,
68 [&]<std::derived_from<openvdb::GridBase> GridT>() {
69 if constexpr (is_supported_grid_type<GridT>) {
70 fn(static_cast<const GridT &>(grid_base));
71 }
72 else {
74 }
75 });
76}
77
78template<typename Fn> inline void to_typed_grid(openvdb::GridBase &grid_base, Fn &&fn)
79{
80 const VolumeGridType grid_type = get_type(grid_base);
81 BKE_volume_grid_type_to_static_type(grid_type,
82 [&]<std::derived_from<openvdb::GridBase> GridT>() {
83 if constexpr (is_supported_grid_type<GridT>) {
84 fn(static_cast<GridT &>(grid_base));
85 }
86 else {
88 }
89 });
90}
91
93openvdb::GridBase::Ptr create_grid_with_topology(const openvdb::MaskTree &topology,
94 const openvdb::math::Transform &transform,
95 const VolumeGridType grid_type);
96
98void set_grid_values(openvdb::GridBase &grid_base, GSpan values, Span<openvdb::Coord> voxels);
99
104void set_tile_values(openvdb::GridBase &grid_base, GSpan values, Span<openvdb::CoordBBox> tiles);
105
110void set_leaf_values_off(openvdb::GridBase &grid_base,
111 const openvdb::Coord &probe_coord,
112 Span<bool> selection);
114void set_grid_values_off(openvdb::GridBase &grid_base,
115 Span<bool> selection,
116 Span<openvdb::Coord> voxels);
117
119void set_tile_values_off(openvdb::GridBase &grid_base,
120 Span<bool> selection,
121 Span<openvdb::CoordBBox> tiles);
122
127void set_mask_leaf_buffer_from_bools(openvdb::BoolGrid &grid,
128 Span<bool> values,
129 const IndexMask &index_mask,
130 Span<openvdb::Coord> voxels);
131
132void set_grid_background(openvdb::GridBase &grid_base, const GPointer value);
133void set_inactive_values(openvdb::GridBase &grid_base, const GPointer value);
134
136void prune_inactive(openvdb::GridBase &grid_base);
137
148void sample_tree_indices(const VolumeGridType grid_type,
149 const openvdb::TreeBase &tree_base,
150 Span<int> xs,
151 Span<int> ys,
152 Span<int> zs,
153 const IndexMask &mask,
154 GMutableSpan r_values);
155
156std::optional<VolumeGridType> cpp_type_to_grid_type(const CPPType &cpp_type);
157
158void evaluate_fields_to_grid(const openvdb::MaskTree &mask_tree,
159 const openvdb::math::Transform &transform,
160 Span<fn::GField> fields,
161 MutableSpan<bke::GVolumeGrid> r_output_grids);
162
163} // namespace blender::bke::volume_grid
164
165#endif /* WITH_OPENVDB */
#define BLI_assert_unreachable()
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
VolumeGridType get_type(const VolumeGridData &grid)
constexpr bool is_same_any_v