diff --git a/source/blender/blenkernel/intern/multires_unsubdivide.cc b/source/blender/blenkernel/intern/multires_unsubdivide.cc index b1a689247a2..2bc291cc3d0 100644 --- a/source/blender/blenkernel/intern/multires_unsubdivide.cc +++ b/source/blender/blenkernel/intern/multires_unsubdivide.cc @@ -9,6 +9,8 @@ * its corresponding grids to match a given original mesh. */ +#include + #include "MEM_guardedalloc.h" #include "DNA_mesh_types.h" @@ -16,7 +18,6 @@ #include "DNA_modifier_types.h" #include "DNA_scene_types.h" -#include "BLI_gsqueue.h" #include "BLI_math_vector.h" #include "BKE_customdata.hh" @@ -165,8 +166,7 @@ static void unsubdivide_face_center_vertex_tag(BMesh *bm, BMVert *initial_vertex { bool *visited_verts = static_cast( MEM_calloc_arrayN(bm->totvert, sizeof(bool), "visited vertices")); - GSQueue *queue; - queue = BLI_gsqueue_new(sizeof(BMVert *)); + std::queue queue; /* Add and tag the vertices connected by a diagonal to initial_vertex to the flood fill queue. If * initial_vertex is a pole and there is a valid solution, those vertices should be the (0,0) of @@ -179,7 +179,7 @@ static void unsubdivide_face_center_vertex_tag(BMesh *bm, BMVert *initial_vertex BM_ITER_ELEM (neighbor_v, &iter_a, f, BM_VERTS_OF_FACE) { int neighbor_vertex_index = BM_elem_index_get(neighbor_v); if (neighbor_v != initial_vertex && is_vertex_diagonal(neighbor_v, initial_vertex)) { - BLI_gsqueue_push(queue, &neighbor_v); + queue.push(neighbor_v); visited_verts[neighbor_vertex_index] = true; BM_elem_flag_set(neighbor_v, BM_ELEM_TAG, true); } @@ -191,43 +191,40 @@ static void unsubdivide_face_center_vertex_tag(BMesh *bm, BMVert *initial_vertex * direction. If a solution exists and `initial_vertex` was a pole, this is guaranteed that will * tag all the (0,0) vertices of the grids, and nothing else. */ /* If it was not a pole, it may or may not find a solution, even if the solution exists. */ - while (!BLI_gsqueue_is_empty(queue)) { - BMVert *from_v; - BLI_gsqueue_pop(queue, &from_v); + while (!queue.empty()) { + BMVert *from_v = queue.front(); + queue.pop(); /* Get the diagonals (first connected step) */ - GSQueue *diagonals; - diagonals = BLI_gsqueue_new(sizeof(BMVert *)); + std::queue diagonals; BM_ITER_ELEM (f, &iter, from_v, BM_FACES_OF_VERT) { BM_ITER_ELEM (neighbor_v, &iter_a, f, BM_VERTS_OF_FACE) { if (neighbor_v != from_v && is_vertex_diagonal(neighbor_v, from_v)) { - BLI_gsqueue_push(diagonals, &neighbor_v); + diagonals.push(neighbor_v); } } } /* Do the second connected step. This vertices are the ones that are added to the flood fill * queue. */ - while (!BLI_gsqueue_is_empty(diagonals)) { - BMVert *diagonal_v; - BLI_gsqueue_pop(diagonals, &diagonal_v); + while (!diagonals.empty()) { + BMVert *diagonal_v = diagonals.front(); + diagonals.pop(); BM_ITER_ELEM (f, &iter, diagonal_v, BM_FACES_OF_VERT) { BM_ITER_ELEM (neighbor_v, &iter_a, f, BM_VERTS_OF_FACE) { int neighbor_vertex_index = BM_elem_index_get(neighbor_v); if (!visited_verts[neighbor_vertex_index] && neighbor_v != diagonal_v && is_vertex_diagonal(neighbor_v, diagonal_v)) { - BLI_gsqueue_push(queue, &neighbor_v); + queue.push(neighbor_v); visited_verts[neighbor_vertex_index] = true; BM_elem_flag_set(neighbor_v, BM_ELEM_TAG, true); } } } } - BLI_gsqueue_free(diagonals); } - BLI_gsqueue_free(queue); MEM_freeN(visited_verts); } @@ -292,10 +289,10 @@ static bool unsubdivide_tag_disconnected_mesh_element(BMesh *bm, int *elem_id, i /* First, get vertex candidates to try to generate possible un-subdivide solution. */ /* Find a vertex pole. If there is a solution on an all quad base mesh, this vertex should be * part of the base mesh. If it isn't, then there is no solution. */ - GSQueue *initial_vertex = BLI_gsqueue_new(sizeof(BMVert *)); + std::queue initial_vertex; BMVert *initial_vertex_pole = unsubdivide_find_any_pole(bm, elem_id, elem); if (initial_vertex_pole != nullptr) { - BLI_gsqueue_push(initial_vertex, &initial_vertex_pole); + initial_vertex.push(initial_vertex_pole); } /* Also try from the different 4 vertices of a quad in the current @@ -317,16 +314,16 @@ static bool unsubdivide_tag_disconnected_mesh_element(BMesh *bm, int *elem_id, i } BM_ITER_ELEM (v, &iter_a, init_face, BM_VERTS_OF_FACE) { - BLI_gsqueue_push(initial_vertex, &v); + initial_vertex.push(v); } bool valid_tag_found = false; /* Check all vertex candidates to a solution. */ - while (!BLI_gsqueue_is_empty(initial_vertex)) { + while (!initial_vertex.empty()) { - BMVert *iv; - BLI_gsqueue_pop(initial_vertex, &iv); + BMVert *iv = initial_vertex.front(); + initial_vertex.pop(); /* Generate a possible solution. */ unsubdivide_face_center_vertex_tag(bm, iv); @@ -347,7 +344,6 @@ static bool unsubdivide_tag_disconnected_mesh_element(BMesh *bm, int *elem_id, i } } } - BLI_gsqueue_free(initial_vertex); return valid_tag_found; } @@ -361,31 +357,29 @@ static int unsubdivide_init_elem_ids(BMesh *bm, int *elem_id) int current_id = 0; for (int i = 0; i < bm->totvert; i++) { if (!visited_verts[i]) { - GSQueue *queue; - queue = BLI_gsqueue_new(sizeof(BMVert *)); + std::queue queue; visited_verts[i] = true; elem_id[i] = current_id; - BMVert *iv = BM_vert_at_index(bm, i); - BLI_gsqueue_push(queue, &iv); + queue.push(BM_vert_at_index(bm, i)); - while (!BLI_gsqueue_is_empty(queue)) { + while (!queue.empty()) { BMIter iter; - BMVert *current_v, *neighbor_v; + BMVert *current_v = queue.front(); + queue.pop(); + BMVert *neighbor_v; BMEdge *ed; - BLI_gsqueue_pop(queue, ¤t_v); BM_ITER_ELEM (ed, &iter, current_v, BM_EDGES_OF_VERT) { neighbor_v = BM_edge_other_vert(ed, current_v); const int neighbor_index = BM_elem_index_get(neighbor_v); if (!visited_verts[neighbor_index]) { visited_verts[neighbor_index] = true; elem_id[neighbor_index] = current_id; - BLI_gsqueue_push(queue, &neighbor_v); + queue.push(neighbor_v); } } } current_id++; - BLI_gsqueue_free(queue); } } MEM_freeN(visited_verts);