Commit: 08d1b312be5e06400672a2bc4b5fe7eed3600be2
Author: Aurel Gruber
Date:   Fri Nov 18 12:54:50 2016 +0100
Branches: uv_unwrapping_slim_algorithm
https://developer.blender.org/rB08d1b312be5e06400672a2bc4b5fe7eed3600be2

Category: UV Unwrapping SLIM Algorithm Integration

integrating SLIM including data gathering and transfer from Blender to SLIM

This commit is huge, because I copied over the code from a different 
repository. Not commit-by-commit.

The Algorithm can be invoked either by choosing SLIM from the dropdown in the 
unwrapping settings or by
hitting ctrl. + m in the uv editor for relaxation. Tried adding it to the menu 
the same way as minimizing stretch is there but failed.

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

M       intern/SLIM
M       source/blender/bmesh/bmesh_class.h
M       source/blender/editors/uvedit/CMakeLists.txt
M       source/blender/editors/uvedit/uvedit_intern.h
M       source/blender/editors/uvedit/uvedit_ops.c
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
M       source/blender/makesdna/DNA_scene_types.h

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

diff --git a/intern/SLIM b/intern/SLIM
index fa4b84c7dd..e897ae04d5 160000
--- a/intern/SLIM
+++ b/intern/SLIM
@@ -1 +1 @@
-Subproject commit fa4b84c7dd2aac4502887999f6b4ee9c524adedf
+Subproject commit e897ae04d52607970344a601fc85c1329f2314ed
diff --git a/source/blender/bmesh/bmesh_class.h 
b/source/blender/bmesh/bmesh_class.h
index 104df625ee..49077b19be 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -99,6 +99,8 @@ typedef struct BMVert {
         *       which is a bit of an abuse of internal bmesh data but also 
works OK for now (use with care!).
         */
        struct BMEdge *e;
+       /* AUREL */
+       int id;
 } BMVert;
 
 typedef struct BMVert_OFlag {
diff --git a/source/blender/editors/uvedit/CMakeLists.txt 
b/source/blender/editors/uvedit/CMakeLists.txt
index 543ef0e066..a7e2da0508 100644
--- a/source/blender/editors/uvedit/CMakeLists.txt
+++ b/source/blender/editors/uvedit/CMakeLists.txt
@@ -31,6 +31,8 @@ set(INC
        ../../../../intern/guardedalloc
        ../../../../intern/eigen
        ../../../../intern/glew-mx
+
+       ../../../../intern/SLIM/src
 )
 
 set(INC_SYS
@@ -56,3 +58,4 @@ endif()
 add_definitions(${GL_DEFINITIONS})
 
 blender_add_lib(bf_editor_uvedit "${SRC}" "${INC}" "${INC_SYS}")
+target_link_libraries(bf_editor_uvedit bf_intern_slim)
diff --git a/source/blender/editors/uvedit/uvedit_intern.h 
b/source/blender/editors/uvedit/uvedit_intern.h
index e028c08091..e8dbb337cf 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -75,6 +75,8 @@ void UV_OT_cube_project(struct wmOperatorType *ot);
 void UV_OT_cylinder_project(struct wmOperatorType *ot);
 void UV_OT_project_from_view(struct wmOperatorType *ot);
 void UV_OT_minimize_stretch(struct wmOperatorType *ot);
+// AUREL SLIM interactive parameterization
+void UV_OT_minimize_stretch_slim(struct wmOperatorType *ot);
 void UV_OT_pack_islands(struct wmOperatorType *ot);
 void UV_OT_reset(struct wmOperatorType *ot);
 void UV_OT_sphere_project(struct wmOperatorType *ot);
diff --git a/source/blender/editors/uvedit/uvedit_ops.c 
b/source/blender/editors/uvedit/uvedit_ops.c
index 193b006cf0..6cdce37ab0 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -4265,6 +4265,8 @@ void ED_operatortypes_uvedit(void)
        WM_operatortype_append(UV_OT_cylinder_project);
        WM_operatortype_append(UV_OT_project_from_view);
        WM_operatortype_append(UV_OT_minimize_stretch);
+       // AUREL SLIM Interactive Parameterization
+       WM_operatortype_append(UV_OT_minimize_stretch_slim);
        WM_operatortype_append(UV_OT_pack_islands);
        WM_operatortype_append(UV_OT_reset);
        WM_operatortype_append(UV_OT_sphere_project);
@@ -4341,6 +4343,8 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
        /* unwrap */
        WM_keymap_add_item(keymap, "UV_OT_unwrap", EKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "UV_OT_minimize_stretch", VKEY, KM_PRESS, 
KM_CTRL, 0);
+       // AUREL SLIM Interactive Parameterization
+       WM_keymap_add_item(keymap, "UV_OT_minimize_stretch_slim", MKEY, 
KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "UV_OT_pack_islands", PKEY, KM_PRESS, 
KM_CTRL, 0);
        WM_keymap_add_item(keymap, "UV_OT_average_islands_scale", AKEY, 
KM_PRESS, KM_CTRL, 0);
 
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c 
b/source/blender/editors/uvedit/uvedit_parametrizer.c
index bdfff123aa..759af69fd3 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -35,6 +35,9 @@
 #include "BLI_boxpack2d.h"
 #include "BLI_convexhull2d.h"
 
+#include "BKE_editmesh.h"
+#include "bmesh.h"
+
 #include "uvedit_parametrizer.h"
 
 #include <math.h>
@@ -113,6 +116,8 @@ typedef struct PVert {
        float uv[2];
        unsigned char flag;
 
+       bool on_boundary_flag;
+       int slimId;
 } PVert; 
 
 typedef struct PEdge {
@@ -199,6 +204,9 @@ typedef struct PChart {
                        float rescale, area;
                        float size[2] /* , trans[2] */;
                } pack;
+               struct PChartSLIM {
+                       bool pins_exist;
+               } slim;
        } u;
 
        unsigned char flag;
@@ -4703,3 +4711,352 @@ void param_flush_restore(ParamHandle *handle)
        }
 }
 
