doxygen: editor entry
[blender.git] / source / blender / blenlib / BLI_pbvh.h
index e1e733c91dfad42cd7eda269b6bd582b0c8ede57..bde6bc3ced4d270f4f7397697c38d8c1b367ea80 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * A BVH for high poly meshes.
- * 
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -17,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 #ifndef BLI_PBVH_H
 #define BLI_PBVH_H
 
+/** \file BLI_pbvh.h
+ *  \ingroup bli
+ *  \brief A BVH for high poly meshes.
+ */
+
 struct MFace;
 struct MVert;
 struct DMGridAdjacency;
@@ -36,18 +39,23 @@ struct ListBase;
 typedef struct PBVH PBVH;
 typedef struct PBVHNode PBVHNode;
 
+typedef struct {
+       float (*co)[3];
+} PBVHProxyNode;
+
 /* Callbacks */
 
 /* returns 1 if the search should continue from this node, 0 otherwise */
 typedef int (*BLI_pbvh_SearchCallback)(PBVHNode *node, void *data);
 
 typedef void (*BLI_pbvh_HitCallback)(PBVHNode *node, void *data);
+typedef void (*BLI_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float* tmin);
 
 /* Building */
 
 PBVH *BLI_pbvh_new(void);
 void BLI_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts,
-                   int totface, int totvert);
+                       int totface, int totvert);
 void BLI_pbvh_build_grids(PBVH *bvh, struct DMGridData **grids,
        struct DMGridAdjacency *gridadj, int totgrid,
        int gridsize, void **gridfaces);
@@ -70,8 +78,8 @@ void BLI_pbvh_search_gather(PBVH *bvh,
    it's up to the callback to find the primitive within the leaves that is
    hit first */
 
-void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitCallback cb, void *data,
-                     float ray_start[3], float ray_normal[3], int original);
+void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data,
+                         float ray_start[3], float ray_normal[3], int original);
 int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
        float ray_start[3], float ray_normal[3], float *dist);
 
@@ -79,7 +87,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
 
 void BLI_pbvh_node_draw(PBVHNode *node, void *data);
 int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data);
-void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3]);
+void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smooth);
 
 /* Node Access */
 
@@ -88,9 +96,9 @@ typedef enum {
 
        PBVH_UpdateNormals = 2,
        PBVH_UpdateBB = 4,
-       PBVH_UpdateOriginalBB = 4,
-       PBVH_UpdateDrawBuffers = 8,
-       PBVH_UpdateRedraw = 16
+       PBVH_UpdateOriginalBB = 8,
+       PBVH_UpdateDrawBuffers = 16,
+       PBVH_UpdateRedraw = 32
 } PBVHNodeFlags;
 
 void BLI_pbvh_node_mark_update(PBVHNode *node);
@@ -100,15 +108,27 @@ void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
        struct DMGridData ***griddata, struct DMGridAdjacency **gridadj);
 void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
        int *uniquevert, int *totvert);
+void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,
+       int **vert_indices, struct MVert **verts);
 
 void BLI_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 void BLI_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 
+float BLI_pbvh_node_get_tmin(PBVHNode* node);
+
 /* Update Normals/Bounding Box/Draw Buffers/Redraw and clear flags */
 
 void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
 void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
 void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
+void BLI_pbvh_grids_update(PBVH *bvh, struct DMGridData **grids,
+       struct DMGridAdjacency *gridadj, void **gridfaces);;
+
+/* vertex deformer */
+float (*BLI_pbvh_get_vertCos(struct PBVH *pbvh))[3];
+void BLI_pbvh_apply_vertCos(struct PBVH *pbvh, float (*vertCos)[3]);
+int BLI_pbvh_isDeformed(struct PBVH *pbvh);
+
 
 /* Vertex Iterator */
 
@@ -149,11 +169,38 @@ typedef struct PBVHVertexIter {
        float *fno;
 } PBVHVertexIter;
 
-void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi, int mode);
+#ifdef _MSC_VER
+#pragma warning (disable:4127) // conditional expression is constant
+#endif
 
 #define BLI_pbvh_vertex_iter_begin(bvh, node, vi, mode) \
-       /* XXX breaks aliasing! */ \
-       BLI_pbvh_node_verts_iter_init(bvh, node, &vi, mode); \
+       { \
+               struct DMGridData **grids; \
+               struct MVert *verts; \
+               int *grid_indices, totgrid, gridsize, *vert_indices, uniq_verts, totvert; \
+               \
+               vi.grid= 0; \
+               vi.no= 0; \
+               vi.fno= 0; \
+               vi.mvert= 0; \
+               vi.skip= 0; \
+               \
+               BLI_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL); \
+               BLI_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert); \
+               BLI_pbvh_node_get_verts(bvh, node, &vert_indices, &verts); \
+               \
+               vi.grids= grids; \
+               vi.grid_indices= grid_indices; \
+               vi.totgrid= (grids)? totgrid: 1; \
+               vi.gridsize= gridsize; \
+               \
+               if(mode == PBVH_ITER_ALL) \
+                       vi.totvert = totvert; \
+               else \
+                       vi.totvert= uniq_verts; \
+               vi.vert_indices= vert_indices; \
+               vi.mverts= verts; \
+       }\
        \
        for(vi.i=0, vi.g=0; vi.g<vi.totgrid; vi.g++) { \
                if(vi.grids) { \
@@ -161,7 +208,7 @@ void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi
                        vi.height= vi.gridsize; \
                        vi.grid= vi.grids[vi.grid_indices[vi.g]]; \
                        vi.skip= 0; \
-                       \
+                        \
                        /*if(mode == PVBH_ITER_UNIQUE) { \
                                vi.grid += subm->grid.offset; \
                                vi.skip= subm->grid.skip; \
@@ -172,7 +219,7 @@ void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi
                        vi.width= vi.totvert; \
                        vi.height= 1; \
                } \
-               \
+                \
                for(vi.gy=0; vi.gy<vi.height; vi.gy++) { \
                        if(vi.grid) vi.grid += vi.skip; \
                        \
@@ -193,6 +240,13 @@ void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi
                } \
        }
 
+void BLI_pbvh_node_get_proxies(PBVHNode* node, PBVHProxyNode** proxies, int* proxy_count);
+void BLI_pbvh_node_free_proxies(PBVHNode* node);
+PBVHProxyNode* BLI_pbvh_node_add_proxy(PBVH* bvh, PBVHNode* node);
+void BLI_pbvh_gather_proxies(PBVH* pbvh, PBVHNode*** nodes,  int* totnode);
+
+//void BLI_pbvh_node_BB_reset(PBVHNode* node);
+//void BLI_pbvh_node_BB_expand(PBVHNode* node, float co[3]);
 
 #endif /* BLI_PBVH_H */