[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58623] branches/ soc-2013-meshdata_transfer/source/blender: Adding feature to shapekey transfer by nearest vertex: supporting basic automatic tolerance setting -based on matching vertices percentage-

Walid Shouman eng.walidshouman at gmail.com
Fri Jul 26 15:45:26 CEST 2013


Revision: 58623
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58623
Author:   walid
Date:     2013-07-26 13:45:25 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
Adding feature to shapekey transfer by nearest vertex: supporting basic automatic tolerance setting -based on matching vertices percentage-

Modified Paths:
--------------
    branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
    branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
    branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c

Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-07-26 12:10:19 UTC (rev 58622)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-07-26 13:45:25 UTC (rev 58623)
@@ -468,7 +468,8 @@
  */
 
 bool BM_mesh_shapekey_copy(BMesh *bm_src, BMesh *bm_dst, float tolerance, float radius_interp, int dist_pow, int no_pow,
-                           bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay)
+                           bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay, bool auto_tol,
+                           float auto_tol_percentage)
 {
 	int CD_offset_src, CD_offset_dst;
 	int CD_basis_src, CD_basis_dst;
@@ -511,6 +512,10 @@
 	float (*eff_vert)[3];				//the effective vertices' shapekeys
 	float* inv_len;
 
+	//supporting automatic tolerance setup
+	float auto_tol_step = 0.001;
+	bool auto_tol_first = true;
+
 	//print_shapekeys_info(bm_src,CD_SHAPEKEY, true, true, SHAPEKEY_VALUES_BY_LAYER);
 
 	//Is that good to support edit mesh mode at the cost of receiving me_src too ?
@@ -588,22 +593,43 @@
 		eff_vert = MEM_mallocN(sizeof(*eff_vert) * num_vert, "eff_vert bmesh_data_transfer.c");
 
 		//get the matches/unmatches and store them in tables
-		for (v = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL); v; v = BM_iter_step(&iter)) {
-			//get the closest vertex from the bmtree of the source mesh to the vertex v within MAXDIST
-			v_match = BKE_bmbvh_find_vert_closest(bmtree, v->co, tolerance);
+		do {
+			if (auto_tol == true)
+			{
+				if (auto_tol_first == true) {
+					tolerance = 0;
+					auto_tol_first = false;
+				}
 
-			//if you find a vertex in the given range, add it to the table
-			if (v_match != NULL)	{
-				inherit_v_table[inherit_vert].v1 = v;
-				inherit_v_table[inherit_vert].v2 = v_match;
-				inherit_vert++;
+				//try tolerances 0.001, 0.002, 0.003, ... 0.01, 0.02, 0.03, ... 0.1, 0.2 ..... till MAX_AUTO_TOL
+				tolerance += auto_tol_step;
+				if (tolerance  >= (auto_tol_step * 10) ) {
+					auto_tol_step *= 10;
+				}
+
+				inherit_vert = 0;
+				interp_vert = 0;
 			}
-			else {
-				interp_v_table[interp_vert] = v;
-				interp_vert++;
+			for (v = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL); v; v = BM_iter_step(&iter)) {
+				//get the closest vertex from the bmtree of the source mesh to the vertex v within MAXDIST
+				v_match = BKE_bmbvh_find_vert_closest(bmtree, v->co, tolerance);
+
+				//if you find a vertex in the given range, add it to the table
+				if (v_match != NULL)	{
+					inherit_v_table[inherit_vert].v1 = v;
+					inherit_v_table[inherit_vert].v2 = v_match;
+					inherit_vert++;
+				}
+				else {
+					interp_v_table[interp_vert] = v;
+					interp_vert++;
+				}
 			}
 		}
+		while ((auto_tol == true) && (((1.0f * inherit_vert) / num_vert) < auto_tol_percentage)
+		       && (tolerance < MAX_AUTO_TOL));
 
+
 		//here we could reallocate all the tables that are related to the interpolation back to the number of
 		//interp_vert to free some memory space, however this reallocation would be time consuming itself
 	}

Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h	2013-07-26 12:10:19 UTC (rev 58622)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h	2013-07-26 13:45:25 UTC (rev 58623)
@@ -42,7 +42,7 @@
 
 bool BM_mesh_shapekey_copy(BMesh *bm_src, BMesh *bm_dst, float tolerance, float radius_interp,
                            int interp_pow, int no_pow, bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode,
-                           int *act_shapekey_lay);
+                           int *act_shapekey_lay, bool auto_tol, float auto_tol_percentage);
 /*bool BM_mesh_shapekey_copy2(BMesh *bm_src, BMesh *bm_dst, float tolerance, float radius_interp,
                            int interp_pow, int no_pow, bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode,
                             int *act_shapekey_lay, float tmp_mat[4]);*/

Modified: branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c	2013-07-26 12:10:19 UTC (rev 58622)
+++ branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c	2013-07-26 13:45:25 UTC (rev 58623)
@@ -319,6 +319,8 @@
 
 	int *act_shapekey_lay = MEM_mallocN(sizeof(*act_shapekey_lay) * 2, "act_shapekey_lay object_shapekey.c");
 
+	bool auto_tol = RNA_boolean_get(op->ptr, "auto_tol");
+	float auto_tol_percentage = RNA_float_get(op->ptr, "auto_tol_percentage");
 	float tolerance = RNA_float_get(op->ptr, "tolerance");
 	float radius_interp = RNA_float_get(op->ptr, "interp_radius");
 	int interp_pow = RNA_int_get(op->ptr, "interp_power");
@@ -428,7 +430,7 @@
 	//*******copy based on nearest vertex
 	if (transfer_mode == ST_USE_NEAREST_VERTEX) {
 		if (!BM_mesh_shapekey_copy(bm_src, bm_dst, tolerance, radius_interp, interp_pow, no_pow, interp_normals,
-				                  replace_mode, act_shapekey_lay)) {
+				                  replace_mode, act_shapekey_lay, auto_tol, auto_tol_percentage)) {
 		BKE_report(op->reports, RPT_ERROR, "Transfer failed (ensure the tolerance is high enough)");
 		return false;
 		}
@@ -760,8 +762,12 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;	//not revised!!
 
 	/* properties */
-	RNA_def_float(ot->srna, "tolerance", 0.5f, 0.001f, 10.0f,
-	              "Tolerance", "Radius of source vertices to inherit from", 0.001f, 5.0f);
+	RNA_def_float(ot->srna, "tolerance", 0.5f, 0.001f, 10.0f, "Manual Tolerance",
+	              "Radius of source vertices to inherit from (won't work with Automatic ON')", 0.001f, 5.0f);
+	RNA_def_boolean(ot->srna, "auto_tol", false,
+	                "Automatic Tolerance", "Choose whether the tolerance is automatic or not (under development)");
+	RNA_def_float(ot->srna, "auto_tol_percentage", .3, 0, 1, "Acceptable vertex percentage",
+	              "Choose the percentage of vertices that seems to match", 0, 1);
 	RNA_def_float(ot->srna, "interp_radius", 1.5f, 0.0f, 100.0f,
 	              "Interp Radius", "Radius of accepted contagious vertices", 0.0f, 10.0f);
 	RNA_def_int(ot->srna, "interp_power", 1, 0, 20,




More information about the Bf-blender-cvs mailing list