2011-02-18 13:58:08 +00:00
|
|
|
/*
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_PBVH_H__
|
|
|
|
|
#define __BLI_PBVH_H__
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
|
2011-02-18 13:58:08 +00:00
|
|
|
/** \file BLI_pbvh.h
|
|
|
|
|
* \ingroup bli
|
|
|
|
|
* \brief A BVH for high poly meshes.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
#include "BLI_bitmap.h"
|
|
|
|
|
|
2012-05-10 20:33:09 +00:00
|
|
|
struct CCGElem;
|
|
|
|
|
struct CCGKey;
|
2012-03-06 02:40:08 +00:00
|
|
|
struct DMFlagMat;
|
2009-12-09 13:37:19 +00:00
|
|
|
struct DMGridAdjacency;
|
2012-03-06 02:40:08 +00:00
|
|
|
struct ListBase;
|
|
|
|
|
struct MFace;
|
|
|
|
|
struct MVert;
|
2009-10-27 19:53:34 +00:00
|
|
|
struct PBVH;
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
struct PBVHNode;
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
typedef struct PBVH PBVH;
|
|
|
|
|
typedef struct PBVHNode PBVHNode;
|
2009-10-27 19:53:34 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
typedef struct {
|
|
|
|
|
float (*co)[3];
|
|
|
|
|
} PBVHProxyNode;
|
|
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* Callbacks */
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* returns 1 if the search should continue from this node, 0 otherwise */
|
2009-11-06 16:46:35 +00:00
|
|
|
typedef int (*BLI_pbvh_SearchCallback)(PBVHNode *node, void *data);
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
|
|
|
|
|
typedef void (*BLI_pbvh_HitCallback)(PBVHNode *node, void *data);
|
2010-07-14 14:11:03 +00:00
|
|
|
typedef void (*BLI_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float* tmin);
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
|
|
|
|
|
/* Building */
|
|
|
|
|
|
|
|
|
|
PBVH *BLI_pbvh_new(void);
|
2009-11-25 13:40:43 +00:00
|
|
|
void BLI_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts,
|
2010-03-22 09:30:00 +00:00
|
|
|
int totface, int totvert);
|
2012-05-10 20:33:09 +00:00
|
|
|
void BLI_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
|
2009-12-09 13:37:19 +00:00
|
|
|
struct DMGridAdjacency *gridadj, int totgrid,
|
2012-05-10 20:33:09 +00:00
|
|
|
struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
|
2012-03-14 06:32:03 +00:00
|
|
|
unsigned int **grid_hidden);
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
void BLI_pbvh_free(PBVH *bvh);
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* Hierarchical Search in the BVH, two methods:
|
2012-03-03 20:19:11 +00:00
|
|
|
* - for each hit calling a callback
|
|
|
|
|
* - gather nodes in an array (easy to multithread) */
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
void BLI_pbvh_search_callback(PBVH *bvh,
|
|
|
|
|
BLI_pbvh_SearchCallback scb, void *search_data,
|
|
|
|
|
BLI_pbvh_HitCallback hcb, void *hit_data);
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
void BLI_pbvh_search_gather(PBVH *bvh,
|
|
|
|
|
BLI_pbvh_SearchCallback scb, void *search_data,
|
|
|
|
|
PBVHNode ***array, int *tot);
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* Raycast
|
2012-03-03 20:19:11 +00:00
|
|
|
* the hit callback is called for all leaf nodes intersecting the ray;
|
|
|
|
|
* it's up to the callback to find the primitive within the leaves that is
|
|
|
|
|
* hit first */
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data,
|
2011-11-11 13:09:14 +00:00
|
|
|
float ray_start[3], float ray_normal[3], int original);
|
2009-11-25 13:40:43 +00:00
|
|
|
int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
|
|
|
|
|
float ray_start[3], float ray_normal[3], float *dist);
|
|
|
|
|
|
|
|
|
|
/* Drawing */
|
|
|
|
|
|
|
|
|
|
void BLI_pbvh_node_draw(PBVHNode *node, void *data);
|
2012-03-06 02:40:08 +00:00
|
|
|
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
|
|
|
|
|
int (*setMaterial)(int, void *attribs));
|
2009-10-27 19:53:34 +00:00
|
|
|
|
2012-03-12 23:03:43 +00:00
|
|
|
/* PBVH Access */
|
|
|
|
|
typedef enum {
|
|
|
|
|
PBVH_FACES,
|
|
|
|
|
PBVH_GRIDS,
|
|
|
|
|
} PBVHType;
|
|
|
|
|
|
|
|
|
|
PBVHType BLI_pbvh_type(const PBVH *bvh);
|
|
|
|
|
|
2012-03-14 06:32:03 +00:00
|
|
|
/* multires hidden data, only valid for type == PBVH_GRIDS */
|
|
|
|
|
unsigned int **BLI_pbvh_grid_hidden(const PBVH *bvh);
|
|
|
|
|
|
2012-05-10 20:33:09 +00:00
|
|
|
/* multires level, only valid for type == PBVH_GRIDS */
|
|
|
|
|
void BLI_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);
|
|
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* Node Access */
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
typedef enum {
|
|
|
|
|
PBVH_Leaf = 1,
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
PBVH_UpdateNormals = 2,
|
|
|
|
|
PBVH_UpdateBB = 4,
|
2009-12-11 14:16:17 +00:00
|
|
|
PBVH_UpdateOriginalBB = 8,
|
|
|
|
|
PBVH_UpdateDrawBuffers = 16,
|
2012-03-14 06:32:25 +00:00
|
|
|
PBVH_UpdateRedraw = 32,
|
|
|
|
|
|
|
|
|
|
PBVH_RebuildDrawBuffers = 64,
|
|
|
|
|
PBVH_FullyHidden = 128
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
} PBVHNodeFlags;
|
2009-10-27 19:53:34 +00:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
void BLI_pbvh_node_mark_update(PBVHNode *node);
|
2012-03-14 06:32:25 +00:00
|
|
|
void BLI_pbvh_node_mark_rebuild_draw(PBVHNode *node);
|
|
|
|
|
void BLI_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden);
|
2009-10-27 19:53:34 +00:00
|
|
|
|
2009-11-25 13:40:43 +00:00
|
|
|
void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
|
2009-12-09 13:37:19 +00:00
|
|
|
int **grid_indices, int *totgrid, int *maxgrid, int *gridsize,
|
2012-05-10 20:33:09 +00:00
|
|
|
struct CCGElem ***grid_elems, struct DMGridAdjacency **gridadj);
|
2009-11-25 13:40:43 +00:00
|
|
|
void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
|
|
|
|
|
int *uniquevert, int *totvert);
|
2009-12-11 16:59:09 +00:00
|
|
|
void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,
|
|
|
|
|
int **vert_indices, struct MVert **verts);
|
2009-11-25 13:40:43 +00:00
|
|
|
|
2009-11-06 16:46:35 +00:00
|
|
|
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]);
|
2009-10-27 19:53:34 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
float BLI_pbvh_node_get_tmin(PBVHNode* node);
|
|
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
/* test if AABB is at least partially inside the planes' volume */
|
|
|
|
|
int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data);
|
|
|
|
|
/* test if AABB is at least partially outside the planes' volume */
|
|
|
|
|
int BLI_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data);
|
|
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
/* Update Normals/Bounding Box/Draw Buffers/Redraw and clear flags */
|
2009-10-27 19:53:34 +00:00
|
|
|
|
2009-11-04 20:36:38 +00:00
|
|
|
void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
|
2009-11-06 16:46:35 +00:00
|
|
|
void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
|
2009-12-09 13:37:19 +00:00
|
|
|
void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
|
2012-05-10 20:33:09 +00:00
|
|
|
void BLI_pbvh_grids_update(PBVH *bvh, struct CCGElem **grid_elems,
|
2011-02-27 08:31:10 +00:00
|
|
|
struct DMGridAdjacency *gridadj, void **gridfaces);
|
2009-11-25 13:40:43 +00:00
|
|
|
|
2010-06-21 20:10:59 +00:00
|
|
|
/* 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);
|
|
|
|
|
|
|
|
|
|
|
2009-11-25 13:40:43 +00:00
|
|
|
/* Vertex Iterator */
|
|
|
|
|
|
|
|
|
|
/* this iterator has quite a lot of code, but it's designed to:
|
2012-03-03 20:19:11 +00:00
|
|
|
* - allow the compiler to eliminate dead code and variables
|
|
|
|
|
* - spend most of the time in the relatively simple inner loop */
|
2009-11-25 13:40:43 +00:00
|
|
|
|
2012-03-14 06:32:25 +00:00
|
|
|
/* note: PBVH_ITER_ALL does not skip hidden vertices,
|
2012-04-22 11:54:53 +00:00
|
|
|
* PBVH_ITER_UNIQUE does */
|
2009-11-25 13:40:43 +00:00
|
|
|
#define PBVH_ITER_ALL 0
|
|
|
|
|
#define PBVH_ITER_UNIQUE 1
|
|
|
|
|
|
|
|
|
|
typedef struct PBVHVertexIter {
|
|
|
|
|
/* iteration */
|
|
|
|
|
int g;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
int gx;
|
|
|
|
|
int gy;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* grid */
|
2012-05-10 20:33:09 +00:00
|
|
|
struct CCGElem **grids;
|
|
|
|
|
struct CCGElem *grid;
|
|
|
|
|
struct CCGKey *key;
|
2012-03-14 06:32:25 +00:00
|
|
|
BLI_bitmap *grid_hidden, gh;
|
2009-11-25 13:40:43 +00:00
|
|
|
int *grid_indices;
|
|
|
|
|
int totgrid;
|
|
|
|
|
int gridsize;
|
|
|
|
|
|
|
|
|
|
/* mesh */
|
|
|
|
|
struct MVert *mverts;
|
|
|
|
|
int totvert;
|
|
|
|
|
int *vert_indices;
|
|
|
|
|
|
|
|
|
|
/* result: these are all computed in the macro, but we assume
|
2012-03-04 04:35:12 +00:00
|
|
|
* that compiler optimization's will skip the ones we don't use */
|
2009-11-25 13:40:43 +00:00
|
|
|
struct MVert *mvert;
|
|
|
|
|
float *co;
|
|
|
|
|
short *no;
|
|
|
|
|
float *fno;
|
|
|
|
|
} PBVHVertexIter;
|
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
#pragma warning (disable:4127) // conditional expression is constant
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-02-22 22:37:01 +00:00
|
|
|
void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
|
|
|
|
|
PBVHVertexIter *vi, int mode);
|
|
|
|
|
|
2009-11-25 13:40:43 +00:00
|
|
|
#define BLI_pbvh_vertex_iter_begin(bvh, node, vi, mode) \
|
2012-02-22 22:37:01 +00:00
|
|
|
pbvh_vertex_iter_init(bvh, node, &vi, mode); \
|
2009-11-25 13:40:43 +00:00
|
|
|
\
|
|
|
|
|
for(vi.i=0, vi.g=0; vi.g<vi.totgrid; vi.g++) { \
|
|
|
|
|
if(vi.grids) { \
|
|
|
|
|
vi.width= vi.gridsize; \
|
|
|
|
|
vi.height= vi.gridsize; \
|
|
|
|
|
vi.grid= vi.grids[vi.grid_indices[vi.g]]; \
|
2012-03-14 06:32:25 +00:00
|
|
|
if(mode == PBVH_ITER_UNIQUE) \
|
|
|
|
|
vi.gh= vi.grid_hidden[vi.grid_indices[vi.g]]; \
|
2009-11-25 13:40:43 +00:00
|
|
|
} \
|
|
|
|
|
else { \
|
|
|
|
|
vi.width= vi.totvert; \
|
|
|
|
|
vi.height= 1; \
|
|
|
|
|
} \
|
2010-03-22 09:30:00 +00:00
|
|
|
\
|
2009-11-25 13:40:43 +00:00
|
|
|
for(vi.gy=0; vi.gy<vi.height; vi.gy++) { \
|
|
|
|
|
for(vi.gx=0; vi.gx<vi.width; vi.gx++, vi.i++) { \
|
|
|
|
|
if(vi.grid) { \
|
2012-05-10 20:33:09 +00:00
|
|
|
vi.co= CCG_elem_co(vi.key, vi.grid); \
|
|
|
|
|
vi.fno= CCG_elem_no(vi.key, vi.grid); \
|
|
|
|
|
vi.grid= CCG_elem_next(vi.key, vi.grid); \
|
2012-03-14 06:32:25 +00:00
|
|
|
if(vi.gh) { \
|
|
|
|
|
if(BLI_BITMAP_GET(vi.gh, vi.gy * vi.gridsize + vi.gx)) \
|
|
|
|
|
continue; \
|
|
|
|
|
} \
|
2009-11-25 13:40:43 +00:00
|
|
|
} \
|
|
|
|
|
else { \
|
|
|
|
|
vi.mvert= &vi.mverts[vi.vert_indices[vi.gx]]; \
|
2012-03-14 06:32:25 +00:00
|
|
|
if(mode == PBVH_ITER_UNIQUE && vi.mvert->flag & ME_HIDE) \
|
|
|
|
|
continue; \
|
2009-11-25 13:40:43 +00:00
|
|
|
vi.co= vi.mvert->co; \
|
|
|
|
|
vi.no= vi.mvert->no; \
|
|
|
|
|
} \
|
|
|
|
|
|
|
|
|
|
#define BLI_pbvh_vertex_iter_end \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
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]);
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#endif /* __BLI_PBVH_H__ */
|
2009-10-27 19:53:34 +00:00
|
|
|
|