Blender  V2.93
BKE_volume.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 struct BoundBox;
28 struct Depsgraph;
29 struct Main;
30 struct Object;
31 struct ReportList;
32 struct Scene;
33 struct Volume;
34 struct VolumeGridVector;
35 
36 /* Module */
37 
38 void BKE_volumes_init(void);
39 
40 /* Datablock Management */
41 
42 void BKE_volume_init_grids(struct Volume *volume);
43 void *BKE_volume_add(struct Main *bmain, const char *name);
44 
45 struct BoundBox *BKE_volume_boundbox_get(struct Object *ob);
46 
47 bool BKE_volume_is_y_up(const struct Volume *volume);
48 bool BKE_volume_is_points_only(const struct Volume *volume);
49 
50 /* Depsgraph */
51 
52 void BKE_volume_eval_geometry(struct Depsgraph *depsgraph, struct Volume *volume);
54  struct Scene *scene,
55  struct Object *object);
56 
57 void BKE_volume_grids_backup_restore(struct Volume *volume,
58  struct VolumeGridVector *grids,
59  const char *filepath);
60 
61 /* Draw Cache */
62 
63 enum {
65 };
66 
67 void BKE_volume_batch_cache_dirty_tag(struct Volume *volume, int mode);
68 void BKE_volume_batch_cache_free(struct Volume *volume);
69 
70 extern void (*BKE_volume_batch_cache_dirty_tag_cb)(struct Volume *volume, int mode);
71 extern void (*BKE_volume_batch_cache_free_cb)(struct Volume *volume);
72 
73 /* Grids
74  *
75  * For volumes referencing a file, the list of grids and metadata must be
76  * loaded before it can be accessed. This happens on-demand, only when needed
77  * by the user interface, dependency graph or render engine. */
78 
79 typedef struct VolumeGrid VolumeGrid;
80 
81 bool BKE_volume_load(const struct Volume *volume, const struct Main *bmain);
82 void BKE_volume_unload(struct Volume *volume);
83 bool BKE_volume_is_loaded(const struct Volume *volume);
84 
85 int BKE_volume_num_grids(const struct Volume *volume);
86 const char *BKE_volume_grids_error_msg(const struct Volume *volume);
87 const char *BKE_volume_grids_frame_filepath(const struct Volume *volume);
88 const VolumeGrid *BKE_volume_grid_get_for_read(const struct Volume *volume, int grid_index);
89 VolumeGrid *BKE_volume_grid_get_for_write(struct Volume *volume, int grid_index);
91 const VolumeGrid *BKE_volume_grid_find_for_read(const struct Volume *volume, const char *name);
92 
93 /* Grid
94  *
95  * By default only grid metadata is loaded, for access to the tree and voxels
96  * BKE_volume_grid_load must be called first. */
97 
98 typedef enum VolumeGridType {
112 
113 bool BKE_volume_grid_load(const struct Volume *volume, const struct VolumeGrid *grid);
114 void BKE_volume_grid_unload(const struct Volume *volume, const struct VolumeGrid *grid);
115 bool BKE_volume_grid_is_loaded(const struct VolumeGrid *grid);
116 
117 /* Metadata */
118 const char *BKE_volume_grid_name(const struct VolumeGrid *grid);
120 int BKE_volume_grid_channels(const struct VolumeGrid *grid);
121 void BKE_volume_grid_transform_matrix(const struct VolumeGrid *grid, float mat[4][4]);
122 
123 /* Volume Editing
124  *
125  * These are intended for modifiers to use on evaluated datablocks.
126  *
127  * new_for_eval creates a volume datablock with no grids or file path, but
128  * preserves other settings such as viewport display options.
129  *
130  * copy_for_eval creates a volume datablock preserving everything except the
131  * file path. Grids are shared with the source datablock, not copied. */
132 
133 struct Volume *BKE_volume_new_for_eval(const struct Volume *volume_src);
134 struct Volume *BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference);
135 
136 struct VolumeGrid *BKE_volume_grid_add(struct Volume *volume,
137  const char *name,
139 void BKE_volume_grid_remove(struct Volume *volume, struct VolumeGrid *grid);
140 
141 /* Simplify */
144 
145 /* File Save */
146 bool BKE_volume_save(const struct Volume *volume,
147  const struct Main *bmain,
148  struct ReportList *reports,
149  const char *filepath);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 /* OpenVDB Grid Access
156  *
157  * Access to OpenVDB grid for C++. These will automatically load grids from
158  * file or copy shared grids to make them writeable. */
159 
160 #ifdef __cplusplus
161 # include "BLI_float3.hh"
162 # include "BLI_float4x4.hh"
163 
164 bool BKE_volume_min_max(const Volume *volume, blender::float3 &r_min, blender::float3 &r_max);
165 
166 # ifdef WITH_OPENVDB
167 # include <openvdb/openvdb.h>
168 # include <openvdb/points/PointDataGrid.h>
169 
170 bool BKE_volume_grid_bounds(openvdb::GridBase::ConstPtr grid,
171  blender::float3 &r_min,
172  blender::float3 &r_max);
173 
174 openvdb::GridBase::ConstPtr BKE_volume_grid_shallow_transform(openvdb::GridBase::ConstPtr grid,
176 
177 openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_metadata(const struct VolumeGrid *grid);
178 openvdb::GridBase::ConstPtr BKE_volume_grid_openvdb_for_read(const struct Volume *volume,
179  const struct VolumeGrid *grid);
180 openvdb::GridBase::Ptr BKE_volume_grid_openvdb_for_write(const struct Volume *volume,
181  struct VolumeGrid *grid,
182  const bool clear);
183 
184 VolumeGridType BKE_volume_grid_type_openvdb(const openvdb::GridBase &grid);
185 
186 template<typename OpType>
187 auto BKE_volume_grid_type_operation(const VolumeGridType grid_type, OpType &&op)
188 {
189  switch (grid_type) {
190  case VOLUME_GRID_FLOAT:
191  return op.template operator()<openvdb::FloatGrid>();
193  return op.template operator()<openvdb::Vec3fGrid>();
194  case VOLUME_GRID_BOOLEAN:
195  return op.template operator()<openvdb::BoolGrid>();
196  case VOLUME_GRID_DOUBLE:
197  return op.template operator()<openvdb::DoubleGrid>();
198  case VOLUME_GRID_INT:
199  return op.template operator()<openvdb::Int32Grid>();
200  case VOLUME_GRID_INT64:
201  return op.template operator()<openvdb::Int64Grid>();
203  return op.template operator()<openvdb::Vec3IGrid>();
205  return op.template operator()<openvdb::Vec3dGrid>();
206  case VOLUME_GRID_STRING:
207  return op.template operator()<openvdb::StringGrid>();
208  case VOLUME_GRID_MASK:
209  return op.template operator()<openvdb::MaskGrid>();
210  case VOLUME_GRID_POINTS:
211  return op.template operator()<openvdb::points::PointDataGrid>();
212  case VOLUME_GRID_UNKNOWN:
213  break;
214  }
215 
216  /* Should never be called. */
217  BLI_assert(!"should never be reached");
218  return op.template operator()<openvdb::FloatGrid>();
219 }
220 
221 openvdb::GridBase::Ptr BKE_volume_grid_create_with_changed_resolution(
222  const VolumeGridType grid_type,
223  const openvdb::GridBase &old_grid,
224  const float resolution_factor);
225 
226 # endif
227 #endif
void(* BKE_volume_batch_cache_dirty_tag_cb)(struct Volume *volume, int mode)
Definition: volume.cc:1118
void BKE_volume_init_grids(struct Volume *volume)
Definition: volume.cc:660
struct VolumeGrid * BKE_volume_grid_add(struct Volume *volume, const char *name, VolumeGridType type)
Definition: volume.cc:1417
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:1128
VolumeGridType
Definition: BKE_volume.h:98
@ VOLUME_GRID_VECTOR_FLOAT
Definition: BKE_volume.h:107
@ VOLUME_GRID_MASK
Definition: BKE_volume.h:105
@ VOLUME_GRID_VECTOR_DOUBLE
Definition: BKE_volume.h:108
@ VOLUME_GRID_VECTOR_INT
Definition: BKE_volume.h:109
@ VOLUME_GRID_UNKNOWN
Definition: BKE_volume.h:99
@ VOLUME_GRID_DOUBLE
Definition: BKE_volume.h:102
@ VOLUME_GRID_BOOLEAN
Definition: BKE_volume.h:100
@ VOLUME_GRID_INT
Definition: BKE_volume.h:103
@ VOLUME_GRID_INT64
Definition: BKE_volume.h:104
@ VOLUME_GRID_POINTS
Definition: BKE_volume.h:110
@ VOLUME_GRID_FLOAT
Definition: BKE_volume.h:101
@ VOLUME_GRID_STRING
Definition: BKE_volume.h:106
struct BoundBox * BKE_volume_boundbox_get(struct Object *ob)
Definition: volume.cc:926
VolumeGrid * BKE_volume_grid_get_for_write(struct Volume *volume, int grid_index)
Definition: volume.cc:1183
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:849
void BKE_volume_batch_cache_dirty_tag(struct Volume *volume, int mode)
Definition: volume.cc:1121
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:1438
void BKE_volume_grids_backup_restore(struct Volume *volume, struct VolumeGridVector *grids, const char *filepath)
Definition: volume.cc:1089
void BKE_volume_eval_geometry(struct Depsgraph *depsgraph, struct Volume *volume)
Definition: volume.cc:1054
@ BKE_VOLUME_BATCH_DIRTY_ALL
Definition: BKE_volume.h:64
const char * BKE_volume_grids_frame_filepath(const struct Volume *volume)
int BKE_volume_grid_channels(const struct VolumeGrid *grid)
void BKE_volumes_init(void)
Definition: volume.cc:496
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:1075
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:1119
bool BKE_volume_is_points_only(const struct Volume *volume)
int BKE_volume_num_grids(const struct Volume *volume)
struct Volume * BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference)
Definition: volume.cc:1390
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_is_loaded(const struct Volume *volume)
void * BKE_volume_add(struct Main *bmain, const char *name)
Definition: volume.cc:671
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(a)
Definition: BLI_assert.h:58
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
_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
Scene scene
const Depsgraph * depsgraph
static void clear(Message *msg)
Definition: msgfmt.c:294
Definition: BKE_main.h:116
bool BKE_volume_min_max(const Volume *volume, float3 &r_min, float3 &r_max)
Definition: volume.cc:900