[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58622] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c : Moving the search for the nearest vertices out of the copying between layers as they 're layer-independent

Walid Shouman eng.walidshouman at gmail.com
Fri Jul 26 14:10:19 CEST 2013


Revision: 58622
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58622
Author:   walid
Date:     2013-07-26 12:10:19 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
Moving the search for the nearest vertices out of the copying between layers as they're  layer-independent

Modified Paths:
--------------
    branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.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 11:44:23 UTC (rev 58621)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-07-26 12:10:19 UTC (rev 58622)
@@ -501,6 +501,8 @@
 	//act as a link between the offsets of the barycentric transformation and the vertices' data
 	float ** weights;
 	BMVert *v_match;
+	int inherit_vert;
+	int interp_vert;
 	BMVert_map *inherit_v_table;
 	BMVert **interp_v_table;			//the vertices for interpolation are those that don't have matches
 										//in the source
@@ -576,66 +578,72 @@
 		//getting the bmtree representing the source (2nd,3rd &4th values should be checked)
 		bmtree = BKE_bmbvh_new(em_src, 0, NULL, false);
 
+		inherit_vert = 0;
+		interp_vert = 0;
+
 		//----allocations for interpolation
 		//those should be reallocated num_effective_v times
 		inv_len = MEM_mallocN(sizeof(*inv_len) * num_vert, "inv_len bmesh_data_transfer.c");
 		//the effective vertices' shapekeys
 		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);
+
+			//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++;
+			}
+		}
+
+		//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
 	}
 
+	//start transfering for each layer
 	for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; src_lay_iter < src_lay_end;
 		src_lay_iter++, dst_lay_iter++) {
-		int ident_vert = 0;
-		int interp_vert = 0;
 
 		//fix the layer index of the source & dest
 		CD_offset_src = CustomData_get_n_offset(&bm_src->vdata, CD_SHAPEKEY,src_lay_iter);	//get the offset of the
 		CD_offset_dst = CustomData_get_n_offset(&bm_dst->vdata, CD_SHAPEKEY,dst_lay_iter);	//lay_iter(th)CD_SHAPEKEY layer
 
-		//getting the bmtree representing the source (2nd,3rd &4th values should be checked)
-		bmtree = BKE_bmbvh_new(em_src, 0, NULL, false);
+		//prepare the vertex coords of the inheriting vertices/matching vertices for the barycentric transformation
+		for (k = 0; k < inherit_vert; k++) {
+			v = inherit_v_table[k].v1;
+			v_match = inherit_v_table[k].v2;
 
-		//the way we do it is by looping over each vertex!!
-		for (v = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL); v; v = BM_iter_step(&iter)) {
-			float tmp1[3];
+			copy_v3_v3(vertexCos_src_basis[k], BM_ELEM_CD_GET_VOID_P(v_match, CD_basis_src));
 
-			//this check may be useless under the current algorithm
-			if (CD_offset_dst != -1) {
-				//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);
+			sub_v3_v3v3(vertexCos_src_offset[k], BM_ELEM_CD_GET_VOID_P(v_match, CD_offset_src),
+			            vertexCos_src_basis[k]);
 
-				//if you find a vertex in the given range .. currently the range is fixed for a high value
-				if (v_match != NULL)	{
-					ident_vert++;
+			copy_v3_v3(vertexCos_dst_basis[k], BM_ELEM_CD_GET_VOID_P(v, CD_basis_dst));
 
-					copy_v3_v3(vertexCos_src_basis[ident_vert - 1], BM_ELEM_CD_GET_VOID_P(v_match, CD_basis_src));
-					copy_v3_v3(tmp1, BM_ELEM_CD_GET_VOID_P(v_match, CD_offset_src));
-					sub_v3_v3v3(vertexCos_src_offset[ident_vert - 1], tmp1, vertexCos_src_basis[ident_vert - 1]);
+			//is that really needed?
+//			zero_v3(vertexCos_dst_offset[k]);
 
-					copy_v3_v3(vertexCos_dst_basis[ident_vert - 1], BM_ELEM_CD_GET_VOID_P(v, CD_basis_dst));
-					zero_v3(vertexCos_dst_offset[ident_vert - 1]);
+			//pointing weights to vertexCos_dst_offset[k]
+			weights[BM_elem_index_get(v)] = vertexCos_dst_offset[k];
 
-					//pointing weights to vertexCos_dst_offset[ident_vert - 1]
-					weights[BM_elem_index_get(v)] = vertexCos_dst_offset[ident_vert - 1];
-
-					inherit_v_table[ident_vert - 1].v1 = v;
-					inherit_v_table[ident_vert - 1].v2 = v_match;
-				}
-				else {
-					interp_vert++;
-					interp_v_table[interp_vert - 1] = v;
-				}
-			}
 		}
 
-		if (!BKE_bmesh_calc_relative_deform(ident_vert, (const float(*)[3])vertexCos_src_basis,
+		if (!BKE_bmesh_calc_relative_deform(inherit_vert, (const float(*)[3])vertexCos_src_basis,
 									   (const float(*)[3])vertexCos_dst_basis, (const float(*)[3])vertexCos_src_offset,
 									   (float(*)[3])vertexCos_dst_offset)) {
 			return false;
 		}
 
 		//updating the main vertices in the destination
-		for (k = 0; k < ident_vert; k++) {
+		for (k = 0; k < inherit_vert; k++) {
 			v = inherit_v_table[k].v1;
 			add_v3_v3v3(BM_ELEM_CD_GET_VOID_P(v,CD_offset_dst), BM_ELEM_CD_GET_VOID_P(v,CD_basis_dst),
 						(float*) weights[BM_elem_index_get(v)]);
@@ -661,7 +669,7 @@
 
 			j = 0;
 			//get the effective vertices
-			for(k = 0; k < ident_vert; k++)
+			for(k = 0; k < inherit_vert; k++)
 			{
 				v2 = inherit_v_table[k].v1;
 				len = len_v3v3(v2->co, v->co);
@@ -717,14 +725,11 @@
 			MEM_freeN(eff_v_weights);
 		}
 	//finished looping over the target's vertices
+	//ready to enter the next layer
+	}
 
-	// reset for the upcoming layer
-	ident_vert = 0;
 	BKE_bmbvh_free(bmtree);
 
-	//ready to enter the next layer
-	}
-
 	MEM_freeN(inv_len);
 	MEM_freeN(eff_vert);
 




More information about the Bf-blender-cvs mailing list