diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-05 09:30:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-05 09:30:55 +0400 |
commit | 1e504bc1230e5f1dbc188c891669d2b59843a129 (patch) | |
tree | 657aa7b7d1ae81b2bd54c88bdb46c001343fb528 | |
parent | 61c73b49d3db67274b24d4299862d36466d9f213 (diff) |
Dyntopo: minor optimizations for edge queue
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_bmesh.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index f56b403bab6..98efc112125 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, |