Blender  V3.3
BKE_volume.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 struct BoundBox;
14 struct Depsgraph;
15 struct Main;
16 struct Object;
17 struct ReportList;
18 struct Scene;
19 struct Volume;
20 struct VolumeGridVector;
21 
22 /* Module */
23 
24 void BKE_volumes_init(void);
25 
26 /* Data-block Management */
27 
28 void BKE_volume_init_grids(struct Volume *volume);
29 void *BKE_volume_add(struct Main *bmain, const char *name);
30 
31 struct BoundBox *BKE_volume_boundbox_get(struct Object *ob);
32 
33 bool BKE_volume_is_y_up(const struct Volume *volume);
34 bool BKE_volume_is_points_only(const struct Volume *volume);
35 
36 /* Depsgraph */
37 
38 void BKE_volume_eval_geometry(struct Depsgraph *depsgraph, struct Volume *volume);
40  struct Scene *scene,
41  struct Object *object);
42 
43 void BKE_volume_grids_backup_restore(struct Volume *volume,
44  struct VolumeGridVector *grids,
45  const char *filepath);
46 
47 /* Draw Cache */
48 
49 enum {
51 };
52 
53 void BKE_volume_batch_cache_dirty_tag(struct Volume *volume, int mode);
54 void BKE_volume_batch_cache_free(struct Volume *volume);
55 
56 extern void (*BKE_volume_batch_cache_dirty_tag_cb)(struct Volume *volume, int mode);
57 extern void (*BKE_volume_batch_cache_free_cb)(struct Volume *volume);
58 
59 /* Grids
60  *
61  * For volumes referencing a file, the list of grids and metadata must be
62  * loaded before it can be accessed. This happens on-demand, only when needed
63  * by the user interface, dependency graph or render engine. */
64 
65 typedef struct VolumeGrid VolumeGrid;
66 
67 bool BKE_volume_load(const struct Volume *volume, const struct Main *bmain);
68 void BKE_volume_unload(struct Volume *volume);
69 bool BKE_volume_is_loaded(const struct Volume *volume);
70 
71 int BKE_volume_num_grids(const struct Volume *volume);
72 const char *BKE_volume_grids_error_msg(const struct Volume *volume);
73 const char *BKE_volume_grids_frame_filepath(const struct Volume *volume);
74 const VolumeGrid *BKE_volume_grid_get_for_read(const struct Volume *volume, int grid_index);
75 VolumeGrid *BKE_volume_grid_get_for_write(struct Volume *volume, int grid_index);
77 /* Tries to find a grid with the given name. Make sure that the volume has been loaded. */
78 const VolumeGrid *BKE_volume_grid_find_for_read(const struct Volume *volume, const char *name);
79 
80 /* Tries to set the name of the velocity field. If no such grid exists with the given base name,
81  * this will try common post-fixes in order to detect velocity fields split into multiple grids.
82  * Return false if neither finding with the base name nor with the post-fixes succeeded. */
83 bool BKE_volume_set_velocity_grid_by_name(struct Volume *volume, const char *base_name);
84 
85 /* Grid
86  *
87  * By default only grid metadata is loaded, for access to the tree and voxels
88  * BKE_volume_grid_load must be called first. */
89 
90 typedef enum VolumeGridType {
103 
104 bool BKE_volume_grid_load(const struct Volume *volume, const struct VolumeGrid *grid);
105 void BKE_volume_grid_unload(const struct Volume *volume, const struct VolumeGrid *grid);
106 bool BKE_volume_grid_is_loaded(const struct VolumeGrid *grid);
107 
108 /* Metadata */
109 
110 const char *BKE_volume_grid_name(const struct VolumeGrid *grid);
112 int BKE_volume_grid_channels(const struct VolumeGrid *grid);
116 void BKE_volume_grid_transform_matrix(const struct VolumeGrid *grid, float mat[4][4]);
117 void BKE_volume_grid_transform_matrix_set(struct VolumeGrid *volume_grid, const float mat[4][4]);
118 
119 /* Volume Editing
120  *
121  * These are intended for modifiers to use on evaluated data-blocks.
122  *
123  * new_for_eval creates a volume data-block with no grids or file path, but
124  * preserves other settings such as viewport display options.
125  *
126  * copy_for_eval creates a volume data-block preserving everything except the
127  * file path. Grids are shared with the source data-block, not copied. */
128 
129 struct Volume *BKE_volume_new_for_eval(const struct Volume *volume_src);
130 struct Volume *BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference);
131 
132 struct VolumeGrid *BKE_volume_grid_add(struct Volume *volume,
133  const char *name,
135 void BKE_volume_grid_remove(struct Volume *volume, struct VolumeGrid *grid);
136 
141 
142 /* Simplify */
145 
146 /* File Save */
147 bool BKE_volume_save(const struct Volume *volume,
148  const struct Main *bmain,
149  struct ReportList *reports,
150  const char *filepath);
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 /* OpenVDB Grid Access
157  *
158  * Access to OpenVDB grid for C++. These will automatically load grids from
159  * file or copy shared grids to make them writeable. */
160 
161 #ifdef __cplusplus
162 # include "BLI_float4x4.hh"
163 # include "BLI_math_vec_types.hh"
164 # include "BLI_string_ref.hh"
165 
166 bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max);
167 
168 # ifdef WITH_OPENVDB
169 # include <openvdb/openvdb.h>
170 # include <openvdb/points/PointDataGrid.h>
171 
172 VolumeGrid *BKE_volume_grid_add_vdb(Volume &volume,
173  blender::StringRef name,
174  openvdb::GridBase::Ptr vdb_grid);
175 
176 bool BKE_volume_grid_bounds(openvdb::GridBase::ConstPtr grid,
177  blender::float3 &r_min,
178  blender::float3 &r_max);
179 
185 openvdb::GridBase::ConstPtr BKE_volume_grid_shallow_transform(openvdb::GridBase::ConstPtr grid,
187 
188 openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_metadata(const struct VolumeGrid *grid);
189 openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const struct Volume *volume,
190  const struct VolumeGrid *grid);
191 openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const struct Volume *volume,
192  struct VolumeGrid *grid,
193  bool clear);
194 
195 void BKE_volume_grid_clear_tree(Volume &volume, VolumeGrid &volume_grid);
196 void BKE_volume_grid_clear_tree(openvdb::GridBase &grid);
197 
198 VolumeGridType BKE_volume_grid_type_openvdb(const openvdb::GridBase &grid);
199 
200 template<typename OpType>
201 auto BKE_volume_grid_type_operation(const VolumeGridType grid_type, OpType &&op)
202 {
203  switch (grid_type) {
204  case VOLUME_GRID_FLOAT:
205  return op.template operator()<openvdb::FloatGrid>();
207  return op.template operator()<openvdb::Vec3fGrid>();
208  case VOLUME_GRID_BOOLEAN:
209  return op.template operator()<openvdb::BoolGrid>();
210  case VOLUME_GRID_DOUBLE:
211  return op.template operator()<openvdb::DoubleGrid>();
212  case VOLUME_GRID_INT:
213  return op.template operator()<openvdb::Int32Grid>();
214  case VOLUME_GRID_INT64:
215  return op.template operator()<openvdb::Int64Grid>();
217  return op.template operator()<openvdb::Vec3IGrid>();
219  return op.template operator()<openvdb::Vec3dGrid>();
220  case VOLUME_GRID_MASK:
221  return op.template operator()<openvdb::MaskGrid>();
222  case VOLUME_GRID_POINTS:
223  return op.template operator()<openvdb::points::PointDataGrid>();
224  case VOLUME_GRID_UNKNOWN:
225  break;
226  }
227 
228  /* Should never be called. */
229  BLI_assert_msg(0, "should never be reached");
230  return op.template operator()<openvdb::FloatGrid>();
231 }
232 
233 openvdb::GridBase::Ptr BKE_volume_grid_create_with_changed_resolution(
234  const VolumeGridType grid_type, const openvdb::GridBase &old_grid, float resolution_factor);
235 
236 # endif
237 #endif
void(* BKE_volume_batch_cache_dirty_tag_cb)(struct Volume *volume, int mode)
Definition: volume.cc:1212
void BKE_volume_init_grids(struct Volume *volume)
Definition: volume.cc:679
struct VolumeGrid * BKE_volume_grid_add(struct Volume *volume, const char *name, VolumeGridType type)
Definition: volume.cc:1542
const VolumeGrid * BKE_volume_grid_get_for_read(const struct Volume *volume, int grid_index)
VolumeGridType BKE_volume_grid_type(const struct VolumeGrid *grid)
void BKE_volume_batch_cache_free(struct Volume *volume)
Definition: volume.cc:1222
VolumeGridType
Definition: BKE_volume.h:90
@ VOLUME_GRID_VECTOR_FLOAT
Definition: BKE_volume.h:98
@ VOLUME_GRID_MASK
Definition: BKE_volume.h:97
@ VOLUME_GRID_VECTOR_DOUBLE
Definition: BKE_volume.h:99
@ VOLUME_GRID_VECTOR_INT
Definition: BKE_volume.h:100
@ VOLUME_GRID_UNKNOWN
Definition: BKE_volume.h:91
@ VOLUME_GRID_DOUBLE
Definition: BKE_volume.h:94
@ VOLUME_GRID_BOOLEAN
Definition: BKE_volume.h:92
@ VOLUME_GRID_INT
Definition: BKE_volume.h:95
@ VOLUME_GRID_INT64
Definition: BKE_volume.h:96
@ VOLUME_GRID_POINTS
Definition: BKE_volume.h:101
@ VOLUME_GRID_FLOAT
Definition: BKE_volume.h:93
struct BoundBox * BKE_volume_boundbox_get(struct Object *ob)
Definition: volume.cc:1007
VolumeGrid * BKE_volume_grid_get_for_write(struct Volume *volume, int grid_index)
Definition: volume.cc:1277
void BKE_volume_grid_transform_matrix(const struct VolumeGrid *grid, float mat[4][4])
int BKE_volume_simplify_level(const struct Depsgraph *depsgraph)
const VolumeGrid * BKE_volume_grid_find_for_read(const struct Volume *volume, const char *name)
void BKE_volume_unload(struct Volume *volume)
Definition: volume.cc:930
void BKE_volume_batch_cache_dirty_tag(struct Volume *volume, int mode)
Definition: volume.cc:1215
bool BKE_volume_save(const struct Volume *volume, const struct Main *bmain, struct ReportList *reports, const char *filepath)
void BKE_volume_grid_remove(struct Volume *volume, struct VolumeGrid *grid)
Definition: volume.cc:1578
void BKE_volume_grids_backup_restore(struct Volume *volume, struct VolumeGridVector *grids, const char *filepath)
Definition: volume.cc:1183
void BKE_volume_eval_geometry(struct Depsgraph *depsgraph, struct Volume *volume)
Definition: volume.cc:1120
const char * BKE_volume_grids_frame_filepath(const struct Volume *volume)
int BKE_volume_grid_channels(const struct VolumeGrid *grid)
void BKE_volume_grid_transform_matrix_set(struct VolumeGrid *volume_grid, const float mat[4][4])
Definition: volume.cc:1480
void BKE_volumes_init(void)
Definition: volume.cc:500
void BKE_volume_grid_unload(const struct Volume *volume, const struct VolumeGrid *grid)
void BKE_volume_data_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object)
Definition: volume.cc:1159
bool BKE_volume_grid_is_loaded(const struct VolumeGrid *grid)
const char * BKE_volume_grid_name(const struct VolumeGrid *grid)
struct Volume * BKE_volume_new_for_eval(const struct Volume *volume_src)
float BKE_volume_simplify_factor(const struct Depsgraph *depsgraph)
void(* BKE_volume_batch_cache_free_cb)(struct Volume *volume)
Definition: volume.cc:1213
bool BKE_volume_is_points_only(const struct Volume *volume)
int BKE_volume_num_grids(const struct Volume *volume)
@ BKE_VOLUME_BATCH_DIRTY_ALL
Definition: BKE_volume.h:50
struct Volume * BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference)
Definition: volume.cc:1515
const VolumeGrid * BKE_volume_grid_active_get_for_read(const struct Volume *volume)
const char * BKE_volume_grids_error_msg(const struct Volume *volume)
bool BKE_volume_grid_determinant_valid(double determinant)
Definition: volume.cc:1593
bool BKE_volume_is_loaded(const struct Volume *volume)
void * BKE_volume_add(struct Main *bmain, const char *name)
Definition: volume.cc:690
bool BKE_volume_set_velocity_grid_by_name(struct Volume *volume, const char *base_name)
Definition: volume.cc:796
bool BKE_volume_grid_load(const struct Volume *volume, const struct VolumeGrid *grid)
bool BKE_volume_load(const struct Volume *volume, const struct Main *bmain)
bool BKE_volume_is_y_up(const struct Volume *volume)
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
btScalar determinant() const
Return the determinant of the matrix.
Definition: btMatrix3x3.h:1022
Scene scene
const Depsgraph * depsgraph
SyclQueue void void size_t num_bytes void
static void clear(Message *msg)
Definition: msgfmt.c:278
std::unique_ptr< T > Ptr
Definition: BLI_any.hh:58
Definition: BKE_main.h:121
void reference()
Definition: graph/node.h:185
bool BKE_volume_min_max(const Volume *volume, float3 &r_min, float3 &r_max)
Definition: volume.cc:981