From 29acdb48899a25c32726ee8411088d8086a5cdb4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Mar 2016 22:07:45 +1100 Subject: Mesh API: add BKE_mesh_vert_edge_vert_map_create Handy when you need to reference connected verts directly. --- source/blender/blenkernel/intern/mesh_mapping.c | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'source/blender/blenkernel/intern/mesh_mapping.c') diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 8dce3c372f6..c8bb2e0e758 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -304,6 +304,49 @@ void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem, *r_mem = indices; } +/** + * A version of #BKE_mesh_vert_edge_map_create that references connected vertices directly (not their edges). + */ +void BKE_mesh_vert_edge_vert_map_create( + MeshElemMap **r_map, int **r_mem, + const MEdge *medge, int totvert, int totedge) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totvert, "vert-edge map"); + int *indices = MEM_mallocN(sizeof(int[2]) * (size_t)totedge, "vert-edge map mem"); + int *i_pt = indices; + + int i; + + /* 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 */ + for (i = 0; i < totvert; i++) { + map[i].indices = i_pt; + i_pt += 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++) { + const unsigned int v[2] = {medge[i].v1, medge[i].v2}; + + map[v[0]].indices[map[v[0]].count] = (int)v[1]; + map[v[1]].indices[map[v[1]].count] = (int)v[0]; + + map[v[0]].count++; + map[v[1]].count++; + } + + *r_map = map; + *r_mem = indices; +} + /** * Generates a map where the key is the edge and the value is a list of polygons that use that edge. * The lists are allocated from one memory pool. -- cgit v1.2.3