[Bf-blender-cvs] [3959203] soc-2016-uv_tools: WIP Simulated Annealing
Phil Gosch
noreply at git.blender.org
Tue Jul 19 19:49:21 CEST 2016
Commit: 39592039be4ca619a1a6be91dbb738cf920ca7dd
Author: Phil Gosch
Date: Tue Jul 19 19:48:54 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rB39592039be4ca619a1a6be91dbb738cf920ca7dd
WIP Simulated Annealing
Stubs for storing the best solution and initial scaling of charts
===================================================================
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 71124f5..4e5582b 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -582,6 +582,18 @@ static void p_chart_uv_scale_origin(PChart *chart, float scale)
p_chart_uv_translate(chart, trans);
}
+static void p_scale_charts(PHandle *handle, float scale)
+{
+ PChart *chart;
+ int i;
+
+ for (i = 0; i < handle->ncharts; i++) {
+ chart = handle->charts[i];
+
+ p_chart_uv_scale(chart, scale);
+ }
+}
+
static void UNUSED_FUNCTION(p_chart_uv_from_array)(PChart *chart, float (*points)[2])
{
PVert *v;
@@ -5408,7 +5420,7 @@ void param_irregular_pack_begin(ParamHandle *handle, float *w_area)
PFace *f;
int npoint, right, i, j;
unsigned int seed = 31415926;
- float used_area;
+ float used_area, init_scale, init_value = 0.9f;
param_assert(phandle->state == PHANDLE_STATE_CONSTRUCTED);
phandle->state = PHANDLE_STATE_PACK;
@@ -5427,7 +5439,10 @@ void param_irregular_pack_begin(ParamHandle *handle, float *w_area)
}
/* Set initial scale of charts */
- /* ToDo SaphireS: Idea: set initial scale so that combined chart area is about 1.0 of UV area */
+ /* ToDo: Do this in p_compute_packing_solution */
+ /*used_area = p_face_uv_area_combined(handle);
+ init_scale = (1.0f / used_area) * init_value;
+ p_scale_charts(handle, init_scale);*/
/* Compute convex hull for each chart -> CW */
chart->u.ipack.convex_hull = p_convex_hull_new(chart);
@@ -5856,6 +5871,25 @@ void param_flush_restore(ParamHandle *handle)
}
}
+void param_store_packing_solution(ParamHandle *handle)
+{
+ PHandle *phandle = (PHandle *)handle;
+ PChart *chart;
+ int i;
+
+ for (i = 0; i < phandle->ncharts; i++) {
+ chart = phandle->charts[i];
+ //chart->u.ipack.best_pos->x = chart->uv[0];
+ //chart->u.ipack.best_pos->y = chart->uv[1];
+ //chart->u.ipack.best_scale = chart-> ?
+ }
+}
+
+void param_restore_packing_solution(ParamHandle *handle)
+{
+
+}
+
/* XXX (SaphireS): Remove */
void param_test(ParamHandle *handle)
{
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 710d4fd..0935a8d 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -108,6 +108,8 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate);
void param_irregular_pack_begin(ParamHandle *handle);
void param_irregular_pack_iter(ParamHandle *handle, float *w_area, unsigned int seed);
void param_irregular_pack_end(ParamHandle *handle);
+void param_store_packing_solution(ParamHandle *handle);
+void param_restore_packing_solution(ParamHandle *handle);
/* Average area for all charts */
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 2708f97..b8b2e83 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -901,7 +901,7 @@ static void irregular_pack_islands_iteration(bContext *C, wmOperator *op, bool i
float wasted_area = 0.0f, dE, r1, r2;
float a = 0.95f; /*ToDo SaphireS: Make operator parameter for testing */
/* ToDo Saphires: Find optimal parameter */
- float k = 5.670367e-8f; /* Stefan-Boltzman constant-like parameter */
+ float k = 0.5f; /* Stefan-Boltzman constant-like parameter */
int local_iter_max = 50;
pi->iter_global++;
@@ -923,6 +923,7 @@ static void irregular_pack_islands_iteration(bContext *C, wmOperator *op, bool i
if (dE < 0) {
/* Current solution is new best solution */
/* ToDo SaphireS: Store last best solution */
+ param_store_packing_solution(pi->handle);
pi->wasted_area_last = wasted_area;
}
else {
@@ -933,6 +934,7 @@ static void irregular_pack_islands_iteration(bContext *C, wmOperator *op, bool i
if (r1 < r2) {
/* Current solution is new best solution */
/* ToDo SaphireS: Store last best solution */
+ param_store_packing_solution(pi->handle);
pi->wasted_area_last = wasted_area;
}
else {
@@ -950,7 +952,7 @@ static void irregular_pack_islands_iteration(bContext *C, wmOperator *op, bool i
if (sa) {
BLI_snprintf(str, sizeof(str),
- IFACE_("Pack Islands (irregular). Iteration: %i, Wasted UV Area: %f"), pi->iter_global, pi->wasted_area_last);
+ IFACE_("Pack Islands (irregular). Iteration: %i, Wasted UV Area (Best Solution): %f"), pi->iter_global, pi->wasted_area_last);
ED_area_headerprint(sa, str);
}
@@ -971,10 +973,13 @@ static void irregular_pack_islands_exit(bContext *C, wmOperator *op, bool cancel
if (pi->timer)
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), pi->timer);
- if (cancel)
- param_flush_restore(pi->handle); /* Restore UVs */
- else
+ if (cancel) {
+ param_flush_restore(pi->handle); /* Restore original UVs */
+ }
+ else {
+ param_restore_packing_solution(pi->handle); /* Restore best solution*/
param_flush(pi->handle); /* Keep new UVs */
+ }
param_irregular_pack_end(pi->handle);
param_delete(pi->handle);
More information about the Bf-blender-cvs
mailing list