BMesh: Minor improvement to face-join
authorCampbell Barton <ideasman42@gmail.com>
Fri, 11 Nov 2016 23:06:53 +0000 (10:06 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 11 Nov 2016 23:30:32 +0000 (10:30 +1100)
Pass in loops instead of edge & faces.
Nearly all callers have the loop-pairs to pass in.

source/blender/bmesh/intern/bmesh_mods.c
source/blender/bmesh/intern/bmesh_mods.h
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/operators/bmo_dissolve.c
source/blender/bmesh/operators/bmo_join_triangles.c
source/blender/bmesh/operators/bmo_triangulate.c
source/blender/bmesh/tools/bmesh_decimate_dissolve.c

index 3979374d8da12cb082e97b91b3a390aab19f2dd0..33adfd458b1c04d3d4caacebbca050c78d2ba109 100644 (file)
@@ -104,7 +104,6 @@ bool BM_vert_dissolve(BMesh *bm, BMVert *v)
  */
 bool BM_disk_dissolve(BMesh *bm, BMVert *v)
 {
-       BMFace *f, *f2;
        BMEdge *e, *keepedge = NULL, *baseedge = NULL;
        int len = 0;
 
@@ -141,7 +140,7 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
                        return false;
                }
 #else
-               if (UNLIKELY(!BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, true))) {
+               if (UNLIKELY(!BM_faces_join_pair(bm, e->l, e->l->radial_next, true))) {
                        return false;
                }
                else if (UNLIKELY(!BM_vert_collapse_faces(bm, v->e, v, 1.0, true, false, true))) {
@@ -159,11 +158,10 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
                }
 
                /* handle two-valence */
-               f = e->l->f;
-               f2 = e->l->radial_next->f;
-
-               if (f != f2 && !BM_faces_join_pair(bm, f, f2, e, true)) {
-                       return false;
+               if (e->l != e->l->radial_next) {
+                       if (!BM_faces_join_pair(bm, e->l, e->l->radial_next, true)) {
+                               return false;
+                       }
                }
 
                return true;
@@ -176,9 +174,9 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
                        done = true;
                        e = v->e;
                        do {
-                               f = NULL;
+                               BMFace *f = NULL;
                                if (BM_edge_is_manifold(e) && (e != baseedge) && (e != keepedge)) {
-                                       f = BM_faces_join_pair(bm, e->l->f, e->l->radial_next->f, e, true);
+                                       f = BM_faces_join_pair(bm, e->l, e->l->radial_next, true);
                                        /* return if couldn't join faces in manifold
                                         * conditions */
                                        /* !disabled for testing why bad things happen */
@@ -204,12 +202,9 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
                
                if (e->l) {
                        /* get remaining two faces */
-                       f = e->l->f;
-                       f2 = e->l->radial_next->f;
-
-                       if (f != f2) {
+                       if (e->l != e->l->radial_next) {
                                /* join two remaining faces */
-                               if (!BM_faces_join_pair(bm, f, f2, e, true)) {
+                               if (!BM_faces_join_pair(bm, e->l, e->l->radial_next, true)) {
                                        return false;
                                }
                        }
@@ -234,20 +229,16 @@ bool BM_disk_dissolve(BMesh *bm, BMVert *v)
  *
  * \return pointer to the combined face
  */
-BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f_a, BMFace *f_b, BMEdge *e, const bool do_del)
+BMFace *BM_faces_join_pair(BMesh *bm, BMLoop *l_a, BMLoop *l_b, const bool do_del)
 {
-       BMFace *faces[2] = {f_a, f_b};
-
-       BMLoop *l_a = BM_face_edge_share_loop(f_a, e);
-       BMLoop *l_b = BM_face_edge_share_loop(f_b, e);
-
-       BLI_assert(l_a && l_b);
+       BLI_assert((l_a != l_b) && (l_a->e == l_b->e));
 
        if (l_a->v == l_b->v) {
                const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
-               bmesh_loop_reverse(bm, f_b, cd_loop_mdisp_offset, true);
+               bmesh_loop_reverse(bm, l_b->f, cd_loop_mdisp_offset, true);
        }
-       
+
+       BMFace *faces[2] = {l_a->f, l_b->f};
        return BM_faces_join(bm, faces, 2, do_del);
 }
 
@@ -1040,7 +1031,7 @@ BMEdge *BM_edge_rotate(BMesh *bm, BMEdge *e, const bool ccw, const short check_f
        f_hflag_prev_2 = l2->f->head.hflag;
 
        /* don't delete the edge, manually remove the edge after so we can copy its attributes */
-       f = BM_faces_join_pair(bm, l1->f, l2->f, e, true);
+       f = BM_faces_join_pair(bm, BM_face_edge_share_loop(l1->f, e), BM_face_edge_share_loop(l2->f, e), true);
 
        if (f == NULL) {
                return NULL;
index 2e557e3b606bdeaed39d45b2061061438a3fec7e..5e95e9a2cc7799b80a39ba6f3cc923f1ce226bf8 100644 (file)
@@ -31,7 +31,7 @@ bool BM_vert_dissolve(BMesh *bm, BMVert *v);
 
 bool BM_disk_dissolve(BMesh *bm, BMVert *v);
 
-BMFace *BM_faces_join_pair(BMesh *bm, BMFace *f1, BMFace *f2, BMEdge *e, const bool do_del);
+BMFace *BM_faces_join_pair(BMesh *bm, BMLoop *l_a, BMLoop *l_b, const bool do_del);
 
 
 /** see: bmesh_polygon_edgenet.h for #BM_face_split_edgenet */
index 22095214133e0b51af91e5bda07796f5bb96adce..0287498482a3ef6b4ef1351fda6ae43bd06a5fdd 100644 (file)
@@ -926,7 +926,8 @@ bool BM_vert_is_manifold(const BMVert *v)
 
        /* count edges while looking for non-manifold edges */
        e_first = e_iter = v->e;
-       l_first = e_iter->l ? e_iter->l : NULL;
+       /* may be null */
+       l_first = e_iter->l;
        do {
                /* loose edge or edge shared by more than two faces,
                 * edges with 1 face user are OK, otherwise we could
index 05efb14a69931ccbfff9a815646446bebff19460..6e3a8a1473d005d0599f57f5e1fadb3152a395eb 100644 (file)
@@ -322,12 +322,12 @@ void bmo_dissolve_edges_exec(BMesh *bm, BMOperator *op)
        }
 
        BMO_ITER (e, &eiter, op->slots_in, "edges", BM_EDGE) {
-               BMFace *fa, *fb;
-               if (BM_edge_face_pair(e, &fa, &fb)) {
+               BMLoop *l_a, *l_b;
+               if (BM_edge_loop_pair(e, &l_a, &l_b)) {
                        BMFace *f_new;
 
                        /* join faces */
-                       f_new = BM_faces_join_pair(bm, fa, fb, e, false);
+                       f_new = BM_faces_join_pair(bm, l_a, l_b, false);
 
                        if (f_new) {
                                /* maintain active face */
@@ -437,12 +437,12 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op)
 
                if (!BMO_vert_flag_test(bm, v, VERT_MARK_PAIR)) {
                        BM_ITER_ELEM (e, &itersub, v, BM_EDGES_OF_VERT) {
-                               BMFace *fa, *fb;
-                               if (BM_edge_face_pair(e, &fa, &fb)) {
+                               BMLoop *l_a, *l_b;
+                               if (BM_edge_loop_pair(e, &l_a, &l_b)) {
                                        BMFace *f_new;
 
                                        /* join faces */
-                                       f_new = BM_faces_join_pair(bm, fa, fb, e, false);
+                                       f_new = BM_faces_join_pair(bm, l_a, l_b, false);
 
                                        /* maintain active face */
                                        if (act_face && bm->act_face == NULL) {
index bc620e4a020fe324bb939463653cebf0aaf4a7ce..655fb3469766137fabe052509484f2d4381d4afb 100644 (file)
@@ -361,16 +361,16 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op)
        qsort(jedges, totedge, sizeof(*jedges), BLI_sortutil_cmp_float);
 
        for (i = 0; i < totedge; i++) {
-               BMFace *f_a, *f_b;
+               BMLoop *l_a, *l_b;
 
                e = jedges[i].data;
-               f_a = e->l->f;
-               f_b = e->l->radial_next->f;
+               l_a = e->l;
+               l_b = e->l->radial_next;
 
                /* check if another edge already claimed this face */
-               if ((f_a->len == 3) && (f_b->len == 3)) {
+               if ((l_a->f->len == 3) && (l_b->f->len == 3)) {
                        BMFace *f_new;
-                       f_new = BM_faces_join_pair(bm, f_a, f_b, e, true);
+                       f_new = BM_faces_join_pair(bm, l_a, l_b, true);
                        if (f_new) {
                                BMO_face_flag_enable(bm, f_new, FACE_OUT);
                        }
index 8938d086c1a097c3f05696b5172638cc4454c567..6bd3174d27a236599e47e262eafcba5904400f2d 100644 (file)
@@ -253,10 +253,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op)
                        if (BMO_edge_flag_test(bm, e, ELE_NEW)) {
                                /* in rare cases the edges face will have already been removed from the edge */
                                if (LIKELY(e->l)) {
-                                       BMFace *f_new = BM_faces_join_pair(
-                                               bm, e->l->f,
-                                               e->l->radial_next->f, e,
-                                               false); /* join faces */
+                                       BMFace *f_new = BM_faces_join_pair(bm, e->l, e->l->radial_next, false);
                                        if (f_new) {
                                                BMO_face_flag_enable(bm, f_new, ELE_NEW);
                                                BM_edge_kill(bm, e);
index 978cceee37cabf4762176a5d39705983e7281a01..e2c36299ddf39111d9097d152981cb2f6be7430f 100644 (file)
@@ -322,9 +322,7 @@ void BM_mesh_decimate_dissolve_ex(
                        i = BM_elem_index_get(e);
 
                        if (BM_edge_is_manifold(e)) {
-                               f_new = BM_faces_join_pair(bm, e->l->f,
-                                                          e->l->radial_next->f, e,
-                                                          false); /* join faces */
+                               f_new = BM_faces_join_pair(bm, e->l, e->l->radial_next, false);
 
                                if (f_new) {
                                        BMLoop *l_first, *l_iter;