[Bf-blender-cvs] [0df325a] mesh-transfer-data: Islands 'TubeCase' WIP: Aaaannnnnnnnnnndd... Working!

Bastien Montagne noreply at git.blender.org
Thu Nov 27 16:25:02 CET 2014


Commit: 0df325aae22570e3b15641fb9d693b9a0ecbef7e
Author: Bastien Montagne
Date:   Thu Nov 27 16:22:23 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rB0df325aae22570e3b15641fb9d693b9a0ecbef7e

Islands 'TubeCase' WIP: Aaaannnnnnnnnnndd... Working!

Now, tons of cleanup and reorg of code ahead, current one is just too much ugly.

Also, have to recheck stupid raycast case, would look like vcos space transform is
wrong again.

===================================================================

M	source/blender/blenkernel/intern/mesh_remap.c

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c
index 6b63474..e7fbc9c 100644
--- a/source/blender/blenkernel/intern/mesh_remap.c
+++ b/source/blender/blenkernel/intern/mesh_remap.c
@@ -356,7 +356,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 			MPoly *polys_src = dm_src->getPolyArray(dm_src);
 			MLoop *loops_src = dm_src->getLoopArray(dm_src);
 			float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
-			int *orig_poly_index_src;
+			int *tessface_to_poly_map_src;
 
 			size_t tmp_buff_size = MREMAP_DEFAULT_BUFSIZE;
 			float (*vcos)[3] = MEM_mallocN(sizeof(*vcos) * tmp_buff_size, __func__);
