[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43937] branches/bmesh/blender/source/ blender/bmesh: use more optimal method of looping over face loops.

Campbell Barton ideasman42 at gmail.com
Tue Feb 7 00:48:52 CET 2012


Revision: 43937
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43937
Author:   campbellbarton
Date:     2012-02-06 23:48:42 +0000 (Mon, 06 Feb 2012)
Log Message:
-----------
use more optimal method of looping over face loops.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_queries.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2012-02-06 22:57:25 UTC (rev 43936)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2012-02-06 23:48:42 UTC (rev 43937)
@@ -364,7 +364,7 @@
 void bmesh_end_edit(BMesh *bm, int flag);
 
 
-#define BM_FACE_FIRST_LOOP(p) ((BMLoopList *)((p)->loops.first))->first
+#define BM_FACE_FIRST_LOOP(p) (((BMLoopList *)((p)->loops.first))->first)
 
 /* size to use for static arrays when dealing with NGons,
  * alloc after this limit is reached.

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-02-06 22:57:25 UTC (rev 43936)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c	2012-02-06 23:48:42 UTC (rev 43937)
@@ -203,7 +203,7 @@
  */
 void BM_face_interp_from_face(BMesh *bm, BMFace *target, BMFace *source)
 {
-	BMLoop *l1, *l2;
+	BMLoop *l_iter;
 	BMLoop *l_first;
 
 	void **blocks = NULL;
@@ -216,20 +216,20 @@
 	BM_Copy_Attributes(bm, bm, source, target);
 
 	i = 0;
-	l2 = l_first = BM_FACE_FIRST_LOOP(source);
+	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l2->v->co);
-		blocks[i] = l2->head.data;
+		copy_v3_v3(cos[i], l_iter->v->co);
+		blocks[i] = l_iter->head.data;
 		i++;
-	} while ((l2 = l2->next) != l_first);
+	} while ((l_iter = l_iter->next) != l_first);
 
 	i = 0;
-	l1 = l_first = BM_FACE_FIRST_LOOP(target);
+	l_iter = l_first = BM_FACE_FIRST_LOOP(target);
 	do {
-		interp_weights_poly_v3(w, cos, source->len, l1->v->co);
-		CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, l1->head.data);
+		interp_weights_poly_v3(w, cos, source->len, l_iter->v->co);
+		CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, l_iter->head.data);
 		i++;
-	} while ((l1 = l1->next) != l_first);
+	} while ((l_iter = l_iter->next) != l_first);
 
 	BLI_array_fixedstack_free(cos);
 	BLI_array_fixedstack_free(w);
@@ -392,16 +392,16 @@
                               double e1[3], double e2[3])
 {
 	double cent[3] = {0.0, 0.0, 0.0}, n[3], p[3];
-	BMLoop *l2;
+	BMLoop *l_first;
+	BMLoop *l_iter;
 	
 	/* computer center */
-	l2 = BM_FACE_FIRST_LOOP(l->f);
+	l_iter = l_first = BM_FACE_FIRST_LOOP(l->f);
 	do {
-		cent[0] += (double)l2->v->co[0];
-		cent[1] += (double)l2->v->co[1];
-		cent[2] += (double)l2->v->co[2];
-		l2 = l2->next;
-	} while (l2 != BM_FACE_FIRST_LOOP(l->f));
+		cent[0] += (double)l_iter->v->co[0];
+		cent[1] += (double)l_iter->v->co[1];
+		cent[2] += (double)l_iter->v->co[2];
+	} while ((l_iter = l_iter->next) != l_first);
 	
 	VECMUL(cent, (1.0 / (double)l->f->len));
 	
@@ -545,7 +545,8 @@
 static void bmesh_loop_interp_mdisps(BMesh *bm, BMLoop *target, BMFace *source)
 {
 	MDisps *mdisps;
-	BMLoop *l2;
+	BMLoop *l_iter;
+	BMLoop *l_first;
 	double x, y, d, v1[3], v2[3], v3[3], v4[3] = {0.0f, 0.0f, 0.0f}, e1[3], e2[3];
 	int ix, iy, res;
 	
@@ -598,22 +599,21 @@
 			VECMUL(co, x);
 			VECADD2(co, co1);
 			
-			l2 = BM_FACE_FIRST_LOOP(source);
+			l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 			do {
 				double x2, y2;
 				MDisps *md1, *md2;
 
 				md1 = CustomData_bmesh_get(&bm->ldata, target->head.data, CD_MDISPS);
-				md2 = CustomData_bmesh_get(&bm->ldata, l2->head.data, CD_MDISPS);
+				md2 = CustomData_bmesh_get(&bm->ldata, l_iter->head.data, CD_MDISPS);
 				
-				if (mdisp_in_mdispquad(bm, target, l2, co, &x2, &y2, res)) {
+				if (mdisp_in_mdispquad(bm, target, l_iter, co, &x2, &y2, res)) {
 					/* int ix2 = (int)x2; */ /* UNUSED */
 					/* int iy2 = (int)y2; */ /* UNUSED */
 					
 					old_mdisps_bilinear(md1->disps[iy * res + ix], md2->disps, res, (float)x2, (float)y2);
 				}
-				l2 = l2->next;
-			} while (l2 != BM_FACE_FIRST_LOOP(source));
+			} while ((l_iter = l_iter->next) != l_first);
 		}
 	}
 }
