Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_parametrizer.c')
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.c450
1 files changed, 300 insertions, 150 deletions
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 913aacec4c8..10b2df48f2f 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -255,8 +255,9 @@ static PHash *phash_new(PHashLink **list, int sizehint)
ph->cursize_id = 0;
ph->list = list;
- while (PHashSizes[ph->cursize_id] < sizehint)
+ while (PHashSizes[ph->cursize_id] < sizehint) {
ph->cursize_id++;
+ }
ph->cursize = PHashSizes[ph->cursize_id];
ph->buckets = (PHashLink **)MEM_callocN(ph->cursize * sizeof(*ph->buckets), "PHashBuckets");
@@ -316,11 +317,14 @@ static PHashLink *phash_lookup(PHash *ph, PHashKey key)
PHashLink *link;
uintptr_t hash = PHASH_hash(ph, key);
- for (link = ph->buckets[hash]; link; link = link->next)
- if (link->key == key)
+ for (link = ph->buckets[hash]; link; link = link->next) {
+ if (link->key == key) {
return link;
- else if (PHASH_hash(ph, link->key) != hash)
+ }
+ else if (PHASH_hash(ph, link->key) != hash) {
return NULL;
+ }
+ }
return link;
}
@@ -329,11 +333,14 @@ static PHashLink *phash_next(PHash *ph, PHashKey key, PHashLink *link)
{
uintptr_t hash = PHASH_hash(ph, key);
- for (link = link->next; link; link = link->next)
- if (link->key == key)
+ for (link = link->next; link; link = link->next) {
+ if (link->key == key) {
return link;
- else if (PHASH_hash(ph, link->key) != hash)
+ }
+ else if (PHASH_hash(ph, link->key) != hash) {
return NULL;
+ }
+ }
return link;
}
@@ -362,12 +369,15 @@ static float p_vec_angle(float *v1, float *v2, float *v3)
{
float dot = p_vec_angle_cos(v1, v2, v3);
- if (dot <= -1.0f)
+ if (dot <= -1.0f) {
return (float)M_PI;
- else if (dot >= 1.0f)
+ }
+ else if (dot >= 1.0f) {
return 0.0f;
- else
+ }
+ else {
return acosf(dot);
+ }
}
static float p_vec2_angle(float *v1, float *v2, float *v3)
@@ -523,8 +533,9 @@ static PBool p_intersect_line_2d_dir(float *v1, float *dir1, float *v2, float *d
div = dir2[0] * dir1[1] - dir2[1] * dir1[0];
- if (div == 0.0f)
+ if (div == 0.0f) {
return P_FALSE;
+ }
lmbda = ((v1[1] - v2[1]) * dir1[0] - (v1[0] - v2[0]) * dir1[1]) / div;
isect[0] = v1[0] + lmbda * dir2[0];
@@ -645,8 +656,9 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v)
e = v->edge;
do {
if (e->orig_uv) {
- if (e->flag & PEDGE_SELECT)
+ if (e->flag & PEDGE_SELECT) {
v->flag |= PVERT_SELECT;
+ }
if (e->flag & PEDGE_PIN) {
pinuv[0] += e->orig_uv[0] * handle->aspx;
@@ -765,10 +777,12 @@ static PVert *p_vert_lookup(PHandle *handle, PHashKey key, const float co[3], PE
{
PVert *v = (PVert *)phash_lookup(handle->hash_verts, key);
- if (v)
+ if (v) {
return v;
- else
+ }
+ else {
return p_vert_add(handle, key, co, e);
+ }
}
static PVert *p_vert_copy(PChart *chart, PVert *v)
@@ -791,10 +805,12 @@ static PEdge *p_edge_lookup(PHandle *handle, PHashKey *vkeys)
PEdge *e = (PEdge *)phash_lookup(handle->hash_edges, key);
while (e) {
- if ((e->vert->u.key == vkeys[0]) && (e->next->vert->u.key == vkeys[1]))
+ if ((e->vert->u.key == vkeys[0]) && (e->next->vert->u.key == vkeys[1])) {
return e;
- else if ((e->vert->u.key == vkeys[1]) && (e->next->vert->u.key == vkeys[0]))
+ }
+ else if ((e->vert->u.key == vkeys[1]) && (e->next->vert->u.key == vkeys[0])) {
return e;
+ }
e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e);
}
@@ -811,12 +827,14 @@ static int p_face_exists(ParamHandle *phandle, ParamKey *pvkeys, int i1, int i2,
while (e) {
if ((e->vert->u.key == vkeys[i1]) && (e->next->vert->u.key == vkeys[i2])) {
- if (e->next->next->vert->u.key == vkeys[i3])
+ if (e->next->next->vert->u.key == vkeys[i3]) {
return P_TRUE;
+ }
}
else if ((e->vert->u.key == vkeys[i2]) && (e->next->vert->u.key == vkeys[i1])) {
- if (e->next->next->vert->u.key == vkeys[i3])
+ if (e->next->next->vert->u.key == vkeys[i3]) {
return P_TRUE;
+ }
}
e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e);
@@ -881,8 +899,9 @@ static PBool p_edge_has_pair(PHandle *handle, PEdge *e, PEdge **pair, PBool impl
PHashKey key1 = e->vert->u.key;
PHashKey key2 = e->next->vert->u.key;
- if (e->flag & PEDGE_SEAM)
+ if (e->flag & PEDGE_SEAM) {
return P_FALSE;
+ }
key = PHASH_edge(key1, key2);
pe = (PEdge *)phash_lookup(handle->hash_edges, key);
@@ -925,8 +944,9 @@ static PBool p_edge_connect_pair(PHandle *handle, PEdge *e, PEdge ***stack, PBoo
PEdge *pair = NULL;
if (!e->pair && p_edge_has_pair(handle, e, &pair, impl)) {
- if (e->vert == pair->vert)
+ if (e->vert == pair->vert) {
p_face_flip(pair->face);
+ }
e->pair = pair;
pair->pair = e;
@@ -952,8 +972,9 @@ static int p_connect_pairs(PHandle *handle, PBool impl)
/* connect pairs, count edges, set vertex-edge pointer to a pairless edge */
for (first = chart->faces; first; first = first->nextlink) {
- if (first->flag & PFACE_CONNECTED)
+ if (first->flag & PFACE_CONNECTED) {
continue;
+ }
*stack = first->edge;
stack++;
@@ -970,12 +991,15 @@ static int p_connect_pairs(PHandle *handle, PBool impl)
/* assign verts to charts so we can sort them later */
f->u.chart = ncharts;
- if (!p_edge_connect_pair(handle, e, &stack, impl))
+ if (!p_edge_connect_pair(handle, e, &stack, impl)) {
e->vert->edge = e;
- if (!p_edge_connect_pair(handle, e1, &stack, impl))
+ }
+ if (!p_edge_connect_pair(handle, e1, &stack, impl)) {
e1->vert->edge = e1;
- if (!p_edge_connect_pair(handle, e2, &stack, impl))
+ }
+ if (!p_edge_connect_pair(handle, e2, &stack, impl)) {
e2->vert->edge = e2;
+ }
}
ncharts++;
@@ -996,18 +1020,21 @@ static void p_split_vert(PChart *chart, PEdge *e)
chart->flag |= PCHART_HAS_PINS;
}
- if (e->flag & PEDGE_VERTEX_SPLIT)
+ if (e->flag & PEDGE_VERTEX_SPLIT) {
return;
+ }
/* rewind to start */
lastwe = e;
- for (we = p_wheel_edge_prev(e); we && (we != e); we = p_wheel_edge_prev(we))
+ for (we = p_wheel_edge_prev(e); we && (we != e); we = p_wheel_edge_prev(we)) {
lastwe = we;
+ }
/* go over all edges in wheel */
for (we = lastwe; we; we = p_wheel_edge_next(we)) {
- if (we->flag & PEDGE_VERTEX_SPLIT)
+ if (we->flag & PEDGE_VERTEX_SPLIT) {
break;
+ }
we->flag |= PEDGE_VERTEX_SPLIT;
@@ -1046,8 +1073,9 @@ static PChart **p_split_charts(PHandle *handle, PChart *chart, int ncharts)
PFace *f, *nextf;
int i;
- for (i = 0; i < ncharts; i++)
+ for (i = 0; i < ncharts; i++) {
charts[i] = p_chart_new(handle);
+ }
f = chart->faces;
while (f) {
@@ -1133,21 +1161,27 @@ static PFace *p_face_add_construct(PHandle *handle,
e3->orig_uv = uv[i3];
if (pin) {
- if (pin[i1])
+ if (pin[i1]) {
e1->flag |= PEDGE_PIN;
- if (pin[i2])
+ }
+ if (pin[i2]) {
e2->flag |= PEDGE_PIN;
- if (pin[i3])
+ }
+ if (pin[i3]) {
e3->flag |= PEDGE_PIN;
+ }
}
if (select) {
- if (select[i1])
+ if (select[i1]) {
e1->flag |= PEDGE_SELECT;
- if (select[i2])
+ }
+ if (select[i2]) {
e2->flag |= PEDGE_SELECT;
- if (select[i3])
+ }
+ if (select[i3]) {
e3->flag |= PEDGE_SELECT;
+ }
}
/* insert into hash */
@@ -1205,12 +1239,14 @@ static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys
* triangles, resulting in two identical triangles. for example in
* suzanne's nose. */
if (dir) {
- if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3))
+ if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) {
return !dir;
+ }
}
else {
- if (p_face_exists(handle, vkeys, 0, 1, 3) || p_face_exists(handle, vkeys, 1, 2, 3))
+ if (p_face_exists(handle, vkeys, 0, 1, 3) || p_face_exists(handle, vkeys, 1, 2, 3)) {
return !dir;
+ }
}
return dir;
@@ -1223,17 +1259,21 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer)
PEdge *e, *be;
float len, maxlen = -1.0;
- if (nboundaries)
+ if (nboundaries) {
*nboundaries = 0;
- if (outer)
+ }
+ if (outer) {
*outer = NULL;
+ }
for (e = chart->edges; e; e = e->nextlink) {
- if (e->pair || (e->flag & PEDGE_DONE))
+ if (e->pair || (e->flag & PEDGE_DONE)) {
continue;
+ }
- if (nboundaries)
+ if (nboundaries) {
(*nboundaries)++;
+ }
len = 0.0f;
@@ -1250,8 +1290,9 @@ static void p_chart_boundaries(PChart *chart, int *nboundaries, PEdge **outer)
}
}
- for (e = chart->edges; e; e = e->nextlink)
+ for (e = chart->edges; e; e = e->nextlink) {
e->flag &= ~PEDGE_DONE;
+ }
}
static float p_edge_boundary_angle(PEdge *e)
@@ -1364,8 +1405,9 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer)
for (e = chart->edges; e; e = e->nextlink) {
/* enext = e->nextlink; - as yet unused */
- if (e->pair || (e->flag & PEDGE_FILLED))
+ if (e->pair || (e->flag & PEDGE_FILLED)) {
continue;
+ }
nedges = 0;
be = e;
@@ -1375,8 +1417,9 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer)
nedges++;
} while (be != e);
- if (e != outer)
+ if (e != outer) {
p_chart_fill_boundary(chart, e, nedges);
+ }
}
}
@@ -2350,8 +2393,9 @@ static void p_abf_setup_system(PAbfSystem *sys)
sys->bstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFbstar");
sys->dstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFdstar");
- for (i = 0; i < sys->ninterior; i++)
+ for (i = 0; i < sys->ninterior; i++) {
sys->lambdaLength[i] = 1.0;
+ }
sys->minangle = 1.0 * M_PI / 180.0;
sys->maxangle = (float)M_PI - sys->minangle;
@@ -2404,16 +2448,18 @@ static float p_abf_compute_sin_product(PAbfSystem *sys, PVert *v, int aid)
sin1 *= sys->cosine[e1->u.id];
sin2 = 0.0;
}
- else
+ else {
sin1 *= sys->sine[e1->u.id];
+ }
if (aid == e2->u.id) {
/* see above */
sin1 = 0.0;
sin2 *= sys->cosine[e2->u.id];
}
- else
+ else {
sin2 *= sys->sine[e2->u.id];
+ }
e = e->next->next->pair;
} while (e && (e != v->edge));
@@ -2504,8 +2550,9 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart)
context = EIG_linear_solver_new(0, nvar, 1);
- for (i = 0; i < nvar; i++)
+ for (i = 0; i < nvar; i++) {
EIG_linear_solver_right_hand_side_add(context, 0, i, sys->bInterior[i]);
+ }
for (f = chart->faces; f; f = f->nextlink) {
float wi1, wi2, wi3, b, si, beta[3], j2[3][3], W[3][3];
@@ -2615,29 +2662,37 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart)
for (i = 0; i < 3; i++) {
int r = vid[i];
- if (r == -1)
+ if (r == -1) {
continue;
+ }
for (j = 0; j < 6; j++) {
int c = vid[j];
- if (c == -1)
+ if (c == -1) {
continue;
+ }
- if (i == 0)
+ if (i == 0) {
EIG_linear_solver_matrix_add(context, r, c, j2[0][i] * row1[j]);
- else
+ }
+ else {
EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[0][i] * row1[j]);
+ }
- if (i == 1)
+ if (i == 1) {
EIG_linear_solver_matrix_add(context, r, c, j2[1][i] * row2[j]);
- else
+ }
+ else {
EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[1][i] * row2[j]);
+ }
- if (i == 2)
+ if (i == 2) {
EIG_linear_solver_matrix_add(context, r, c, j2[2][i] * row3[j]);
- else
+ }
+ else {
EIG_linear_solver_matrix_add(context, r + ninterior, c, j2[2][i] * row3[j]);
+ }
}
}
}
@@ -2693,10 +2748,12 @@ static PBool p_abf_matrix_invert(PAbfSystem *sys, PChart *chart)
/* clamp */
e = f->edge;
do {
- if (sys->alpha[e->u.id] > (float)M_PI)
+ if (sys->alpha[e->u.id] > (float)M_PI) {
sys->alpha[e->u.id] = (float)M_PI;
- else if (sys->alpha[e->u.id] < 0.0f)
+ }
+ else if (sys->alpha[e->u.id] < 0.0f) {
sys->alpha[e->u.id] = 0.0f;
+ }
} while (e != f->edge);
}
@@ -2728,8 +2785,9 @@ static PBool p_chart_abf_solve(PChart *chart)
v->flag |= PVERT_INTERIOR;
v->u.id = sys.ninterior++;
}
- else
+ else {
v->flag &= ~PVERT_INTERIOR;
+ }
}
for (f = chart->faces; f; f = f->nextlink) {
@@ -2755,18 +2813,24 @@ static PBool p_chart_abf_solve(PChart *chart)
e3 = e2->next;
p_face_angles(f, &a1, &a2, &a3);
- if (a1 < sys.minangle)
+ if (a1 < sys.minangle) {
a1 = sys.minangle;
- else if (a1 > sys.maxangle)
+ }
+ else if (a1 > sys.maxangle) {
a1 = sys.maxangle;
- if (a2 < sys.minangle)
+ }
+ if (a2 < sys.minangle) {
a2 = sys.minangle;
- else if (a2 > sys.maxangle)
+ }
+ else if (a2 > sys.maxangle) {
a2 = sys.maxangle;
- if (a3 < sys.minangle)
+ }
+ if (a3 < sys.minangle) {
a3 = sys.minangle;
- else if (a3 > sys.maxangle)
+ }
+ else if (a3 > sys.maxangle) {
a3 = sys.maxangle;
+ }
sys.alpha[e1->u.id] = sys.beta[e1->u.id] = a1;
sys.alpha[e2->u.id] = sys.beta[e2->u.id] = a2;
@@ -2808,8 +2872,9 @@ static PBool p_chart_abf_solve(PChart *chart)
/* lastnorm = norm; */ /* UNUSED */
- if (norm < limit)
+ if (norm < limit) {
break;
+ }
if (!p_abf_matrix_invert(&sys, chart)) {
param_warning("ABF failed to invert matrix");
@@ -2906,12 +2971,14 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV
if ((be->vert->flag & PVERT_SPLIT) ||
(lastbe->vert->flag & nextbe->vert->flag & PVERT_SPLIT)) {
if (!cure) {
- if (be == outer)
+ if (be == outer) {
firste1 = be;
+ }
cure = be;
}
- else
+ else {
curlen += p_edge_length(lastbe);
+ }
}
else if (cure) {
if (curlen > maxlen) {
@@ -2944,8 +3011,9 @@ static PBool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PV
}
}
- if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen))
+ if (!maxe1 || !maxe2 || (maxlen < 0.5f * totlen)) {
return P_FALSE;
+ }
/* find pin1 in the split vertices */
be1 = maxe1;
@@ -3054,12 +3122,14 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf)
for (v = chart->verts; v; v = v->nextlink) {
if (v->flag & PVERT_PIN) {
npins++;
- if (v->flag & PVERT_SELECT)
+ if (v->flag & PVERT_SELECT) {
select = P_TRUE;
+ }
}
- if (!(v->flag & PVERT_SELECT))
+ if (!(v->flag & PVERT_SELECT)) {
deselect = P_TRUE;
+ }
}
if ((live && (!select || !deselect)) || (npins == 1)) {
@@ -3072,8 +3142,9 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf)
#endif
if (abf) {
- if (!p_chart_abf_solve(chart))
+ if (!p_chart_abf_solve(chart)) {
param_warning("ABF solving failed: falling back to LSCM.\n");
+ }
}
if (npins <= 1) {
@@ -3091,8 +3162,9 @@ static void p_chart_lscm_begin(PChart *chart, PBool live, PBool abf)
chart->u.lscm.pin2 = pin2;
}
- for (v = chart->verts; v; v = v->nextlink)
+ for (v = chart->verts; v; v = v->nextlink) {
v->u.id = id++;
+ }
chart->u.lscm.context = EIG_linear_least_squares_solver_new(
2 * chart->nfaces, 2 * chart->nverts, 1);
@@ -3113,9 +3185,11 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
/* TODO: make loading pins work for simplify/complexify. */
#endif
- for (v = chart->verts; v; v = v->nextlink)
- if (v->flag & PVERT_PIN)
+ for (v = chart->verts; v; v = v->nextlink) {
+ if (v->flag & PVERT_PIN) {
p_vert_load_pin_select_uvs(handle, v); /* reload for live */
+ }
+ }
if (chart->u.lscm.pin1) {
EIG_linear_solver_variable_lock(context, 2 * pin1->u.id);
@@ -3152,10 +3226,12 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
if ((v1->flag & PVERT_PIN) && (v2->flag & PVERT_PIN) && (v3->flag & PVERT_PIN)) {
float area = p_face_uv_area_signed(f);
- if (area > 0.0f)
+ if (area > 0.0f) {
area_pinned_up += area;
- else
+ }
+ else {
area_pinned_down -= area;
+ }
}
}
@@ -3176,8 +3252,9 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
a2 = *(alpha++);
a3 = *(alpha++);
}
- else
+ else {
p_face_angles(f, &a1, &a2, &a3);
+ }
if (flip_faces) {
SWAP(float, a2, a3);
@@ -3240,8 +3317,9 @@ static PBool p_chart_lscm_solve(PHandle *handle, PChart *chart)
static void p_chart_lscm_end(PChart *chart)
{
- if (chart->u.lscm.context)
+ if (chart->u.lscm.context) {
EIG_linear_solver_delete(chart->u.lscm.context);
+ }
if (chart->u.lscm.abf_alpha) {
MEM_freeN(chart->u.lscm.abf_alpha);
@@ -3261,11 +3339,14 @@ static void p_stretch_pin_boundary(PChart *chart)
{
PVert *v;
- for (v = chart->verts; v; v = v->nextlink)
- if (v->edge->pair == NULL)
+ for (v = chart->verts; v; v = v->nextlink) {
+ if (v->edge->pair == NULL) {
v->flag |= PVERT_PIN;
- else
+ }
+ else {
v->flag &= ~PVERT_PIN;
+ }
+ }
}
static float p_face_stretch(PFace *f)
@@ -3278,8 +3359,9 @@ static float p_face_stretch(PFace *f)
area = p_face_uv_area_signed(f);
- if (area <= 0.0f) /* flipped face -> infinite stretch */
+ if (area <= 0.0f) { /* flipped face -> infinite stretch */
return 1e10f;
+ }
w = 1.0f / (2.0f * area);
@@ -3315,8 +3397,9 @@ static float p_face_stretch(PFace *f)
c = dot_v3v3(Pt, Pt);
T = sqrtf(0.5f * (a + c));
- if (f->flag & PFACE_FILLED)
+ if (f->flag & PFACE_FILLED) {
T *= 0.2f;
+ }
return T;
}
@@ -3343,8 +3426,9 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng)
float orig_uv[2], dir[2], random_angle, trusted_radius;
for (v = chart->verts; v; v = v->nextlink) {
- if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT))
+ if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT)) {
continue;
+ }
orig_stretch = p_stretch_compute_vertex(v);
orig_uv[0] = v->uv[0];
@@ -3394,8 +3478,9 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng)
}
/* no luck, stretch has increased, reset to old values */
- if (stretch >= orig_stretch)
+ if (stretch >= orig_stretch) {
copy_v2_v2(v->uv, orig_uv);
+ }
}
}
@@ -3406,18 +3491,23 @@ static int p_compare_geometric_uv(const void *a, const void *b)
const PVert *v1 = *(const PVert *const *)a;
const PVert *v2 = *(const PVert *const *)b;
- if (v1->uv[0] < v2->uv[0])
+ if (v1->uv[0] < v2->uv[0]) {
return -1;
+ }
else if (v1->uv[0] == v2->uv[0]) {
- if (v1->uv[1] < v2->uv[1])
+ if (v1->uv[1] < v2->uv[1]) {
return -1;
- else if (v1->uv[1] == v2->uv[1])
+ }
+ else if (v1->uv[1] == v2->uv[1]) {
return 0;
- else
+ }
+ else {
return 1;
+ }
}
- else
+ else {
return 1;
+ }
}
static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int *right)
@@ -3431,8 +3521,9 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int
p_chart_boundaries(chart, NULL, &be);
- if (!be)
+ if (!be) {
return P_FALSE;
+ }
e = be;
do {
@@ -3455,10 +3546,12 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int
ulen = llen = 0;
for (p = points, i = 0; i < npoints; i++, p++) {
- while ((ulen > 1) && (p_area_signed(U[ulen - 2]->uv, (*p)->uv, U[ulen - 1]->uv) <= 0))
+ while ((ulen > 1) && (p_area_signed(U[ulen - 2]->uv, (*p)->uv, U[ulen - 1]->uv) <= 0)) {
ulen--;
- while ((llen > 1) && (p_area_signed(L[llen - 2]->uv, (*p)->uv, L[llen - 1]->uv) >= 0))
+ }
+ while ((llen > 1) && (p_area_signed(L[llen - 2]->uv, (*p)->uv, L[llen - 1]->uv) >= 0)) {
llen--;
+ }
U[ulen] = *p;
ulen++;
@@ -3467,12 +3560,14 @@ static PBool p_chart_convex_hull(PChart *chart, PVert ***verts, int *nverts, int
}
npoints = 0;
- for (p = points, i = 0; i < ulen; i++, p++, npoints++)
+ for (p = points, i = 0; i < ulen; i++, p++, npoints++) {
*p = U[i];
+ }
/* the first and last point in L are left out, since they are also in U */
- for (i = llen - 2; i > 0; i--, p++, npoints++)
+ for (i = llen - 2; i > 0; i--, p++, npoints++) {
*p = L[i];
+ }
*verts = points;
*nverts = npoints;
@@ -3494,14 +3589,17 @@ static float p_rectangle_area(float *p1, float *dir, float *p2, float *p3, float
orthodir[0] = dir[1];
orthodir[1] = -dir[0];
- if (!p_intersect_line_2d_dir(p1, dir, p2, orthodir, corner1))
+ if (!p_intersect_line_2d_dir(p1, dir, p2, orthodir, corner1)) {
return 1e10;
+ }
- if (!p_intersect_line_2d_dir(p1, dir, p4, orthodir, corner2))
+ if (!p_intersect_line_2d_dir(p1, dir, p4, orthodir, corner2)) {
return 1e10;
+ }
- if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3))
+ if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3)) {
return 1e10;
+ }
return len_v2v2(corner1, corner2) * len_v2v2(corner2, corner3);
}
@@ -3517,8 +3615,9 @@ static float p_chart_minimum_area_angle(PChart *chart)
PVert **points, *p1, *p2, *p3, *p4, *p1n;
/* compute convex hull */
- if (!p_chart_convex_hull(chart, &points, &npoints, &right))
+ if (!p_chart_convex_hull(chart, &points, &npoints, &right)) {
return 0.0;
+ }
/* find left/top/right/bottom points, and compute angle for each point */
angles = MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles");
@@ -3577,11 +3676,12 @@ static float p_chart_minimum_area_angle(PChart *chart)
i_min = 0;
mina = 1e10;
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; i++) {
if (a[i] < mina) {
mina = a[i];
i_min = i;
}
+ }
rotated += mina;
nextidx = (idx[i_min] + 1) % npoints;
@@ -3618,8 +3718,9 @@ static float p_chart_minimum_area_angle(PChart *chart)
}
/* try keeping rotation as small as possible */
- if (minangle > (float)(M_PI / 4))
+ if (minangle > (float)(M_PI / 4)) {
minangle -= (float)(M_PI / 2.0);
+ }
MEM_freeN(angles);
MEM_freeN(points);
@@ -3712,8 +3813,9 @@ static SmoothNode *p_node_new(
node->tri = tri;
node->ntri = ntri;
- if (ntri <= 10 || depth >= 15)
+ if (ntri <= 10 || depth >= 15) {
return node;
+ }
t1 = MEM_mallocN(sizeof(*t1) * ntri, "PNodeTri1");
t2 = MEM_mallocN(sizeof(*t2) * ntri, "PNodeTri1");
@@ -3761,12 +3863,15 @@ static SmoothNode *p_node_new(
static void p_node_delete(SmoothNode *node)
{
- if (node->c1)
+ if (node->c1) {
p_node_delete(node->c1);
- if (node->c2)
+ }
+ if (node->c2) {
p_node_delete(node->c2);
- if (node->tri)
+ }
+ if (node->tri) {
MEM_freeN(node->tri);
+ }
}
static PBool p_node_intersect(SmoothNode *node, float co[2])
@@ -3774,17 +3879,21 @@ static PBool p_node_intersect(SmoothNode *node, float co[2])
int i;
if (node->tri) {
- for (i = 0; i < node->ntri; i++)
- if (p_triangle_inside(node->tri[i], co))
+ for (i = 0; i < node->ntri; i++) {
+ if (p_triangle_inside(node->tri[i], co)) {
return P_TRUE;
+ }
+ }
return P_FALSE;
}
else {
- if (co[node->axis] < node->split)
+ if (co[node->axis] < node->split) {
return p_node_intersect(node->c1, co);
- else
+ }
+ else {
return p_node_intersect(node->c2, co);
+ }
}
}
@@ -3795,12 +3904,15 @@ static int p_compare_float(const void *a_, const void *b_)
const float a = *(const float *)a_;
const float b = *(const float *)b_;
- if (a < b)
+ if (a < b) {
return -1;
- else if (a == b)
+ }
+ else if (a == b) {
return 0;
- else
+ }
+ else {
return 1;
+ }
}
static float p_smooth_median_edge_length(PChart *chart)
@@ -3811,8 +3923,9 @@ static float p_smooth_median_edge_length(PChart *chart)
int i;
/* ok, so i'm lazy */
- for (i = 0, e = chart->edges; e; e = e->nextlink, i++)
+ for (i = 0, e = chart->edges; e; e = e->nextlink, i++) {
lengths[i] = p_edge_length(e);
+ }
qsort(lengths, i, sizeof(float), p_compare_float);
@@ -3845,14 +3958,16 @@ static void p_smooth(PChart *chart)
SmoothNode *root;
MemArena *arena;
- if (nedges == 0)
+ if (nedges == 0) {
return;
+ }
p_chart_uv_bbox(chart, minv, maxv);
median = p_smooth_median_edge_length(chart) * 0.10f;
- if (median == 0.0f)
+ if (median == 0.0f) {
return;
+ }
invmedian = 1.0f / median;
@@ -3905,8 +4020,9 @@ static void p_smooth(PChart *chart)
gridx = gridx * 2 + 1;
gridy = gridy * 2 + 1;
- if ((gridx <= 2) || (gridy <= 2))
+ if ((gridx <= 2) || (gridy <= 2)) {
return;
+ }
edgesx = gridx - 1;
edgesy = gridy - 1;
@@ -3922,20 +4038,27 @@ static void p_smooth(PChart *chart)
vedges = MEM_mallocN(sizeof(float) * esize, "PSmoothVEdges");
if (!nodes || !nodesx || !nodesy || !oldnodesx || !oldnodesy || !hedges || !vedges) {
- if (nodes)
+ if (nodes) {
MEM_freeN(nodes);
- if (nodesx)
+ }
+ if (nodesx) {
MEM_freeN(nodesx);
- if (nodesy)
+ }
+ if (nodesy) {
MEM_freeN(nodesy);
- if (oldnodesx)
+ }
+ if (oldnodesx) {
MEM_freeN(oldnodesx);
- if (oldnodesy)
+ }
+ if (oldnodesy) {
MEM_freeN(oldnodesy);
- if (hedges)
+ }
+ if (hedges) {
MEM_freeN(hedges);
- if (vedges)
+ }
+ if (vedges) {
MEM_freeN(vedges);
+ }
// printf("Not enough memory for area smoothing grid");
return;
@@ -4062,12 +4185,14 @@ static void p_smooth(PChart *chart)
}
}
- if (d < dlimit)
+ if (d < dlimit) {
break;
+ }
}
- if (moved < climit)
+ if (moved < climit) {
break;
+ }
}
MEM_freeN(oldnodesx);
@@ -4084,10 +4209,12 @@ static void p_smooth(PChart *chart)
MEM_freeN(nodesx);
MEM_freeN(nodesy);
- if (triangles)
+ if (triangles) {
MEM_freeN(triangles);
- if (tri)
+ }
+ if (tri) {
MEM_freeN(tri);
+ }
// printf("Not enough memory for area smoothing grid");
return;
@@ -4149,9 +4276,11 @@ static void p_smooth(PChart *chart)
arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "param smooth arena");
root = p_node_new(arena, tri, esize * 2, minv, maxv, 0);
- for (v = chart->verts; v; v = v->nextlink)
- if (!p_node_intersect(root, v->uv))
+ for (v = chart->verts; v; v = v->nextlink) {
+ if (!p_node_intersect(root, v->uv)) {
param_warning("area smoothing error: couldn't find mapping triangle\n");
+ }
+ }
p_node_delete(root);
BLI_memarena_free(arena);
@@ -4197,11 +4326,13 @@ void param_delete(ParamHandle *handle)
param_assert((phandle->state == PHANDLE_STATE_ALLOCATED) ||
(phandle->state == PHANDLE_STATE_CONSTRUCTED));
- for (i = 0; i < phandle->ncharts; i++)
+ for (i = 0; i < phandle->ncharts; i++) {
p_chart_delete(phandle->charts[i]);
+ }
- if (phandle->charts)
+ if (phandle->charts) {
MEM_freeN(phandle->charts);
+ }
if (phandle->construction_chart) {
p_chart_delete(phandle->construction_chart);
@@ -4323,8 +4454,9 @@ void param_edge_set_seam(ParamHandle *handle, ParamKey *vkeys)
param_assert(phandle->state == PHANDLE_STATE_ALLOCATED);
e = p_edge_lookup(phandle, vkeys);
- if (e)
+ if (e) {
e->flag |= PEDGE_SEAM;
+ }
}
void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl)
@@ -4361,11 +4493,13 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl)
phandle->charts[j] = chart;
j++;
- if (fill && (nboundaries > 1))
+ if (fill && (nboundaries > 1)) {
p_chart_fill_boundaries(chart, outer);
+ }
- for (v = chart->verts; v; v = v->nextlink)
+ for (v = chart->verts; v; v = v->nextlink) {
p_vert_load_pin_select_uvs(handle, v);
+ }
}
phandle->ncharts = j;
@@ -4383,8 +4517,9 @@ void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf)
phandle->state = PHANDLE_STATE_LSCM;
for (i = 0; i < phandle->ncharts; i++) {
- for (f = phandle->charts[i]->faces; f; f = f->nextlink)
+ for (f = phandle->charts[i]->faces; f; f = f->nextlink) {
p_face_backup_uvs(f);
+ }
p_chart_lscm_begin(phandle->charts[i], (PBool)live, (PBool)abf);
}
}
@@ -4404,11 +4539,13 @@ void param_lscm_solve(ParamHandle *handle)
if (chart->u.lscm.context) {
result = p_chart_lscm_solve(phandle, chart);
- if (result && !(chart->flag & PCHART_HAS_PINS))
+ if (result && !(chart->flag & PCHART_HAS_PINS)) {
p_chart_rotate_minimum_area(chart);
+ }
- if (!result || (chart->u.lscm.pin1))
+ if (!result || (chart->u.lscm.pin1)) {
p_chart_lscm_end(chart);
+ }
}
}
}
@@ -4447,8 +4584,9 @@ void param_stretch_begin(ParamHandle *handle)
for (i = 0; i < phandle->ncharts; i++) {
chart = phandle->charts[i];
- for (v = chart->verts; v; v = v->nextlink)
+ for (v = chart->verts; v; v = v->nextlink) {
v->flag &= ~PVERT_PIN; /* don't use user-defined pins */
+ }
p_stretch_pin_boundary(chart);
@@ -4503,8 +4641,9 @@ void param_smooth_area(ParamHandle *handle)
PChart *chart = phandle->charts[i];
PVert *v;
- for (v = chart->verts; v; v = v->nextlink)
+ for (v = chart->verts; v; v = v->nextlink) {
v->flag &= ~PVERT_PIN;
+ }
p_smooth(chart);
}
@@ -4557,16 +4696,18 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p
PHandle *phandle = (PHandle *)handle;
- if (phandle->ncharts == 0)
+ if (phandle->ncharts == 0) {
return;
+ }
/* this could be its own function */
if (do_rotate) {
param_pack_rotate(handle, ignore_pinned);
}
- if (phandle->aspx != phandle->aspy)
+ if (phandle->aspx != phandle->aspy) {
param_scale(handle, 1.0f / phandle->aspx, 1.0f / phandle->aspy);
+ }
/* we may not use all these boxes */
boxarray = MEM_mallocN(phandle->ncharts * sizeof(BoxPack), "BoxPack box");
@@ -4592,8 +4733,9 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p
box->h = chart->u.pack.size[1] + trans[1];
box->index = i; /* warning this index skips PCHART_HAS_PINS boxes */
- if (margin > 0.0f)
+ if (margin > 0.0f) {
area += (double)sqrtf(box->w * box->h);
+ }
}
if (margin > 0.0f) {
@@ -4622,10 +4764,12 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p
BLI_box_pack_2d(boxarray, phandle->ncharts - unpacked, &tot_width, &tot_height);
- if (tot_height > tot_width)
+ if (tot_height > tot_width) {
scale = 1.0f / tot_height;
- else
+ }
+ else {
scale = 1.0f / tot_width;
+ }
for (i = 0; i < phandle->ncharts - unpacked; i++) {
box = boxarray + i;
@@ -4638,8 +4782,9 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate, bool ignore_p
}
MEM_freeN(boxarray);
- if (phandle->aspx != phandle->aspy)
+ if (phandle->aspx != phandle->aspy) {
param_scale(handle, phandle->aspx, phandle->aspy);
+ }
}
void param_average(ParamHandle *handle, bool ignore_pinned)
@@ -4651,8 +4796,9 @@ void param_average(ParamHandle *handle, bool ignore_pinned)
float minv[2], maxv[2], trans[2];
PHandle *phandle = (PHandle *)handle;
- if (phandle->ncharts == 0)
+ if (phandle->ncharts == 0) {
return;
+ }
for (i = 0; i < phandle->ncharts; i++) {
PFace *f;
@@ -4729,13 +4875,16 @@ void param_flush(ParamHandle *handle)
for (i = 0; i < phandle->ncharts; i++) {
chart = phandle->charts[i];
- if ((phandle->state == PHANDLE_STATE_LSCM) && !chart->u.lscm.context)
+ if ((phandle->state == PHANDLE_STATE_LSCM) && !chart->u.lscm.context) {
continue;
+ }
- if (phandle->blend == 0.0f)
+ if (phandle->blend == 0.0f) {
p_flush_uvs(phandle, chart);
- else
+ }
+ else {
p_flush_uvs_blend(phandle, chart, phandle->blend);
+ }
}
}
@@ -4749,7 +4898,8 @@ void param_flush_restore(ParamHandle *handle)
for (i = 0; i < phandle->ncharts; i++) {
chart = phandle->charts[i];
- for (f = chart->faces; f; f = f->nextlink)
+ for (f = chart->faces; f; f = f->nextlink) {
p_face_restore_uvs(f);
+ }
}
}