[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51754] trunk/blender/source/blender: add the option to select Equal/Greater/Less when selecting similar.

Campbell Barton ideasman42 at gmail.com
Tue Oct 30 08:29:21 CET 2012


Revision: 51754
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51754
Author:   campbellbarton
Date:     2012-10-30 07:29:17 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
add the option to select Equal/Greater/Less when selecting similar.

Recently addons were submitted for review and this was the only advantage they had over blenders existing internal
select-similar tool.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    trunk/blender/source/blender/bmesh/intern/bmesh_operators.h
    trunk/blender/source/blender/bmesh/operators/bmo_utils.c
    trunk/blender/source/blender/editors/mesh/editmesh_select.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2012-10-30 06:43:30 UTC (rev 51753)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2012-10-30 07:29:17 UTC (rev 51754)
@@ -822,10 +822,11 @@
  */
 static BMOpDefine bmo_similar_faces_def = {
 	"similar_faces",
-	{{BMO_OP_SLOT_ELEMENT_BUF, "faces"}, /* input faces */
-	 {BMO_OP_SLOT_ELEMENT_BUF, "faceout"}, /* output faces */
-	 {BMO_OP_SLOT_INT, "type"},			/* type of selection */
-	 {BMO_OP_SLOT_FLT, "thresh"},		/* threshold of selection */
+	{{BMO_OP_SLOT_ELEMENT_BUF, "faces"},    /* input faces */
+	 {BMO_OP_SLOT_ELEMENT_BUF, "faceout"},  /* output faces */
+	 {BMO_OP_SLOT_INT, "type"},             /* type of selection */
+	 {BMO_OP_SLOT_FLT, "thresh"},           /* threshold of selection */
+	 {BMO_OP_SLOT_INT, "compare"},          /* comparison method */
 	 {0} /* null-terminating sentinel */},
 	bmo_similar_faces_exec,
 	0
@@ -838,10 +839,11 @@
  */
 static BMOpDefine bmo_similar_edges_def = {
 	"similar_edges",
-	{{BMO_OP_SLOT_ELEMENT_BUF, "edges"}, /* input edges */
-	 {BMO_OP_SLOT_ELEMENT_BUF, "edgeout"}, /* output edges */
-	 {BMO_OP_SLOT_INT, "type"},			/* type of selection */
-	 {BMO_OP_SLOT_FLT, "thresh"},		/* threshold of selection */
+	{{BMO_OP_SLOT_ELEMENT_BUF, "edges"},    /* input edges */
+	 {BMO_OP_SLOT_ELEMENT_BUF, "edgeout"},  /* output edges */
+	 {BMO_OP_SLOT_INT, "type"},             /* type of selection */
+	 {BMO_OP_SLOT_FLT, "thresh"},           /* threshold of selection */
+	 {BMO_OP_SLOT_INT, "compare"},          /* comparison method */
 	 {0} /* null-terminating sentinel */},
 	bmo_similar_edges_exec,
 	0
@@ -854,10 +856,11 @@
  */
 static BMOpDefine bmo_similar_verts_def = {
 	"similar_verts",
-	{{BMO_OP_SLOT_ELEMENT_BUF, "verts"}, /* input vertices */
-	 {BMO_OP_SLOT_ELEMENT_BUF, "vertout"}, /* output vertices */
-	 {BMO_OP_SLOT_INT, "type"},			/* type of selection */
-	 {BMO_OP_SLOT_FLT, "thresh"},		/* threshold of selection */
+	{{BMO_OP_SLOT_ELEMENT_BUF, "verts"},    /* input vertices */
+	 {BMO_OP_SLOT_ELEMENT_BUF, "vertout"},  /* output vertices */
+	 {BMO_OP_SLOT_INT, "type"},             /* type of selection */
+	 {BMO_OP_SLOT_FLT, "thresh"},           /* threshold of selection */
+	 {BMO_OP_SLOT_INT, "compare"},          /* comparison method */
 	 {0} /* null-terminating sentinel */},
 	bmo_similar_verts_exec,
 	0

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.h	2012-10-30 06:43:30 UTC (rev 51753)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.h	2012-10-30 07:29:17 UTC (rev 51754)
@@ -46,6 +46,12 @@
 	SUBDIV_SELECT_LOOPCUT
 };
 
+enum {
+	SIM_CMP_EQ = 0,
+	SIM_CMP_GT,
+	SIM_CMP_LT
+};
+
 /* similar face selection slot values */
 enum {
 	SIMFACE_MATERIAL = 201,

Modified: trunk/blender/source/blender/bmesh/operators/bmo_utils.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_utils.c	2012-10-30 06:43:30 UTC (rev 51753)
+++ trunk/blender/source/blender/bmesh/operators/bmo_utils.c	2012-10-30 07:29:17 UTC (rev 51754)
@@ -528,6 +528,34 @@
 	};
 } SimSel_FaceExt;
 
+static int bm_sel_similar_cmp_fl(const float delta, const float thresh, const int compare)
+{
+	switch (compare) {
+		case SIM_CMP_EQ:
+			return (fabsf(delta) <= thresh);
+		case SIM_CMP_GT:
+			return ((delta + thresh) >= 0.0f);
+		case SIM_CMP_LT:
+			return ((delta - thresh) <= 0.0f);
+		default:
+			BLI_assert(0);
+	}
+}
+
+static int bm_sel_similar_cmp_i(const int delta, const int compare)
+{
+	switch (compare) {
+		case SIM_CMP_EQ:
+			return (delta == 0);
+		case SIM_CMP_GT:
+			return (delta > 0);
+		case SIM_CMP_LT:
+			return (delta < 0);
+		default:
+			BLI_assert(0);
+	}
+}
+
 /*
  * Select similar faces, the choices are in the enum in source/blender/bmesh/bmesh_operators.h
  * We select either similar faces based on material, image, area, perimeter, normal, or the coplanar faces
@@ -545,7 +573,12 @@
 	const int type = BMO_slot_int_get(op, "type");
 	const float thresh = BMO_slot_float_get(op, "thresh");
 	const float thresh_radians = thresh * (float)M_PI;
+	const int compare = BMO_slot_int_get(op, "compare");
 
+	/* initial_elem - other_elem */
+	float delta_fl;
+	int   delta_i;
+
 	num_total = BM_mesh_elem_count(bm, BM_FACE);
 
 	/*
@@ -648,7 +681,8 @@
 					case SIMFACE_COPLANAR:
 						angle = angle_normalized_v3v3(fs->no, fm->no); /* angle -> 0 */
 						if (angle <= thresh_radians) { /* and dot product difference -> 0 */
-							if (fabsf(f_ext[i].d - f_ext[indices[idx]].d) <= thresh) {
+							delta_fl = f_ext[i].d - f_ext[indices[idx]].d;
+							if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 								BMO_elem_flag_enable(bm, fm, FACE_MARK);
 								cont = FALSE;
 							}
@@ -656,25 +690,30 @@
 						break;
 
 					case SIMFACE_AREA:
-						if (fabsf(f_ext[i].area - f_ext[indices[idx]].area) <= thresh) {
+						delta_fl = f_ext[i].area - f_ext[indices[idx]].area;
+						if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 							BMO_elem_flag_enable(bm, fm, FACE_MARK);
 							cont = FALSE;
 						}
 						break;
 
 					case SIMFACE_SIDES:
-						if (fm->len == fs->len) {
+						delta_i = fm->len - fs->len;
+						if (bm_sel_similar_cmp_i(delta_i, compare)) {
 							BMO_elem_flag_enable(bm, fm, FACE_MARK);
 							cont = FALSE;
 						}
 						break;
 
 					case SIMFACE_PERIMETER:
-						if (fabsf(f_ext[i].perim - f_ext[indices[idx]].perim) <= thresh) {
+						delta_fl = f_ext[i].perim - f_ext[indices[idx]].perim;
+						if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 							BMO_elem_flag_enable(bm, fm, FACE_MARK);
 							cont = FALSE;
 						}
 						break;
+					default:
+						BLI_assert(0);
 				}
 			}
 		}
@@ -725,9 +764,14 @@
 	float angle;
 
 	int num_sels = 0, num_total = 0;
-	int type = BMO_slot_int_get(op, "type");
+	const int type = BMO_slot_int_get(op, "type");
 	const float thresh = BMO_slot_float_get(op, "thresh");
+	const int compare = BMO_slot_int_get(op, "compare");
 
+	/* initial_elem - other_elem */
+	float delta_fl;
+	int   delta_i;
+
 	/* sanity checks that the data we need is available */
 	switch (type) {
 		case SIMEDGE_CREASE:
@@ -799,7 +843,8 @@
 				es = e_ext[indices[idx]].e;
 				switch (type) {
 					case SIMEDGE_LENGTH:
-						if (fabsf(e_ext[i].length - e_ext[indices[idx]].length) <= thresh) {
+						delta_fl = e_ext[i].length - e_ext[indices[idx]].length;
+						if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 							BMO_elem_flag_enable(bm, e, EDGE_MARK);
 							cont = FALSE;
 						}
@@ -819,7 +864,8 @@
 						break;
 
 					case SIMEDGE_FACE:
-						if (e_ext[i].faces == e_ext[indices[idx]].faces) {
+						delta_i = e_ext[i].faces - e_ext[indices[idx]].faces;
+						if (bm_sel_similar_cmp_i(delta_i, compare)) {
 							BMO_elem_flag_enable(bm, e, EDGE_MARK);
 							cont = FALSE;
 						}
@@ -845,8 +891,9 @@
 
 							c1 = CustomData_bmesh_get(&bm->edata, e->head.data, CD_CREASE);
 							c2 = CustomData_bmesh_get(&bm->edata, es->head.data, CD_CREASE);
+							delta_fl = *c1 - *c2;
 
-							if (fabsf(*c1 - *c2) <= thresh) {
+							if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 								BMO_elem_flag_enable(bm, e, EDGE_MARK);
 								cont = FALSE;
 							}
@@ -859,8 +906,9 @@
 
 							c1 = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BWEIGHT);
 							c2 = CustomData_bmesh_get(&bm->edata, es->head.data, CD_BWEIGHT);
+							delta_fl = *c1 - *c2;
 
-							if (fabsf(*c1 - *c2) <= thresh) {
+							if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
 								BMO_elem_flag_enable(bm, e, EDGE_MARK);
 								cont = FALSE;
 							}
@@ -880,6 +928,8 @@
 							cont = FALSE;
 						}
 						break;
+					default:
+						BLI_assert(0);
 				}
 			}
 		}
@@ -919,10 +969,15 @@
 	SimSel_VertExt *v_ext = NULL;
 	int *indices = NULL;
 	int num_total = 0, num_sels = 0, i = 0, idx = 0;
-	int type = BMO_slot_int_get(op, "type");
+	const int type = BMO_slot_int_get(op, "type");
 	const float thresh = BMO_slot_float_get(op, "thresh");
 	const float thresh_radians = thresh * (float)M_PI;
+	const int compare = BMO_slot_int_get(op, "compare");
 
+	/* initial_elem - other_elem */
+//	float delta_fl;
+	int   delta_i;
+
 	num_total = BM_mesh_elem_count(bm, BM_VERT);
 
 	/* iterate through all selected edges and mark them */
@@ -982,7 +1037,8 @@
 						break;
 					case SIMVERT_FACE:
 						/* number of adjacent faces */
-						if (v_ext[i].num_faces == v_ext[indices[idx]].num_faces) {
+						delta_i = v_ext[i].num_faces - v_ext[indices[idx]].num_faces;
+						if (bm_sel_similar_cmp_i(delta_i, compare)) {
 							BMO_elem_flag_enable(bm, v, VERT_MARK);
 							cont = FALSE;
 						}
@@ -990,6 +1046,7 @@
 
 					case SIMVERT_VGROUP:
 						if (v_ext[i].dvert != NULL && v_ext[indices[idx]].dvert != NULL) {
+							/* XXX, todo, make static function for this */
 							int v1, v2;
 							for (v1 = 0; v1 < v_ext[i].dvert->totweight && cont == 1; v1++) {
 								for (v2 = 0; v2 < v_ext[indices[idx]].dvert->totweight; v2++) {
@@ -1004,11 +1061,14 @@
 						break;
 					case SIMVERT_EDGE:
 						/* number of adjacent edges */
-						if (v_ext[i].num_edges == v_ext[indices[idx]].num_edges) {
+						delta_i = v_ext[i].num_edges - v_ext[indices[idx]].num_edges;
+						if (bm_sel_similar_cmp_i(delta_i, compare)) {
 							BMO_elem_flag_enable(bm, v, VERT_MARK);
 							cont = FALSE;
 						}
 						break;
+					default:
+						BLI_assert(0);
 				}
 			}
 		}
@@ -1249,7 +1309,7 @@
 	ElemNode *vert_list = NULL;
 
 	int num_total = 0 /*, num_sels = 0 */, i = 0;
-	int type = BMO_slot_int_get(op, "type");
+	const int type = BMO_slot_int_get(op, "type");
 
 	BMO_ITER (vs, &vs_iter, bm, op, "startv", BM_VERT) {
 		sv = vs;

Modified: trunk/blender/source/blender/editors/mesh/editmesh_select.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_select.c	2012-10-30 06:43:30 UTC (rev 51753)
+++ trunk/blender/source/blender/editors/mesh/editmesh_select.c	2012-10-30 07:29:17 UTC (rev 51754)
@@ -671,6 +671,11 @@
 }
 
 /* ****************  SIMILAR "group" SELECTS. FACE, EDGE AND VERTEX ************** */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list