[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43631] branches/bmesh/blender/source/ blender: improve editmode triangulation by re-using the loop array when
Campbell Barton
ideasman42 at gmail.com
Mon Jan 23 14:25:17 CET 2012
Revision: 43631
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43631
Author: campbellbarton
Date: 2012-01-23 13:25:06 +0000 (Mon, 23 Jan 2012)
Log Message:
-----------
improve editmode triangulation by re-using the loop array when
possiblem, this has to guess when the size is too big so as to re-
well.
If this isnt done, then the number of faces is used to allocate the
initial array to at least avoid many small allocs.
added BLI_array_reserve() to reserve elements and avoid reallocing many
small arrays when the loop starts.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/intern/editderivedmesh.c
branches/bmesh/blender/source/blender/blenlib/BLI_array.h
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/editderivedmesh.c 2012-01-23 13:15:40 UTC (rev 43630)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/editderivedmesh.c 2012-01-23 13:25:06 UTC (rev 43631)
@@ -121,8 +121,34 @@
BMLoop *l;
int i = 0, j;
+#if 0
+ /* note, we could be clever and re-use this array but would need to ensure
+ * its realloced at some point, for now just free it */
if (tm->looptris) MEM_freeN(tm->looptris);
+ /* Use tm->tottri when set, this means no reallocs while transforming,
+ * (unless scanfill fails), otherwise... */
+ /* 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(looptris, (tm->tottri && tm->tottri < bm->totface * 3) ? tm->tottri : bm->totface);
+#else
+
+ /* this means no reallocs for quad dominant models, for */
+ if ( (tm->looptris != NULL) &&
+ (tm->tottri != 0) &&
+ /* (totrti <= bm->totface * 2) would be fine for all quads,
+ * but incase there are some ngons, still re-use the array */
+ (tm->tottri <= bm->totface * 3))
+ {
+ looptris = tm->looptris;
+ }
+ else {
+ if (tm->looptris) MEM_freeN(tm->looptris);
+ BLI_array_reserve(looptris, bm->totface);
+ }
+
+#endif
+
f = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
for ( ; f; f=BMIter_Step(&iter)) {
/*don't consider two-edged faces*/
@@ -168,6 +194,7 @@
EditVert *v, *lastv=NULL, *firstv=NULL;
EditEdge *e;
EditFace *efa;
+ int totfilltri;
BLI_begin_edgefill();
/*scanfill time*/
@@ -190,15 +217,14 @@
/*complete the loop*/
BLI_addfilledge(firstv, v);
- BLI_edgefill(2);
+ totfilltri = BLI_edgefill(2);
+ BLI_array_growitems(looptris, totfilltri);
for (efa = fillfacebase.first; efa; efa=efa->next) {
BMLoop *l1= efa->v1->tmp.p;
BMLoop *l2= efa->v2->tmp.p;
BMLoop *l3= efa->v3->tmp.p;
- BLI_array_growone(looptris);
-
if (BM_GetIndex(l1) > BM_GetIndex(l2)) { SWAP(BMLoop*, l1, l2); }
if (BM_GetIndex(l2) > BM_GetIndex(l3)) { SWAP(BMLoop*, l2, l3); }
if (BM_GetIndex(l1) > BM_GetIndex(l2)) { SWAP(BMLoop*, l1, l2); }
Modified: branches/bmesh/blender/source/blender/blenlib/BLI_array.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_array.h 2012-01-23 13:15:40 UTC (rev 43630)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_array.h 2012-01-23 13:25:06 UTC (rev 43631)
@@ -140,6 +140,10 @@
(&arr[_##arr##_count - 1]) \
)
+#define BLI_array_reserve(arr, num) \
+ BLI_array_growitems(arr, num), (void)(_##arr##_count -= num)
+
+
#define BLI_array_free(arr) \
if (arr && (char *)arr != _##arr##_static) { \
BLI_array_fake_user(arr); \
More information about the Bf-blender-cvs
mailing list