[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59365] trunk/blender/source/blender: code cleanup: bmesh duplicate functions

Campbell Barton ideasman42 at gmail.com
Wed Aug 21 16:35:52 CEST 2013


Revision: 59365
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59365
Author:   campbellbarton
Date:     2013-08-21 14:35:51 +0000 (Wed, 21 Aug 2013)
Log Message:
-----------
code cleanup: bmesh duplicate functions
- avoid using an iterator when stepping around an edges radial loop.
- use naming constant with the rest of the bmesh operators.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim.c
    trunk/blender/source/blender/bmesh/operators/bmo_dupe.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim.c	2013-08-21 13:26:17 UTC (rev 59364)
+++ trunk/blender/source/blender/blenkernel/intern/anim.c	2013-08-21 14:35:51 UTC (rev 59365)
@@ -493,7 +493,6 @@
 	BevList *bl;
 	BevPoint *bevp, *bevpn, *bevpfirst, *bevplast;
 	PathPoint *pp;
-	Curve *cu;
 	Nurb *nu;
 	Path *path;
 	float *fp, *dist, *maxdist, xyz[3];
@@ -506,7 +505,6 @@
 	if (ob == NULL || ob->type != OB_CURVE) {
 		return;
 	}
-	cu = ob->data;
 
 	if (ob->curve_cache->path) free_path(ob->curve_cache->path);
 	ob->curve_cache->path = NULL;

Modified: trunk/blender/source/blender/bmesh/operators/bmo_dupe.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_dupe.c	2013-08-21 13:26:17 UTC (rev 59364)
+++ trunk/blender/source/blender/bmesh/operators/bmo_dupe.c	2013-08-21 14:35:51 UTC (rev 59365)
@@ -46,23 +46,23 @@
  *
  * Copy an existing vertex from one bmesh to another.
  */
-static BMVert *copy_vertex(BMesh *source_mesh, BMVert *source_vertex, BMesh *target_mesh, GHash *vhash)
+static BMVert *bmo_vert_copy(BMesh *bm_dst, BMesh *bm_src, BMVert *v_src, GHash *vhash)
 {
-	BMVert *target_vertex = NULL;
+	BMVert *v_dst;
 
 	/* Create a new vertex */
-	target_vertex = BM_vert_create(target_mesh, source_vertex->co, NULL, BM_CREATE_SKIP_CD);
+	v_dst = BM_vert_create(bm_dst, v_src->co, NULL, BM_CREATE_SKIP_CD);
 	
 	/* Insert new vertex into the vert hash */
-	BLI_ghash_insert(vhash, source_vertex, target_vertex);
-	
+	BLI_ghash_insert(vhash, v_src, v_dst);
+
 	/* Copy attributes */
-	BM_elem_attrs_copy(source_mesh, target_mesh, source_vertex, target_vertex);
+	BM_elem_attrs_copy(bm_src, bm_dst, v_src, v_dst);
+
+	/* Mark the vert for output */
+	BMO_elem_flag_enable(bm_dst, v_dst, DUPE_NEW);
 	
-	/* Set internal op flags */
-	BMO_elem_flag_enable(target_mesh, target_vertex, DUPE_NEW);
-	
-	return target_vertex;
+	return v_dst;
 }
 
 /**
@@ -70,55 +70,55 @@
  *
  * Copy an existing edge from one bmesh to another.
  */
