2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-05-07 20:42:16 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-05-07 20:42:16 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2006 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2008-05-13 00:42:51 +00:00
|
|
|
* Contributor(s): Daniel Genrich, Andre Pinto
|
2008-05-07 20:42:16 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_KDOPBVH_H__
|
|
|
|
#define __BLI_KDOPBVH_H__
|
2008-05-07 20:42:16 +00:00
|
|
|
|
2011-02-18 13:58:08 +00:00
|
|
|
/** \file BLI_kdopbvh.h
|
|
|
|
* \ingroup bli
|
|
|
|
* \author Daniel Genrich
|
|
|
|
* \author Andre Pinto
|
|
|
|
*/
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-05-07 20:42:16 +00:00
|
|
|
struct BVHTree;
|
|
|
|
typedef struct BVHTree BVHTree;
|
2015-08-21 17:46:23 +10:00
|
|
|
#define USE_KDOPBVH_WATERTIGHT
|
2008-05-07 20:42:16 +00:00
|
|
|
|
|
|
|
typedef struct BVHTreeOverlap {
|
|
|
|
int indexA;
|
|
|
|
int indexB;
|
|
|
|
} BVHTreeOverlap;
|
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
typedef struct BVHTreeNearest {
|
|
|
|
int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */
|
|
|
|
float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
|
|
|
|
float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
|
2014-02-03 02:46:45 +11:00
|
|
|
float dist_sq; /* squared distance to search arround */
|
2012-05-30 12:53:13 +00:00
|
|
|
int flags;
|
2008-08-07 17:27:29 +00:00
|
|
|
} BVHTreeNearest;
|
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
typedef struct BVHTreeRay {
|
|
|
|
float origin[3]; /* ray origin */
|
|
|
|
float direction[3]; /* ray direction */
|
|
|
|
float radius; /* radius around ray */
|
2015-08-21 17:46:23 +10:00
|
|
|
#ifdef USE_KDOPBVH_WATERTIGHT
|
|
|
|
struct IsectRayPrecalc *isect_precalc;
|
|
|
|
#endif
|
2008-08-07 17:27:29 +00:00
|
|
|
} BVHTreeRay;
|
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
typedef struct BVHTreeRayHit {
|
|
|
|
int index; /* index of the tree node (untouched if no hit is found) */
|
|
|
|
float co[3]; /* coordinates of the hit point */
|
|
|
|
float no[3]; /* normal on hit point */
|
|
|
|
float dist; /* distance to the hit point */
|
2008-08-07 17:27:29 +00:00
|
|
|
} BVHTreeRayHit;
|
|
|
|
|
2015-08-21 17:46:23 +10:00
|
|
|
enum {
|
|
|
|
/* calculate IsectRayPrecalc data */
|
|
|
|
BVH_RAYCAST_WATERTIGHT = (1 << 0),
|
|
|
|
};
|
|
|
|
#define BVH_RAYCAST_DEFAULT (BVH_RAYCAST_WATERTIGHT)
|
2016-01-12 09:37:56 +01:00
|
|
|
#define BVH_RAYCAST_DIST_MAX (FLT_MAX / 2.0f)
|
2015-08-21 17:46:23 +10:00
|
|
|
|
2008-08-07 17:27:29 +00:00
|
|
|
/* callback must update nearest in case it finds a nearest result */
|
2012-10-15 23:11:59 +00:00
|
|
|
typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest);
|
2008-08-07 17:27:29 +00:00
|
|
|
|
|
|
|
/* callback must update hit in case it finds a nearest successful hit */
|
2012-05-12 20:39:39 +00:00
|
|
|
typedef void (*BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
|
2008-08-07 17:27:29 +00:00
|
|
|
|
2016-01-25 18:18:30 +11:00
|
|
|
/* callback must update nearest to ray in case it finds a nearest result */
|
|
|
|
typedef void(*BVHTree_NearestToRayCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeNearest *nearest);
|
|
|
|
|
2015-08-20 17:32:25 +10:00
|
|
|
/* callback to check if 2 nodes overlap (use thread if intersection results need to be stored) */
|
2015-08-20 19:22:09 +10:00
|
|
|
typedef bool (*BVHTree_OverlapCallback)(void *userdata, int index_a, int index_b, int thread);
|
2015-08-20 17:32:25 +10:00
|
|
|
|
2008-10-01 03:35:53 +00:00
|
|
|
/* callback to range search query */
|
2014-02-03 02:46:45 +11:00
|
|
|
typedef void (*BVHTree_RangeQuery)(void *userdata, int index, float dist_sq);
|
2008-08-07 17:27:29 +00:00
|
|
|
|
2008-05-07 20:42:16 +00:00
|
|
|
BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
|
|
|
|
void BLI_bvhtree_free(BVHTree *tree);
|
|
|
|
|
|
|
|
/* construct: first insert points, then call balance */
|
2013-09-04 20:33:50 +00:00
|
|
|
void BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints);
|
2008-05-07 20:42:16 +00:00
|
|
|
void BLI_bvhtree_balance(BVHTree *tree);
|
|
|
|
|
|
|
|
/* update: first update points/nodes, then call update_tree to refit the bounding volumes */
|
2014-09-16 09:14:33 +10:00
|
|
|
bool BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints);
|
2008-05-07 20:42:16 +00:00
|
|
|
void BLI_bvhtree_update_tree(BVHTree *tree);
|
|
|
|
|
2015-08-20 19:22:09 +10:00
|
|
|
int BLI_bvhtree_overlap_thread_num(const BVHTree *tree);
|
2015-08-20 17:32:25 +10:00
|
|
|
|
2008-05-07 20:42:16 +00:00
|
|
|
/* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */
|
2015-08-20 17:32:25 +10:00
|
|
|
BVHTreeOverlap *BLI_bvhtree_overlap(
|
|
|
|
const BVHTree *tree1, const BVHTree *tree2, unsigned int *r_overlap_tot,
|
|
|
|
BVHTree_OverlapCallback callback, void *userdata);
|
2008-05-07 20:42:16 +00:00
|
|
|
|
2012-10-24 08:16:49 +00:00
|
|
|
float BLI_bvhtree_getepsilon(const BVHTree *tree);
|
2008-05-07 20:42:16 +00:00
|
|
|
|
2012-10-15 23:11:59 +00:00
|
|
|
/* find nearest node to the given coordinates
|
|
|
|
* (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */
|
|
|
|
int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest,
|
|
|
|
BVHTree_NearestPointCallback callback, void *userdata);
|
2008-08-07 17:27:29 +00:00
|
|
|
|
2016-01-25 18:18:30 +11:00
|
|
|
int BLI_bvhtree_find_nearest_to_ray(
|
|
|
|
BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeNearest *nearest,
|
|
|
|
BVHTree_NearestToRayCallback callback, void *userdata);
|
|
|
|
|
2015-08-21 17:46:23 +10:00
|
|
|
int BLI_bvhtree_ray_cast_ex(
|
|
|
|
BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
|
|
|
|
BVHTree_RayCastCallback callback, void *userdata,
|
|
|
|
int flag);
|
|
|
|
int BLI_bvhtree_ray_cast(
|
|
|
|
BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit,
|
|
|
|
BVHTree_RayCastCallback callback, void *userdata);
|
|
|
|
|
|
|
|
int BLI_bvhtree_ray_cast_all_ex(
|
|
|
|
BVHTree *tree, const float co[3], const float dir[3], float radius,
|
|
|
|
BVHTree_RayCastCallback callback, void *userdata,
|
|
|
|
int flag);
|
|
|
|
int BLI_bvhtree_ray_cast_all(
|
|
|
|
BVHTree *tree, const float co[3], const float dir[3], float radius,
|
|
|
|
BVHTree_RayCastCallback callback, void *userdata);
|
2014-10-22 16:36:23 +02:00
|
|
|
|
2012-10-15 23:11:59 +00:00
|
|
|
float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3]);
|
2009-07-30 15:00:26 +00:00
|
|
|
|
2008-10-01 03:35:53 +00:00
|
|
|
/* range query */
|
2012-10-15 23:11:59 +00:00
|
|
|
int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius,
|
|
|
|
BVHTree_RangeQuery callback, void *userdata);
|
2008-10-01 03:35:53 +00:00
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-01 03:35:53 +00:00
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#endif /* __BLI_KDOPBVH_H__ */
|