52
typedef struct BVHTreeNearest
54
int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */
55
float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
56
float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
57
float dist; /* squared distance to search arround */
53
#define BVH_ONQUAD (1 << 0)
55
typedef struct BVHTreeNearest {
56
int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */
57
float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
58
float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
59
float dist; /* squared distance to search arround */
60
typedef struct BVHTreeRay
62
float origin[3]; /* ray origin */
63
float direction[3]; /* ray direction */
64
float radius; /* radius around ray */
63
typedef struct BVHTreeRay {
64
float origin[3]; /* ray origin */
65
float direction[3]; /* ray direction */
66
float radius; /* radius around ray */
67
typedef struct BVHTreeRayHit
69
int index; /* index of the tree node (untouched if no hit is found) */
70
float co[3]; /* coordinates of the hit point */
71
float no[3]; /* normal on hit point */
72
float dist; /* distance to the hit point */
69
typedef struct BVHTreeRayHit {
70
int index; /* index of the tree node (untouched if no hit is found) */
71
float co[3]; /* coordinates of the hit point */
72
float no[3]; /* normal on hit point */
73
float dist; /* distance to the hit point */
75
77
/* callback must update nearest in case it finds a nearest result */
76
typedef void (*BVHTree_NearestPointCallback) (void *userdata, int index, const float *co, BVHTreeNearest *nearest);
78
typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest);
78
80
/* callback must update hit in case it finds a nearest successful hit */
79
typedef void (*BVHTree_RayCastCallback) (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
81
typedef void (*BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
81
83
/* callback to range search query */
82
typedef void (*BVHTree_RangeQuery) (void *userdata, int index, float squared_dist);
84
typedef void (*BVHTree_RangeQuery)(void *userdata, int index, float squared_dist);
84
86
BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
85
87
void BLI_bvhtree_free(BVHTree *tree);
87
89
/* construct: first insert points, then call balance */
88
int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints);
90
int BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints);
89
91
void BLI_bvhtree_balance(BVHTree *tree);
91
93
/* update: first update points/nodes, then call update_tree to refit the bounding volumes */
92
int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const float *co_moving, int numpoints);
94
int BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints);
93
95
void BLI_bvhtree_update_tree(BVHTree *tree);
95
97
/* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */
96
98
BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int *result);
98
float BLI_bvhtree_getepsilon(BVHTree *tree);
100
/* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */
101
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata);
103
int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata);
105
float BLI_bvhtree_bb_raycast(float *bv, const float light_start[3], const float light_end[3], float pos[3]);
100
float BLI_bvhtree_getepsilon(const BVHTree *tree);
102
/* find nearest node to the given coordinates
103
* (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */
104
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest,
105
BVHTree_NearestPointCallback callback, void *userdata);
107
int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
108
BVHTree_RayCastCallback callback, void *userdata);
110
float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3]);
107
112
/* range query */
108
int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata);
113
int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius,
114
BVHTree_RangeQuery callback, void *userdata);
110
116
#ifdef __cplusplus
114
#endif // __BLI_KDOPBVH_H__
120
#endif /* __BLI_KDOPBVH_H__ */