Commit: 690b90f1e2cb949a3cdfb02678be844c4808f2cb
Author: Campbell Barton
Date:   Sun Apr 12 15:21:40 2015 +1000
Branches: master
https://developer.blender.org/rB690b90f1e2cb949a3cdfb02678be844c4808f2cb

BMesh: minor optimization counting adjacent data

add BM_***_count_is_over(), _count_is_equal()

Useful if we only want to know if the count is a smaller value.

===================================================================

M       source/blender/blenkernel/intern/pbvh_bmesh.c
M       source/blender/bmesh/intern/bmesh_core.c
M       source/blender/bmesh/intern/bmesh_mods.c
M       source/blender/bmesh/intern/bmesh_private.h
M       source/blender/bmesh/intern/bmesh_queries.c
M       source/blender/bmesh/intern/bmesh_queries.h
M       source/blender/bmesh/intern/bmesh_structure.c
M       source/blender/bmesh/intern/bmesh_structure.h
M       source/blender/bmesh/tools/bmesh_beautify.c
M       source/blender/bmesh/tools/bmesh_bevel.c
M       source/blender/editors/mesh/editmesh_rip.c
M       source/blender/editors/mesh/editmesh_select.c
M       source/blender/editors/sculpt_paint/paint_stroke.c
M       source/blender/python/bmesh/bmesh_py_utils.c

===================================================================

diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c 
b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 01bca44..92fdfa9 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -369,6 +369,7 @@ static BMFace *pbvh_bmesh_face_create(
 }
 
 /* Return the number of faces in 'node' that use vertex 'v' */
+#if 0
 static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, PBVHNode *node, BMVert *v)
 {
        BMIter bm_iter;
@@ -376,12 +377,33 @@ static int pbvh_bmesh_node_vert_use_count(PBVH *bvh, 
PBVHNode *node, BMVert *v)
        int count = 0;
 
        BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) {
-               PBVHNode *f_node;
+               PBVHNode *f_node = pbvh_bmesh_node_lookup(bvh, f);
+               if (f_node == node) {
+                       count++;
+               }
+       }
 
-               f_node = pbvh_bmesh_node_lookup(bvh, f);
+       return count;
+}
+#endif
+
+#define pbvh_bmesh_node_vert_use_count_is_equal(bvh, node, v, n) \
+       (pbvh_bmesh_node_vert_use_count_ex(bvh, node, v, (n) + 1) == n)
 
-               if (f_node == node)
+static int pbvh_bmesh_node_vert_use_count_ex(PBVH *bvh, PBVHNode *node, BMVert 
*v, const int count_max)
+{
+       BMIter bm_iter;
+       BMFace *f;
+       int count = 0;
+
+       BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) {
+               PBVHNode *f_node = pbvh_bmesh_node_lookup(bvh, f);
+               if (f_node == node) {
                        count++;
+                       if (count == count_max) {
+                               break;
+                       }
+               }
        }
 
        return count;
