diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 07:27:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 09:08:54 +0400 |
commit | 0cf8ee1c03301d5fae329a4640f20fbf788cd468 (patch) | |
tree | 6fd500619ef7fa155f1bc4f669102d7e99f97456 /source/blender | |
parent | 5f267ab9f313a028c0900755608226f34d462b6e (diff) |
BMesh: use stack for subdiv face data (no realloc)
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index fc507cdbd21..0d9ce4b2731 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -32,6 +32,7 @@ #include "BLI_rand.h" #include "BLI_array.h" #include "BLI_noise.h" +#include "BLI_stack.h" #include "BKE_customdata.h" @@ -766,8 +767,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BMOpSlot *einput; const SubDPattern *pat; SubDParams params; - SubDFaceData *facedata = NULL; - BLI_array_declare(facedata); + BLI_Stack *facedata; BMIter viter, fiter, liter; BMVert *v, **verts = NULL; BMEdge *edge; @@ -782,7 +782,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_array_declare(verts); float smooth, fractal, along_normal; bool use_sphere, use_single_edge, use_grid_fill, use_only_quads; - int cornertype, seed, i, j, matched, a, b, numcuts, totesel, smooth_falloff; + int cornertype, seed, i, j, a, b, numcuts, totesel, smooth_falloff; BMO_slot_buffer_flag_enable(bm, op->slots_in, "edges", BM_EDGE, SUBD_SPLIT); @@ -875,9 +875,12 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BM_EDGE, EDGE_PERCENT); + facedata = BLI_stack_new(sizeof(SubDFaceData), __func__); + BM_ITER_MESH (face, &fiter, bm, BM_FACES_OF_MESH) { BMEdge *e1 = NULL, *e2 = NULL; float vec1[3], vec2[3]; + bool matched = false; /* skip non-quads if requested */ if (use_only_quads && face->len != 4) @@ -891,8 +894,6 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BLI_array_grow_items(edges, face->len); BLI_array_grow_items(verts, face->len); - matched = 0; - totesel = 0; BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, i) { edges[i] = l_new->e; @@ -930,12 +931,13 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } } if (matched) { - BLI_array_grow_one(facedata); - b = BLI_array_count(facedata) - 1; - facedata[b].pat = pat; - facedata[b].start = verts[i]; - facedata[b].face = face; - facedata[b].totedgesel = totesel; + SubDFaceData *fd; + + fd = BLI_stack_push_r(facedata); + fd->pat = pat; + fd->start = verts[i]; + fd->face = face; + fd->totedgesel = totesel; BMO_elem_flag_enable(bm, face, SUBD_SPLIT); break; } @@ -966,15 +968,15 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } } if (matched) { - BLI_array_grow_one(facedata); - j = BLI_array_count(facedata) - 1; + SubDFaceData *fd; BMO_elem_flag_enable(bm, face, SUBD_SPLIT); - facedata[j].pat = pat; - facedata[j].start = verts[a]; - facedata[j].face = face; - facedata[j].totedgesel = totesel; + fd = BLI_stack_push_r(facedata); + fd->pat = pat; + fd->start = verts[a]; + fd->face = face; + fd->totedgesel = totesel; break; } } @@ -982,16 +984,16 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } if (!matched && totesel) { - BLI_array_grow_one(facedata); - j = BLI_array_count(facedata) - 1; + SubDFaceData *fd; BMO_elem_flag_enable(bm, face, SUBD_SPLIT); /* must initialize all members here */ - facedata[j].start = NULL; - facedata[j].pat = NULL; - facedata[j].totedgesel = totesel; - facedata[j].face = face; + fd = BLI_stack_push_r(facedata); + fd->start = NULL; + fd->pat = NULL; + fd->totedgesel = totesel; + fd->face = face; } } @@ -1009,16 +1011,17 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) copy_v3_v3(v->co, co); } - i = 0; - for (i = 0; i < BLI_array_count(facedata); i++) { - face = facedata[i].face; + for (; !BLI_stack_is_empty(facedata); BLI_stack_discard(facedata)) { + SubDFaceData *fd = BLI_stack_peek(facedata); + + face = fd->face; /* figure out which pattern to use */ BLI_array_empty(verts); - pat = facedata[i].pat; + pat = fd->pat; - if (!pat && facedata[i].totedgesel == 2) { + if (!pat && fd->totedgesel == 2) { int vlen; /* ok, no pattern. we still may be able to do something */ @@ -1131,7 +1134,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) a = 0; BM_ITER_ELEM_INDEX (l_new, &liter, face, BM_LOOPS_OF_FACE, j) { - if (l_new->v == facedata[i].start) { + if (l_new->v == fd->start) { a = j + 1; break; } @@ -1156,7 +1159,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) BM_data_layer_free_n(bm, &bm->vdata, CD_SHAPEKEY, params.shape_info.tmpkey); - if (facedata) BLI_array_free(facedata); + BLI_stack_free(facedata); if (edges) BLI_array_free(edges); if (verts) BLI_array_free(verts); BLI_array_free(loops_split); |