Blender V5.3
BKE_volume_openvdb.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#ifdef WITH_OPENVDB
12
13# include <openvdb/openvdb.h> /* IWYU pragma: export */
14# include <openvdb/points/PointDataGrid.h> /* IWYU pragma: export */
15# include <optional>
16
17# include "BLI_bounds_types.hh"
21# include "BLI_string_ref.hh"
22
23# include "BKE_volume_enums.hh"
24# include "BKE_volume_grid_fwd.hh"
25
26# include "openvdb_fwd.hh"
27
28namespace blender {
29
30struct Volume;
31
32bke::VolumeGridData *BKE_volume_grid_add_vdb(Volume &volume,
33 StringRef name,
34 openvdb::GridBase::Ptr vdb_grid);
35
36void BKE_volume_metadata_set(Volume &volume, openvdb::MetaMap::Ptr metadata);
37
38std::optional<Bounds<float3>> BKE_volume_grid_bounds(openvdb::GridBase::ConstPtr grid);
39
45openvdb::GridBase::ConstPtr BKE_volume_grid_shallow_transform(openvdb::GridBase::ConstPtr grid,
46 const float4x4 &transform);
47
48float4x4 BKE_volume_transform_to_blender(const openvdb::math::Transform &transform);
49openvdb::math::Transform BKE_volume_transform_to_openvdb(const float4x4 &transform);
50
51template<typename OpType>
52auto BKE_volume_grid_type_operation(const VolumeGridType grid_type, OpType &&op)
53{
54 switch (grid_type) {
56 return op.template operator()<openvdb::FloatGrid>();
58 return op.template operator()<openvdb::Vec3fGrid>();
60 return op.template operator()<openvdb::BoolGrid>();
62 return op.template operator()<openvdb::DoubleGrid>();
63 case VOLUME_GRID_INT:
64 return op.template operator()<openvdb::Int32Grid>();
66 return op.template operator()<openvdb::Int64Grid>();
68 return op.template operator()<openvdb::Vec3IGrid>();
70 return op.template operator()<openvdb::Vec3dGrid>();
72 return op.template operator()<openvdb::MaskGrid>();
74 return op.template operator()<openvdb::points::PointDataGrid>();
76 break;
77 }
78
79 /* Should never be called. */
80 BLI_assert_msg(0, "should never be reached");
81 return op.template operator()<openvdb::FloatGrid>();
82}
83
84template<typename Fn>
85inline void BKE_volume_grid_type_to_static_type(const VolumeGridType grid_type, Fn &&fn)
86{
87 switch (grid_type) {
89 return fn.template operator()<openvdb::FloatGrid>();
91 return fn.template operator()<openvdb::Vec3fGrid>();
93 return fn.template operator()<openvdb::BoolGrid>();
95 return fn.template operator()<openvdb::DoubleGrid>();
96 case VOLUME_GRID_INT:
97 return fn.template operator()<openvdb::Int32Grid>();
99 return fn.template operator()<openvdb::Int64Grid>();
101 return fn.template operator()<openvdb::Vec3IGrid>();
103 return fn.template operator()<openvdb::Vec3dGrid>();
104 case VOLUME_GRID_MASK:
105 return fn.template operator()<openvdb::MaskGrid>();
107 return fn.template operator()<openvdb::points::PointDataGrid>();
109 break;
110 }
112}
113
114template<typename Fn>
115inline bool BKE_volume_grid_type_to_blender_value_type(const VolumeGridType grid_type, Fn &&fn)
116{
117 switch (grid_type) {
119 fn.template operator()<float>();
120 return true;
122 fn.template operator()<float3>();
123 return true;
125 fn.template operator()<bool>();
126 return true;
128 fn.template operator()<double>();
129 return true;
130 case VOLUME_GRID_INT:
131 fn.template operator()<int>();
132 return true;
134 fn.template operator()<int64_t>();
135 return true;
137 fn.template operator()<int3>();
138 return true;
140 fn.template operator()<double3>();
141 return true;
142 case VOLUME_GRID_MASK:
145 break;
146 }
147 return false;
148}
149
150openvdb::GridBase::Ptr BKE_volume_grid_create_with_changed_resolution(
151 const VolumeGridType grid_type, const openvdb::GridBase &old_grid, float resolution_factor);
152
153} // namespace blender
154
155#endif
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 3 > int3
@ VOLUME_GRID_VECTOR_FLOAT
@ VOLUME_GRID_VECTOR_DOUBLE
VecBase< double, 3 > double3
VecBase< float, 3 > float3