+/*     AUREL THESIS
+       In the following are all functions necessary to transfer data from the 
native part to SLIM.
+ */
+void allocate_memory_for_pointerarrays(matrix_transfer *mt, PHandle *phandle);
+void allocate_memory_for_matrices(const int chartNr, const PHandle *phandle, 
const matrix_transfer *mt);
+void create_weight_matrix(const int chartNr, const PHandle *phandle, 
matrix_transfer *mt, float *tempW, MDeformVert *dvert, int defgrp_index, 
BMEditMesh *em);
+void transfer_vertices(const int chartNr, const PHandle *phandle, 
matrix_transfer *mt, float *tempW);
+void transfer_edges(const int chartNr, const PHandle *phandle, const 
matrix_transfer *mt);
+void transfer_boundary_vertices(const int chartNr, const PHandle *phandle, 
const matrix_transfer *mt, float *tempW);
+void transfer_faces(const int chartNr, const PHandle *phandle, const 
matrix_transfer *mt);
+
+/* AUREL THESIS: Conversion Function to build matrix for SLIM Parametrization 
*/
+void convert_blender_slim(ParamHandle *handle, matrix_transfer *mt, bool 
selectionOnly, MDeformVert *dvert, int defgrp_index, BMEditMesh *em)
+{
+       PHandle *phandle = (PHandle *)handle;
+
+       // 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;
+
+       /*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 each chart, fill up matrices*/
+
+       //printf("number of charts: %d \n", mt->nCharts);
+       for (chartNr = 0; chartNr < phandle->ncharts; chartNr++) {
+               mt->nPinnedVertices[chartNr] = 0;
+               mt->nBoundaryVertices[chartNr] = 0;
+
+               float *tempW = MEM_mallocN(mt->nVerts[chartNr] * 
sizeof(*tempW), " Weight-per-face Vector, ordered by BM_ITER_MESH_INDEX");
+
+               create_weight_matrix(chartNr, phandle, mt, tempW, dvert, 
defgrp_index, em);
+               transfer_boundary_vertices(chartNr, phandle, mt, tempW);
+               transfer_vertices(chartNr, phandle, mt, tempW);
+               transfer_edges(chartNr, phandle, mt);
+               transfer_faces(chartNr, phandle, mt);
+
+               mt->PPmatrices[chartNr] = 
MEM_reallocN_id(mt->PPmatrices[chartNr], mt->nPinnedVertices[chartNr] * 2 * 
sizeof(**mt->PPmatrices), "Pinned-Vertex-position Matrix");
+               mt->Pmatrices[chartNr] = 
MEM_reallocN_id(mt->Pmatrices[chartNr], mt->nPinnedVertices[chartNr] * 
sizeof(**mt->Pmatrices), " Pinned-Vertex Matrix");
+               mt->Bvectors[chartNr] = MEM_reallocN_id(mt->Bvectors[chartNr], 
mt->nBoundaryVertices[chartNr] * sizeof(**mt->Bvectors), " boundary-Vertex 
Matrix");
+               mt->Ematrices[chartNr] = 
MEM_reallocN_id(mt->Ematrices[chartNr], (mt->nEdges[chartNr] + 
mt->nBoundaryVertices[chartNr]) * 2 * sizeof(**mt->Ematrices), " 
boundarys-Vertex Matrix");
+       }
+
+};
+
+/*     AUREL THESIS
+       Allocate pointer arrays for each matrix-group. Meaning as many pointers 
per array as there are charts.
+ */
+void allocate_memory_for_pointerarrays(matrix_transfer *mt, PHandle *phandle){
+       mt->nCharts = phandle->ncharts;
+       mt->nVerts = MEM_mallocN(mt->nCharts * sizeof(*mt->nVerts), "Array of 
number of vertices per Chart");
+       mt->nFaces = MEM_mallocN(mt->nCharts * sizeof(*mt->nFaces), "Array of 
number of Faces per Chart");
+       mt->nEdges = MEM_mallocN(mt->nCharts * sizeof(*mt->nEdges), "Array of 
number of Edges per Chart");
+       mt->nPinnedVertices = MEM_mallocN(mt->nCharts * 
sizeof(*mt->nPinnedVertices), "Array of number of Faces per Chart");
+       mt->nBoundaryVertices = MEM_mallocN(mt->nCharts * 
sizeof(*mt->nBoundaryVertices), "Array of number of Faces per Chart");
+
+       mt->Vmatrices = MEM_mallocN(mt->nCharts * sizeof(*mt->Vmatrices), 
"Array of pointers to Vertex matrices");
+       mt->UVmatrices = MEM_mallocN(mt->nCharts * sizeof(*mt->UVmatrices), 
"Array of pointers to UV matrices");
+       mt->PPmatrices = MEM_mallocN(mt->nCharts * sizeof(*mt->PPmatrices), 
"Array of pointers to Pinned-Vertex-Position matrices");
+
+       mt->Fmatrices = MEM_mallocN(mt->nCharts * sizeof(*mt->Fmatrices), 
"Array of pointers to Face matrices");
+       mt->Pmatrices = MEM_mallocN(mt->nCharts * sizeof(*mt->Pmatrices), 
"Array of pointers to Pinned-Vertex matrices");
+       mt->Bvectors = MEM_mallocN(mt->nCharts * sizeof(*mt->Bvectors), "Array 
of pointers to boundary-Vertex vectors");
+       mt->Ematrices = MEM_mallocN(mt->nCharts * sizeof(*mt->Ematrices), 
"Array of pointers to Edge matrices");
+
+       mt->ELvectors = MEM_mallocN(mt->nCharts * sizeof(*mt->ELvectors), 
"Array of pointers to Edge-Length vectors");
+       mt->Wvectors = MEM_mallocN(mt->nCharts * sizeof(*mt->Wvectors), "Array 
of pointers to weight-per-face vectors");
+}
+
+/*     AUREL THESIS
+       For one chart, allocate memory. If no accurate estimate (e.g. for 
number of pinned vertices) overestimate and
+       correct later.
+ */
+void allocate_memory_for_matrices(const int chartNr, const PHandle *phandle, 
const matrix_transfer *mt){
+
+       mt->nVerts[chartNr] = phandle->charts[chartNr]->nverts;
+       mt->nFaces[chartNr] = phandle->charts[chartNr]->nfaces;
+       mt->nEdges[chartNr] = phandle->charts[chartNr]->nedges;
+
+       mt->Vmatrices[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 3 * 
sizeof(**mt->Vmatrices), "Vertex Matrix");
+       mt->UVmatrices[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 2 * 
sizeof(**mt->UVmatrices), "UV Matrix");
+       mt->PPmatrices[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 2 * 
sizeof(**mt->PPmatrices), "Pinned-Vertex-position Matrix");
+
+       mt->Fmatrices[chartNr] = MEM_mallocN(mt->nFaces[chartNr] * 3 * 
sizeof(**mt->Fmatrices), "Face Matrix");
+       mt->Pmatrices[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 
sizeof(**mt->Pmatrices), " Pinned-Vertex Matrix");
+       mt->Bvectors[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 
sizeof(**mt->Bvectors), " Boundary-Vertex Vector");
+       mt->Wvectors[chartNr] = MEM_mallocN(mt->nVerts[chartNr] * 
sizeof(**mt->Wvectors), " Weight-per-face Vector");
+
+       mt->Ematrices[chartNr] = MEM_mallocN(mt->nEdges[chartNr] * 2 * 2 * 
sizeof(**mt->Ematrices), " Edge matrix");
+       mt->ELvectors[chartNr] = MEM_mallocN(mt->nEdges[chartNr] * 2 * 
sizeof(**mt->ELvectors), " Edge-Length Vector");
+}
+
+/

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to