[Bf-blender-cvs] [45ed0ee] soc-2016-uv_tools: Added initial "Use concave hulls" option to operator

Phil Gosch noreply at git.blender.org
Tue Aug 9 01:40:07 CEST 2016


Commit: 45ed0ee455a2f8bfad51f6f76e8d603bc8eb9224
Author: Phil Gosch
Date:   Tue Aug 9 01:39:48 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rB45ed0ee455a2f8bfad51f6f76e8d603bc8eb9224

Added initial "Use concave hulls" option to operator

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

M	source/blender/editors/uvedit/uvedit_parametrizer.c
M	source/blender/editors/uvedit/uvedit_parametrizer.h
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c

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

diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index a137f80..bb84109 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -5318,6 +5318,17 @@ bool p_point_inside_nfp(PNoFitPolygon *nfp, float p[2])
 	return c;
 }
 
+bool p_check_concave(PChart *chart, int nboundaries, PEdge *outer)
+{
+	if (nboundaries <= 4) {
+		return false;
+	}
+
+	/* ToDo SaphireS */
+
+	return false;
+}
+
 bool p_temp_cfr_check(PNoFitPolygon **nfps, PNoFitPolygon *ifp, float p[2], int nfp_count, int index)
 {
 	int i;
@@ -5730,13 +5741,14 @@ bool p_compute_packing_solution(PHandle *phandle, float margin /* ToDo SaphireS:
 	return true;
 }
 
-void param_irregular_pack_begin(ParamHandle *handle, float *w_area, float margin, int rot_step)
+void param_irregular_pack_begin(ParamHandle *handle, float *w_area, float margin, int rot_step, bool concave)
 {
 	PHandle *phandle = (PHandle *)handle;
 	PChart *chart;
 	PVert **points;
+	PEdge *outer;
 	PFace *f;
-	int npoint, right, i, j;
+	int npoint, right, i, j, nboundaries = 0;
 	unsigned int seed = 31415925;
 	float used_area, init_scale, init_value = 0.6f, randf1, rot;
 
@@ -5777,25 +5789,46 @@ void param_irregular_pack_begin(ParamHandle *handle, float *w_area, float margin
 		printf("init rot for chart[%i]: %f\n", i, rot);
 		//p_chart_rotate(chart, rot); /* ToDo SaphireS: Rotate in origin and transform back to original pos! */
 
-		/* Compute convex hull for each chart -> CW */
-		chart->u.ipack.convex_hull = p_convex_hull_new(chart); 
-		chart->u.ipack.best_pos = MEM_callocN(sizeof(PPointUV), "PPointUV");
+		p_chart_boundaries(chart, &nboundaries, &outer);
 
-		chart->u.ipack.area = p_chart_uv_area_signed(chart); /* used for sorting */
+		if (concave && p_check_concave(chart, nboundaries, outer)) {
+
+			/* ToDo SaphireS */
+
+			/* Decompose concave hull into convex hulls */
 
-		/* Apply margin here */
-		if (!(compare_ff(margin, 0.0f, 0.0001f))) {
-			p_convex_hull_grow(chart->u.ipack.convex_hull, margin);
-			p_convex_hull_update(chart->u.ipack.convex_hull, false);
+			/* Store convex hulls with chart */
+
+			/* For each convex hull: */
+			/* Apply margin */
+
+			/* Compute horizontal angle for edges of hull (Needed for NFP) */
+
+			/* Compute edge lengths */
+
+			/* ToDo SaphireS: turn last few steps into a reusable function for cleaner code */
 		}
+		else {
+			/* Compute convex hull for each chart -> CW */
+			chart->u.ipack.convex_hull = p_convex_hull_new(chart);
+			chart->u.ipack.best_pos = MEM_callocN(sizeof(PPointUV), "PPointUV");
 
-		/* Compute horizontal angle for edges of hull (Needed for NFP) */
-		p_convex_hull_compute_horizontal_angles(chart->u.ipack.convex_hull);
-		/* Compute edge lengths */
-		p_convex_hull_compute_edge_components(chart->u.ipack.convex_hull);
+			/* Apply margin here */
+			if (!(compare_ff(margin, 0.0f, 0.0001f))) {
+				p_convex_hull_grow(chart->u.ipack.convex_hull, margin);
+				p_convex_hull_update(chart->u.ipack.convex_hull, false);
+			}
+
+			/* Compute horizontal angle for edges of hull (Needed for NFP) */
+			p_convex_hull_compute_horizontal_angles(chart->u.ipack.convex_hull);
+			/* Compute edge lengths */
+			p_convex_hull_compute_edge_components(chart->u.ipack.convex_hull);
 
-		/* DEBUG */
-		printf("Bounds of chart [%i]: minx: %f, maxx: %f, miny: %f,maxy: %f\n", i, chart->u.ipack.convex_hull->min_v[0], chart->u.ipack.convex_hull->max_v[0], chart->u.ipack.convex_hull->min_v[1], chart->u.ipack.convex_hull->max_v[1]);
+			/* DEBUG */
+			printf("Bounds of chart [%i]: minx: %f, maxx: %f, miny: %f,maxy: %f\n", i, chart->u.ipack.convex_hull->min_v[0], chart->u.ipack.convex_hull->max_v[0], chart->u.ipack.convex_hull->min_v[1], chart->u.ipack.convex_hull->max_v[1]);
+		}
+
+		chart->u.ipack.area = p_chart_uv_area_signed(chart); /* used for sorting */
 	}
 
 	/* Sort UV islands by area */
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 6bc0e8a..b29dd16 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -105,7 +105,7 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate);
 
 /* Packing 2.0 */
 
-void param_irregular_pack_begin(ParamHandle *handle, float *w_area, float margin, int rot_step);
+void param_irregular_pack_begin(ParamHandle *handle, float *w_area, float margin, int rot_step, bool concave);
 void param_irregular_pack_iter(ParamHandle *handle, float *w_area, unsigned int seed, int rot_step, float margin);
 void param_irregular_pack_end(ParamHandle *handle);
 void param_store_packing_solution(ParamHandle *handle);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index b72047e..bd94633 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -848,6 +848,7 @@ typedef struct PackIslands {
 	int iter_global, iter_local, iter_max;
 	wmTimer *timer;
 	float wasted_area_last, margin;
+	bool use_concave;
 	SimulatedAnnealing *sa;
 } PackIslands;
 
@@ -877,6 +878,7 @@ static bool irregular_pack_islands_init(bContext *C, wmOperator *op)
 	pi->iter_global = 0;
 	pi->iter_local = 0;
 	pi->margin = RNA_float_get(op->ptr, "margin") / 2.0f; /* Only apply half the margin per chart */
+	pi->use_concave = RNA_boolean_get(op->ptr, "concave");
 	pi->handle = construct_param_handle(scene, obedit, em->bm, hparams);
 	pi->lasttime = PIL_check_seconds_timer();
 
@@ -893,7 +895,11 @@ static bool irregular_pack_islands_init(bContext *C, wmOperator *op)
 	if (average_scale)
 		param_average(pi->handle);
 
-	param_irregular_pack_begin(pi->handle, &wasted_area, pi->margin, pi->sa->rot_steps /* SA */);
+	param_irregular_pack_begin(pi->handle, 
+							   &wasted_area, 
+							   pi->margin, 
+							   pi->sa->rot_steps,
+							   pi->use_concave /* SA */);
 	pi->wasted_area_last = wasted_area;
 
 	op->customdata = pi;
@@ -922,7 +928,11 @@ static void irregular_pack_islands_iteration(bContext *C, wmOperator *op, bool i
 
 	/* Find neighboring solution */
 	/*ToDo Saphires: Pass SA parameters */
-	param_irregular_pack_iter(pi->handle, &wasted_area, pi->iter_global, pi->sa->rot_steps, pi->margin /* SA */);
+	param_irregular_pack_iter(pi->handle, 
+							  &wasted_area, 
+							  pi->iter_global, 
+							  pi->sa->rot_steps, 
+							  pi->margin /* SA */);
 
 	/* delta Energy */
 	dE = wasted_area - pi->wasted_area_last;
@@ -1087,6 +1097,7 @@ void UV_OT_irregular_pack_islands(wmOperatorType *ot)
 	ot->poll = ED_operator_uvedit;
 
 	/* properties */
+	RNA_def_boolean(ot->srna, "concave", true, "Use concave boundaries", "Use concave boundaries (slower but better results)");
 	RNA_def_float(ot->srna, "margin", 0.0f, 0.0f, 1.0f, "Margin", "Border Margin/Padding to apply per UV island", 0.0f, 1.0f);
 	RNA_def_int(ot->srna, "rotation_steps", 4, 0, 360, "Rotation Steps", "Allowed rotations to try during packing. (2=180�, 4=90�, etc.)", 0, 360);
 	RNA_def_int(ot->srna, "iterations", 0, 0, INT_MAX, "Iterations", "Number of iterations to run, 0 is unlimited when run interactively", 0, 10000);




More information about the Bf-blender-cvs mailing list