diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-21 11:28:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-21 11:28:14 +0400 |
commit | 99433a34667ea3c9fd10be6214e905288304e95f (patch) | |
tree | c23b9a700466021cadd3c2f2943560f855c7fb24 | |
parent | f576c281ba7746175dd9bae0a644cda4513bd51c (diff) |
minor bmesh improvements
- use 2 omp sections for vert -> (edge, face) selection flushing.
- dont use face-loop iterator for cddm_from_bmesh_ex conversion to give some speedup (some modifiers use this).
- use float(*)[3] for functions that return coords.
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 34 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_marking.c | 59 |
5 files changed, 64 insertions, 55 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 3fc1b7d6136..5515509e92d 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -132,7 +132,7 @@ void mesh_update_customdata_pointers(struct Mesh *me, const short do_ensure_tess void BKE_mesh_make_local(struct Mesh *me); void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]); void BKE_mesh_texspace_calc(struct Mesh *me); -float *BKE_mesh_orco_verts_get(struct Object *ob); +float (*BKE_mesh_orco_verts_get(struct Object *ob))[3]; void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totvert, int invert); int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr); struct Mesh *BKE_mesh_from_object(struct Object *ob); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 010839764b2..2dc01513149 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -857,30 +857,27 @@ DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob, return dm; } -static float *get_editbmesh_orco_verts(BMEditMesh *em) +static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3] { BMIter iter; BMVert *eve; - float *orco; - int a, totvert; + float (*orco)[3]; + int i; /* these may not really be the orco's, but it's only for preview. * could be solver better once, but isn't simple */ - - totvert = em->bm->totvert; - orco = MEM_mallocN(sizeof(float) * 3 * totvert, "BMEditMesh Orco"); + orco = MEM_mallocN(sizeof(float) * 3 * em->bm->totvert, "BMEditMesh Orco"); - eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (a = 0; eve; eve = BM_iter_step(&iter), a += 3) { - copy_v3_v3(orco + a, eve->co); + BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { + copy_v3_v3(orco[i], eve->co); } return orco; } /* orco custom data layer */ -static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free) +static float (*get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free))[3] { *free = 0; @@ -889,9 +886,9 @@ static void *get_orco_coords_dm(Object *ob, BMEditMesh *em, int layer, int *free *free = 1; if (em) - return (float(*)[3])get_editbmesh_orco_verts(em); + return get_editbmesh_orco_verts(em); else - return (float(*)[3])BKE_mesh_orco_verts_get(ob); + return BKE_mesh_orco_verts_get(ob); } else if (layer == CD_CLOTH_ORCO) { /* apply shape key for cloth, this should really be solved @@ -1815,17 +1812,18 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos BLI_linklist_free((LinkNode *)datamasks, NULL); } -float (*editbmesh_get_vertex_cos(BMEditMesh * em, int *numVerts_r))[3] +float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[3] { - int i, numVerts = *numVerts_r = em->bm->totvert; - float (*cos)[3]; BMIter iter; BMVert *eve; + float (*cos)[3]; + int i; + + *numVerts_r = em->bm->totvert; - cos = MEM_mallocN(sizeof(float) * 3 * numVerts, "vertexcos"); + cos = MEM_mallocN(sizeof(float) * 3 * em->bm->totvert, "vertexcos"); - eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); - for (i = 0; eve; eve = BM_iter_step(&iter), i++) { + BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { copy_v3_v3(cos[i], eve->co); } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 34adeb4fefb..61d0936d41d 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1875,7 +1875,7 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps, bm->totface); CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - BMIter iter, liter; + BMIter iter; BMVert *eve; BMEdge *eed; BMFace *efa; @@ -1913,7 +1913,7 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps, CD_CALLOC, dm->numLoopData); CustomData_merge(&bm->pdata, &dm->polyData, mask, CD_CALLOC, dm->numPolyData); - + /* add tessellation mface layers */ if (use_tessface) { CustomData_from_bmeshpoly(&dm->faceData, &dm->polyData, &dm->loopData, em_tottri); @@ -2002,7 +2002,8 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps, j = 0; efa = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); for (i = 0; efa; i++, efa = BM_iter_step(&iter), index++) { - BMLoop *l; + BMLoop *l_iter; + BMLoop *l_first; MPoly *mp = &mpoly[i]; BM_elem_index_set(efa, i); /* set_inline */ @@ -2011,15 +2012,16 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps, mp->flag = BM_face_flag_to_mflag(efa); mp->loopstart = j; mp->mat_nr = efa->mat_nr; - - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - mloop->v = BM_elem_index_get(l->v); - mloop->e = BM_elem_index_get(l->e); - CustomData_from_bmesh_block(&bm->ldata, &dm->loopData, l->head.data, j); + + l_iter = l_first = BM_FACE_FIRST_LOOP(efa); + do { + mloop->v = BM_elem_index_get(l_iter->v); + mloop->e = BM_elem_index_get(l_iter->e); + CustomData_from_bmesh_block(&bm->ldata, &dm->loopData, l_iter->head.data, j); j++; mloop++; - } + } while ((l_iter = l_iter->next) != l_first); CustomData_from_bmesh_block(&bm->pdata, &dm->polyData, efa->head.data, i); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 55cf2743bfa..960607154da 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -731,7 +731,7 @@ void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_siz if (r_size) copy_v3_v3(r_size, me->size); } -float *BKE_mesh_orco_verts_get(Object *ob) +float (*BKE_mesh_orco_verts_get(Object *ob))[3] { Mesh *me = ob->data; MVert *mvert = NULL; @@ -748,7 +748,7 @@ float *BKE_mesh_orco_verts_get(Object *ob) copy_v3_v3(vcos[a], mvert->co); } - return (float *)vcos; + return vcos; } void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int invert) diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index b1ec4cde44b..669be315cc6 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -86,41 +86,50 @@ void BM_mesh_select_mode_flush_ex(BMesh *bm, const short selectmode) BMIter eiter; BMIter fiter; - int ok; - if (selectmode & SCE_SELECT_VERTEX) { - BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e->v1, BM_ELEM_SELECT) && - BM_elem_flag_test(e->v2, BM_ELEM_SELECT) && - !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + /* both loops only set edge/face flags and read off verts */ +#pragma omp parallel sections if (bm->totedge + bm->totface >= BM_OMP_LIMIT) + { +#pragma omp section { - BM_elem_flag_enable(e, BM_ELEM_SELECT); - } - else { - BM_elem_flag_disable(e, BM_ELEM_SELECT); + BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e->v1, BM_ELEM_SELECT) && + BM_elem_flag_test(e->v2, BM_ELEM_SELECT) && + !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) + { + BM_elem_flag_enable(e, BM_ELEM_SELECT); + } + else { + BM_elem_flag_disable(e, BM_ELEM_SELECT); + } + } } - } - BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - ok = TRUE; - if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { - l_iter = l_first = BM_FACE_FIRST_LOOP(f); - do { - if (!BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT)) { +#pragma omp section + { + BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { + int ok = TRUE; + if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + do { + if (!BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT)) { + ok = FALSE; + break; + } + } while ((l_iter = l_iter->next) != l_first); + } + else { ok = FALSE; - break; } - } while ((l_iter = l_iter->next) != l_first); - } - else { - ok = FALSE; - } - BM_elem_flag_set(f, BM_ELEM_SELECT, ok); + BM_elem_flag_set(f, BM_ELEM_SELECT, ok); + } + } } + /* end sections */ } else if (selectmode & SCE_SELECT_EDGE) { BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { - ok = TRUE; + int ok = TRUE; if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { |