Edge/Vert Slide: avoid redundant loop angle calls
authorCampbell Barton <ideasman42@gmail.com>
Mon, 23 Feb 2015 04:44:28 +0000 (15:44 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 23 Feb 2015 04:44:28 +0000 (15:44 +1100)
No need to calculate loop angle for each layer

source/blender/bmesh/intern/bmesh_interp.c
source/blender/bmesh/intern/bmesh_interp.h
source/blender/editors/transform/transform.c

index 0c27da3644825d3b255a470f1b8cc4be981e318e..b7a72e2e2ae626afcf43d23600d2dbcb8e2e161d 100644 (file)
@@ -921,6 +921,7 @@ struct LoopWalkCtx {
        /* same for all groups */
        int type;
        int cd_layer_offset;
+       const float *loop_weights;
        MemArena *arena;
 
        /* --- Per loop fan vars --- */
@@ -953,10 +954,11 @@ struct LoopGroupCD {
 
 static void bm_loop_walk_add(struct LoopWalkCtx *lwc, BMLoop *l)
 {
-       const float w = BM_loop_calc_face_angle(l);
+       const int i = BM_elem_index_get(l);
+       const float w = lwc->loop_weights[i];
        BM_elem_flag_enable(l, BM_ELEM_INTERNAL_TAG);
        lwc->data_array[lwc->data_len] = BM_ELEM_CD_GET_VOID_P(l, lwc->cd_layer_offset);
-       lwc->data_index_array[lwc->data_len] = BM_elem_index_get(l);
+       lwc->data_index_array[lwc->data_len] = i;
        lwc->weight_array[lwc->data_len] = w;
        lwc->weight_accum += w;
 
@@ -994,7 +996,8 @@ static void bm_loop_walk_data(struct LoopWalkCtx *lwc, BMLoop *l_walk)
        }
 }
 
-LinkNode *BM_vert_loop_groups_data_layer_create(BMesh *bm, BMVert *v, int layer_n, MemArena *arena)
+LinkNode *BM_vert_loop_groups_data_layer_create(
+        BMesh *bm, BMVert *v, int layer_n, const float *loop_weights, MemArena *arena)
 {
        struct LoopWalkCtx lwc;
        LinkNode *groups = NULL;
@@ -1005,6 +1008,7 @@ LinkNode *BM_vert_loop_groups_data_layer_create(BMesh *bm, BMVert *v, int layer_
 
        lwc.type = bm->ldata.layers[layer_n].type;
        lwc.cd_layer_offset = bm->ldata.layers[layer_n].offset;
+       lwc.loop_weights = loop_weights;
        lwc.arena = arena;
 
        loop_num = 0;
index 117333b52e363c40a75813f33d63f0ce4dcfabf8..8493d401a32f5f7875e4ed2eb353b7b5f2d04c91 100644 (file)
@@ -56,7 +56,8 @@ void  BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source,
 void  BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f);
 
 struct LinkNode *BM_vert_loop_groups_data_layer_create(
-        BMesh *bm, BMVert *v, const int layer_n, struct MemArena *arena);
+        BMesh *bm, BMVert *v, const int layer_n,
+        const float *loop_weights, struct MemArena *arena);
 void BM_vert_loop_groups_data_layer_merge(
         BMesh *bm, struct LinkNode *groups, const int layer_n);
 void BM_vert_loop_groups_data_layer_merge_weights(
index 8421f4dd3feae6fc3360a4d47b0b66628e8d1e09..4c95bd899b7f10401f78f9e770590e6139859e03 100644 (file)
@@ -5241,6 +5241,43 @@ static void slide_origdata_init_data(
        }
 }
 
+static void slide_origdata_create_data_vert(
+        BMesh *bm, SlideOrigData *sod,
+        TransDataGenericSlideVert *sv)
+{
+       BMIter liter;
+       int j, l_num;
+       float *loop_weights;
+
+       /* copy face data */
+       // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT) {
+       BM_iter_init(&liter, bm, BM_LOOPS_OF_VERT, sv->v);
+       l_num = liter.count;
+       loop_weights = BLI_array_alloca(loop_weights, l_num);
+       for (j = 0; j < l_num; j++) {
+               BMLoop *l = BM_iter_step(&liter);
+               if (!BLI_ghash_haskey(sod->origfaces, l->f)) {
+                       BMFace *f_copy = BM_face_copy(sod->bm_origfaces, bm, l->f, true, true);
+                       BLI_ghash_insert(sod->origfaces, l->f, f_copy);
+               }
+               loop_weights[j] = BM_loop_calc_face_angle(l);
+       }
+
+       /* store cd_loop_groups */
+       if (l_num != 0) {
+               sv->cd_loop_groups = BLI_memarena_alloc(sod->arena, sod->layer_math_map_num * sizeof(void *));
+               for (j = 0; j < sod->layer_math_map_num; j++) {
+                       const int layer_nr = sod->layer_math_map[j];
+                       sv->cd_loop_groups[j] = BM_vert_loop_groups_data_layer_create(bm, sv->v, layer_nr, loop_weights, sod->arena);
+               }
+       }
+       else {
+               sv->cd_loop_groups = NULL;
+       }
+
+       BLI_ghash_insert(sod->origverts, sv->v, sv);
+}
+
 static void slide_origdata_create_data(
         TransInfo *t, SlideOrigData *sod,
         TransDataGenericSlideVert *sv, unsigned int v_stride, unsigned int v_num)
@@ -5250,9 +5287,7 @@ static void slide_origdata_create_data(
                BMesh *bm = em->bm;
                unsigned int i;
 
-               const int *layer_math_map;
                int layer_index_dst;
-               int layer_groups_array_size;
                int j;
 
                /* over alloc, only 'math' layers are indexed */
@@ -5264,41 +5299,14 @@ static void slide_origdata_create_data(
                        }
                }
                BLI_assert(layer_index_dst != 0);
-               layer_math_map = sod->layer_math_map;
-               layer_groups_array_size = layer_index_dst * sizeof(void *);
                sod->layer_math_map_num = layer_index_dst;
 
                sod->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
 
                sod->origverts = BLI_ghash_ptr_new_ex(__func__, v_num);
 
-               for (i = 0; i < v_num; i++, sv = (void *)(((char *)sv) + v_stride)) {
-                       BMIter fiter;
-                       BMFace *f;
-                       bool has_faces = false;
-
-                       /* copy face data */
-                       BM_ITER_ELEM (f, &fiter, sv->v, BM_FACES_OF_VERT) {
-                               if (!BLI_ghash_haskey(sod->origfaces, f)) {
-                                       BMFace *f_copy = BM_face_copy(sod->bm_origfaces, bm, f, true, true);
-                                       BLI_ghash_insert(sod->origfaces, f, f_copy);
-                               }
-                               has_faces = true;
-                       }
-
-                       /* store cd_loop_groups */
-                       if (has_faces) {
-                               sv->cd_loop_groups = BLI_memarena_alloc(sod->arena, layer_groups_array_size);
-                               for (j = 0; j < layer_index_dst; j++) {
-                                       const int layer_nr = layer_math_map[j];
-                                       sv->cd_loop_groups[j] = BM_vert_loop_groups_data_layer_create(bm, sv->v, layer_nr, sod->arena);
-                               }
-                       }
-                       else {
-                               sv->cd_loop_groups = NULL;
-                       }
-
-                       BLI_ghash_insert(sod->origverts, sv->v, sv);
+               for (i = 0; i < v_num; i++, sv = POINTER_OFFSET(sv, v_stride)) {
+                       slide_origdata_create_data_vert(bm, sod, sv);
                }
        }
 }
@@ -5370,7 +5378,7 @@ static void slide_origdata_interp_data(
                BMesh *bm = em->bm;
                unsigned int i;
 
-               for (i = 0; i < v_num; i++, sv = (void *)(((char *)sv) + v_stride)) {
+               for (i = 0; i < v_num; i++, sv = POINTER_OFFSET(sv, v_stride)) {
 
                        if (sv->cd_loop_groups) {
                                slide_origdata_interp_data_vert(sod, bm, is_final, sv);