3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2006 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): Daniel Genrich, Andre Pinto
26 * ***** END GPL LICENSE BLOCK *****
36 typedef struct BVHTree BVHTree;
38 typedef struct BVHTreeOverlap {
43 typedef struct BVHTreeNearest
45 int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */
46 float nearest[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */
47 float dist; /* squared distance to search arround */
50 /* returns square of the minimum distance from given co to the node, nearest point is stored on nearest */
51 typedef float (*BVHTree_NearestPointCallback) (void *userdata, int index, const float *co, float *nearest);
54 BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis);
55 void BLI_bvhtree_free(BVHTree *tree);
57 /* construct: first insert points, then call balance */
58 int BLI_bvhtree_insert(BVHTree *tree, int index, float *co, int numpoints);
59 void BLI_bvhtree_balance(BVHTree *tree);
61 /* update: first update points/nodes, then call update_tree to refit the bounding volumes */
62 int BLI_bvhtree_update_node(BVHTree *tree, int index, float *co, float *co_moving, int numpoints);
63 void BLI_bvhtree_update_tree(BVHTree *tree);
65 /* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */
66 BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, int *result);
68 float BLI_bvhtree_getepsilon(BVHTree *tree);
70 /* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */
71 int BLI_bvhtree_find_nearest(BVHTree *tree, float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata);
73 #endif // BLI_KDOPBVH_H