[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58704] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools: UV transfer through faces: several fixes for the islands' seams finding -WIP-

Walid Shouman eng.walidshouman at gmail.com
Mon Jul 29 05:10:12 CEST 2013


Revision: 58704
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58704
Author:   walid
Date:     2013-07-29 03:10:09 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
UV transfer through faces: several fixes for the islands' seams finding -WIP-

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_path.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-29 03:01:53 UTC (rev 58703)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-07-29 03:10:09 UTC (rev 58704)
@@ -279,14 +279,13 @@
 		if (link_iter == NULL) {
 			continue;
 		}
-
-		while (link_iter->next != NULL) {
+	do {
 			if (e == (BMEdge*) link_iter->link) {
 				return true;
 			}
 
 			link_iter = link_iter->next;
-		}
+		} while (link_iter != NULL);
 	}
 
 	//end of search
@@ -306,6 +305,20 @@
 	}
 }
 
+/**
+ * @brief BM_test_unvisited_vert_cb: callback for find vert path
+ * @param v: vert under test
+ * @param visited_verts: table of marked vertices (true for visited)
+ * @return "false" if the vertex was visited
+ */
+
+bool BM_test_unvisited_vert_cb(BMVert *v, bool *visited_verts);
+bool BM_test_unvisited_vert_cb(BMVert *v, bool *visited_verts)
+{
+	return (!(visited_verts[BM_elem_index_get(v)] == true));
+}
+
+
 LinkNode *BM_get_vert_path_relative_to_edge(BMesh *bm_dst, BMBVHTree *bm_dst_tree, BMEdge *e, float rad_search, bool *visited_verts_dst);
 
 /**
@@ -324,11 +337,11 @@
 	BMVert *v_start, *v_end;
 
 	v_start = BKE_bmbvh_find_vert_closest(bm_dst_tree, e->v1->co, rad_search);
-	v_end = BKE_bmbvh_find_vert_closest(bm_dst_tree, e->v1->co, rad_search);
+	v_end = BKE_bmbvh_find_vert_closest(bm_dst_tree, e->v2->co, rad_search);
 
 	if ((v_start != NULL) && (v_end != NULL) && (v_start->head.index != v_end->head.index)) {
 		return BM_mesh_calc_path_vert(bm_dst, v_start, v_end, true, visited_verts_dst,
-		                       (bool (*)(BMVert *, void *))BM_test_and_set_visited_vert_cb);
+		                       (bool (*)(BMVert *, void *))BM_test_unvisited_vert_cb);
 	}
 	else
 		return NULL;
@@ -1289,6 +1302,7 @@
 	int j, i;								//path_counter
 	float island_tolerance = FLT_MAX;
 	LinkNode *vert_path_fragment;
+	LinkNode *vert_path_iter;
 	//=======end of island finding def
 
 	//Is that good to support edit mesh mode at the cost of receiving me_src too ?
@@ -1401,7 +1415,8 @@
 	vert_paths = MEM_mallocN(sizeof(*vert_paths) * path_count, "vert_paths bmesh_data_transfer.c");
 
 	for (j = 0; j < path_count; j++) {
-		visited_verts_dst = MEM_mallocN(sizeof(visited_verts_dst) * bm_dst->totvert, "visited_verts_dst bmesh_data_transfer.c");
+		//calloc as they are unvisited in adance
+		visited_verts_dst = MEM_callocN(sizeof(visited_verts_dst) * bm_dst->totvert, "visited_verts_dst bmesh_data_transfer.c");
 		path_iter = edge_paths[j];
 
 		do { //for each edge in a path
@@ -1411,13 +1426,24 @@
 			//-----------get path fragments corresponding to each edge
 			/// we may need to use a struct that has the edge and the start/end of each path (ie:v_start, v_end)
 			/// to facilitate the mapping
-			vert_path_fragment = BM_get_vert_path_relative_to_edge(bm_dst, bmtree_src, path_iter->link, island_tolerance, visited_verts_dst);
+			vert_path_fragment = BM_get_vert_path_relative_to_edge(bm_dst, bmtree_src, (BMEdge*) path_iter->link, island_tolerance, visited_verts_dst);
 			//===========now we have the whole vert_paths that are relative to each edge_path
 
-			//append the fragment to the previous ones
-			BLI_linklist_append(&vert_paths[j], vert_path_fragment);	//we may be appending NULLs
+			if (vert_path_fragment != NULL) {
+				//append the fragment to the previous ones
+				BLI_linklist_append(&vert_paths[j], vert_path_fragment);	//appending a NULL isn't supported by
+																			//the BLI_linklist!
+				//mark what we found as visited as we append
+				vert_path_iter = vert_path_fragment;
+				do {
+					visited_verts_dst[((BMVert*)vert_path_iter->link)->head.index] = true;
 
+					vert_path_iter = vert_path_iter->next;
+				} while (vert_path_iter != NULL);
+
+			}
 			path_iter = path_iter->next;
+
 		} while(path_iter != NULL);
 		//if (vert_paths[j] == NULL) //then no path was found ... the user could either increase the island tolerance or
 		//add more details so that the edge_path finds a relative vert_path
@@ -1428,6 +1454,10 @@
 		MEM_freeN(visited_verts_dst);
 	}
 
+	// cases that we need to handle
+	/// those that represent a single edge?
+	/// and what if we got acceptable relative paths to different edges that aren't successive!? ie an edge gave
+	/// a successful vert path and the next one didn't ...
 	//remove the vert_paths[j] == NULL
 	for (j = 0; j < path_count;j++) {
 		for (i = j; i < path_count; i++)

Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_path.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_path.c	2013-07-29 03:01:53 UTC (rev 58703)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_path.c	2013-07-29 03:10:09 UTC (rev 58704)
@@ -379,7 +379,7 @@
 			BM_elem_flag_disable(e, BM_ELEM_TAG);
 
 			//only those verts shall be tested later! so we don't care about the verts surrounding other edges
-			BM_ITER_ELEM (v, &viter, bm, BM_VERTS_OF_EDGE) {
+			BM_ITER_ELEM (v, &viter, e, BM_VERTS_OF_EDGE) {
 				BM_elem_flag_disable(v, BM_ELEM_TAG);
 			}
 		}
@@ -408,7 +408,8 @@
 
 	//we'll loop till we find an edge in the table ... we're sure in previous that one exists
 	BM_ITER_ELEM (e_dst, &eiter, e_src->v1, BM_EDGES_OF_VERT) {
-		if (ind_e_table[e_dst->head.index] == false) {		// Unavailable edge!
+		// an edge that we shouldn't pass by Or the source is the same edge as the dst
+		if ((ind_e_table[e_dst->head.index] == false) || (e_dst->head.index == e_src->head.index)) {
 			continue;
 		}
 //		memset(*edges_prev, '\0', sizeof(*edges_prev) * tot_edge);




More information about the Bf-blender-cvs mailing list