[Bf-blender-cvs] [257d385] mesh-transfer-data: Switch mesh bvhtree partial-building to use BLI_bitmap's.
Bastien Montagne
noreply at git.blender.org
Wed Oct 15 13:11:17 CEST 2014
Commit: 257d38544e4b0948ebef985af327a6199715b181
Author: Bastien Montagne
Date: Tue Oct 14 10:19:09 2014 +0200
Branches: mesh-transfer-data
https://developer.blender.org/rB257d38544e4b0948ebef985af327a6199715b181
Switch mesh bvhtree partial-building to use BLI_bitmap's.
===================================================================
M source/blender/blenkernel/BKE_bvhutils.h
M source/blender/blenkernel/intern/bvhutils.c
M source/blender/blenkernel/intern/mesh_mapping.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index f8649e9..5a63b44 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -31,6 +31,7 @@
* \ingroup bke
*/
+#include "BLI_bitmap.h"
#include "BLI_kdopbvh.h"
/*
@@ -80,7 +81,7 @@ typedef struct BVHTreeFromMesh {
*/
BVHTree *bvhtree_from_mesh_verts(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
BVHTree *bvhtree_from_mesh_verts_ex(struct BVHTreeFromMesh *data, struct MVert *vert, const int numVerts,
- const bool vert_allocated, bool *mask, int numVerts_active,
+ const bool vert_allocated, BLI_bitmap *mask, int numVerts_active,
float epsilon, int tree_type, int axis);
BVHTree *bvhtree_from_mesh_edges(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
@@ -88,7 +89,7 @@ BVHTree *bvhtree_from_mesh_edges(struct BVHTreeFromMesh *data, struct DerivedMes
BVHTree *bvhtree_from_mesh_faces(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis);
BVHTree *bvhtree_from_mesh_faces_ex(struct BVHTreeFromMesh *data, struct MVert *vert, const bool vert_allocated,
struct MFace *face, const int numFaces, const bool face_allocated,
- bool *mask, int numFaces_active,
+ BLI_bitmap *mask, int numFaces_active,
float epsilon, int tree_type, int axis);
/*
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index acc1dcb..3cc3eed 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -242,9 +242,12 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float co[3
/*
* BVH builders
*/
+
+/* ***** Vertex ***** */
+
static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon, int tree_type, int axis,
MVert *vert, const int numVerts,
- bool *mask, int numVerts_active)
+ BLI_bitmap *mask, int numVerts_active)
{
BVHTree *tree = NULL;
int i;
@@ -253,7 +256,7 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon, int tree_type
if (mask && numVerts_active < 0) {
numVerts_active = 0;
for (i = 0; i < numVerts; i++) {
- if (mask[i]) {
+ if (BLI_BITMAP_TEST_BOOL(mask, i)) {
numVerts_active++;
}
}
@@ -266,7 +269,7 @@ static BVHTree *bvhtree_from_mesh_verts_create_tree(float epsilon, int tree_type
if (tree) {
for (i = 0; i < numVerts; i++) {
- if (mask && !mask[i]) {
+ if (mask && !BLI_BITMAP_TEST_BOOL(mask, i)) {
continue;
}
BLI_bvhtree_insert(tree, i, vert[i].co, 1);
@@ -350,7 +353,7 @@ BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, DerivedMesh *dm, float e
* \param numVerts_active if >= 0, number of active verts to add to BVH tree (else will be computed from mask).
*/
BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data, MVert *vert, const int numVerts, const bool vert_allocated,
- bool *mask, int numVerts_active,
+ BLI_bitmap *mask, int numVerts_active,
float epsilon, int tree_type, int axis)
{
BVHTree *tree = bvhtree_from_mesh_verts_create_tree(epsilon, tree_type, axis, vert, numVerts, mask, numVerts_active);
@@ -361,6 +364,8 @@ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data, MVert *vert, const in
return data->tree;
}
+/* ***** Edge ***** */
+
/* Builds a bvh tree where nodes are the edges of the given dm */
BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis)
{
@@ -398,7 +403,7 @@ BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *dm, float e
BLI_bvhtree_balance(tree);
/* Save on cache for later use */
-// printf("BVHTree built and saved on cache\n");
+ /* printf("BVHTree built and saved on cache\n"); */
bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_EDGES);
}
}
@@ -406,7 +411,7 @@ BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *dm, float e
BLI_rw_mutex_unlock(&cache_rwlock);
}
else {
-// printf("BVHTree is already build, using cached tree\n");
+ /* printf("BVHTree is already build, using cached tree\n"); */
}
@@ -436,12 +441,13 @@ BVHTree *bvhtree_from_mesh_edges(BVHTreeFromMesh *data, DerivedMesh *dm, float e
}
}
return data->tree;
-
}
+/* ***** Tessellated face ***** */
+
static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int tree_type, int axis,
BMEditMesh *em, MVert *vert, MFace *face, const int numFaces,
- bool *mask, int numFaces_active)
+ BLI_bitmap *mask, int numFaces_active)
{
BVHTree *tree = NULL;
int i;
@@ -450,7 +456,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int tree_type
if (mask && numFaces_active < 0) {
numFaces_active = 0;
for (i = 0; i < numFaces; i++) {
- if (mask[i]) {
+ if (BLI_BITMAP_TEST_BOOL(mask, i)) {
numFaces_active++;
}
}
@@ -482,7 +488,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int tree_type
for (i = 0; i < numFaces; i++) {
const BMLoop **ltri = looptris[i];
BMFace *f = ltri[0]->f;
- bool insert = mask ? mask[i] : true;
+ bool insert = mask ? BLI_BITMAP_TEST_BOOL(mask, i) : true;
/* Start with the assumption the triangle should be included for snapping. */
if (f == f_prev) {
@@ -525,7 +531,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int tree_type
if (vert && face) {
for (i = 0; i < numFaces; i++) {
float co[4][3];
- if (mask && !mask[i]) {
+ if (mask && !BLI_BITMAP_TEST_BOOL(mask, i)) {
continue;
}
@@ -651,7 +657,7 @@ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float e
*/
BVHTree *bvhtree_from_mesh_faces_ex(BVHTreeFromMesh *data, MVert *vert, const bool vert_allocated,
MFace *face, const int numFaces, const bool face_allocated,
- bool *mask, int numFaces_active, float epsilon, int tree_type, int axis)
+ BLI_bitmap *mask, int numFaces_active, float epsilon, int tree_type, int axis)
{
BVHTree *tree = bvhtree_from_mesh_faces_create_tree(epsilon, tree_type, axis, NULL, vert, face, numFaces,
mask, numFaces_active);
@@ -685,7 +691,10 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
}
-/* BVHCache */
+/*
+ * BVHCache
+ */
+
typedef struct BVHCacheItem {
int type;
BVHTree *tree;
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index dd6d93d..0111740 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -27,11 +27,14 @@
* eg: polys connected to verts, UV's connected to verts.
*/
+#include <limits.h>
+
#include "MEM_guardedalloc.h"
#include "DNA_meshdata_types.h"
#include "BLI_utildefines.h"
+#include "BLI_bitmap.h"
#include "BLI_math.h"
#include "BKE_bvhutils.h"
@@ -42,7 +45,6 @@
#include "BLI_strict_flags.h"
-
/* -------------------------------------------------------------------- */
/** \name Mesh Connectivity Mapping
@@ -1614,17 +1616,17 @@ void BKE_dm2mesh_mapping_loops_compute(
/* Build our BVHtrees, either from verts or tessfaces. */
if (use_from_vert) {
if (use_islands) {
- bool *verts_active = MEM_mallocN(sizeof(*verts_active) * (size_t)num_verts_src, __func__);
+ BLI_bitmap *verts_active = BLI_BITMAP_NEW((size_t)num_verts_src, __func__);
for (tidx = 0; tidx < num_trees; tidx++) {
MeshIslandItem *isld = &islands.islands[tidx];
if (isld) {
int num_verts_active = 0;
- memset(verts_active, 0, sizeof(*verts_active) * (size_t)num_verts_src);
+ BLI_BITMAP_SET_ALL(verts_active, false, (size_t)num_verts_src);
for (i = 0; i < isld->nbr_polys; i++) {
MPoly *mp_src = &polys_src[isld->polys_idx[i]];
for (lidx_src = mp_src->loopstart; lidx_src < mp_src->loopstart + mp_src->totloop; lidx_src++) {
- verts_active[loops_src[lidx_src].v] = true;
+ BLI_BITMAP_ENABLE(verts_active, loops_src[lidx_src].v);
num_verts_active++;
}
}
@@ -1649,7 +1651,7 @@ void BKE_dm2mesh_mapping_loops_compute(
if (use_islands) {
/* bvhtree here uses tesselated faces... */
const unsigned int dirty_tess_flag = dm_src->dirty & DM_DIRTY_TESS_CDLAYERS;
- bool *faces_active;
+ BLI_bitmap *faces_active;
/* We do not care about tessellated data here, only geometry itself is important. */
if (dirty_tess_flag) {
@@ -1662,18 +1664,17 @@ void BKE_dm2mesh_mapping_loops_compute(
faces_src = DM_get_tessface_array(dm_src, &faces_allocated_src);
num_faces_src = dm_src->getNumTessFaces(dm_src);
orig_poly_idx_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
- faces_active = MEM_mallocN(sizeof(*faces_active) * (size_t)num_faces_src, __func__);
+ faces_active = BLI_BITMAP_NEW((size_t)num_faces_src, __func__);
for (tidx = 0; tidx < num_trees; tidx++) {
MeshIslandItem *isld = &islands.islands[tidx];
if (isld) {
int num_faces_active = 0;
- memset(faces_active, 0, sizeof(*faces_active) * (size_t)num_faces_src);
+ BLI_BITMAP_SET_ALL(faces_active, false, (size_t)num_faces_src);
for (i = 0; i < num_faces_src; i++) {
MPoly *mp_src = &polys_src[ori
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list