-static BMEdge *copy_edge(BMOperator *op,
-                         BMOpSlot *slot_boundarymap_out,
-                         BMesh *source_mesh,
-                         BMEdge *source_edge, BMesh *target_mesh,
-                         GHash *vhash, GHash *ehash)
+static BMEdge *bmo_edge_copy(BMOperator *op,
+                             BMOpSlot *slot_boundarymap_out,
+                             BMesh *bm_dst, BMesh *bm_src,
+                             BMEdge *e_src,
+                             GHash *vhash, GHash *ehash)
 {
-	BMEdge *target_edge = NULL;
-	BMVert *target_vert1, *target_vert2;
-	BMFace *face;
-	BMIter fiter;
-	int rlen;
+	BMEdge *e_dst;
+	BMVert *e_dst_v1, *e_dst_v2;
+	unsigned int rlen;
 
 	/* see if any of the neighboring faces are
 	 * not being duplicated.  in that case,
 	 * add it to the new/old map. */
+	/* lookup edge */
 	rlen = 0;
-	for (face = BM_iter_new(&fiter, source_mesh, BM_FACES_OF_EDGE, source_edge);
-	     face;
-	     face = BM_iter_step(&fiter))
-	{
-		if (BMO_elem_flag_test(source_mesh, face, DUPE_INPUT)) {
-			rlen++;
-		}
+	if (e_src->l) {
+		BMLoop *l_iter_src, *l_first_src;
+		l_iter_src = l_first_src = e_src->l;
+		do {
+			if (BMO_elem_flag_test(bm_src, l_iter_src->e, DUPE_INPUT)) {
+				rlen++;
+			}
+		} while ((l_iter_src = l_iter_src->radial_next) != l_first_src);
 	}
 
 	/* Lookup v1 and v2 */
-	target_vert1 = BLI_ghash_lookup(vhash, source_edge->v1);
-	target_vert2 = BLI_ghash_lookup(vhash, source_edge->v2);
+	e_dst_v1 = BLI_ghash_lookup(vhash, e_src->v1);
+	e_dst_v2 = BLI_ghash_lookup(vhash, e_src->v2);
 	
 	/* Create a new edge */
-	target_edge = BM_edge_create(target_mesh, target_vert1, target_vert2, NULL, BM_CREATE_SKIP_CD);
+	e_dst = BM_edge_create(bm_dst, e_dst_v1, e_dst_v2, NULL, BM_CREATE_SKIP_CD);
 	
 	/* add to new/old edge map if necassary */
 	if (rlen < 2) {
 		/* not sure what non-manifold cases of greater then three
 		 * radial should do. */
-		BMO_slot_map_elem_insert(op, slot_boundarymap_out, source_edge, target_edge);
+		BMO_slot_map_elem_insert(op, slot_boundarymap_out, e_src, e_dst);
 	}
 
 	/* Insert new edge into the edge hash */
-	BLI_ghash_insert(ehash, source_edge, target_edge);
-	
+	BLI_ghash_insert(ehash, e_src, e_dst);
+
 	/* Copy attributes */
-	BM_elem_attrs_copy(source_mesh, target_mesh, source_edge, target_edge);
+	BM_elem_attrs_copy(bm_src, bm_dst, e_src, e_dst);
+
+	/* Mark the edge for output */
+	BMO_elem_flag_enable(bm_dst, e_dst, DUPE_NEW);
 	
-	/* Set internal op flags */
-	BMO_elem_flag_enable(target_mesh, target_edge, DUPE_NEW);
-	
-	return target_edge;
+	return e_dst;
 }
 
 /**
@@ -126,20 +126,19 @@
  *
  * Copy an existing face from one bmesh to another.
  */
-static BMFace *copy_face(BMOperator *op,
-                         BMOpSlot *slot_facemap_out,
-                         BMesh *bm_dst, BMesh *bm_src,
-                         BMFace *source_face,
-                         GHash *vhash, GHash *ehash)
+static BMFace *bmo_face_copy(BMOperator *op,
+                             BMOpSlot *slot_facemap_out,
+                             BMesh *bm_dst, BMesh *bm_src,
+                             BMFace *f_src,
+                             GHash *vhash, GHash *ehash)
 {
-	/* BMVert *target_vert1, *target_vert2; */ /* UNUSED */
-	BMVert **vtar = BLI_array_alloca(vtar, source_face->len);
-	BMEdge **edar = BLI_array_alloca(edar, source_face->len);
+	BMFace *f_dst;
+	BMVert **vtar = BLI_array_alloca(vtar, f_src->len);
+	BMEdge **edar = BLI_array_alloca(edar, f_src->len);
 	BMLoop *l_iter_src, *l_iter_dst, *l_first_src;
-	BMFace *f_dst = NULL;
 	int i;
 
-	l_first_src = BM_FACE_FIRST_LOOP(source_face);
+	l_first_src = BM_FACE_FIRST_LOOP(f_src);
 
 	/* lookup edge */
 	l_iter_src = l_first_src;
@@ -151,12 +150,12 @@
 	} while ((l_iter_src = l_iter_src->next) != l_first_src);
 
 	/* create new face */
-	f_dst = BM_face_create(bm_dst, vtar, edar, source_face->len, source_face, BM_CREATE_NOP);
-	BMO_slot_map_elem_insert(op, slot_facemap_out, source_face, f_dst);
-	BMO_slot_map_elem_insert(op, slot_facemap_out, f_dst, source_face);
+	f_dst = BM_face_create(bm_dst, vtar, edar, f_src->len, NULL, BM_CREATE_SKIP_CD);
+	BMO_slot_map_elem_insert(op, slot_facemap_out, f_src, f_dst);
+	BMO_slot_map_elem_insert(op, slot_facemap_out, f_dst, f_src);
 
-	/* mark the face for output */
-	BMO_elem_flag_enable(bm_dst, f_dst, DUPE_NEW);
+	/* Copy attributes */
+	BM_elem_attrs_copy(bm_src, bm_dst, f_src, f_dst);
 	
 	/* copy per-loop custom data */
 	l_iter_src = l_first_src;
@@ -166,6 +165,9 @@
 	} while ((l_iter_dst = l_iter_dst->next),
 	         (l_iter_src = l_iter_src->next) != l_first_src);
 
+	/* Mark the face for output */
+	BMO_elem_flag_enable(bm_dst, f_dst, DUPE_NEW);
+
 	return f_dst;
 }
 
@@ -174,7 +176,7 @@
  *
  * Internal Copy function.
  */
-static void bmo_mesh_copy(BMOperator *op, BMesh *bm_src, BMesh *bm_dst)
+static void bmo_mesh_copy(BMOperator *op, BMesh *bm_dst, BMesh *bm_src)
 {
 
 	BMVert *v = NULL, *v2;
@@ -200,7 +202,7 @@
 			BMIter iter;
 			bool isolated = true;
 
-			v2 = copy_vertex(bm_src, v, bm_dst, vhash);
+			v2 = bmo_vert_copy(bm_dst, bm_src, v, vhash);
 
 			BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) {
 				if (BMO_elem_flag_test(bm_src, f, DUPE_INPUT)) {
@@ -233,15 +235,15 @@
 		{
 			/* make sure that verts are copied */
 			if (!BMO_elem_flag_test(bm_src, e->v1, DUPE_DONE)) {
-				copy_vertex(bm_src, e->v1, bm_dst, vhash);
+				bmo_vert_copy(bm_dst, bm_src, e->v1, vhash);
 				BMO_elem_flag_enable(bm_src, e->v1, DUPE_DONE);
 			}
 			if (!BMO_elem_flag_test(bm_src, e->v2, DUPE_DONE)) {
-				copy_vertex(bm_src, e->v2, bm_dst, vhash);
+				bmo_vert_copy(bm_dst, bm_src, e->v2, vhash);
 				BMO_elem_flag_enable(bm_src, e->v2, DUPE_DONE);
 			}
 			/* now copy the actual edge */
-			copy_edge(op, slot_boundary_map_out, bm_src, e, bm_dst, vhash, ehash);
+			bmo_edge_copy(op, slot_boundary_map_out, bm_dst, bm_src, e, vhash, ehash);
 			BMO_elem_flag_enable(bm_src, e, DUPE_DONE);
 		}
 	}
@@ -252,7 +254,7 @@
 			/* vertex pass */
 			BM_ITER_ELEM (v, &viter, f, BM_VERTS_OF_FACE) {
 				if (!BMO_elem_flag_test(bm_src, v, DUPE_DONE)) {
-					copy_vertex(bm_src, v, bm_dst, vhash);
+					bmo_vert_copy(bm_dst, bm_src, v, vhash);
 					BMO_elem_flag_enable(bm_src, v, DUPE_DONE);
 				}
 			}
@@ -260,12 +262,12 @@
 			/* edge pass */
 			BM_ITER_ELEM (e, &eiter, f, BM_EDGES_OF_FACE) {
 				if (!BMO_elem_flag_test(bm_src, e, DUPE_DONE)) {
-					copy_edge(op, slot_boundary_map_out, bm_src, e, bm_dst, vhash, ehash);
+					bmo_edge_copy(op, slot_boundary_map_out, bm_dst, bm_src, e, vhash, ehash);
 					BMO_elem_flag_enable(bm_src, e, DUPE_DONE);
 				}
 			}
 
-			copy_face(op, slot_face_map_out, bm_dst, bm_src, f, vhash, ehash);
+			bmo_face_copy(op, slot_face_map_out, bm_dst, bm_src, f, vhash, ehash);
 			BMO_elem_flag_enable(bm_src, f, DUPE_DONE);
 		}
 	}
@@ -298,16 +300,16 @@
 void bmo_duplicate_exec(BMesh *bm, BMOperator *op)
 {
 	BMOperator *dupeop = op;
-	BMesh *bm2 = BMO_slot_ptr_get(op->slots_in, "dest");
+	BMesh *bm_dst = BMO_slot_ptr_get(op->slots_in, "dest");
 	
-	if (!bm2)
-		bm2 = bm;
+	if (!bm_dst)
+		bm_dst = bm;
 
 	/* flag input */
 	BMO_slot_buffer_flag_enable(bm, dupeop->slots_in, "geom", BM_ALL_NOLOOP, DUPE_INPUT);
 
 	/* use the internal copy function */
-	bmo_mesh_copy(dupeop, bm, bm2);
+	bmo_mesh_copy(dupeop, bm_dst, bm);
 	
 	/* Output */
 	/* First copy the input buffers to output buffers - original data */
@@ -457,13 +459,14 @@
 	float axis[3];
 	float rmat[3][3];
 	float phi;
-	int steps, do_dupli, a, usedvec;
+	int steps, do_dupli, a;
+	bool use_dvec;
 
 	BMO_slot_vec_get(op->slots_in, "cent", cent);
 	BMO_slot_vec_get(op->slots_in, "axis", axis);
 	normalize_v3(axis);
 	BMO_slot_vec_get(op->slots_in, "dvec", dvec);
-	usedvec = !is_zero_v3(dvec);
+	use_dvec = !is_zero_v3(dvec);
 	steps    = BMO_slot_int_get(op->slots_in,   "steps");
 	phi      = BMO_slot_float_get(op->slots_in, "angle") / steps;
 	do_dupli = BMO_slot_bool_get(op->slots_in,  "use_duplicate");
@@ -495,7 +498,7 @@
 			BMO_op_finish(bm, &extop);
 		}
 
-		if (usedvec) {
+		if (use_dvec) {
 			mul_m3_v3(rmat, dvec);
 			BMO_op_callf(bm, op->flag,
 			             "translate vec=%v space=%s verts=%S",




More information about the Bf-blender-cvs mailing list