@@ -484,13 +506,13 @@ static void pbvh_bmesh_face_remove(PBVH *bvh, BMFace *f)
        l_iter = l_first = BM_FACE_FIRST_LOOP(f);
        do {
                v = l_iter->v;
-               if (pbvh_bmesh_node_vert_use_count(bvh, f_node, v) == 1) {
+               if (pbvh_bmesh_node_vert_use_count_is_equal(bvh, f_node, v, 1)) 
{
                        if (BLI_gset_haskey(f_node->bm_unique_verts, v)) {
                                /* Find a different node that uses 'v' */
                                PBVHNode *new_node;
 
                                new_node = pbvh_bmesh_vert_other_node_find(bvh, 
v);
-                               BLI_assert(new_node || BM_vert_face_count(v) == 
1);
+                               BLI_assert(new_node || 
BM_vert_face_count_is_equal(v, 1));
 
                                if (new_node) {
                                        pbvh_bmesh_vert_ownership_transfer(bvh, 
new_node, v);
@@ -810,13 +832,11 @@ static void pbvh_bmesh_split_edge(EdgeQueueContext 
*eq_ctx, PBVH *bvh,
                BM_face_kill(bvh->bm, f_adj);
 
                /* Ensure new vertex is in the node */
-               if (!BLI_gset_haskey(bvh->nodes[ni].bm_unique_verts, v_new) &&
-                   !BLI_gset_haskey(bvh->nodes[ni].bm_other_verts, v_new))
-               {
-                       BLI_gset_insert(bvh->nodes[ni].bm_other_verts, v_new);
+               if (!BLI_gset_haskey(bvh->nodes[ni].bm_unique_verts, v_new)) {
+                       BLI_gset_add(bvh->nodes[ni].bm_other_verts, v_new);
                }
 
-               if (BM_vert_edge_count(v_opp) >= 9) {
+               if (BM_vert_edge_count_is_over(v_opp, 8)) {
                        BMIter bm_iter;
                        BMEdge *e2;
 
@@ -945,10 +965,8 @@ static void pbvh_bmesh_collapse_edge(
                        pbvh_bmesh_face_create(bvh, ni, v_tri, e_tri, f);
 
                        /* Ensure that v_conn is in the new face's node */
-                       if (!BLI_gset_haskey(n->bm_unique_verts, v_conn) &&
-                           !BLI_gset_haskey(n->bm_other_verts,  v_conn))
-                       {
-                               BLI_gset_insert(n->bm_other_verts, v_conn);
+                       if (!BLI_gset_haskey(n->bm_unique_verts, v_conn)) {
+                               BLI_gset_add(n->bm_other_verts, v_conn);
                        }
                }
 
@@ -973,7 +991,7 @@ static void pbvh_bmesh_collapse_edge(
                /* Check if any of the face's vertices are now unused, if so
                 * remove them from the PBVH */
                for (j = 0; j < 3; j++) {
-                       if (v_tri[j] != v_del && BM_vert_face_count(v_tri[j]) 
== 1) {
+                       if (v_tri[j] != v_del && 
BM_vert_face_count_is_equal(v_tri[j], 1)) {
                                BLI_gset_insert(deleted_verts, v_tri[j]);
                                pbvh_bmesh_vert_remove(bvh, v_tri[j]);
                        }
@@ -1010,7 +1028,7 @@ static void pbvh_bmesh_collapse_edge(
        }
 
        /* Delete v_del */
-       BLI_assert(BM_vert_face_count(v_del) == 0);
+       BLI_assert(!BM_vert_face_check(v_del));
        BLI_gset_insert(deleted_verts, v_del);
        BM_log_vert_removed(bvh->bm_log, v_del, eq_ctx->cd_vert_mask_offset);
        BM_vert_kill(bvh->bm, v_del);
@@ -1641,7 +1659,7 @@ static void pbvh_bmesh_verify(PBVH *bvh)
 
                        GSET_ITER (gs_iter, n->bm_other_verts) {
                                BMVert *v = BLI_gsetIterator_getKey(&gs_iter);
-                               BLI_assert(BM_vert_face_count(v) > 0);
+                               BLI_assert(!BM_vert_face_check(v));
                                BLI_assert(BLI_gset_haskey(verts_all, v));
                        }
                }
diff --git a/source/blender/bmesh/intern/bmesh_core.c 
b/source/blender/bmesh/intern/bmesh_core.c
index 9e08077..ad35f6e 100644
--- a/source/blender/bmesh/intern/bmesh_core.c
+++ b/source/blender/bmesh/intern/bmesh_core.c
@@ -1111,7 +1111,7 @@ BMFace *BM_faces_join(BMesh *bm, BMFace **faces, int 
totface, const bool do_del)
                                if (!d1 && !d2 && 
!BM_ELEM_API_FLAG_TEST(l_iter->e, _FLAG_JF)) {
                                        /* don't remove an edge it makes up the 
side of another face
                                         * else this will remove the face as 
well - campbell */
-                                       if (BM_edge_face_count(l_iter->e) <= 2) 
{
+                                       if 
(!BM_edge_face_count_is_over(l_iter->e, 3)) {
                                                if (do_del) {
                                                        
BLI_array_append(deledges, l_iter->e);
                                                }
diff --git a/source/blender/bmesh/intern/bmesh_mods.c 
b/source/blender/bmesh/intern/bmesh_mods.c
index 7b3f64d..85e9ec3 100644
--- a/source/blender/bmesh/intern/bmesh_mods.c
+++ b/source/blender/bmesh/intern/bmesh_mods.c
@@ -72,7 +72,8 @@
  */
 bool BM_vert_dissolve(BMesh *bm, BMVert *v)
 {
-       const int len = BM_vert_edge_count(v);
+       /* logic for 3 or more is identical */
+       const int len = BM_vert_edge_count_ex(v, 3);
        
        if (len == 1) {
                BM_vert_kill(bm, v); /* will kill edges too */
@@ -97,7 +98,7 @@ bool BM_vert_dissolve(BMesh *bm, BMVert *v)
                        return false;
                }
        }
-       else if (len == 2 && BM_vert_face_count(v) == 1) {
+       else if (len == 2 && BM_vert_face_count_is_equal(v, 1)) {
                /* boundary vertex on a face */
                return (BM_vert_collapse_edge(bm, v->e, v, true, true) != NULL);
        }
diff --git a/source/blender/bmesh/intern/bmesh_private.h 
b/source/blender/bmesh/intern/bmesh_private.h
index 102a677..814015a 100644
--- a/source/blender/bmesh/intern/bmesh_private.h
+++ b/source/blender/bmesh/intern/bmesh_private.h
@@ -54,6 +54,7 @@ int bmesh_elem_check(void *element, const char htype);
 #endif
 
 int bmesh_radial_length(const BMLoop *l);
+int bmesh_disk_count_ex(const BMVert *v, const int count_max);
 int bmesh_disk_count(const BMVert *v);
 
 /**
diff --git a/source/blender/bmesh/intern/bmesh_queries.c 
b/source/blender/bmesh/intern/bmesh_queries.c
index 7c557cb..392f8b0 100644
--- a/source/blender/bmesh/intern/bmesh_queries.c
+++ b/source/blender/bmesh/intern/bmesh_queries.c
@@ -750,6 +750,11 @@ int BM_vert_edge_count(const BMVert *v)
        return bmesh_disk_count(v);
 }
 
+int BM_vert_edge_count_ex(const BMVert *v, const int count_max)
+{
+       return bmesh_disk_count_ex(v, count_max);
+}
+
 int BM_vert_edge_count_nonwire(const BMVert *v)
 {
        int count = 0;
@@ -770,13 +775,30 @@ int BM_edge_face_count(const BMEdge *e)
        int count = 0;
 
        if (e->l) {
-               BMLoop *l_iter;
-               BMLoop *l_first;
+               BMLoop *l_iter, *l_first;
 
                l_iter = l_first = e->l;
+               do {
+                       count++;
+               } while ((l_iter = l_iter->radial_next) != l_first);
+       }
 
+       return count;
+}
+
+int BM_edge_face_count_ex(const BMEdge *e, const int count_max)
+{
+       int count = 0;
+
+       if (e->l) {
+               BMLoop *l_iter, *l_first;
+
+               l_iter = l_first = e->l;
                do {
                        count++;
+                       if (count == count_max) {
+                               break;
+                       }
                } while ((l_iter = l_iter->radial_next) != l_first);
        }
 
@@ -792,6 +814,21 @@ int BM_vert_face_count(const BMVert *v)
        return bmesh_disk_facevert_count(v);
 }
 
+int BM_vert_face_count_ex(const BMVert *v, int count_max)
+{
+       return bmesh_disk_facevert_count_ex(v, count_max);
+}
+
+/**
+ * Return true if the vertex is connected to _any_ faces.
+ *
+ * same as ``BM_vert_face_count(v) != 0`` or ``BM_vert_find_first_loop(v) == 
NULL``
+ */
+bool BM_vert_face_check(BMVert *v)
+{
+       return v->e && (bmesh_disk_faceedge_find_first(v->e, v) != NULL);
+}
+
 /**
  * Tests whether or not the vertex is part of a wire edge.
  * (ie: has no faces attached to it)
diff --git a/source/blender/bmesh/intern/bmesh_queries.h 
b/source/blender/bmesh/intern/bmesh_queries.h
index 4ee5588..6d25d9f 100644
--- a/source/blender/bmesh/intern/bmesh_queries.h
+++ b/source/blender/bmesh/intern/bmesh_queries.h
@@ -65,12 +65,22 @@ BMFace *BM_vert_pair_share_face_by_angle(
         const bool allow_adjacent) ATTR_NONNULL();
 
 int     BM_vert_edge_count_nonwire(const BMVert *v) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
+#define BM_vert_edge_count_is_equal(v, n) (BM_vert_edge_count_ex(v, (n) + 1) 
== n)
+#define BM_vert_edge_count_is_over(v, n) (BM_vert_edge_count_ex(v, (n) + 1) == 
(n) + 1)
+int     BM_vert_edge_count_ex(const BMVert *v, const int count_max) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 int     BM_vert_edge_count(const BMVert *v) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
+#define BM_edge_face_count_is_equal(e, n) (BM_edge_face_count_ex(e, (n) + 1) 
== n)
+#define BM_edge_face_count_is_over(e, n) (BM_edge_face_count_ex(e, (n) + 1) == 
(n) + 1)
+int     BM_edge_face_count_ex(const BMEdge *e, const int count_max) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 int     BM_edge_face_count(const BMEdge *e) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
+#define BM_vert_face_count_is_equal(v, n) (BM_vert_face_count_ex(v, (n) + 1) 
== n)
+#define BM_vert_face_count_is_over(v, n) (BM_vert_face_count_ex(v, (n) + 1) == 
(n) + 1)
+int     BM_vert_face_count_ex(const BMVert *v, int count_max) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 int     BM_vert_face_count(const BMVert *v) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
 BMEdge *BM_vert_other_disk_edge(BMVert *v, BMEdge *e) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
 
 bool    BM_vert_is_edge_pair(const BMVert *v) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
+bool    BM_vert_face_check(BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 bool    BM_vert_is_wire(const BMVert *v) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
 BLI_INLINE bool    BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT 
ATTR_NONNULL();
 
diff --git a/source/blender/bmesh/intern/bmesh_structure.c 
b/source/blender/bmesh/intern/bmesh_structure.c
index 3e8002c..cf56c3b 100644
--- a/source/blender/bmesh/intern/bmesh_structure.c
+++ b/source/blender/bmesh/intern/bmesh_structure.c
@@ -206,6 +206,22 @@ int bmesh_disk_count(const BMVert *v)
        return count;
 }
 
+int bmesh_disk_count_ex(const BMVert *v, const int count_max)
+{
+       int count = 0;
+       if (v->e) {
+

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to