[Bf-blender-cvs] [899b7ff1de1] master: Cleanup: avoid converting from CCGElem to SubdivCCGCoord
Brecht Van Lommel
noreply at git.blender.org
Tue Oct 8 17:45:15 CEST 2019
Commit: 899b7ff1de1fb648f23765aa412ddc41707ed557
Author: Brecht Van Lommel
Date: Tue Oct 8 16:08:16 2019 +0200
Branches: master
https://developer.blender.org/rB899b7ff1de1fb648f23765aa412ddc41707ed557
Cleanup: avoid converting from CCGElem to SubdivCCGCoord
The other direction is faster.
===================================================================
M source/blender/blenkernel/BKE_subdiv_ccg.h
M source/blender/blenkernel/intern/subdiv_ccg.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h
index 6e2733eb1ac..7c0963680c5 100644
--- a/source/blender/blenkernel/BKE_subdiv_ccg.h
+++ b/source/blender/blenkernel/BKE_subdiv_ccg.h
@@ -92,6 +92,14 @@ typedef struct SubdivToCCGSettings {
bool need_mask;
} SubdivToCCGSettings;
+typedef struct SubdivCCGCoord {
+ /* Index of the grid within SubdivCCG::grids array. */
+ int grid_index;
+
+ /* Coordinate within the grid. */
+ short x, y;
+} SubdivCCGCoord;
+
/* This is actually a coarse face, which consists of multiple CCG grids. */
typedef struct SubdivCCGFace {
/* Total number of grids in this face.
@@ -107,15 +115,15 @@ typedef struct SubdivCCGFace {
typedef struct SubdivCCGAdjacentEdge {
int num_adjacent_faces;
/* Indexed by adjacent face index, then by point index on the edge.
- * points to a grid element. */
- struct CCGElem ***boundary_elements;
+ * points to a coordinate into the grids. */
+ struct SubdivCCGCoord **boundary_coords;
} 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, points to a grid element. */
- struct CCGElem **corner_elements;
+ /* Indexed by adjacent face index, points to a coordinate in the grids. */
+ struct SubdivCCGCoord *corner_coords;
} SubdivCCGAdjacentVertex;
/* Representation of subdivision surface which uses CCG grids. */
@@ -254,14 +262,6 @@ void BKE_subdiv_ccg_topology_counters(const SubdivCCG *subdiv_ccg,
int *r_num_faces,
int *r_num_loops);
-typedef struct SubdivCCGCoord {
- /* Index of the grid within SubdivCCG::grids array. */
- int grid_index;
-
- /* Coordinate within the grid. */
- int x, y;
-} SubdivCCGCoord;
-
typedef struct SubdivCCGNeighbors {
SubdivCCGCoord *coords;
int size;
diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c
index 66db58ec683..bdab444b77a 100644
--- a/source/blender/blenkernel/intern/subdiv_ccg.c
+++ b/source/blender/blenkernel/intern/subdiv_ccg.c
@@ -386,20 +386,33 @@ static void subdiv_ccg_allocate_adjacent_edges(SubdivCCG *subdiv_ccg, const int
subdiv_ccg->num_adjacent_edges, sizeof(*subdiv_ccg->adjacent_edges), "ccg adjacent edges");
}
+static SubdivCCGCoord subdiv_ccg_coord(int grid_index, int x, int y)
+{
+ SubdivCCGCoord coord = {.grid_index = grid_index, .x = x, .y = y};
+ return coord;
+}
+
+static CCGElem *subdiv_ccg_coord_to_elem(const CCGKey *key,
+ const SubdivCCG *subdiv_ccg,
+ const SubdivCCGCoord *coord)
+{
+ return CCG_grid_elem(key, subdiv_ccg->grids[coord->grid_index], coord->x, coord->y);
+}
+
/* Returns storage where boundary elements are to be stored. */
-static CCGElem **subdiv_ccg_adjacent_edge_add_face(SubdivCCG *subdiv_ccg,
- SubdivCCGAdjacentEdge *adjacent_edge)
+static SubdivCCGCoord *subdiv_ccg_adjacent_edge_add_face(SubdivCCG *subdiv_ccg,
+ 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;
/* Allocate memory for the boundary elements. */
- adjacent_edge->boundary_elements = MEM_reallocN(adjacent_edge->boundary_elements,
- adjacent_edge->num_adjacent_faces *
- sizeof(*adjacent_edge->boundary_elements));
- adjacent_edge->boundary_elements[adjacent_face_index] = MEM_malloc_arrayN(
- grid_size * 2, sizeof(CCGElem *), "ccg adjacent boundary");
- return adjacent_edge->boundary_elements[adjacent_face_index];
+ adjacent_edge->boundary_coords = MEM_reallocN(adjacent_edge->boundary_coords,
+ adjacent_edge->num_adjacent_faces *
+ sizeof(*adjacent_edge->boundary_coords));
+ adjacent_edge->boundary_coords[adjacent_face_index] = MEM_malloc_arrayN(
+ grid_size * 2, sizeof(SubdivCCGCoord), "ccg adjacent boundary");
+ return adjacent_edge->boundary_coords[adjacent_face_index];
}
static void subdiv_ccg_init_faces_edge_neighborhood(SubdivCCG *subdiv_ccg)
@@ -419,9 +432,6 @@ static void subdiv_ccg_init_faces_edge_neighborhood(SubdivCCG *subdiv_ccg)
StaticOrHeapIntStorage face_edges_storage;
static_or_heap_storage_init(&face_vertices_storage);
static_or_heap_storage_init(&face_edges_storage);
- /* Key to access elements. */
- CCGKey key;
- BKE_subdiv_ccg_key_top_level(&key, subdiv_ccg);
/* Store adjacency for all faces. */
const int num_faces = subdiv_ccg->num_faces;
for (int face_index = 0; face_index < num_faces; face_index++) {
@@ -443,33 +453,32 @@ static void subdiv_ccg_init_faces_edge_neighborhood(SubdivCCG *subdiv_ccg)
const bool is_edge_flipped = (edge_vertices[0] != vertex_index);
/* Grid which is adjacent to the current corner. */
const int current_grid_index = face->start_grid_index + corner;
- CCGElem *current_grid = subdiv_ccg->grids[current_grid_index];
/* Grid which is adjacent to the next corner. */
const int next_grid_index = face->start_grid_index + (corner + 1) % num_face_grids;
- 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);
+ SubdivCCGCoord *boundary_coords = 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) {
for (int i = 0; i < grid_size; i++) {
- boundary_elements[boundary_element_index++] = CCG_grid_elem(
- &key, next_grid, grid_size - i - 1, grid_size - 1);
+ boundary_coords[boundary_element_index++] = subdiv_ccg_coord(
+ next_grid_index, grid_size - i - 1, grid_size - 1);
}
for (int i = 0; i < grid_size; i++) {
- boundary_elements[boundary_element_index++] = CCG_grid_elem(
- &key, current_grid, grid_size - 1, i);
+ boundary_coords[boundary_element_index++] = subdiv_ccg_coord(
+ current_grid_index, grid_size - 1, i);
}
}
else {
for (int i = 0; i < grid_size; i++) {
- boundary_elements[boundary_element_index++] = CCG_grid_elem(
- &key, current_grid, grid_size - 1, grid_size - i - 1);
+ boundary_coords[boundary_element_index++] = subdiv_ccg_coord(
+ current_grid_index, grid_size - 1, grid_size - i - 1);
}
for (int i = 0; i < grid_size; i++) {
- boundary_elements[boundary_element_index++] = CCG_grid_elem(
- &key, next_grid, i, grid_size - 1);
+ boundary_coords[boundary_element_index++] = subdiv_ccg_coord(
+ next_grid_index, i, grid_size - 1);
}
}
}
@@ -489,15 +498,16 @@ 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)
+static SubdivCCGCoord *subdiv_ccg_adjacent_vertex_add_face(
+ SubdivCCGAdjacentVertex *adjacent_vertex)
{
const int adjacent_face_index = adjacent_vertex->num_adjacent_faces;
++adjacent_vertex->num_adjacent_faces;
/* Allocate memory for the boundary elements. */
- adjacent_vertex->corner_elements = MEM_reallocN(adjacent_vertex->corner_elements,
- adjacent_vertex->num_adjacent_faces *
- sizeof(*adjacent_vertex->corner_elements));
- return &adjacent_vertex->corner_elements[adjacent_face_index];
+ adjacent_vertex->corner_coords = MEM_reallocN(adjacent_vertex->corner_coords,
+ adjacent_vertex->num_adjacent_faces *
+ sizeof(*adjacent_vertex->corner_coords));
+ return &adjacent_vertex->corner_coords[adjacent_face_index];
}
static void subdiv_ccg_init_faces_vertex_neighborhood(SubdivCCG *subdiv_ccg)
@@ -530,11 +540,10 @@ static void subdiv_ccg_init_faces_vertex_neighborhood(SubdivCCG *subdiv_ccg)
const int vertex_index = face_vertices[corner];
/* Grid which is adjacent to the current corner. */
const int grid_index = face->start_grid_index + corner;
- 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);
- *corner_element = CCG_grid_elem(&key, grid, grid_size - 1, grid_size - 1);
+ SubdivCCGCoord *corner_coord = subdiv_ccg_adjacent_vertex_add_face(adjacent_vertex);
+ *corner_coord = subdiv_ccg_coord(grid_index, grid_size - 1, grid_size - 1);
}
}
/* Free possibly heap-allocated storage. */
@@ -627,15 +636,15 @@ void BKE_subdiv_ccg_destroy(SubdivCCG *subdiv_ccg)
for (int i = 0; i < subdiv_ccg->num_adjacent_edges; i++) {
SubdivCCGAdjacentEdge *adjacent_edge = &subdiv_ccg->adjacent_edges[i];
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->boundary_coords[face_index]);
}
- MEM_SAFE_FREE(adjacent_edge->boundary_elements);
+ MEM_S
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list