5 * ***** BEGIN GPL LICENSE BLOCK *****
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * The Original Code is Copyright (C) 2006 by NaN Holding BV.
22 * All rights reserved.
24 * The Original Code is: all of this file.
26 * Contributor(s): Daniel Genrich, Andre Pinto
28 * ***** END GPL LICENSE BLOCK *****
38 typedef struct BVHTree BVHTree;
40 typedef struct BVHTreeOverlap {
45 typedef struct BVHTreeNearest
47 int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */
48 float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
49 float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
50 float dist; /* squared distance to search arround */
53 typedef struct BVHTreeRay
55 float origin[3]; /* ray origin */
56 float direction[3]; /* ray direction */
57 float radius; /* radius around ray */
60 typedef struct BVHTreeRayHit
62 int index; /* index of the tree node (untouched if no hit is found) */
63 float co[3]; /* coordinates of the hit point */
64 float no[3]; /* normal on hit point */
65 float dist; /* distance to the hit point */
68 /* callback must update nearest in case it finds a nearest result */
69 typedef void (*BVHTree_NearestPointCallback) (void *userdata, int index, const float *co, BVHTreeNearest *nearest);
71 /* callback must update hit in case it finds a nearest successful hit */
72 typedef void (*BVHTree_RayCastCallback) (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit);
75 BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
76 void BLI_bvhtree_free(BVHTree *tree);
78 /* construct: first insert points, then call balance */
79 int BLI_bvhtree_insert(BVHTree *tree, int index, float *co, int numpoints);
80 void BLI_bvhtree_balance(BVHTree *tree);
82 /* update: first update points/nodes, then call update_tree to refit the bounding volumes */
83 int BLI_bvhtree_update_node(BVHTree *tree, int index, float *co, float *co_moving, int numpoints);
84 void BLI_bvhtree_update_tree(BVHTree *tree);
86 /* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */
87 BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result);
89 float BLI_bvhtree_getepsilon(BVHTree *tree);
91 /* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */
92 int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata);
94 int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata);
96 #endif // BLI_KDOPBVH_H