diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-15 20:32:08 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-15 20:32:08 +0400 |
commit | 37552ac167fabb9c8dcc6d5dfd9ae8c61cd17bd3 (patch) | |
tree | ffcbaa75f4fbc4f498a71426e51248faf2d0dd98 /source/blender/blenkernel/intern | |
parent | 7b31c3c1980f9499f85f9ac74c0b87fd014adb1b (diff) |
Update create_vert_edge_map() to match create_vert_poly_map().
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index d478302931f..e3876f438f7 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2287,21 +2287,39 @@ void create_vert_poly_map(MeshElemMap **map, int **mem, /* Generates a map where the key is the vertex and the value is a list * of edges that use that vertex as an endpoint. The lists are allocated * from one memory pool. */ -void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, const int totvert, const int totedge) +void create_vert_edge_map(MeshElemMap **map, int **mem, + const MEdge *medge, int totvert, int totedge) { - int i, j; - IndexNode *node = NULL; - - (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map"); - (*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem"); - node = *mem; + int i, *indices; + + (*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map"); + (*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem"); + + /* Count number of edges for each vertex */ + for (i = 0; i < totedge; i++) { + (*map)[medge[i].v1].count++; + (*map)[medge[i].v2].count++; + } + /* Assign indices mem */ + indices = (*mem); + for (i = 0; i < totvert; i++) { + (*map)[i].indices = indices; + indices += (*map)[i].count; + + /* Reset 'count' for use as index in last loop */ + (*map)[i].count = 0; + } + /* Find the users */ - for (i = 0; i < totedge; ++i) { - for (j = 0; j < 2; ++j, ++node) { - node->index = i; - BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node); - } + for (i = 0; i < totedge; i++) { + const int v[2] = {medge[i].v1, medge[i].v2}; + + (*map)[v[0]].indices[(*map)[v[0]].count] = i; + (*map)[v[1]].indices[(*map)[v[1]].count] = i; + + (*map)[v[0]].count++; + (*map)[v[1]].count++; } } |