Blender V2.61 - r43446

BLI_kdopbvh.h

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