Revision: 53341
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53341
Author:   campbellbarton
Date:     2012-12-27 06:39:27 +0000 (Thu, 27 Dec 2012)
Log Message:
-----------
add option to BLI_scanfill_calc() - BLI_SCANFILL_CALC_HOLES, gives some speedup 
for BMesh ngons which never have holes and ensures predictable triangle count 
(totvert - 2), which is needed for pre-calculating array size.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/displist.c
    trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
    trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/blenlib/BLI_scanfill.h
    trunk/blender/source/blender/blenlib/intern/scanfill.c
    trunk/blender/source/blender/windowmanager/intern/wm_gesture.c

Modified: trunk/blender/source/blender/blenkernel/intern/displist.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/displist.c   2012-12-27 
05:08:16 UTC (rev 53340)
+++ trunk/blender/source/blender/blenkernel/intern/displist.c   2012-12-27 
06:39:27 UTC (rev 53341)
@@ -506,7 +506,7 @@
                }
 
                /* XXX (obedit && obedit->actcol)?(obedit->actcol-1):0)) { */
-               if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, 
BLI_SCANFILL_CALC_REMOVE_DOUBLES))) {
+               if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, 
BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES))) {
                        if (tot) {
                                dlnew = MEM_callocN(sizeof(DispList), 
"filldisplist");
                                dlnew->type = DL_INDEX3;

Modified: trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c    
2012-12-27 05:08:16 UTC (rev 53340)
+++ trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c    
2012-12-27 06:39:27 UTC (rev 53341)
@@ -173,12 +173,10 @@
                        i += 1;
 #else
                        /* more cryptic but faster */
-                       {
-                               BMLoop **l_ptr = looptris[i++];
-                               l_ptr[0] = l = BM_FACE_FIRST_LOOP(efa);
-                               l_ptr[1] = l = l->next;
-                               l_ptr[2] = l->next;
-                       }
+                       BMLoop **l_ptr = looptris[i++];
+                       l_ptr[0] = l = BM_FACE_FIRST_LOOP(efa);
+                       l_ptr[1] = l = l->next;
+                       l_ptr[2] = l->next;
 #endif
                }
                else if (efa->len == 4) {
@@ -201,14 +199,12 @@
                        i += 1;
 #else
                        /* more cryptic but faster */
-                       {
-                               BMLoop **l_ptr_a = looptris[i++];
-                               BMLoop **l_ptr_b = looptris[i++];
-                               (l_ptr_a[0] = l_ptr_b[0] = l = 
BM_FACE_FIRST_LOOP(efa));
-                               (l_ptr_a[1]              = l = l->next);
-                               (l_ptr_a[2] = l_ptr_b[1] = l = l->next);
-                               (             l_ptr_b[2] = l->next);
-                       }
+                       BMLoop **l_ptr_a = looptris[i++];
+                       BMLoop **l_ptr_b = looptris[i++];
+                       (l_ptr_a[0] = l_ptr_b[0] = l = BM_FACE_FIRST_LOOP(efa));
+                       (l_ptr_a[1]              = l = l->next);
+                       (l_ptr_a[2] = l_ptr_b[1] = l = l->next);
+                       (             l_ptr_b[2] = l->next);
 #endif
                }
 
@@ -222,7 +218,7 @@
                        ScanFillVert *sf_vert, *sf_vert_last = NULL, 
*sf_vert_first = NULL;
                        /* ScanFillEdge *e; */ /* UNUSED */
                        ScanFillFace *sf_tri;
-                       /* int totfilltri; */  /* UNUSED */
+                       int totfilltri;
 
                        BLI_scanfill_begin(&sf_ctx);
 
@@ -250,9 +246,11 @@
                        /* complete the loop */
                        BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert);
 
-                       /* totfilltri = */ BLI_scanfill_calc_ex(&sf_ctx, 0, 
efa->no);
+                       totfilltri = BLI_scanfill_calc_ex(&sf_ctx, 0, efa->no);
+                       BLI_assert(totfilltri <= efa->len - 2);
 
                        for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri 
