diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-02 13:49:18 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-03 13:36:01 +0300 |
commit | 9a4042bed80737a80a8fc6b75372e532f8fb05c7 (patch) | |
tree | 3ed78bbc9bd139f205ef7e5fa17f3c4f4bd3bd3c | |
parent | 0cc45eaac4b9a285e1d1eea12adb355c661f2da7 (diff) |
Subdiv CCG: Cleanup, remove unused data from adjacency storage
Makes it easier to initialze adjacency, avoid extra re-allocations during
initialization, reduces memory footprint.
-rw-r--r-- | source/blender/blenkernel/BKE_subdiv_ccg.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subdiv_ccg.c | 22 |
2 files changed, 4 insertions, 22 deletions
diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h index e235193a486..9b7c613aa94 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.h +++ b/source/blender/blenkernel/BKE_subdiv_ccg.h @@ -106,8 +106,6 @@ typedef struct SubdivCCGFace { /* Definition of an edge which is adjacent to at least one of the faces. */ typedef struct SubdivCCGAdjacentEdge { int num_adjacent_faces; - /* Indexed by adjacent face index. */ - SubdivCCGFace **faces; /* Indexed by adjacent face index, then by point index on the edge. * points to a grid element. */ struct CCGElem ***boundary_elements; @@ -116,8 +114,6 @@ typedef struct SubdivCCGAdjacentEdge { /* Definition of a vertex which is adjacent to at least one of the faces. */ typedef struct SubdivCCGAdjacentVertex { int num_adjacent_faces; - /* Indexed by adjacent face index. */ - SubdivCCGFace **faces; /* Indexed by adjacent face index, points to a grid element. */ struct CCGElem **corner_elements; } SubdivCCGAdjacentVertex; diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index 9ae0841bc82..bbd73db42bf 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -387,16 +387,11 @@ static void subdiv_ccg_allocate_adjacent_edges(SubdivCCG *subdiv_ccg, const int /* Returns storage where boundary elements are to be stored. */ static CCGElem **subdiv_ccg_adjacent_edge_add_face(SubdivCCG *subdiv_ccg, - SubdivCCGAdjacentEdge *adjacent_edge, - SubdivCCGFace *face) + SubdivCCGAdjacentEdge *adjacent_edge) { const int grid_size = subdiv_ccg->grid_size * 2; const int adjacent_face_index = adjacent_edge->num_adjacent_faces; ++adjacent_edge->num_adjacent_faces; - /* Store new adjacent face. */ - adjacent_edge->faces = MEM_reallocN( - adjacent_edge->faces, adjacent_edge->num_adjacent_faces * sizeof(*adjacent_edge->faces)); - adjacent_edge->faces[adjacent_face_index] = face; /* Allocate memory for the boundary elements. */ adjacent_edge->boundary_elements = MEM_reallocN(adjacent_edge->boundary_elements, adjacent_edge->num_adjacent_faces * @@ -453,8 +448,7 @@ static void subdiv_ccg_init_faces_edge_neighborhood(SubdivCCG *subdiv_ccg) CCGElem *next_grid = subdiv_ccg->grids[next_grid_index]; /* Add new face to the adjacent edge. */ SubdivCCGAdjacentEdge *adjacent_edge = &subdiv_ccg->adjacent_edges[edge_index]; - CCGElem **boundary_elements = subdiv_ccg_adjacent_edge_add_face( - subdiv_ccg, adjacent_edge, face); + CCGElem **boundary_elements = subdiv_ccg_adjacent_edge_add_face(subdiv_ccg, adjacent_edge); /* Fill CCG elements along the edge. */ int boundary_element_index = 0; if (is_edge_flipped) { @@ -494,16 +488,10 @@ static void subdiv_ccg_allocate_adjacent_vertices(SubdivCCG *subdiv_ccg, const i /* Returns storage where corner elements are to be stored. This is a pointer * to the actual storage. */ -static CCGElem **subdiv_ccg_adjacent_vertex_add_face(SubdivCCGAdjacentVertex *adjacent_vertex, - SubdivCCGFace *face) +static CCGElem **subdiv_ccg_adjacent_vertex_add_face(SubdivCCGAdjacentVertex *adjacent_vertex) { const int adjacent_face_index = adjacent_vertex->num_adjacent_faces; ++adjacent_vertex->num_adjacent_faces; - /* Store new adjacent face. */ - adjacent_vertex->faces = MEM_reallocN(adjacent_vertex->faces, - adjacent_vertex->num_adjacent_faces * - sizeof(*adjacent_vertex->faces)); - adjacent_vertex->faces[adjacent_face_index] = face; /* Allocate memory for the boundary elements. */ adjacent_vertex->corner_elements = MEM_reallocN(adjacent_vertex->corner_elements, adjacent_vertex->num_adjacent_faces * @@ -544,7 +532,7 @@ static void subdiv_ccg_init_faces_vertex_neighborhood(SubdivCCG *subdiv_ccg) CCGElem *grid = subdiv_ccg->grids[grid_index]; /* Add new face to the adjacent edge. */ SubdivCCGAdjacentVertex *adjacent_vertex = &subdiv_ccg->adjacent_vertices[vertex_index]; - CCGElem **corner_element = subdiv_ccg_adjacent_vertex_add_face(adjacent_vertex, face); + CCGElem **corner_element = subdiv_ccg_adjacent_vertex_add_face(adjacent_vertex); *corner_element = CCG_grid_elem(&key, grid, grid_size - 1, grid_size - 1); } } @@ -640,14 +628,12 @@ void BKE_subdiv_ccg_destroy(SubdivCCG *subdiv_ccg) for (int face_index = 0; face_index < adjacent_edge->num_adjacent_faces; face_index++) { MEM_SAFE_FREE(adjacent_edge->boundary_elements[face_index]); } - MEM_SAFE_FREE(adjacent_edge->faces); MEM_SAFE_FREE(adjacent_edge->boundary_elements); } MEM_SAFE_FREE(subdiv_ccg->adjacent_edges); /* Free map of adjacent vertices. */ for (int i = 0; i < subdiv_ccg->num_adjacent_vertices; i++) { SubdivCCGAdjacentVertex *adjacent_vertex = &subdiv_ccg->adjacent_vertices[i]; - MEM_SAFE_FREE(adjacent_vertex->faces); MEM_SAFE_FREE(adjacent_vertex->corner_elements); } MEM_SAFE_FREE(subdiv_ccg->adjacent_vertices); |