[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38318] branches/soc-2011-avocado/blender/ source/blender/editors/mesh: Some bug fixes in stretch calculation and code clean up.
shuvro sarker
shuvro05 at gmail.com
Tue Jul 12 04:40:34 CEST 2011
Revision: 38318
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38318
Author: shuvro
Date: 2011-07-12 02:40:30 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Some bug fixes in stretch calculation and code clean up.
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-11 18:41:58 UTC (rev 38317)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c 2011-07-12 02:40:30 UTC (rev 38318)
@@ -35,19 +35,6 @@
/* ------------------------ Code from Andrea ------------------------ */
-static int find_index(int index, int* face_indices, int nindices)
-{
- int found = 0;
- int i;
- for (i=0; i<nindices; ++i) {
- if (index == face_indices[i]) {
- found = 1;
- break;
- }
- }
- return found;
-}
-
static void autoseam_clear_seam(BMesh *bm)
{
BMIter edge_iter;
@@ -74,21 +61,21 @@
face=BMIter_New(&face_iter,bm, BM_FACES_OF_EDGE, edge);
if (face) {
int idx1 = BM_GetIndex(face);
- bPlus = find_index(idx1, fplus, nplus);
+ bPlus = find_element_in_array(idx1, fplus, nplus);
other_face = face=BMIter_Step(&face_iter);
while (other_face && !bSeam) {
int idx2 = BM_GetIndex(other_face);
- if (bPlus) {
+ if (bPlus >= 0) {
/* first face is in F+, so we look for face in F- for the seam */
- bSeam = find_index(idx2, fminus, nminus);
+ bSeam = find_element_in_array(idx2, fminus, nminus);
} else {
/* first face is in F-, so we look for face in F+ for the seam */
- bSeam = find_index(idx2, fplus, nplus);
+ bSeam = find_element_in_array(idx2, fplus, nplus);
}
other_face=BMIter_Step(&face_iter);
}
}
- if (bSeam){
+ if (bSeam >= 0){
BM_SetHFlag(edge, BM_SEAM);
}
}
@@ -108,18 +95,16 @@
}
}
-int is_element_in_array(int element, int *array, int num_array_element)
+int find_element_in_array(int element, int *array, int num_array_element)
{
- int i;
-
- for(i = 0; i < num_array_element; i++){
- if(array[i] == element) return 1;
- }
-
+ int i;
+ for(i = 0; i < num_array_element; i++)
+ if(array[i] == element) return i;
return -1;
}
-static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial, int num_faces, int *faces, int set_mapping )
+/* creates dual graph of the selected mesh*/
+static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial, int num_faces, int *faces)
{
BMEdge *edge;
BMLoop *loop;
@@ -127,7 +112,6 @@
float edge_length;
float poly_centres[2][3];
- //int k;
for(edge = BMIter_New(&edge_iter, bm, BM_EDGES_OF_MESH, bm ); edge; edge= BMIter_Step(&edge_iter))
{
@@ -137,8 +121,6 @@
BM_ITER(loop, &face_iter, bm, BM_LOOPS_OF_EDGE, edge) {
- //printf("indexes : %d %d\n", loop->f->head.index,loop->radial_next->f->head.index);
-
if(!combinatorial){
autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, 1.0);
min_value = 1.0;
@@ -154,13 +136,14 @@
edge_length = sqrt(dx*dx + dy*dy + dz*dz);
if(num_faces != -1){
- int is_first_index = is_element_in_array(loop->f->head.index, faces, num_faces);
+ int is_first_index = find_element_in_array(loop->f->head.index, faces, num_faces);
- if(is_first_index == 1){
- int is_second_index = is_element_in_array(loop->radial_next->f->head.index, faces, num_faces);
- if(is_second_index == 1){
- autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
+ if(is_first_index >= 0){
+ int is_second_index = find_element_in_array(loop->radial_next->f->head.index, faces, num_faces);
+
+ if(is_second_index >= 0){
+ autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
if(edge_length < min_value) min_value = edge_length;
}
@@ -195,7 +178,6 @@
}
/* do some additional tasks to make the call. */
state[u] = Black;
- //*num_nodes = *num_nodes - 1;
*remaining_nodes = *remaining_nodes - 1;
component[*component_size] = u;
*component_size = *component_size + 1;
@@ -276,37 +258,25 @@
float a,c,T, face_area;
float w, tmp[3];
float *uv[3];
- //vertices
float Ps[3], Pt[3];
float v[3][3];
- //edge vectors
- float e1[3], e2[3];
- float cross_product[3];
MLoopUV *luv;
- /* 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);
-
-
+
/* 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;
copy_v3_v3(v[i], looptris[i]->v->co);
}
+
+ face_area = 0.5 * (((uv[1][0] - uv[0][0])*(uv[2][1] - uv[0][1])) -
+ ((uv[2][0] - uv[0][0])*(uv[1][1] - uv[0][1])));
+ if (face_area <= 0.0f)
+ return 1e10f;
+
+ w = 1.0f/(2.0f*face_area);
+
// compute derivatives
copy_v3_v3(Ps, v[0]);
@@ -340,10 +310,7 @@
a= dot_v3v3(Ps, Ps);
c= dot_v3v3(Pt, Pt);
- T = sqrt(0.5f*(a + c));
-// if (face->flag & PFACE_FILLED)
-// T *= 0.2f;
-
+ T = sqrt(0.5f*(a + c));
return T;
}
@@ -422,7 +389,7 @@
autoseam_set_min_value(adj_plus, min_value);
for(i = 0; i < nplus; i++){
- /*set's the mapping of the face index.This is placed here to reduce extra computation.*/
+ /*sets the mapping of the face index.This is placed here to reduce extra computation.*/
autoseam_set_mapping(adj_plus, i, fplus[i]);
@@ -439,7 +406,7 @@
autoseam_set_min_value(adj_minus, min_value);
for(i = 0; i < nminus; i++){
- /*set's the mapping of the face index.This is placed here to reduce extra computation.*/
+ /*sets the mapping of the face index.This is placed here to reduce extra computation.*/
autoseam_set_mapping(adj_minus, i, fminus[i]);
for(j = i+1; j < nminus; j++){
@@ -478,8 +445,6 @@
static int generate_seam_exec(bContext *C, wmOperator *op)
{
AUTOSEAM_Adjacency adj;
- int i, iterations;
- //AUTOSEAM_Adjacency adj_big;
int maxdepth= RNA_int_get(op->ptr, "depth");
int is_combinatorial = RNA_boolean_get(op->ptr, "is_combinatorial");
int method = RNA_enum_get(op->ptr, "method");
@@ -502,7 +467,7 @@
autoseam_prepare_graph(bm);
/* this creates the adjacency matrix */
- autoseam_create_graph(adj, bm, is_combinatorial, -1, NULL, 1);
+ autoseam_create_graph(adj, bm, is_combinatorial, -1, NULL);
/* set the min value for adjcacency calculation. */
autoseam_set_min_value(adj, min_value);
@@ -567,12 +532,6 @@
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.");
- /* 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);
-
-
}
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-11 18:41:58 UTC (rev 38317)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h 2011-07-12 02:40:30 UTC (rev 38318)
@@ -71,6 +71,7 @@
int get_sign(float number);
static void autoseam_clear_seam(BMesh *bm);
int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch);
+int find_element_in_array(int element, int *array, int num_array_element);
More information about the Bf-blender-cvs
mailing list