Blender V5.0
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
24
25using LeafNodeMask = openvdb::util::NodeMask<3u>;
26
27using GetVoxelsFn = FunctionRef<void(MutableSpan<openvdb::Coord> r_voxels)>;
32using ProcessLeafFn = FunctionRef<void(const LeafNodeMask &leaf_node_mask,
33 const openvdb::CoordBBox &leaf_bbox,
34 GetVoxelsFn get_voxels_fn)>;
38using ProcessTilesFn = FunctionRef<void(Span<openvdb::CoordBBox> tiles)>;
43using ProcessVoxelsFn = FunctionRef<void(Span<openvdb::Coord> voxels)>;
44
49void parallel_grid_topology_tasks(const openvdb::MaskTree &mask_tree,
50 ProcessLeafFn process_leaf_fn,
51 ProcessVoxelsFn process_voxels_fn,
52 ProcessTilesFn process_tiles_fn);
53
54template<typename GridT>
55constexpr bool is_supported_grid_type = is_same_any_v<GridT,
56 openvdb::FloatGrid,
57 openvdb::Vec3fGrid,
58 openvdb::BoolGrid,
59 openvdb::Int32Grid,
60 openvdb::Vec4fGrid>;
61
62template<typename Fn> inline void to_typed_grid(const openvdb::GridBase &grid_base, Fn &&fn)
63{
64 const VolumeGridType grid_type = get_type(grid_base);
65 BKE_volume_grid_type_to_static_type(grid_type, [&](auto type_tag) {
66 using GridT = typename decltype(type_tag)::type;
67 if constexpr (is_supported_grid_type<GridT>) {
68 fn(static_cast<const GridT &>(grid_base));
69 }
70 else {
72 }
73 });
74}
75
76template<typename Fn> inline void to_typed_grid(openvdb::GridBase &grid_base, Fn &&fn)
77{
78 const VolumeGridType grid_type = get_type(grid_base);
79 BKE_volume_grid_type_to_static_type(grid_type, [&](auto type_tag) {
80 using GridT = typename decltype(type_tag)::type;
81 if constexpr (is_supported_grid_type<GridT>) {
82 fn(static_cast<GridT &>(grid_base));
83 }
84 else {
86 }
87 });
88}
89
91openvdb::GridBase::Ptr create_grid_with_topology(const openvdb::MaskTree &topology,
92 const openvdb::math::Transform &transform,
93 const VolumeGridType grid_type);
94
96void set_grid_values(openvdb::GridBase &grid_base, GSpan values, Span<openvdb::Coord> voxels);
97
102void set_tile_values(openvdb::GridBase &grid_base, GSpan values, Span<openvdb::CoordBBox> tiles);
103
108void set_mask_leaf_buffer_from_bools(openvdb::BoolGrid &grid,
109 Span<bool> values,
110 const IndexMask &index_mask,
111 Span<openvdb::Coord> voxels);
112
113void set_grid_background(openvdb::GridBase &grid_base, const GPointer value);
114
116void prune_inactive(openvdb::GridBase &grid_base);
117
118} // namespace blender::bke::volume_grid
119
121
122#endif /* WITH_OPENVDB */
VolumeGridType
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
VolumeGridType get_type(const VolumeGridData &grid)
constexpr bool is_same_any_v