Mesh API: add BKE_mesh_vert_edge_vert_map_create

Handy when you need to reference connected verts directly.
This commit is contained in:
Campbell Barton 2016-03-22 22:07:45 +11:00
parent 3b5dec4afc
commit 29acdb4889
3 changed files with 48 additions and 5 deletions

@ -119,6 +119,9 @@ void BKE_mesh_vert_loop_map_create(
void BKE_mesh_vert_edge_map_create(
MeshElemMap **r_map, int **r_mem,
const struct MEdge *medge, int totvert, int totedge);
void BKE_mesh_vert_edge_vert_map_create(
MeshElemMap **r_map, int **r_mem,
const struct MEdge *medge, int totvert, int totedge);
void BKE_mesh_edge_poly_map_create(
MeshElemMap **r_map, int **r_mem,
const struct MEdge *medge, const int totedge,

@ -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.

@ -1792,11 +1792,8 @@ static void vgroup_smooth_subset(
for (int i = 0; i < dvert_tot; i++) {
MVert *v = &me->mvert[i];
if (v->flag & SELECT) {
int j;
for (j = 0; j < emap[i].count; j++) {
MEdge *e = &me->medge[emap[i].indices[j]];
const int i_other = (e->v1 == i ? e->v2 : e->v1);
MVert *v_other = &me->mvert[i_other];
for (int j = 0; j < emap[i].count; j++) {
MVert *v_other = &me->mvert[emap[i].indices[j]];
if ((source == WEIGHT_SMOOTH_ALL) ||
(source == ((v_other->flag & SELECT) != 0)))
{