Cleanup: Sculpt: Use Map instead of GHash for dyntopo edge collapse

This commit is contained in:
Hans Goudey
2025-03-01 18:11:44 -05:00
parent aafcc5d3b9
commit 0d28c93f08

View File

@@ -7,8 +7,8 @@
*/
#include "BLI_bounds.hh"
#include "BLI_ghash.h"
#include "BLI_heap_simple.h"
#include "BLI_map.hh"
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
@@ -179,10 +179,10 @@ static BMFace *bm_face_exists_tri_from_loop_vert(BMLoop *l_radial_first, BMVert
* Uses a map of vertices to lookup the final target.
* References can't point to previous items (would cause infinite loop).
*/
static BMVert *bm_vert_hash_lookup_chain(GHash *deleted_verts, BMVert *v)
static BMVert *bm_vert_hash_lookup_chain(Map<BMVert *, BMVert *> &deleted_verts, BMVert *v)
{
while (true) {
BMVert **v_next_p = (BMVert **)BLI_ghash_lookup_p(deleted_verts, v);
BMVert **v_next_p = deleted_verts.lookup_ptr(v);
if (v_next_p == nullptr) {
/* Not remapped. */
return v;
@@ -1588,7 +1588,7 @@ static void pbvh_bmesh_collapse_edge(BMesh &bm,
BMEdge *e,
BMVert *v1,
BMVert *v2,
GHash *deleted_verts,
Map<BMVert *, BMVert *> &deleted_verts,
EdgeQueueContext *eq_ctx)
{
const bool v1_on_boundary = is_boundary_vert(*v1);
@@ -1737,7 +1737,7 @@ static void pbvh_bmesh_collapse_edge(BMesh &bm,
if (v_tri[j] == v_conn) {
v_conn = nullptr;
}
BLI_ghash_insert(deleted_verts, v_tri[j], nullptr);
deleted_verts.add_new(v_tri[j], nullptr);
BM_vert_kill(&bm, v_tri[j]);
}
}
@@ -1769,7 +1769,7 @@ static void pbvh_bmesh_collapse_edge(BMesh &bm,
BLI_assert(!BM_vert_face_check(v_del));
BM_log_vert_removed(&bm_log, v_del, eq_ctx->cd_vert_mask_offset);
/* v_conn == nullptr is OK */
BLI_ghash_insert(deleted_verts, v_del, v_conn);
deleted_verts.add_new(v_del, v_conn);
BM_vert_kill(&bm, v_del);
}
@@ -1787,7 +1787,7 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
const float min_len_squared = min_edge_len * min_edge_len;
bool any_collapsed = false;
/* Deleted verts point to vertices they were merged into, or nullptr when removed. */
GHash *deleted_verts = BLI_ghash_ptr_new("deleted_verts");
Map<BMVert *, BMVert *> deleted_verts;
while (!BLI_heapsimple_is_empty(eq_ctx->q->heap)) {
BMVert **pair = static_cast<BMVert **>(BLI_heapsimple_pop_min(eq_ctx->q->heap));
@@ -1840,8 +1840,6 @@ static bool pbvh_bmesh_collapse_short_edges(EdgeQueueContext *eq_ctx,
eq_ctx);
}
BLI_ghash_free(deleted_verts, nullptr, nullptr);
CLOG_INFO(&LOG, 2, "Short edge collapse took %f seconds.", BLI_time_now_seconds() - start_time);
return any_collapsed;