Blender V5.0
BLI_kdopbvh.hh
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
10
11#include "BLI_function_ref.hh"
13#include "BLI_sys_types.h"
14
15struct BVHTree;
17
18struct BVHTree;
19#define USE_KDOPBVH_WATERTIGHT
20
22 union {
23 struct {
24 float min, max;
25 };
26 /* alternate access */
27 float range[2];
28 };
29};
30
32 int indexA;
33 int indexB;
34};
35
39 int index;
42 float co[3];
45 float no[3];
47 float dist_sq;
48 int flags;
49};
50
51struct BVHTreeRay {
53 float origin[3];
55 float direction[3];
57 float radius;
58#ifdef USE_KDOPBVH_WATERTIGHT
60#endif
61};
62
65 int index;
67 float co[3];
69 float no[3];
71 float dist;
72};
73
74enum {
77 /* Use a specialized self-overlap traversal to only test and output every
78 * pair once, rather than twice in different order as usual. */
79 BVH_OVERLAP_SELF = (1 << 2),
80};
81enum {
82 /* Use a priority queue to process nodes in the optimal order (for slow callbacks) */
84};
85enum {
86 /* calculate IsectRayPrecalc data */
88};
89#define BVH_RAYCAST_DEFAULT (BVH_RAYCAST_WATERTIGHT)
90#define BVH_RAYCAST_DIST_MAX (FLT_MAX / 2.0f)
91
95using BVHTree_NearestPointCallback = void (*)(void *userdata,
96 int index,
97 const float co[3],
98 BVHTreeNearest *nearest);
99
103using BVHTree_RayCastCallback = void (*)(void *userdata,
104 int index,
105 const BVHTreeRay *ray,
106 BVHTreeRayHit *hit);
107
111using BVHTree_OverlapCallback = bool (*)(void *userdata, int index_a, int index_b, int thread);
112
116using BVHTree_RangeQuery = void (*)(void *userdata, int index, const float co[3], float dist_sq);
117
121using BVHTree_NearestProjectedCallback = void (*)(void *userdata,
122 int index,
123 const DistProjectedAABBPrecalc *precalc,
124 const float (*clip_plane)[4],
125 int clip_plane_len,
126 BVHTreeNearest *nearest);
127
129
131 public:
133 {
135 }
136};
137
141BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
142
146void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints);
148
154 BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints);
162
169
177 const BVHTree *tree2,
178 uint *r_overlap_num,
180 void *userdata,
181 uint max_interactions,
182 int flag);
184 const BVHTree *tree2,
185 unsigned int *r_overlap_num,
187 void *userdata);
193 unsigned int *r_overlap_num,
195 void *userdata);
196
197int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint *r_intersect_num);
198
212void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], float r_bb_max[3]);
213
220 const float co[3],
221 BVHTreeNearest *nearest,
223 void *userdata,
224 int flag);
226 const float co[3],
227 BVHTreeNearest *nearest,
229 void *userdata);
230
236 const float co[3],
237 float dist_sq,
239 void *userdata);
240
242 const float co[3],
243 const float dir[3],
244 float radius,
245 BVHTreeRayHit *hit,
247 void *userdata,
248 int flag);
250 const float co[3],
251 const float dir[3],
252 float radius,
253 BVHTreeRayHit *hit,
255 void *userdata);
256
267 const float co[3],
268 const float dir[3],
269 float radius,
270 float hit_dist,
272 void *userdata,
273 int flag);
275 const float co[3],
276 const float dir[3],
277 float radius,
278 float hit_dist,
280 void *userdata);
281
282float BLI_bvhtree_bb_raycast(const float bv[6],
283 const float light_start[3],
284 const float light_end[3],
285 float pos[3]);
286
291 const float co[3],
292 float radius,
293 BVHTree_RangeQuery callback,
294 void *userdata);
295
297 float projmat[4][4],
298 float winsize[2],
299 float mval[2],
300 float (*clip_planes)[4],
301 int clip_plane_len,
302 BVHTreeNearest *nearest,
304 void *userdata);
305
309extern const float bvhtree_kdop_axes[13][3];
310
311namespace blender {
312
314 FunctionRef<void(int index, const BVHTreeRay &ray, BVHTreeRayHit &hit)>;
315
317 const float3 co,
318 const float3 dir,
319 float radius,
320 float hit_dist,
322{
324 &tree,
325 co,
326 dir,
327 radius,
328 hit_dist,
329 [](void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) {
331 fn(index, *ray, *hit);
332 },
333 &fn);
334}
335
336using BVHTree_RangeQuery_CPP = FunctionRef<void(int index, const float3 &co, float dist_sq)>;
337
339 const float3 co,
340 float radius,
342{
344 &tree,
345 co,
346 radius,
347 [](void *userdata, const int index, const float co[3], const float dist_sq) {
348 BVHTree_RangeQuery_CPP fn = *static_cast<BVHTree_RangeQuery_CPP *>(userdata);
349 fn(index, co, dist_sq);
350 },
351 &fn);
352}
353
354} // namespace blender
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)
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])
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]
bool(*)(void *userdata, int index_a, int index_b, int thread) BVHTree_OverlapCallback
@ BVH_RAYCAST_WATERTIGHT
void(*)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) BVHTree_RayCastCallback
@ BVH_OVERLAP_USE_THREADING
@ BVH_OVERLAP_RETURN_PAIRS
@ BVH_OVERLAP_SELF
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 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)
void(*)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest) BVHTree_NearestPointCallback
int BLI_bvhtree_get_len(const BVHTree *tree)
int BLI_bvhtree_overlap_thread_num(const BVHTree *tree)
void(*)(void *userdata, int index, const float co[3], float dist_sq) BVHTree_RangeQuery
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)
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)
void(*)(void *userdata, int index, const DistProjectedAABBPrecalc *precalc, const float(*clip_plane)[4], int clip_plane_len, BVHTreeNearest *nearest) BVHTree_NearestProjectedCallback
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)
@ BVH_NEAREST_OPTIMAL_ORDER
int BLI_bvhtree_find_nearest_ex(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata, int flag)
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
void operator()(BVHTree *tree)
nullptr float
KDTree_3d * tree
uint pos
FunctionRef< void(int index, const BVHTreeRay &ray, BVHTreeRayHit &hit)> BVHTree_RayCastCallback_CPP
void BLI_bvhtree_range_query_cpp(const BVHTree &tree, const float3 co, float radius, BVHTree_RangeQuery_CPP fn)
FunctionRef< void(int index, const float3 &co, float dist_sq)> BVHTree_RangeQuery_CPP
void BLI_bvhtree_ray_cast_all_cpp(const BVHTree &tree, const float3 co, const float3 dir, float radius, float hit_dist, BVHTree_RayCastCallback_CPP fn)
VecBase< float, 3 > float3
float origin[3]
struct IsectRayPrecalc * isect_precalc
float direction[3]
uint8_t flag
Definition wm_window.cc:145