= sf_tri->next) {
+                               BMLoop **l_ptr = looptris[i++];
                                BMLoop *l1 = sf_tri->v1->tmp.p;
                                BMLoop *l2 = sf_tri->v2->tmp.p;
                                BMLoop *l3 = sf_tri->v3->tmp.p;
@@ -261,10 +259,9 @@
                                if (BM_elem_index_get(l2) > 
BM_elem_index_get(l3)) { SWAP(BMLoop *, l2, l3); }
                                if (BM_elem_index_get(l1) > 
BM_elem_index_get(l2)) { SWAP(BMLoop *, l1, l2); }
 
-                               looptris[i][0] = l1;
-                               looptris[i][1] = l2;
-                               looptris[i][2] = l3;
-                               i += 1;
+                               l_ptr[0] = l1;
+                               l_ptr[1] = l2;
+                               l_ptr[2] = l3;
                        }
 
                        BLI_scanfill_end(&sf_ctx);

Modified: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c     
2012-12-27 05:08:16 UTC (rev 53340)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c     
2012-12-27 06:39:27 UTC (rev 53341)
@@ -933,7 +933,7 @@
                        }
 
                        /* main scan-fill */
-                       sf_tri_tot = BLI_scanfill_calc_ex(&sf_ctx, 0, zvec);
+                       sf_tri_tot = BLI_scanfill_calc_ex(&sf_ctx, 
BLI_SCANFILL_CALC_HOLES, zvec);
 
                        face_array = MEM_mallocN(sizeof(*face_array) * 
(sf_tri_tot + tot_feather_quads), "maskrast_face_index");
                        face_index = 0;

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c       2012-12-27 
05:08:16 UTC (rev 53340)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c       2012-12-27 
06:39:27 UTC (rev 53341)
@@ -2488,7 +2488,7 @@
  */
 int BKE_mesh_recalc_tessellation(CustomData *fdata,
                                  CustomData *ldata, CustomData *pdata,
-                                 MVert *mvert, int totface, int 
UNUSED(totloop),
+                                 MVert *mvert, int totface, int totloop,
                                  int totpoly,
                                  /* when tessellating to recalculate normals 
after
                                   * we can skip copying here */
@@ -2503,15 +2503,15 @@
 #define TESSFACE_SCANFILL (1 << 0)
 #define TESSFACE_IS_QUAD  (1 << 1)
 
+       const int looptris_tot = poly_to_tri_count(totpoly, totloop);
+
        MPoly *mp, *mpoly;
        MLoop *ml, *mloop;
-       MFace *mface = NULL, *mf;
-       BLI_array_declare(mface);
+       MFace *mface, *mf;
        ScanFillContext sf_ctx;
        ScanFillVert *sf_vert, *sf_vert_last, *sf_vert_first;
        ScanFillFace *sf_tri;
-       int *mface_to_poly_map = NULL;
-       BLI_array_declare(mface_to_poly_map);
+       int *mface_to_poly_map;
        int lindex[4]; /* only ever use 3 in this case */
        int poly_index, j, mface_index;
 
@@ -2525,8 +2525,9 @@
 
        /* allocate the length of totfaces, avoid many small reallocs,
         * if all faces are tri's it will be correct, quads == 2x allocs */
-       BLI_array_reserve(mface_to_poly_map, totpoly);
-       BLI_array_reserve(mface, totpoly);
+       /* take care. we are _not_ calloc'ing so be sure to initialize each 
field */
+       mface_to_poly_map = MEM_mallocN(sizeof(*mface_to_poly_map) * 
looptris_tot, __func__);
+       mface             = MEM_mallocN(sizeof(*mface) *             
looptris_tot, __func__);
 
        mface_index = 0;
        mp = mpoly;
@@ -2538,8 +2539,6 @@
 #ifdef USE_TESSFACE_SPEEDUP
 
 #define ML_TO_MF(i1, i2, i3)                                                  \
-               BLI_array_grow_one(mface_to_poly_map);                          
      \
-               BLI_array_grow_one(mface);                                      
      \
                mface_to_poly_map[mface_index] = poly_index;                    
      \
                mf = &mface[mface_index];                                       
      \
                /* set loop indices, transformed to vert indices later */       
      \
@@ -2549,12 +2548,11 @@
                mf->v4 = 0;                                                     
      \
                mf->mat_nr = mp->mat_nr;                                        
      \
                mf->flag = mp->flag;                                            
      \
+               mf->edcode = 0;                                                 
      \
                (void)0
 
 /* ALMOST IDENTICAL TO DEFINE ABOVE (see EXCEPTION) */
 #define ML_TO_MF_QUAD()                                                       \
-               BLI_array_grow_one(mface_to_poly_map);                          
      \
-               BLI_array_grow_one(mface);                                      
      \
                mface_to_poly_map[mface_index] = poly_index;                    
      \
                mf = &mface[mface_index];                                       
      \
                /* set loop indices, transformed to vert indices later */       
      \
@@ -2564,7 +2562,7 @@
                mf->v4 = mp->loopstart + 3; /* EXCEPTION */                     
      \
                mf->mat_nr = mp->mat_nr;                                        
      \
                mf->flag = mp->flag;                                            
      \
-               mf->edcode |= TESSFACE_IS_QUAD; /* EXCEPTION */                 
      \
+               mf->edcode = TESSFACE_IS_QUAD; /* EXCEPTION */                  
      \
                (void)0
 
 
@@ -2607,29 +2605,26 @@
                        BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, 
sf_vert_first);
                        
                        totfilltri = BLI_scanfill_calc(&sf_ctx, 0);
