[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60403] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c : Code Rewrite: obtaining the loop mapping through the vertex mapping

Walid Shouman eng.walidshouman at gmail.com
Sat Sep 28 01:52:17 CEST 2013


Revision: 60403
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60403
Author:   walid
Date:     2013-09-27 23:52:17 +0000 (Fri, 27 Sep 2013)
Log Message:
-----------
Code Rewrite: obtaining the loop mapping through the vertex mapping

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-09-27 20:29:07 UTC (rev 60402)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-09-27 23:52:17 UTC (rev 60403)
@@ -35,7 +35,40 @@
 //---------------------------*
 //----------------------*
 //******************
+BMLoop* BM_vert_find_best_tan_match_loop(BMVert *v_src, BMLoop *l_dst);
 
+BMLoop* BM_vert_find_best_tan_match_loop(BMVert *v_src, BMLoop *l_dst) {
+
+	BMLoop *l, *l_src;
+	BMIter liter;
+	float l_dst_tan[3], l_src_tan[3];
+
+	float dot_product, prev_dot_product;
+
+	if (BM_vert_edge_count(v_src) == 0) {
+		return NULL;
+	}
+
+	dot_product = -1;
+	prev_dot_product = -2;
+
+	BM_loop_calc_face_tangent(l_dst, l_dst_tan);
+
+	BM_ITER_ELEM (l_src, &liter, v_src, BM_LOOPS_OF_VERT) {
+		BM_loop_calc_face_tangent(l_src, l_src_tan);
+
+		dot_product = dot_v3v3(l_src_tan, l_dst_tan);
+
+		if (dot_product > prev_dot_product) {
+			l = l_src;
+			prev_dot_product = dot_product;
+		}
+
+	}
+
+	return l;
+}
+
 BMLoop* BM_face_find_best_tan_match_loop(BMFace *f_src, BMLoop *l_dst);
 
 BMLoop* BM_face_find_best_tan_match_loop(BMFace *f_src, BMLoop *l_dst) {
@@ -82,21 +115,23 @@
 } BMVert_match;
 
 //---------------helping functions-----------------------
+int* BM_transform_index_mapping(BMesh *bm_src, BMElem **array_dst, int array_dst_count, int *index_mapping_in,
+                                int UNUSED_htype_from, int UNUSED_htype_to);
 void *BM_mesh_mapping(BMesh *bm_src, BMesh *bm_dst, const char htype);
 
 //--------------index based transfer functions ----------
 static void BM_mesh_cd_transfer_array(CustomData *cd_src, BMElem **array_src, int array_src_count,
                                        CustomData *cd_dst, BMElem **array_dst, int array_dst_count,
-                                       const int layer_type, const struct ReplaceLayerInfo *UNUSED_replace_info);
+                                       const int layer_type, const struct ReplaceLayerInfo *replace_info);
 
 static void BM_mesh_transfer_aligned(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type,
                                      const struct ReplaceLayerInfo *replace_info);
 
 //--------------topology based transfer functions ------
 void BM_mesh_cd_transfer_mapped(CustomData *cd_src, BMElem **array_src, int array_src_count,
-                                      CustomData *cd_dst, BMElem **array_dst, int array_dst_count,
-                                      const int layer_type, const struct ReplaceLayerInfo *UNUSED_replace_info,
-                                      int *index_mapping);
+                                CustomData *cd_dst, BMElem **array_dst, int array_dst_count,
+                                const int layer_type, const struct ReplaceLayerInfo *replace_info,
+                                int *index_mapping);
 
 static void BM_mesh_transfer_mapped(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type,
                                     const struct ReplaceLayerInfo *replace_info);
@@ -249,9 +284,9 @@
 }
 
 void BM_mesh_cd_transfer_mapped(CustomData *cd_src, BMElem **array_src, int array_src_count,
-                                      CustomData *cd_dst, BMElem **array_dst, int array_dst_count,
-                                      const int layer_type, const struct ReplaceLayerInfo *replace_info,
-                                      int *index_mapping)
+                                CustomData *cd_dst, BMElem **array_dst, int array_dst_count,
+                                const int layer_type, const struct ReplaceLayerInfo *replace_info,
+                                int *index_mapping)
 {
 	//... copy between arrays with a mapping! ...
 	int dst_lay_start = replace_info->dst_lay_start;
@@ -407,7 +442,8 @@
 					array_dst[l->head.index] = (BMElem*) l;
 				}
 			}
-			index_mapping = BM_mesh_mapping(bm_src, bm_dst, BM_LOOP);
+			index_mapping = BM_mesh_mapping(bm_src, bm_dst, BM_VERT);
+			index_mapping = BM_transform_index_mapping(bm_src, array_dst, array_dst_len, index_mapping, BM_VERT, BM_LOOP);
 
 			break;
 
@@ -436,8 +472,6 @@
 			///should the pdata be associated to the FACES_OF_MESH?
 	}
 
-//	BM_mesh_cd_transfer_array(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info);
-
 	BM_mesh_cd_transfer_mapped(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info,
 	                           index_mapping);
 
@@ -535,3 +569,44 @@
 		}
 	}
 }
+
+int* BM_transform_index_mapping(BMesh *bm_src,BMElem **array_dst, int array_dst_count, int *index_mapping_in,
+                                int UNUSED(htype_from), int UNUSED(htype_to))
+{
+	int i;
+	BMElem *ele_dst;
+	BMElem *ele_src;
+	BMLoop *l_dst;
+	BMVert *v_src;
+	int *index_mapping_out = MEM_mallocN(array_dst_count * sizeof(*index_mapping_out),
+	                                     "index_mapping_out bmesh_data_transfer.c");
+
+	for (i = 0; i < array_dst_count; i++) {	//for each destination loop
+		int v_dst_index;
+
+		//get the respective destination vertex index
+		ele_dst = array_dst[i];
+		l_dst = (BMLoop*) ele_dst;
+		v_dst_index = index_mapping_in[BM_elem_index_get(l_dst->v)];
+
+		//check it has got a mapping
+		if (v_dst_index == -1) { //should never be reached
+			index_mapping_out[i] = -1;
+			continue;
+		}
+
+		//find the best loop match within the respective source vertix
+		//is it safe to extract the bmloops from bmelems
+		v_src = BM_vert_at_index(bm_src, v_dst_index);
+		ele_src = (BMElem*) BM_vert_find_best_tan_match_loop(v_src, (BMLoop*) ele_dst);
+
+		if (ele_src == NULL) {	//should never be reached
+			index_mapping_out[i] = -1;
+			continue;
+		}
+
+		index_mapping_out[i] = ele_src->head.index;
+	}
+
+	return index_mapping_out;
+}




More information about the Bf-blender-cvs mailing list