@@ -728,7 +728,7 @@
 void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source, 
                               int do_vertex, int do_multires)
 {
-	BMLoop *l;
+	BMLoop *l_iter;
 	BMLoop *l_first;
 	void **blocks = NULL;
 	void **vblocks = NULL;
@@ -742,20 +742,20 @@
 	BM_Copy_Attributes(bm, bm, source, target->f);
 
 	i = 0;
-	l = l_first = BM_FACE_FIRST_LOOP(source);
+	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l->v->co);
+		copy_v3_v3(cos[i], l_iter->v->co);
 		add_v3_v3(cent, cos[i]);
 		
 		w[i] = 0.0f;
-		blocks[i] = l->head.data;
+		blocks[i] = l_iter->head.data;
 	
 		if (do_vertex) {
-			vblocks[i] = l->v->head.data;
+			vblocks[i] = l_iter->v->head.data;
 		}
 		i++;
 	
-	} while ((l = l->next) != l_first);
+	} while ((l_iter = l_iter->next) != l_first);
 
 	/* find best projection of face XY, XZ or YZ: barycentric weights of
 	 * the 2d projected coords are the same and faster to compute */
@@ -804,7 +804,7 @@
 
 void BM_vert_interp_from_face(BMesh *bm, BMVert *v, BMFace *source)
 {
-	BMLoop *l;
+	BMLoop *l_iter;
 	BMLoop *l_first;
 	void **blocks = NULL;
 	float (*cos)[3] = NULL, *w = NULL, cent[3] = {0.0f, 0.0f, 0.0f};
@@ -814,15 +814,15 @@
 	int i;
 
 	i = 0;
-	l = l_first = BM_FACE_FIRST_LOOP(source);
+	l_iter = l_first = BM_FACE_FIRST_LOOP(source);
 	do {
-		copy_v3_v3(cos[i], l->v->co);
+		copy_v3_v3(cos[i], l_iter->v->co);
 		add_v3_v3(cent, cos[i]);
 
 		w[i] = 0.0f;
-		blocks[i] = l->v->head.data;
+		blocks[i] = l_iter->v->head.data;
 		i++;
-	} while ((l = l->next) != l_first);
+	} while ((l_iter = l_iter->next) != l_first);
 
 	/* scale source face coordinates a bit, so points sitting directonly on an
      * edge will work. */

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c	2012-02-06 22:57:25 UTC (rev 43936)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c	2012-02-06 23:48:42 UTC (rev 43937)
@@ -79,7 +79,8 @@
 void BM_SelectMode_Flush(BMesh *bm)
 {
 	BMEdge *e;
-	BMLoop *l;
+	BMLoop *l_iter;
+	BMLoop *l_first;
 	BMFace *f;
 
 	BMIter edges;
@@ -98,12 +99,12 @@
 		}
 		for (f = BMIter_New(&faces, bm, BM_FACES_OF_MESH, bm); f; f = BMIter_Step(&faces)) {
 			totsel = 0;
-			l = (BMLoop *) BM_FACE_FIRST_LOOP(f);
+			l_iter = l_first = BM_FACE_FIRST_LOOP(f);
 			do {
-				if (BM_TestHFlag(l->v, BM_SELECT))
+				if (BM_TestHFlag(l_iter->v, BM_SELECT)) {
 					totsel++;
-				l = l->next;
-			} while (l != BM_FACE_FIRST_LOOP(f));
+				}
+			} while ((l_iter = l_iter->next) != l_first);
 			
 			if (totsel == f->len && !BM_TestHFlag(f, BM_HIDDEN)) {
 				BM_SetHFlag(f, BM_SELECT);
@@ -116,12 +117,12 @@
 	else if (bm->selectmode & SCE_SELECT_EDGE) {
 		for (f = BMIter_New(&faces, bm, BM_FACES_OF_MESH, bm); f; f = BMIter_Step(&faces)) {
 			totsel = 0;
-			l = BM_FACE_FIRST_LOOP(f);
+			l_iter = l_first = BM_FACE_FIRST_LOOP(f);
 			do {
-				if (BM_TestHFlag(&(l->e->head), BM_SELECT))
+				if (BM_TestHFlag(&(l_iter->e->head), BM_SELECT)) {
 					totsel++;
-				l = l->next;
-			} while (l != BM_FACE_FIRST_LOOP(f));
+				}
+			} while ((l_iter = l_iter->next) != l_first);
 			
 			if (totsel == f->len && !BM_TestHFlag(f, BM_HIDDEN)) {
 				BM_SetHFlag(f, BM_SELECT);
@@ -240,7 +241,8 @@
 
 void BM_Select_Face(BMesh *bm, BMFace *f, int select)
 {
-	BMLoop *l;
+	BMLoop *l_iter;
+	BMLoop *l_first;
 
 	if (BM_TestHFlag(f, BM_HIDDEN)) {
 		return;
@@ -250,12 +252,11 @@
 		if (!BM_TestHFlag(f, BM_SELECT)) bm->totfacesel += 1;
 
 		BM_SetHFlag(&(f->head), BM_SELECT);
-		l = (BMLoop *) BM_FACE_FIRST_LOOP(f);
+		l_iter = l_first = BM_FACE_FIRST_LOOP(f);
 		do {
-			BM_Select_Vert(bm, l->v, TRUE);
-			BM_Select_Edge(bm, l->e, TRUE);
-			l = l->next;
-		} while (l != BM_FACE_FIRST_LOOP(f));
+			BM_Select_Vert(bm, l_iter->v, TRUE);
+			BM_Select_Edge(bm, l_iter->e, TRUE);
+		} while ((l_iter = l_iter->next) != l_first);
 	}
 	else {
 		BMIter liter;

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2012-02-06 22:57:25 UTC (rev 43936)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2012-02-06 23:48:42 UTC (rev 43937)
@@ -265,15 +265,15 @@
 	
 	jed = e;
 	if (!jed) {
+		BMLoop *l_first;
 		/* search for an edge that has both these faces in its radial cycl */
-		l1 = BM_FACE_FIRST_LOOP(f1);
+		l1 = l_first = BM_FACE_FIRST_LOOP(f1);
 		do {
 			if (l1->radial_next->f == f2) {
 				jed = l1->e;
 				break;
 			}
-			l1 = l1->next;
-		} while (l1 != BM_FACE_FIRST_LOOP(f1));
+		} while ((l1 = l1->next) != l_first);
 	}
 
 	if (!jed) {
@@ -365,19 +365,18 @@
 	
 		/* handle multires update */
 		if (has_mdisp && (nf != f)) {
-			BMLoop *l;
+			BMLoop *l_iter;
+			BMLoop *l_first;
 
-			l = BM_FACE_FIRST_LOOP(f);
+			l_iter = l_first = BM_FACE_FIRST_LOOP(f);
 			do {
-				BM_loop_interp_from_face(bm, l, of, 0, 1);
-				l = l->next;
-			} while (l != BM_FACE_FIRST_LOOP(f));
+				BM_loop_interp_from_face(bm, l_iter, of, 0, 1);
+			} while ((l_iter = l_iter->next) != l_first);
 
-			l = BM_FACE_FIRST_LOOP(nf);
+			l_iter = l_first = BM_FACE_FIRST_LOOP(nf);
 			do {
-				BM_loop_interp_from_face(bm, l, of, 0, 1);
-				l = l->next;
-			} while (l != BM_FACE_FIRST_LOOP(nf));
+				BM_loop_interp_from_face(bm, l_iter, of, 0, 1);
+			} while ((l_iter = l_iter->next) != l_first);
 
 			BM_Kill_Face(bm, of);
 
@@ -607,11 +606,12 @@
 				
 				do {
 					if (!BLI_smallhash_haskey(&hash, (intptr_t)l->f)) {
-						l2 = BM_FACE_FIRST_LOOP(l->f);
+						BMLoop *l2_first;
+
+						l2 = l2_first = BM_FACE_FIRST_LOOP(l->f);
 						do {
 							BM_loop_interp_multires(bm, l2, oldfaces[i]);
-							l2 = l2->next;
-						} while (l2 != BM_FACE_FIRST_LOOP(l->f));
+						} while ((l2 = l2->next) != l2_first);
 					}
 					l = l->radial_next;
 				} while (l != e1->l);

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2012-02-06 22:57:25 UTC (rev 43936)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2012-02-06 23:48:42 UTC (rev 43937)
@@ -203,30 +203,31 @@
 	BMVert **verts = NULL;
 	BLI_array_staticdeclare(edges, BM_NGON_STACK_SIZE);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list