-                       if (totfilltri) {
-                               BLI_array_grow_items(mface_to_poly_map, 
totfilltri);
-                               BLI_array_grow_items(mface, totfilltri);
+                       BLI_assert(totfilltri <= mp->totloop - 2);
 
-                               for (sf_tri = sf_ctx.fillfacebase.first; 
sf_tri; sf_tri = sf_tri->next, mf++) {
-                                       mface_to_poly_map[mface_index] = 
poly_index;
-                                       mf = &mface[mface_index];
+                       for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri 
= sf_tri->next, mf++) {
+                               mface_to_poly_map[mface_index] = poly_index;
+                               mf = &mface[mface_index];
 
-                                       /* set loop indices, transformed to 
vert indices later */
-                                       mf->v1 = sf_tri->v1->keyindex;
-                                       mf->v2 = sf_tri->v2->keyindex;
-                                       mf->v3 = sf_tri->v3->keyindex;
-                                       mf->v4 = 0;
+                               /* set loop indices, transformed to vert 
indices later */
+                               mf->v1 = sf_tri->v1->keyindex;
+                               mf->v2 = sf_tri->v2->keyindex;
+                               mf->v3 = sf_tri->v3->keyindex;
+                               mf->v4 = 0;
 
-                                       mf->mat_nr = mp->mat_nr;
-                                       mf->flag = mp->flag;
+                               mf->mat_nr = mp->mat_nr;
+                               mf->flag = mp->flag;
 
 #ifdef USE_TESSFACE_SPEEDUP
-                                       mf->edcode |= TESSFACE_SCANFILL; /* tag 
for sorting loop indices */
+                               mf->edcode = TESSFACE_SCANFILL; /* tag for 
sorting loop indices */
 #endif
 
-                                       mface_index++;
-                               }
+                               mface_index++;
                        }
        
                        BLI_scanfill_end(&sf_ctx);
@@ -2639,9 +2634,10 @@
        CustomData_free(fdata, totface);
        totface = mface_index;
 
+       BLI_assert(totface <= looptris_tot);
 
        /* not essential but without this we store over-alloc'd memory in the 
CustomData layers */
-       if (LIKELY((MEM_allocN_len(mface) / sizeof(*mface)) != totface)) {
+       if (LIKELY(looptris_tot != totface)) {
                mface = MEM_reallocN(mface, sizeof(*mface) * totface);
                mface_to_poly_map = MEM_reallocN(mface_to_poly_map, 
sizeof(*mface_to_poly_map) * totface);
        }

Modified: trunk/blender/source/blender/blenlib/BLI_scanfill.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_scanfill.h 2012-12-27 05:08:16 UTC 
(rev 53340)
+++ trunk/blender/source/blender/blenlib/BLI_scanfill.h 2012-12-27 06:39:27 UTC 
(rev 53341)
@@ -101,6 +101,10 @@
         * Assumes ordered edges, otherwise we risk an eternal loop
         * removing double verts. - campbell */
        BLI_SCANFILL_CALC_REMOVE_DOUBLES   = (1 << 1),
+
+       /* note: This flag removes checks for overlapping polygons.
+        * when this flag is set, we'll never get back more faces then (totvert 
- 2)*/
+       BLI_SCANFILL_CALC_HOLES            = (1 << 2)
 };
 
 int BLI_scanfill_begin(ScanFillContext *sf_ctx);

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to