@@ -366,7 +366,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 			dm_src->getVertCos(dm_src, vcos_src);
 			bvhtree_from_mesh_faces(&treedata, dm_src, (mode & MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6);
 			/* bvhtree here uses tesselated faces... */
-			orig_poly_index_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
+			tessface_to_poly_map_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
 
 			if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) {
 				for (i = 0; i < numverts_dst; i++) {
@@ -379,7 +379,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 					        &treedata, &rayhit, space_transform,
 					        tmp_co, tmp_no, ray_radius, max_dist, &hit_dist))
 					{
-						MPoly *mp_src = &polys_src[orig_poly_index_src[rayhit.index]];
+						MPoly *mp_src = &polys_src[tessface_to_poly_map_src[rayhit.index]];
 						const int sources_num = mesh_remap_interp_poly_data_get(
 						        mp_src, loops_src, (const float (*)[3])vcos_src, rayhit.co,
 						        &tmp_buff_size, &vcos, false, &indices, &weights, true, NULL);
@@ -405,7 +405,7 @@ void BKE_mesh_remap_calc_verts_from_dm(
 					        &treedata, &nearest, space_transform,
 					        tmp_co, max_dist_sq, &hit_dist))
 					{
-						MPoly *mp = &polys_src[orig_poly_index_src[nearest.index]];
+						MPoly *mp = &polys_src[tessface_to_poly_map_src[nearest.index]];
 
 						if (mode == MREMAP_MODE_VERT_POLY_NEAREST) {
 							int index;
@@ -619,12 +619,12 @@ void BKE_mesh_remap_calc_edges_from_dm(
 			MPoly *polys_src = dm_src->getPolyArray(dm_src);
 			MLoop *loops_src = dm_src->getLoopArray(dm_src);
 			float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__);
-			int *orig_poly_index_src;
+			int *tessface_to_poly_map_src;
 
 			dm_src->getVertCos(dm_src, vcos_src);
 			bvhtree_from_mesh_faces(&treedata, dm_src, 0.0f, 2, 6);
 			/* bvhtree here uses tesselated faces... */
-			orig_poly_index_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
+			tessface_to_poly_map_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
 
 			for (i = 0; i < numedges_dst; i++) {
 				float tmp_co[3];
@@ -635,7 +635,7 @@ void BKE_mesh_remap_calc_edges_from_dm(
 				        &treedata, &nearest, space_transform,
 				        tmp_co, max_dist_sq, &hit_dist))
 				{
-					MPoly *mp_src = &polys_src[orig_poly_index_src[nearest.index]];
+					MPoly *mp_src = &polys_src[tessface_to_poly_map_src[nearest.index]];
 					MLoop *ml_src = &loops_src[mp_src->loopstart];
 					int nloops = mp_src->totloop;
 					float best_dist_sq = FLT_MAX;
@@ -801,14 +801,14 @@ typedef struct AStarPathGraph {
 
 typedef struct AStarPathSolution {
 	/* Final 'most useful' data. */
-	ListBase path;  /* as nodes' indices */
-	int steps;  /* number of steps (i.e. walked links) in path (nodes num, including start and end, is steps + 1). */
+	int steps;  /* Number of steps (i.e. walked links) in path (nodes num, including start and end, is steps + 1). */
+	int *prev_nodes;  /* Store the path, in reversed order (from destination to source node), as indices. */
+	AStarPathLink **prev_links;  /* Indices are nodes' ones, as prev_nodes, but they map to relevant link. */
 
 	void *custom_data;
 
 	/* Mostly runtime data. */
 	BLI_bitmap *done_nodes;
-	int *prev_nodes;
 	float *g_costs;
 	int *g_steps;
 
@@ -870,7 +870,6 @@ static int astar_path_node_link_other_node(AStarPathLink *lnk, const int idx)
 	return (lnk->nodes[0] == idx) ? lnk->nodes[1] : lnk->nodes[0];
 }
 
-
 static void astar_path_solution_init(AStarPathGraph *as_graph, AStarPathSolution *as_solution, void *custom_data)
 {
 	MemArena *mem = as_solution->mem;
@@ -882,15 +881,15 @@ static void astar_path_solution_init(AStarPathGraph *as_graph, AStarPathSolution
 	}
 	/* else memarena should be cleared */
 
-	BLI_listbase_clear(&as_solution->path);
 	as_solution->steps = 0;
+	as_solution->prev_nodes = BLI_memarena_alloc(mem, sizeof(*as_solution->prev_nodes) * node_num);
+	as_solution->prev_links = BLI_memarena_alloc(mem, sizeof(*as_solution->prev_links) * node_num);
+
 	as_solution->custom_data = custom_data;
 
 	as_solution->done_nodes = BLI_BITMAP_NEW_MEMARENA(mem, node_num);
-	as_solution->prev_nodes = BLI_memarena_alloc(mem, sizeof(*as_solution->prev_nodes) * node_num);
 	as_solution->g_costs = BLI_memarena_alloc(mem, sizeof(*as_solution->g_costs) * node_num);
 	as_solution->g_steps = BLI_memarena_alloc(mem, sizeof(*as_solution->g_steps) * node_num);
-
 }
 
 static void astar_path_solution_clear(AStarPathSolution *as_solution)
@@ -899,12 +898,13 @@ static void astar_path_solution_clear(AStarPathSolution *as_solution)
 		BLI_memarena_clear(as_solution->mem);
 	}
 
-	BLI_listbase_clear(&as_solution->path);
 	as_solution->steps = 0;
+	as_solution->prev_nodes = NULL;
+	as_solution->prev_links = NULL;
+
 	as_solution->custom_data = NULL;
 
 	as_solution->done_nodes = NULL;
-	as_solution->prev_nodes = NULL;
 	as_solution->g_costs = NULL;
 	as_solution->g_steps = NULL;
 }
@@ -923,12 +923,13 @@ static bool astar_solve(
 {
 	Heap *todo_nodes;
 
-	MemArena *mem = r_solution->mem;
 	BLI_bitmap *done_nodes = r_solution->done_nodes;
 	int *prev_nodes = r_solution->prev_nodes;
+	AStarPathLink **prev_links = r_solution->prev_links;
 	float *g_costs = r_solution->g_costs;
 	int *g_steps = r_solution->g_steps;
 
+	r_solution->steps = 0;
 	prev_nodes[node_index_src] = -1;
 	BLI_BITMAP_SET_ALL(done_nodes, false, as_graph->node_num);
 	fill_vn_fl(g_costs, as_graph->node_num, FLT_MAX);
@@ -960,18 +961,8 @@ static bool astar_solve(
 		}
 
 		if (node_curr_idx == node_index_dst) {
-			LinkData *steps_data, *sd;
-			int steps = g_steps[node_curr_idx];
-			int i;
-
-			r_solution->steps = steps++;
-			sd = steps_data = BLI_memarena_alloc(mem, sizeof(*steps_data) * ((size_t)steps));
-
-			for (i = node_curr_idx; i != -1; i = prev_nodes[i], sd++, steps--) {
-				sd->data = SET_INT_IN_POINTER(i);
-				BLI_addhead(&r_solution->path, sd);
-			}
-			BLI_assert(steps >= 0);
+			/* Success! Path found... */
+			r_solution->steps = g_steps[node_curr_idx] + 1;
 
 			BLI_heap_free(todo_nodes, NULL);
 			return true;
@@ -988,6 +979,7 @@ static bool astar_solve(
 
 				if (g_cst < g_costs[node_next_idx]) {
 					prev_nodes[node_next_idx] = node_curr_idx;
+					prev_links[node_next_idx] = link;
 					g_costs[node_next_idx] = g_cst;
 					g_steps[node_next_idx] = g_steps[node_curr_idx] + 1;
 					/* We might have this node already in heap, but since this 'instance' will be evaluated first,
@@ -1021,6 +1013,7 @@ static void mesh_island_to_astar_path_graph_edge_process(
 		const int p_idx = edge_to_poly_map[edge_idx].indices[i];
 		MPoly *mp = &polys[p_idx];
 		const int p_isld_idx = islands ? poly_isld_index_map[p_idx] : p_idx;
+		void *custom_data = is_einnercut ? SET_INT_IN_POINTER(edge_idx) : SET_INT_IN_POINTER(-1);
 
 		if (UNLIKELY(islands && (islands->items_to_islands[mp->loopstart] != island_index))) {
 			/* poly not in current island, happens with border edges... */
@@ -1048,7 +1041,7 @@ static void mesh_island_to_astar_path_graph_edge_process(
 				continue;
 			}
 			dist_cost = len_v3v3(poly_centers[p_isld_idx_other], poly_centers[p_isld_idx]);
-			astar_path_node_link_add(as_graph, p_isld_idx_other, p_isld_idx, dist_cost, SET_INT_IN_POINTER(is_einnercut));
+			astar_path_node_link_add(as_graph, p_isld_idx_other, p_isld_idx, dist_cost, custom_data);
 		}
 
 		p_isld_indices[i] = p_isld_idx;
@@ -1136,7 +1129,7 @@ static float mesh_remap_calc_loops_astar_f_cost(
 {
 	float *co_next, *co_dest;
 
-	if (link && GET_INT_FROM_POINTER(link->custom_data)) {
+	if (link && (GET_INT_FROM_POINTER(link->custom_data) != -1)) {
 		/* An innercut edge... We tag our solution as potentially crossing innercuts.
 		 * Note it might not be the case in the end (AStar will explore around optimal path), but helps
 		 * trimming off some processing later... */
@@ -1152,6 +1145,9 @@ static float mesh_remap_calc_loops_astar_f_cost(
 	return (link ? (as_solution->g_costs[node_idx_curr] + link->cost) : 0.0f) + len_v3v3(co_next, co_dest);
 }
 
+#define ASTAR_STEPS_MAX 6
+
+
 void BKE_mesh_remap_calc_loops_from_dm(
         const int mode, const SpaceTransform *space_transform, const float max_dist, const float ray_radius,
         MVert *verts_dst, const int numverts_dst, MEdge *edges_dst, const int numedges_dst,
@@ -1188,7 +1184,7 @@ void BKE_mesh_remap_calc_loops_from_dm(
 		bool use_islands = false;
 
 		AStarPathGraph *as_graphdata = NULL;
-		AStarPathSolution as_solution = {{0}};
+		AStarPathSolution as_solution = {0};
 
 		float (*poly_nors_src)[3] = NULL;
 		float (*loop_nors_src)[3] = NULL;
@@ -1199,9 +1195,14 @@ void BKE_mesh_remap_calc_loops_from_dm(
 		int *vert_to_loop_map_src_buff = NULL;
 		MeshElemMap *vert_to_poly_map_src = NULL;
 		int *vert_to_poly_map_src_buff = NULL;
-		MeshElemMap *edge_to_poly_map = NULL;
-		int *edge_to_poly_map_buff = NULL;
+		MeshElemMap *edge_to_poly_map_src = NULL;
+		int *edge_to_poly_map_src_buff = NULL;
+		MeshElemMap *poly_to_tessface_map_src = NULL;
+		int *poly_to_tessface_map_src_buff = NULL;
+
+		/* Unlike above, those are one-to-one mappings, simpler! */
 		int *loop_to_poly_map_src = NULL;
+		int *tessface_to_poly_map_src = NULL;
 
 		bool verts_allocated_src;
 		MVert *verts_src = DM_get_vert_array(dm_src, &verts_allocated_src);
@@ -1220,8 +1221,6 @@ void BKE_mesh_remap_calc_loops_from_dm(
 		MFace *faces_src = NULL;
 		int num_faces_src;
 
-		int *orig_poly_index_src = NULL;
-
 		size_t buff_size_interp = MREMAP_D

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list