Revision: 38245
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38245
Author: shuvro
Date: 2011-07-09 04:04:26 +0000 (Sat, 09 Jul 2011)
Log Message:
-----------
Improved implementation of strectch calculation and integration of it with the
recursive autoseam function as another stopping criterion.
Modified Paths:
--------------
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h
Modified:
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
===================================================================
---
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
2011-07-09 01:14:07 UTC (rev 38244)
+++
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
2011-07-09 04:04:26 UTC (rev 38245)
@@ -32,15 +32,8 @@
#include "bmesh_private.h"
-#define EDGE_NEW 1
-#define FACE_NEW 1
-#define ELE_NEW 1
-#define FACE_MARK 2
-#define EDGE_MARK 4
-
-
/* ------------------------ Code from Andrea ------------------------ */
static int find_index(int index, int* face_indices, int nindices)
{
@@ -93,7 +86,6 @@
bSeam = find_index(idx2, fplus,
nplus);
}
other_face=BMIter_Step(&face_iter);
- //printf("indexes are %d %d\n", idx1,
idx2);
}
}
if (bSeam){
@@ -262,7 +254,7 @@
}
/* now call the recursive function for a single
component*/
- generate_seam_recursive(bm, connected_adjacency, adj,
recursion_depth, C);
+ generate_seam_recursive(bm, connected_adjacency, adj,
recursion_depth, C, -1.0);
}
@@ -276,74 +268,68 @@
}
-/* The function assumes that there this is a triangulated face*/
-float stretch_of_triangulated_face(BMesh *bm, BMFace *face, bContext *C)
+/* It calculates stretch for a single triangulated mesh */
+
+float stretch_of_triangulated_face(BMLoop **looptris, BMesh *bm)
{
- BMVert *vert[3];
- BMEdge *edge[3];
- int i = 0;
- BMIter iter2;
- //BMVert *v;
- BMEdge *e;
- float Ps[3], Pt[3];
+ int i;
+ float a,c,T, face_area;
+ float w, tmp[3];
float *uv[3];
- float face_area = BM_face_area(face);
- BMLoop *l;
+ //vertices
+ float Ps[3], Pt[3];
+ float v[3][3];
+ //edge vectors
+ float e1[3], e2[3];
+ float cross_product[3];
MLoopUV *luv;
- BMIter liter;
- float a,c,T;
- int j;
- float w, tmp[3];
-// Scene *scene= CTX_data_scene(C);
-// Object *obedit= CTX_data_edit_object(C);
-// if(!ED_uvedit_ensure_uvs(C, scene, obedit)) {
-// //invalid case
-// return -1.0;
-// }
+ /* Now calculate the face are first */
+ copy_v3_v3(v[0], looptris[0]->v->co);
+ copy_v3_v3(v[1], looptris[1]->v->co);
+ copy_v3_v3(v[2], looptris[2]->v->co);
+ sub_v3_v3v3(e1, v[3], v[1]);
+ sub_v3_v3v3(e2, v[3], v[2]);
+
+ cross_v3_v3v3(cross_product, e1, e2);
+ face_area = 0.5 * len_v3(cross_product);
+
if (face_area <= 0.0f)
return 1e10f;
- w= 1.0f/(2.0f*face_area);
+ w = 1.0f/(2.0f*face_area);
- i = 0;
- BM_ITER(e, &iter2, bm, BM_EDGES_OF_FACE, face) {
- //if(i == 3) break;
- edge[i++] = e;
- }
-
- /* now get the texture co-ordinates */
- i = 0;
- BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, face) {
- luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV);
+
+ /* Now we need to find out the UV's for each vertex */
+ for(i = 0; i < 3; i++){
+ luv = CustomData_bmesh_get(&bm->ldata, looptris[i]->head.data,
CD_MLOOPUV);
uv[i] = luv->uv;
- vert[i++] = l->v;
-
+ copy_v3_v3(v[i], looptris[i]->v->co);
}
// compute derivatives
- copy_v3_v3(Ps, vert[0]->co);
+ copy_v3_v3(Ps, v[0]);
mul_v3_fl(Ps, (uv[1][1] - uv[2][1]));
- copy_v3_v3(tmp, vert[1]->co);
+ copy_v3_v3(tmp, v[1]);
mul_v3_fl(tmp, (uv[2][1] - uv[0][1]));
add_v3_v3(Ps, tmp);
- copy_v3_v3(tmp, vert[2]->co);
+ copy_v3_v3(tmp, v[2]);
mul_v3_fl(tmp, (uv[0][1] - uv[1][1]));
add_v3_v3(Ps, tmp);
mul_v3_fl(Ps, w);
- copy_v3_v3(Pt, vert[0]->co);
+ copy_v3_v3(Pt, v[0]);
mul_v3_fl(Pt, (uv[2][0] - uv[1][0]));
- copy_v3_v3(tmp, vert[1]->co);
+ copy_v3_v3(tmp, v[1]);
mul_v3_fl(tmp, (uv[0][0] - uv[2][0]));
add_v3_v3(Pt, tmp);
- copy_v3_v3(tmp, vert[2]->co);
+ copy_v3_v3(tmp, v[2]);
mul_v3_fl(tmp, (uv[1][0] - uv[0][0]));
add_v3_v3(Pt, tmp);
@@ -364,13 +350,7 @@
float stretch_of_mesh(bContext *C)
{
-
- BMIter face_iter;
- BMFace *face, **newfaces = NULL;
- BLI_array_declare(newfaces);
- float (*projectverts)[3] = NULL;
- BLI_array_declare(projectverts);
- int i, lastlen=0;
+ int i;
Scene *scene= CTX_data_scene(C);
Object *obedit= CTX_data_edit_object(C);
BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
@@ -379,74 +359,41 @@
float total_stretch = 0.0;
/*first of all, unwrap the mesh once again*/
-
if(!ED_uvedit_ensure_uvs(C, scene, obedit)) {
//invalid case
return -1.0;
}
ED_unwrap_lscm(scene, obedit, TRUE);
- /*
- Now calculate the stretch.
- sum = 0;
- for all the faces of the mesh,
- triangulate each face,
- for all the faces that is generated for the triangulation
- sum += strecth_of_face
- return sum;
- */
+ for (i=0; i < em->tottri; i++) {
+ total_stretch += stretch_of_triangulated_face(em->looptris[i], bm);
+ }
- i = 0;
- for(face = BMIter_New(&face_iter, bm, BM_FACES_OF_MESH, NULL); face;
face= BMIter_Step(&face_iter))
- {
- BMFace *temp_face;
- int count_faces = 0;
-
- if (lastlen < face->len) {
- BLI_array_empty(projectverts);
- BLI_array_empty(newfaces);
- /* allocate necessary memories*/
- for (lastlen=0; lastlen < face->len; lastlen++) {
- BLI_array_growone(projectverts);
- BLI_array_growone(projectverts);
- BLI_array_growone(projectverts);
- BLI_array_growone(newfaces);
- }
- }
-
- /* triangulate face */
- BM_Triangulate_Face(bm, face, projectverts, EDGE_NEW, FACE_NEW,
newfaces);
-
- for (i=0; newfaces[i]; i++) {
- //calculate strecth for each face, update stretch
- total_stretch += stretch_of_triangulated_face(bm, newfaces[i], C);
- count_faces++;
- }
-
- /* join the triangulated faces. */
- if(count_faces > 1) temp_face = BM_Join_TwoFaces(bm, newfaces[0],
newfaces[1], NULL);
- for(i = 2; newfaces[i]; i++ ){
- temp_face = BM_Join_TwoFaces(bm, temp_face, newfaces[i], NULL);
- }
- }
-
- BLI_array_free(projectverts);
- BLI_array_free(newfaces);
return total_stretch;
}
-int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj,
AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C)
+int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj,
AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch)
{
int s;
int i, j;
int num_faces;
int *fplus, *fminus;
unsigned int nplus, nminus;
+
AUTOSEAM_Adjacency adj_plus;
AUTOSEAM_Adjacency adj_minus;
+ if(stretch < 0.0){
+ stretch = stretch_of_mesh(C);
+ }
+ else{
+ float temp = stretch_of_mesh(C);
+ /* stretch is increasing, so stop here*/
+ if(temp > stretch) return 0;
+ else stretch = temp;
+ }
if(!recursion_depth) {
autoseam_delete_adjacency(adj);
@@ -469,8 +416,7 @@
/* mark the seam on the mesh */
//autoseam_clear_seam(bm);
autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
-
- printf("Stretch value is: %f\n", stretch_of_mesh(C));
+
/* create adj_plus */
adj_plus = autoseam_create_adjacency(nplus);
autoseam_set_min_value(adj_plus, min_value);
@@ -514,11 +460,11 @@
/* recursive calls for two parts of the mesh. */
if(nplus > 0){
//can we construct PChart for this part and calculate strectch for
that part?
- generate_seam_recursive(bm, adj_plus, adj_big, recursion_depth,
C);
+ generate_seam_recursive(bm, adj_plus, adj_big, recursion_depth,
C, stretch);
}
if(nminus > 0){
//same is applicable for this part.
- generate_seam_recursive(bm, adj_minus, adj_big,
recursion_depth, C);
+ generate_seam_recursive(bm, adj_minus, adj_big,
recursion_depth, C, stretch);
}
autoseam_delete_adjacency(adj);
@@ -584,17 +530,6 @@
ED_unwrap_lscm(scene, obedit, TRUE);
-
- /* Now try to minimize the stretch of the mesh */
-// minimize_stretch_init(C, op);
-//
-// iterations= RNA_int_get(op->ptr, "iterations");
-// for(i=0; i<iterations; i++)
-// minimize_stretch_iteration(C, op, 0);
-// minimize_stretch_exit(C, op, 0);
-
-
-
/*reset the min_value*/
min_value = INF;
@@ -627,7 +562,7 @@
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_int(ot->srna, "depth", 1, 0, 6, "Recursion Depth", "Max.
recursion depth", 0, 6);
- RNA_def_boolean(ot->srna, "is_combinatorial", 1, "Calculate
Combinatorial", "Store combinatorial edge distance in dual graph.");
+ RNA_def_boolean(ot->srna, "is_combinatorial", 0, "Calculate
Combinatorial", "Store combinatorial edge distance in dual graph.");
RNA_def_enum(ot->srna, "method", method_items, 0, "Method", "Unwrapping
method. Angle Based usually gives better results than Conformal, while being
somewhat slower.");
RNA_def_boolean(ot->srna, "fill_holes", 1, "Fill Holes", "Virtual fill
holes in mesh before unwrapping, to better avoid overlaps and preserve
symmetry.");
RNA_def_boolean(ot->srna, "correct_aspect", 1, "Correct Aspect", "Map
UV's taking image aspect ratio into account.");
@@ -635,7 +570,7 @@
/* Adding parameters for minimizing the stretch */
RNA_def_boolean(ot->srna, "fill_holes", 1, "Fill Holes", "Virtual fill
holes in mesh before unwrapping, to better avoid overlaps and preserve
symmetry.");
RNA_def_float_factor(ot->srna, "blend", 0.0f, 0.0f, 1.0f, "Blend",
"Blend factor between stretch minimized and original.", 0.0f, 1.0f);
- RNA_def_int(ot->srna, "iterations", 2, 0, INT_MAX, "Iterations",
"Number of iterations to run, 0 is unlimited when run interactively.", 0, 100);
+ //RNA_def_int(ot->srna, "iterations", 2, 0, INT_MAX, "Iterations",
"Number of iterations to run, 0 is unlimited when run interactively.", 0, 100);
}
Modified:
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h
===================================================================
---
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h
2011-07-09 01:14:07 UTC (rev 38244)
+++
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h
2011-07-09 04:04:26 UTC (rev 38245)
@@ -70,7 +70,7 @@
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs