[Bf-blender-cvs] [1e504bc] master: Dyntopo: minor optimizations for edge queue

Campbell Barton noreply at git.blender.org
Sat Apr 5 07:32:40 CEST 2014


Commit: 1e504bc1230e5f1dbc188c891669d2b59843a129
Author: Campbell Barton
Date:   Sat Apr 5 16:30:55 2014 +1100
https://developer.blender.org/rB1e504bc1230e5f1dbc188c891669d2b59843a129

Dyntopo: minor optimizations for edge queue

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

M	source/blender/blenkernel/intern/pbvh_bmesh.c

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

diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index f56b403..98efc11 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -552,7 +552,7 @@ static void long_edge_queue_edge_add(EdgeQueueContext *eq_ctx,
 {
 	const float len_sq = BM_edge_calc_length_squared(e);
 	if (len_sq > eq_ctx->q->limit_len_squared)
-		edge_queue_insert(eq_ctx, e, 1.0f / len_sq);
+		edge_queue_insert(eq_ctx, e, -len_sq);
 }
 
 static void short_edge_queue_edge_add(EdgeQueueContext *eq_ctx,
@@ -781,17 +781,20 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx, PBVH *bvh,
 
 	while (!BLI_heap_is_empty(eq_ctx->q->heap)) {
 		BMVert **pair = BLI_heap_popmin(eq_ctx->q->heap);
+		BMVert *v1 = pair[0], *v2 = pair[1];
 		BMEdge *e;
 
+		BLI_mempool_free(eq_ctx->pool, pair);
+		pair = NULL;
+
+		if (len_squared_v3v3(v1->co, v2->co) <= eq_ctx->q->limit_len_squared)
+			continue;
+
 		/* Check that the edge still exists */
-		if (!(e = BM_edge_exists(pair[0], pair[1]))) {
-			BLI_mempool_free(eq_ctx->pool, pair);
+		if (!(e = BM_edge_exists(v1, v2))) {
 			continue;
 		}
 
-		BLI_mempool_free(eq_ctx->pool, pair);
-		pair = NULL;
-
 		/* Check that the edge's vertices are still in the PBVH. It's
 		 * possible that an edge collapse has deleted adjacent faces
 		 * and the node has been split, thus leaving wire edges and
@@ -802,9 +805,6 @@ static bool pbvh_bmesh_subdivide_long_edges(EdgeQueueContext *eq_ctx, PBVH *bvh,
 			continue;
 		}
 
-		if (BM_edge_calc_length_squared(e) <= eq_ctx->q->limit_len_squared)
-			continue;
-
 		any_subdivided = true;
 
 		pbvh_bmesh_split_edge(eq_ctx, bvh, e, edge_loops);
@@ -975,22 +975,27 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
 
 	while (!BLI_heap_is_empty(eq_ctx->q->heap)) {
 		BMVert **pair = BLI_heap_popmin(eq_ctx->q->heap);
+		BMVert *v1 = pair[0], *v2 = pair[1];
 		BMEdge *e;
-		BMVert *v1, *v2;
 
-		v1 = pair[0];
-		v2 = pair[1];
 		BLI_mempool_free(eq_ctx->pool, pair);
 		pair = NULL;
 
-		/* Check that the vertices/edge still exist */
+		/* Check the verts still exist */
 		if (BLI_ghash_haskey(deleted_verts, v1) ||
-		    BLI_ghash_haskey(deleted_verts, v2) ||
-		    !(e = BM_edge_exists(v1, v2)))
+		    BLI_ghash_haskey(deleted_verts, v2))
 		{
 			continue;
 		}
 
+		if (len_squared_v3v3(v1->co, v2->co) >= min_len_squared)
+			continue;
+
+		/* Check that the edge still exists */
+		if (!(e = BM_edge_exists(v1, v2))) {
+			continue;
+		}
+
 		/* Check that the edge's vertices are still in the PBVH. It's
 		 * possible that an edge collapse has deleted adjacent faces
 		 * and the node has been split, thus leaving wire edges and
@@ -1001,9 +1006,6 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
 			continue;
 		}
 
-		if (BM_edge_calc_length_squared(e) >= min_len_squared)
-			continue;
-
 		any_collapsed = true;
 
 		pbvh_bmesh_collapse_edge(bvh, e, v1, v2,




More information about the Bf-blender-cvs mailing list