|
Blender
V2.59
|
00001 /* 00002 * $Id: BLI_kdopbvh.h 34966 2011-02-18 13:58:08Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2006 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): Daniel Genrich, Andre Pinto 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00030 00031 #ifndef BLI_KDOPBVH_H 00032 #define BLI_KDOPBVH_H 00033 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 #include <float.h> 00045 00046 struct BVHTree; 00047 typedef struct BVHTree BVHTree; 00048 00049 typedef struct BVHTreeOverlap { 00050 int indexA; 00051 int indexB; 00052 } BVHTreeOverlap; 00053 00054 typedef struct BVHTreeNearest 00055 { 00056 int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */ 00057 float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */ 00058 float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */ 00059 float dist; /* squared distance to search arround */ 00060 } BVHTreeNearest; 00061 00062 typedef struct BVHTreeRay 00063 { 00064 float origin[3]; /* ray origin */ 00065 float direction[3]; /* ray direction */ 00066 float radius; /* radius around ray */ 00067 } BVHTreeRay; 00068 00069 typedef struct BVHTreeRayHit 00070 { 00071 int index; /* index of the tree node (untouched if no hit is found) */ 00072 float co[3]; /* coordinates of the hit point */ 00073 float no[3]; /* normal on hit point */ 00074 float dist; /* distance to the hit point */ 00075 } BVHTreeRayHit; 00076 00077 /* callback must update nearest in case it finds a nearest result */ 00078 typedef void (*BVHTree_NearestPointCallback) (void *userdata, int index, const float *co, BVHTreeNearest *nearest); 00079 00080 /* callback must update hit in case it finds a nearest successful hit */ 00081 typedef void (*BVHTree_RayCastCallback) (void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit); 00082 00083 /* callback to range search query */ 00084 typedef void (*BVHTree_RangeQuery) (void *userdata, int index, float squared_dist); 00085 00086 BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis); 00087 void BLI_bvhtree_free(BVHTree *tree); 00088 00089 /* construct: first insert points, then call balance */ 00090 int BLI_bvhtree_insert(BVHTree *tree, int index, float *co, int numpoints); 00091 void BLI_bvhtree_balance(BVHTree *tree); 00092 00093 /* update: first update points/nodes, then call update_tree to refit the bounding volumes */ 00094 int BLI_bvhtree_update_node(BVHTree *tree, int index, float *co, float *co_moving, int numpoints); 00095 void BLI_bvhtree_update_tree(BVHTree *tree); 00096 00097 /* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */ 00098 BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int *result); 00099 00100 float BLI_bvhtree_getepsilon(BVHTree *tree); 00101 00102 /* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */ 00103 int BLI_bvhtree_find_nearest(BVHTree *tree, const float *co, BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata); 00104 00105 int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata); 00106 00107 float BLI_bvhtree_bb_raycast(float *bv, float *light_start, float *light_end, float *pos); 00108 00109 /* range query */ 00110 int BLI_bvhtree_range_query(BVHTree *tree, const float *co, float radius, BVHTree_RangeQuery callback, void *userdata); 00111 00112 #ifdef __cplusplus 00113 } 00114 #endif 00115 00116 #endif // BLI_KDOPBVH_H 00117