diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-26 02:23:40 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-26 02:23:40 +0400 |
commit | c65b3b73fd2c0c0011ef36d8fc36301de4a42fe0 (patch) | |
tree | 3a45d161d5814bf403ffa9093a2d417b6f7a960e /source/blender/bmesh/intern | |
parent | 72e1316dc4b607440430779d78a26a76a4527c4b (diff) |
bmesh api cleanup
* better type safety for BM_elem_flag_* and BM_elem_index_* functions.
* add BMElem type to be used where BMFace/Edge/Vert/Loop can be interchanged.
* fix bug in select manifold, found when making functions more strict.
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 8 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_inline.c | 37 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_marking.c | 78 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_newcore.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 28 |
6 files changed, 80 insertions, 81 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index 202d43c67c0..399975c2e48 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -566,7 +566,7 @@ void BM_elem_attrs_copy(BMesh *source_mesh, BMesh *target_mesh, const void *sour return; /* First we copy select */ - if (BM_elem_flag_test(source, BM_ELEM_SELECT)) { + if (BM_elem_flag_test((BMElem *)sheader, BM_ELEM_SELECT)) { BM_elem_select_set(target_mesh, target, TRUE); } @@ -706,11 +706,11 @@ BMesh *BM_mesh_copy(BMesh *bmold) void *ele = NULL; if (ese->htype == BM_VERT) - ele = vtable[BM_elem_index_get(ese->data)]; + ele = vtable[BM_elem_index_get(ese->ele)]; else if (ese->htype == BM_EDGE) - ele = etable[BM_elem_index_get(ese->data)]; + ele = etable[BM_elem_index_get(ese->ele)]; else if (ese->htype == BM_FACE) { - ele = ftable[BM_elem_index_get(ese->data)]; + ele = ftable[BM_elem_index_get(ese->ele)]; } else { BLI_assert(0); diff --git a/source/blender/bmesh/intern/bmesh_inline.c b/source/blender/bmesh/intern/bmesh_inline.c index b855c4b865a..0f2932fde24 100644 --- a/source/blender/bmesh/intern/bmesh_inline.c +++ b/source/blender/bmesh/intern/bmesh_inline.c @@ -31,47 +31,46 @@ #include "bmesh.h" -BM_INLINE char BM_elem_flag_test(const void *element, const char hflag) +BM_INLINE char _bm_elem_flag_test(const BMHeader *ele, const char hflag) { - return ((const BMHeader *)element)->hflag & hflag; + return ele->hflag & hflag; } -BM_INLINE void BM_elem_flag_enable(void *element, const char hflag) +BM_INLINE void _bm_elem_flag_enable(BMHeader *ele, const char hflag) { - ((BMHeader *)element)->hflag |= hflag; + ele->hflag |= hflag; } -BM_INLINE void BM_elem_flag_disable(void *element, const char hflag) +BM_INLINE void _bm_elem_flag_disable(BMHeader *ele, const char hflag) { - ((BMHeader *)element)->hflag &= ~hflag; + ele->hflag &= ~hflag; } -BM_INLINE void BM_elem_flag_set(void *element, const char hflag, const int val) +BM_INLINE void _bm_elem_flag_set(BMHeader *ele, const char hflag, const int val) { - if (val) BM_elem_flag_enable(element, hflag); - else BM_elem_flag_disable(element, hflag); + if (val) _bm_elem_flag_enable(ele, hflag); + else _bm_elem_flag_disable(ele, hflag); } -BM_INLINE void BM_elem_flag_toggle(void *element, const char hflag) +BM_INLINE void _bm_elem_flag_toggle(BMHeader *ele, const char hflag) { - ((BMHeader *)element)->hflag ^= hflag; + ele->hflag ^= hflag; } -BM_INLINE void BM_elem_flag_merge(void *element_a, void *element_b) +BM_INLINE void _bm_elem_flag_merge(BMHeader *ele_a, BMHeader *ele_b) { - ((BMHeader *)element_a)->hflag = - ((BMHeader *)element_b)->hflag = (((BMHeader *)element_a)->hflag | - ((BMHeader *)element_b)->hflag); + ele_a->hflag = ele_b->hflag = ele_a->hflag | ele_b->hflag; } -BM_INLINE void BM_elem_index_set(void *element, const int index) + +BM_INLINE void _bm_elem_index_set(BMHeader *ele, const int index) { - ((BMHeader *)element)->index = index; + ele->index = index; } -BM_INLINE int BM_elem_index_get(const void *element) +BM_INLINE int _bm_elem_index_get(const BMHeader *ele) { - return ((BMHeader *)element)->index; + return ele->index; } #endif /* __BMESH_INLINE_C__ */ diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index be542dfef0f..78c85e089e1 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -55,7 +55,7 @@ static void recount_totsels(BMesh *bm) { BMIter iter; - BMHeader *ele; + BMElem *ele; const char iter_types[3] = {BM_VERTS_OF_MESH, BM_EDGES_OF_MESH, BM_FACES_OF_MESH}; @@ -124,7 +124,7 @@ void BM_mesh_select_mode_flush(BMesh *bm) 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->e->head), BM_ELEM_SELECT)) { + if (!BM_elem_flag_test(l_iter->e, BM_ELEM_SELECT)) { ok = FALSE; break; } @@ -286,13 +286,13 @@ void BM_edge_select_set(BMesh *bm, BMEdge *e, int select) if (select) { if (!BM_elem_flag_test(e, BM_ELEM_SELECT)) bm->totedgesel += 1; - BM_elem_flag_enable(&(e->head), BM_ELEM_SELECT); + BM_elem_flag_enable(e, BM_ELEM_SELECT); BM_elem_select_set(bm, e->v1, TRUE); BM_elem_select_set(bm, e->v2, TRUE); } else { if (BM_elem_flag_test(e, BM_ELEM_SELECT)) bm->totedgesel -= 1; - BM_elem_flag_disable(&(e->head), BM_ELEM_SELECT); + BM_elem_flag_disable(e, BM_ELEM_SELECT); if ( bm->selectmode == SCE_SELECT_EDGE || bm->selectmode == SCE_SELECT_FACE || @@ -352,7 +352,7 @@ void BM_face_select_set(BMesh *bm, BMFace *f, int select) bm->totfacesel++; } - BM_elem_flag_enable(&(f->head), BM_ELEM_SELECT); + BM_elem_flag_enable(f, BM_ELEM_SELECT); l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { BM_vert_select_set(bm, l_iter->v, TRUE); @@ -364,7 +364,7 @@ void BM_face_select_set(BMesh *bm, BMFace *f, int select) BMLoop *l; if (BM_elem_flag_test(f, BM_ELEM_SELECT)) bm->totfacesel -= 1; - BM_elem_flag_disable(&(f->head), BM_ELEM_SELECT); + BM_elem_flag_disable(f, BM_ELEM_SELECT); /* flush down to edges */ BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) { @@ -427,7 +427,7 @@ void BM_select_mode_set(BMesh *bm, int selectmode) for (v = BM_iter_new(&verts, bm, BM_VERTS_OF_MESH, bm); v; v = BM_iter_step(&verts)) BM_elem_flag_disable(v, 0); for (e = BM_iter_new(&edges, bm, BM_EDGES_OF_MESH, bm); e; e = BM_iter_step(&edges)) { - if (BM_elem_flag_test(&(e->head), BM_ELEM_SELECT)) { + if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { BM_edge_select_set(bm, e, TRUE); } } @@ -437,7 +437,7 @@ void BM_select_mode_set(BMesh *bm, int selectmode) for (e = BM_iter_new(&edges, bm, BM_EDGES_OF_MESH, bm); e; e = BM_iter_step(&edges)) BM_elem_flag_disable(e, 0); for (f = BM_iter_new(&faces, bm, BM_FACES_OF_MESH, bm); f; f = BM_iter_step(&faces)) { - if (BM_elem_flag_test(&(f->head), BM_ELEM_SELECT)) { + if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { BM_face_select_set(bm, f, TRUE); } } @@ -448,26 +448,26 @@ void BM_select_mode_set(BMesh *bm, int selectmode) int BM_mesh_count_flag(struct BMesh *bm, const char htype, const char hflag, int respecthide) { - BMHeader *head; + BMElem *ele; BMIter iter; int tot = 0; if (htype & BM_VERT) { - for (head = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); head; head = BM_iter_step(&iter)) { - if (respecthide && BM_elem_flag_test(head, BM_ELEM_HIDDEN)) continue; - if (BM_elem_flag_test(head, hflag)) tot++; + for (ele = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) { + if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue; + if (BM_elem_flag_test(ele, hflag)) tot++; } } if (htype & BM_EDGE) { - for (head = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); head; head = BM_iter_step(&iter)) { - if (respecthide && BM_elem_flag_test(head, BM_ELEM_HIDDEN)) continue; - if (BM_elem_flag_test(head, hflag)) tot++; + for (ele = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) { + if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue; + if (BM_elem_flag_test(ele, hflag)) tot++; } } if (htype & BM_FACE) { - for (head = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); head; head = BM_iter_step(&iter)) { - if (respecthide && BM_elem_flag_test(head, BM_ELEM_HIDDEN)) continue; - if (BM_elem_flag_test(head, hflag)) tot++; + for (ele = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) { + if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue; + if (BM_elem_flag_test(ele, hflag)) tot++; } } @@ -515,7 +515,7 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) ese = bm->selected.last; for ( ; ese; ese = ese->prev) { if (ese->htype == BM_FACE) { - f = (BMFace *)ese->data; + f = (BMFace *)ese->ele; if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { f = NULL; @@ -549,16 +549,16 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) void BM_editselection_center(BMesh *bm, float r_center[3], BMEditSelection *ese) { if (ese->htype == BM_VERT) { - BMVert *eve = ese->data; + BMVert *eve = (BMVert *)ese->ele; copy_v3_v3(r_center, eve->co); } else if (ese->htype == BM_EDGE) { - BMEdge *eed = ese->data; + BMEdge *eed = (BMEdge *)ese->ele; add_v3_v3v3(r_center, eed->v1->co, eed->v2->co); mul_v3_fl(r_center, 0.5); } else if (ese->htype == BM_FACE) { - BMFace *efa = ese->data; + BMFace *efa = (BMFace *)ese->ele; BM_face_center_bounds_calc(bm, efa, r_center); } } @@ -566,11 +566,11 @@ void BM_editselection_center(BMesh *bm, float r_center[3], BMEditSelection *ese) void BM_editselection_normal(float r_normal[3], BMEditSelection *ese) { if (ese->htype == BM_VERT) { - BMVert *eve = ese->data; + BMVert *eve = (BMVert *)ese->ele; copy_v3_v3(r_normal, eve->no); } else if (ese->htype == BM_EDGE) { - BMEdge *eed = ese->data; + BMEdge *eed = (BMEdge *)ese->ele; float plane[3]; /* need a plane to correct the normal */ float vec[3]; /* temp vec storage */ @@ -587,7 +587,7 @@ void BM_editselection_normal(float r_normal[3], BMEditSelection *ese) } else if (ese->htype == BM_FACE) { - BMFace *efa = ese->data; + BMFace *efa = (BMFace *)ese->ele; copy_v3_v3(r_normal, efa->no); } } @@ -600,7 +600,7 @@ void BM_editselection_normal(float r_normal[3], BMEditSelection *ese) void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) { if (ese->htype == BM_VERT) { - BMVert *eve = ese->data; + BMVert *eve = (BMVert *)ese->ele; float vec[3] = {0.0f, 0.0f, 0.0f}; if (ese->prev) { /* use previously selected data to make a useful vertex plane */ @@ -619,7 +619,7 @@ void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) } } else if (ese->htype == BM_EDGE) { - BMEdge *eed = ese->data; + BMEdge *eed = (BMEdge *)ese->ele; /* the plane is simple, it runs along the edge * however selecting different edges can swap the direction of the y axis. @@ -635,7 +635,7 @@ void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) } else if (ese->htype == BM_FACE) { - BMFace *efa = ese->data; + BMFace *efa = (BMFace *)ese->ele; float vec[3] = {0.0f, 0.0f, 0.0f}; /* for now, use face normal */ @@ -693,12 +693,12 @@ void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) normalize_v3(r_plane); } -int BM_select_history_check(BMesh *bm, void *data) +int BM_select_history_check(BMesh *bm, const BMElem *ele) { BMEditSelection *ese; for (ese = bm->selected.first; ese; ese = ese->next) { - if (ese->data == data) { + if (ese->ele == ele) { return TRUE; } } @@ -706,11 +706,11 @@ int BM_select_history_check(BMesh *bm, void *data) return FALSE; } -void BM_select_history_remove(BMesh *bm, void *data) +void BM_select_history_remove(BMesh *bm, BMElem *ele) { BMEditSelection *ese; for (ese = bm->selected.first; ese; ese = ese->next) { - if (ese->data == data) { + if (ese->ele == ele) { BLI_freelinkN(&(bm->selected), ese); break; } @@ -723,13 +723,13 @@ void BM_select_history_clear(BMesh *bm) bm->selected.first = bm->selected.last = NULL; } -void BM_select_history_store(BMesh *bm, void *data) +void BM_select_history_store(BMesh *bm, BMElem *ele) { BMEditSelection *ese; - if (!BM_select_history_check(bm, data)) { + if (!BM_select_history_check(bm, ele)) { ese = (BMEditSelection *) MEM_callocN(sizeof(BMEditSelection), "BMEdit Selection"); - ese->htype = ((BMHeader *)data)->htype; - ese->data = data; + ese->htype = ((BMHeader *)ele)->htype; + ese->ele = ele; BLI_addtail(&(bm->selected), ese); } } @@ -742,7 +742,7 @@ void BM_select_history_validate(BMesh *bm) while (ese) { nextese = ese->next; - if (!BM_elem_flag_test(ese->data, BM_ELEM_SELECT)) { + if (!BM_elem_flag_test(ese->ele, BM_ELEM_SELECT)) { BLI_freelinkN(&(bm->selected), ese); } ese = nextese; @@ -755,7 +755,7 @@ void BM_mesh_elem_flag_disable_all(BMesh *bm, const char htype, const char hflag BM_EDGES_OF_MESH, BM_FACES_OF_MESH}; BMIter iter; - BMHeader *ele; + BMElem *ele; int i; if (hflag & BM_ELEM_SELECT) { @@ -781,7 +781,7 @@ void BM_mesh_elem_flag_enable_all(BMesh *bm, const char htype, const char hflag) BM_EDGES_OF_MESH, BM_FACES_OF_MESH}; BMIter iter; - BMHeader *ele; + BMElem *ele; int i; if (hflag & BM_ELEM_SELECT) { diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index b5132312d3c..097c87ca1c6 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -478,7 +478,7 @@ void bmesh_end_edit(BMesh *bm, int flag) void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag) { BMIter iter; - BMHeader *ele; + BMElem *ele; #ifdef DEBUG BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__); @@ -552,7 +552,7 @@ void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *fu const char *type_names[3] = {"vert", "edge", "face"}; BMIter iter; - BMHeader *ele; + BMElem *ele; int i; int is_any_error = 0; diff --git a/source/blender/bmesh/intern/bmesh_newcore.c b/source/blender/bmesh/intern/bmesh_newcore.c index 31e141a77e0..2966af9baf8 100644 --- a/source/blender/bmesh/intern/bmesh_newcore.c +++ b/source/blender/bmesh/intern/bmesh_newcore.c @@ -463,7 +463,7 @@ static void bmesh_kill_only_vert(BMesh *bm, BMVert *v) bm->totvert--; bm->elem_index_dirty |= BM_VERT; - BM_select_history_remove(bm, v); + BM_select_history_remove(bm, (BMElem *)v); if (v->head.data) CustomData_bmesh_free_block(&bm->vdata, &v->head.data); @@ -476,7 +476,7 @@ static void bmesh_kill_only_edge(BMesh *bm, BMEdge *e) bm->totedge--; bm->elem_index_dirty |= BM_EDGE; - BM_select_history_remove(bm, e); + BM_select_history_remove(bm, (BMElem *)e); if (e->head.data) CustomData_bmesh_free_block(&bm->edata, &e->head.data); @@ -493,7 +493,7 @@ static void bmesh_kill_only_face(BMesh *bm, BMFace *f) bm->totface--; bm->elem_index_dirty |= BM_FACE; - BM_select_history_remove(bm, f); + BM_select_history_remove(bm, (BMElem *)f); if (f->head.data) CustomData_bmesh_free_block(&bm->pdata, &f->head.data); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index f0898734d4c..af291eca072 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -693,7 +693,7 @@ void BMO_slot_from_hflag(BMesh *bm, BMOperator *op, const char *slotname, const char hflag, const char htype) { BMIter elements; - BMHeader *e; + BMElem *ele; BMOpSlot *output = BMO_slot_get(op, slotname); int totelement = 0, i = 0; @@ -703,27 +703,27 @@ void BMO_slot_from_hflag(BMesh *bm, BMOperator *op, const char *slotname, bmo_slot_buffer_alloc(op, slotname, totelement); if (htype & BM_VERT) { - for (e = BM_iter_new(&elements, bm, BM_VERTS_OF_MESH, bm); e; e = BM_iter_step(&elements)) { - if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_elem_flag_test(e, hflag)) { - ((BMHeader **)output->data.p)[i] = e; + for (ele = BM_iter_new(&elements, bm, BM_VERTS_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) { + if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) { + ((BMElem **)output->data.p)[i] = ele; i++; } } } if (htype & BM_EDGE) { - for (e = BM_iter_new(&elements, bm, BM_EDGES_OF_MESH, bm); e; e = BM_iter_step(&elements)) { - if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_elem_flag_test(e, hflag)) { - ((BMHeader **)output->data.p)[i] = e; + for (ele = BM_iter_new(&elements, bm, BM_EDGES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) { + if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) { + ((BMElem **)output->data.p)[i] = ele; i++; } } } if (htype & BM_FACE) { - for (e = BM_iter_new(&elements, bm, BM_FACES_OF_MESH, bm); e; e = BM_iter_step(&elements)) { - if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_elem_flag_test(e, hflag)) { - ((BMHeader **)output->data.p)[i] = e; + for (ele = BM_iter_new(&elements, bm, BM_FACES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) { + if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) { + ((BMElem **)output->data.p)[i] = ele; i++; } } @@ -796,7 +796,7 @@ void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOperator *op, const char *slotnam const char hflag, const char htype, char do_flush_select) { BMOpSlot *slot = BMO_slot_get(op, slotname); - BMHeader **data = slot->data.p; + BMElem **data = slot->data.p; int i; BLI_assert(slot->slottype > BMO_OP_SLOT_VEC); @@ -806,7 +806,7 @@ void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOperator *op, const char *slotnam } for (i = 0; i < slot->len; i++) { - if (!(htype & data[i]->htype)) + if (!(htype & data[i]->head.htype)) continue; if (do_flush_select) { @@ -827,7 +827,7 @@ void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOperator *op, const char *slotna const char hflag, const char htype, char do_flush_select) { BMOpSlot *slot = BMO_slot_get(op, slotname); - BMHeader **data = slot->data.p; + BMElem **data = slot->data.p; int i; BLI_assert(slot->slottype > BMO_OP_SLOT_VEC); @@ -837,7 +837,7 @@ void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOperator *op, const char *slotna } for (i = 0; i < slot->len; i++) { - if (!(htype & data[i]->htype)) + if (!(htype & data[i]->head.htype)) continue; if (do_flush_select) { |