Blender V4.3
BLI_kdopbvh.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_sys_types.h"
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17struct BVHTree;
19
20typedef struct BVHTree BVHTree;
21#define USE_KDOPBVH_WATERTIGHT
22
23typedef struct BVHTreeAxisRange {
24 union {
25 struct {
26 float min, max;
27 };
28 /* alternate access */
29 float range[2];
30 };
32
37
38typedef struct BVHTreeNearest {
41 int index;
44 float co[3];
47 float no[3];
49 float dist_sq;
50 int flags;
52
53typedef struct BVHTreeRay {
55 float origin[3];
57 float direction[3];
59 float radius;
60#ifdef USE_KDOPBVH_WATERTIGHT
62#endif
64
65typedef struct BVHTreeRayHit {
67 int index;
69 float co[3];
71 float no[3];
73 float dist;
75
76enum {
79 /* Use a specialized self-overlap traversal to only test and output every
80 * pair once, rather than twice in different order as usual. */
81 BVH_OVERLAP_SELF = (1 << 2),
82};
83enum {
84 /* Use a priority queue to process nodes in the optimal order (for slow callbacks) */
86};
87enum {
88 /* calculate IsectRayPrecalc data */
90};
91#define BVH_RAYCAST_DEFAULT (BVH_RAYCAST_WATERTIGHT)
92#define BVH_RAYCAST_DIST_MAX (FLT_MAX / 2.0f)
93
97typedef void (*BVHTree_NearestPointCallback)(void *userdata,
98 int index,
99 const float co[3],
100 BVHTreeNearest *nearest);
101
105typedef void (*BVHTree_RayCastCallback)(void *userdata,
106 int index,
107 const BVHTreeRay *ray,
108 BVHTreeRayHit *hit);
109
113typedef bool (*BVHTree_OverlapCallback)(void *userdata, int index_a, int index_b, int thread);
114
118typedef void (*BVHTree_RangeQuery)(void *userdata, int index, const float co[3], float dist_sq);
119
123typedef void (*BVHTree_NearestProjectedCallback)(void *userdata,
124 int index,
125 const struct DistProjectedAABBPrecalc *precalc,
126 const float (*clip_plane)[4],
127 int clip_plane_len,
128 BVHTreeNearest *nearest);
129
133BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
135
139void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints);
141
147 BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints);
155
162
170 const BVHTree *tree2,
171 uint *r_overlap_num,
173 void *userdata,
174 uint max_interactions,
175 int flag);
177 const BVHTree *tree2,
178 unsigned int *r_overlap_num,
180 void *userdata);
186 unsigned int *r_overlap_num,
188 void *userdata);
189
190int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_intersect_num);
191
205void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], float r_bb_max[3]);
206
213 const float co[3],
214 BVHTreeNearest *nearest,
216 void *userdata,
217 int flag);
219 const float co[3],
220 BVHTreeNearest *nearest,
222 void *userdata);
223
229 const float co[3],
230 float dist_sq,
232 void *userdata);
233
235 const float co[3],
236 const float dir[3],
237 float radius,
238 BVHTreeRayHit *hit,
240 void *userdata,
241 int flag);
243 const float co[3],
244 const float dir[3],
245 float radius,
246 BVHTreeRayHit *hit,
248 void *userdata);
249
260 const float co[3],
261 const float dir[3],
262 float radius,
263 float hit_dist,
265 void *userdata,
266 int flag);
268 const float co[3],
269 const float dir[3],
270 float radius,
271 float hit_dist,
273 void *userdata);
274
275float BLI_bvhtree_bb_raycast(const float bv[6],
276 const float light_start[3],
277 const float light_end[3],
278 float pos[3]);
279
284 const float co[3],
285 float radius,
287 void *userdata);
288
290 float projmat[4][4],
291 float winsize[2],
292 float mval[2],
293 float (*clip_planes)[4],
294 int clip_plane_len,
295 BVHTreeNearest *nearest,
297 void *userdata);
298
302extern const float bvhtree_kdop_axes[13][3];
303
304#ifdef __cplusplus
305}
306#endif
307
308#ifdef __cplusplus
309
310# include "BLI_function_ref.hh"
311# include "BLI_math_vector.hh"
312
313namespace blender {
314
315using BVHTree_RayCastCallback_CPP =
316 FunctionRef<void(int index, const BVHTreeRay &ray, BVHTreeRayHit &hit)>;
317
318inline void BLI_bvhtree_ray_cast_all_cpp(const BVHTree &tree,
319 const float3 co,
320 const float3 dir,
321 float radius,
322 float hit_dist,
323 BVHTree_RayCastCallback_CPP fn)
324{
326 &tree,
327 co,
328 dir,
329 radius,
330 hit_dist,
331 [](void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) {
332 BVHTree_RayCastCallback_CPP fn = *static_cast<BVHTree_RayCastCallback_CPP *>(userdata);
333 fn(index, *ray, *hit);
334 },
335 &fn);
336}
337
338using BVHTree_RangeQuery_CPP = FunctionRef<void(int index, const float3 &co, float dist_sq)>;
339
340inline void BLI_bvhtree_range_query_cpp(const BVHTree &tree,
341 const float3 co,
342 float radius,
343 BVHTree_RangeQuery_CPP fn)
344{
346 &tree,
347 co,
348 radius,
349 [](void *userdata, const int index, const float co[3], const float dist_sq) {
350 BVHTree_RangeQuery_CPP fn = *static_cast<BVHTree_RangeQuery_CPP *>(userdata);
351 fn(index, co, dist_sq);
352 },
353 &fn);
354}
355
356} // namespace blender
357
358#endif
struct BVHTreeNearest BVHTreeNearest
@ BVH_RAYCAST_WATERTIGHT
Definition BLI_kdopbvh.h:89
BVHTree * BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
int * BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_intersect_num)
@ BVH_OVERLAP_USE_THREADING
Definition BLI_kdopbvh.h:77
@ BVH_OVERLAP_RETURN_PAIRS
Definition BLI_kdopbvh.h:78
@ BVH_OVERLAP_SELF
Definition BLI_kdopbvh.h:81
struct BVHTreeOverlap BVHTreeOverlap
int BLI_bvhtree_get_tree_type(const BVHTree *tree)
void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], float r_bb_max[3])
@ BVH_NEAREST_OPTIMAL_ORDER
Definition BLI_kdopbvh.h:85
int BLI_bvhtree_find_nearest_projected(const BVHTree *tree, float projmat[4][4], float winsize[2], float mval[2], float(*clip_planes)[4], int clip_plane_len, BVHTreeNearest *nearest, BVHTree_NearestProjectedCallback callback, void *userdata)
const float bvhtree_kdop_axes[13][3]
void BLI_bvhtree_balance(BVHTree *tree)
void BLI_bvhtree_update_tree(BVHTree *tree)
float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3])
void BLI_bvhtree_ray_cast_all_ex(const BVHTree *tree, const float co[3], const float dir[3], float radius, float hit_dist, BVHTree_RayCastCallback callback, void *userdata, int flag)
void BLI_bvhtree_free(BVHTree *tree)
void(* BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints)
BVHTreeOverlap * BLI_bvhtree_overlap_ex(const BVHTree *tree1, const BVHTree *tree2, uint *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata, uint max_interactions, int flag)
BVHTreeOverlap * BLI_bvhtree_overlap_self(const BVHTree *tree, unsigned int *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata)
bool BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints)
void BLI_bvhtree_ray_cast_all(const BVHTree *tree, const float co[3], const float dir[3], float radius, float hit_dist, BVHTree_RayCastCallback callback, void *userdata)
int BLI_bvhtree_get_len(const BVHTree *tree)
int BLI_bvhtree_overlap_thread_num(const BVHTree *tree)
void(* BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
Definition BLI_kdopbvh.h:97
bool(* BVHTree_OverlapCallback)(void *userdata, int index_a, int index_b, int thread)
int BLI_bvhtree_ray_cast_ex(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata, int flag)
struct BVHTreeAxisRange BVHTreeAxisRange
struct BVHTreeRayHit BVHTreeRayHit
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
float BLI_bvhtree_get_epsilon(const BVHTree *tree)
struct BVHTreeRay BVHTreeRay
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
int BLI_bvhtree_find_nearest_first(const BVHTree *tree, const float co[3], float dist_sq, BVHTree_NearestPointCallback callback, void *userdata)
int BLI_bvhtree_find_nearest_ex(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata, int flag)
void(* BVHTree_RangeQuery)(void *userdata, int index, const float co[3], float dist_sq)
void(* BVHTree_NearestProjectedCallback)(void *userdata, int index, const struct DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], int clip_plane_len, BVHTreeNearest *nearest)
int BLI_bvhtree_range_query(const BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata)
BVHTreeOverlap * BLI_bvhtree_overlap(const BVHTree *tree1, const BVHTree *tree2, unsigned int *r_overlap_num, BVHTree_OverlapCallback callback, void *userdata)
unsigned int uint
DEGForeachIDComponentCallback callback
KDTree_3d * tree
draw_view in_light_buf[] float
float co[3]
Definition BLI_kdopbvh.h:69
float origin[3]
Definition BLI_kdopbvh.h:55
struct IsectRayPrecalc * isect_precalc
Definition BLI_kdopbvh.h:61
float radius
Definition BLI_kdopbvh.h:59
uint8_t flag
Definition wm_window.cc:138