[Bf-blender-cvs] [183ca1af3fc] uv_unwrapping_slim_algorithm: SLIM: move most SLIM integration behind param_* API, reuse more code.
Brecht Van Lommel
noreply at git.blender.org
Mon Mar 27 22:44:37 CEST 2017
Commit: 183ca1af3fcd599462a71660dcf98cb3e6cd5b9a
Author: Brecht Van Lommel
Date: Sat Mar 25 16:33:37 2017 +0100
Branches: uv_unwrapping_slim_algorithm
https://developer.blender.org/rB183ca1af3fcd599462a71660dcf98cb3e6cd5b9a
SLIM: move most SLIM integration behind param_* API, reuse more code.
===================================================================
M intern/slim/slim_matrix_transfer.h
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/intern/slim/slim_matrix_transfer.h b/intern/slim/slim_matrix_transfer.h
index 2c6e883cdf6..a2d0c38f956 100644
--- a/intern/slim/slim_matrix_transfer.h
+++ b/intern/slim/slim_matrix_transfer.h
@@ -69,6 +69,10 @@ typedef struct {
int reflection_mode;
double relative_scale;
+ /* external */
+ int n_iterations;
+ bool skip_initialization;
+ bool is_minimize_stretch;
} SLIMMatrixTransfer;
#ifdef __cplusplus
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 862c36fe6d6..9955e31c59f 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -206,6 +206,7 @@ typedef struct PChart {
} pack;
struct PChartSLIM {
bool pins_exist;
+ void *ptr;
} slim;
} u;
@@ -243,14 +244,7 @@ typedef struct PHandle {
char do_aspect;
// SLIM uv unwrapping
- SLIMMatrixTransfer *mt;
- int n_iterations;
- bool skip_initialization;
- float *weight_array;
- bool is_minimize_stretch;
-
- // For minimize_stretch and live unwrap
- void* recurringSlim;
+ SLIMMatrixTransfer *slim_mt;
} PHandle;
/* PHash
@@ -4199,37 +4193,6 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl)
phandle->state = PHANDLE_STATE_CONSTRUCTED;
}
-
-void param_begin(ParamHandle *handle, ParamBool abf, bool use_slim)
-{
- if (use_slim) {
- param_slim_begin(handle);
- }
- else {
- param_lscm_begin(handle, PARAM_FALSE, abf);
- }
-}
-
-void param_solve(ParamHandle *handle, bool use_slim)
-{
- if (use_slim) {
- param_slim_solve(handle);
- }
- else {
- param_lscm_solve(handle);
- }
-}
-
-void param_end(ParamHandle *handle, bool use_slim)
-{
- if (use_slim) {
- param_slim_end(handle);
- }
- else {
- param_lscm_end(handle);
- }
-}
-
void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf)
{
PHandle *phandle = (PHandle *)handle;
@@ -4551,7 +4514,7 @@ void param_flush_restore(ParamHandle *handle)
/* Allocate pointer arrays for each matrix-group. Meaning as many pointers per
* array as there are charts. */
-static void allocate_memory_for_pointerarrays(SLIMMatrixTransfer *mt, PHandle *phandle)
+static void slim_allocate_pointerarrays(SLIMMatrixTransfer *mt, PHandle *phandle)
{
mt->n_charts = phandle->ncharts;
mt->n_verts = MEM_mallocN(mt->n_charts * sizeof(*mt->n_verts), "Array of number of vertices per Chart");
@@ -4573,9 +4536,9 @@ static void allocate_memory_for_pointerarrays(SLIMMatrixTransfer *mt, PHandle *p
mt->w_vectors = MEM_mallocN(mt->n_charts * sizeof(*mt->w_vectors), "Array of pointers to weight-per-face vectors");
}
-/* For one chart, allocate memory. If no accurate estimate (e.g. for number of pinned vertices) overestimate and
- * correct later. */
-static void allocate_memory_for_matrices(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
+/* For one chart, allocate memory. If no accurate estimate (e.g. for number of
+ * pinned vertices) overestimate and correct later. */
+static void slim_allocate_matrices(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
{
mt->n_verts[chartNr] = phandle->charts[chartNr]->nverts;
mt->n_faces[chartNr] = phandle->charts[chartNr]->nfaces;
@@ -4596,19 +4559,18 @@ static void allocate_memory_for_matrices(const int chartNr, const PHandle *phand
}
/* Transfer edges and edge lengths */
-static void transfer_edges(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
+static void slim_transfer_edges(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
{
PChart *chart = phandle->charts[chartNr];
int *E = mt->e_matrices[chartNr];
double *EL = mt->el_vectors[chartNr];
- int eid = 0;
-
- PEdge *e, *e1;
PEdge *outer;
p_chart_boundaries(chart, NULL, &outer);
+
PEdge *be = outer;
+ int eid = 0;
do {
E[eid] = be->vert->slim_id;
@@ -4620,8 +4582,8 @@ static void transfer_edges(const int chartNr, const PHandle *phandle, const SLIM
} while (be != outer);
- for (e = chart->edges; e; e = e->nextlink) {
- e1 = e->next;
+ for (PEdge *e = chart->edges; e; e = e->nextlink) {
+ PEdge *e1 = e->next;
E[eid] = e->vert->slim_id;
EL[eid] = p_edge_length(e);
@@ -4632,27 +4594,22 @@ static void transfer_edges(const int chartNr, const PHandle *phandle, const SLIM
}
/* Transfer vertices and pinned information */
-static void transfer_vertices(const int chartNr, const PHandle *phandle, SLIMMatrixTransfer *mt, float *temp_w)
+static void slim_transfer_vertices(const int chartNr, const PHandle *phandle, SLIMMatrixTransfer *mt)
{
PChart *chart = phandle->charts[chartNr];
- PVert *v;
-
- double *V, *UV, *PP;
- float *W;
- int *P;
int r = mt->n_verts[chartNr];
- V = mt->v_matrices[chartNr];
- UV = mt->uv_matrices[chartNr];
- P = mt->p_matrices[chartNr];
- PP = mt->pp_matrices[chartNr];
- W = mt->w_vectors[chartNr];
+ double *V = mt->v_matrices[chartNr];
+ double *UV = mt->uv_matrices[chartNr];
+ int *P = mt->p_matrices[chartNr];
+ double *PP = mt->pp_matrices[chartNr];
+ float *W = mt->w_vectors[chartNr];
int pVid = 0;
int vid = mt->n_boundary_vertices[chartNr];
- //For every vertex, fill up V matrix and P matrix (pinned vertices)
- for (v = chart->verts; v; v = v->nextlink) {
+ /* For every vertex, fill up V matrix and P matrix (pinned vertices) */
+ for (PVert *v = chart->verts; v; v = v->nextlink) {
if (!v->on_boundary_flag) {
if (mt->with_weighted_parameterization) {
W[vid] = v->weight;
@@ -4669,7 +4626,7 @@ static void transfer_vertices(const int chartNr, const PHandle *phandle, SLIMMat
UV[v->slim_id] = v->uv[0];
UV[r + v->slim_id] = v->uv[1];
- if (v->flag & PVERT_PIN || (phandle->is_minimize_stretch && !(v->flag & PVERT_SELECT))) {
+ if (v->flag & PVERT_PIN || (mt->is_minimize_stretch && !(v->flag & PVERT_SELECT))) {
mt->pinned_vertices = true;
mt->n_pinned_vertices[chartNr] += 1;
@@ -4682,7 +4639,7 @@ static void transfer_vertices(const int chartNr, const PHandle *phandle, SLIMMat
}
/* Transfer boundary vertices */
-static void transfer_boundary_vertices(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt, float *temp_w)
+static void slim_transfer_boundary_vertices(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
{
PChart *chart = phandle->charts[chartNr];
@@ -4702,7 +4659,6 @@ static void transfer_boundary_vertices(const int chartNr, const PHandle *phandle
int vid = 0;
do {
-
if (mt->with_weighted_parameterization) {
W[vid] = be->vert->weight;
}
@@ -4719,21 +4675,15 @@ static void transfer_boundary_vertices(const int chartNr, const PHandle *phandle
}
/* Transfer faces */
-static void transfer_faces(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
+static void slim_transfer_faces(const int chartNr, const PHandle *phandle, const SLIMMatrixTransfer *mt)
{
PChart *chart = phandle->charts[chartNr];
-
- PFace *f;
-
- PEdge *e;
- PEdge *e1;
- PEdge *e2;
-
int fid = 0;
- for (f = chart->faces; f; f = f->nextlink) {
- e = f->edge;
- e1 = e->next;
- e2 = e1->next;
+
+ for (PFace *f = chart->faces; f; f = f->nextlink) {
+ PEdge *e = f->edge;
+ PEdge *e1 = e->next;
+ PEdge *e2 = e1->next;
int r = mt->n_faces[chartNr];
int *F;
@@ -4748,70 +4698,58 @@ static void transfer_faces(const int chartNr, const PHandle *phandle, const SLIM
}
/* Conversion Function to build matrix for SLIM Parametrization */
-static void convert_blender_slim(ParamHandle *handle)
+static void slim_convert_blender(ParamHandle *handle)
{
PHandle *phandle = (PHandle *)handle;
- SLIMMatrixTransfer *mt = phandle->mt;
+ SLIMMatrixTransfer *mt = phandle->slim_mt;
// allocate memory for the arrays that hold the pointers to the matrices for each chart
// there are #charts pointers of each kind
- allocate_memory_for_pointerarrays(mt, phandle);
-
- int chartNr;
+ slim_allocate_pointerarrays(mt, phandle);
/* Allocate memory for matrices of Vertices,Faces etc. for each chart */
- for (chartNr = 0; chartNr<phandle->ncharts; chartNr++) {
- allocate_memory_for_matrices(chartNr, phandle, mt);
+ for (int i = 0; i < phandle->ncharts; i++) {
+ slim_allocate_matrices(i, phandle, mt);
}
/* For each chart, fill up matrices */
+ for (int i = 0; i < phandle->ncharts; i++) {
+ mt->n_pinned_vertices[i] = 0;
+ mt->n_boundary_vertices[i] = 0;
- for (chartNr = 0; chartNr < phandle->ncharts; chartNr++) {
- mt->n_pinned_vertices[chartNr] = 0;
- mt->n_boundary_vertices[chartNr] = 0;
-
- transfer_boundary_vertices(chartNr, phandle, mt, phandle->weight_array);
- transfer_vertices(chartNr, phandle, mt, phandle->weight_array);
- transfer_edges(chartNr, phandle, mt);
- transfer_faces(chartNr, phandle, mt);
-
- mt->pp_matrices[chartNr] = MEM_reallocN_id(mt->pp_matrices[chartNr], mt->n_pinned_vertices[chartNr] * 2 * sizeof(**mt->pp_matrices), "Pinned-Vertex-position Matrix");
- mt->p_matrices[chartNr] = MEM_reallocN_id(mt->p_matrices[chartNr], mt->n_pinned_vertices[chartNr] * sizeof(**mt->p_matrices), " Pinned-Vertex Matrix");
- mt->b_vectors[chartNr] = MEM_reallocN_id(mt->b_vectors[chartNr], mt->n_boundary_vertices[chartNr] * sizeof(**mt->b_vectors), " boundary-Vertex Matrix");
- mt->e_matrices[chartNr] = MEM_reallocN_id(mt->e_matrices[chartNr], (mt->n_edges[chartNr] + mt->n_boundary_vertices[chartNr]) * 2 * sizeof(**mt->e_matrices), " boundarys-Vertex Matrix");
+ slim_transfer_boundary_vertices(i, phandle, mt);
+ slim_transfer_vertices(i, phandle, mt);
+ slim_transfer_edges(i, phandle, mt);
+ slim_transfer_faces(i, phandle, mt);
- if (mt->n_pinned_vertices[chartNr] > 0) {
- mt->transform_islands = false;
- }
- }
-
- if (phandle->weight_array) {
- MEM_freeN(phandle->weight_array);
+ mt->pp_matrices[i] = MEM_reallocN_id(mt->pp_matrices[i], mt->n_pinned_vertices[i] * 2 * sizeof(**mt->pp_matrices), "Pinned-Vertex-position Matrix");
+ mt->p_matrices[i] = MEM_reallocN_id(mt->p_matrices[i], mt->n_pinned_vertices[i] * sizeof(**mt->p_matrices), " Pinned-Vertex Matrix");
+ mt->b_vectors[i] = MEM_reallocN_id(mt->b_vectors[i], mt->n_boundary_vertices[i] * sizeof(**mt->b_vectors), " bo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list