[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37789] branches/soc-2011-avocado/blender/ source/blender/editors/mesh/autoseam_tools.c: Done some progress on recursive implementation of autoseam.
shuvro sarker
shuvro05 at gmail.com
Fri Jun 24 12:56:09 CEST 2011
Revision: 37789
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37789
Author: shuvro
Date: 2011-06-24 10:56:08 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
Done some progress on recursive implementation of autoseam. Not in a proper functioning position for now. Need to do some more works on it.
Modified Paths:
--------------
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
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-06-24 06:39:03 UTC (rev 37788)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c 2011-06-24 10:56:08 UTC (rev 37789)
@@ -58,6 +58,7 @@
#include "bmesh.h"
#include "WM_api.h"
+#define MAX_DEPTH 4
int get_sign(float number){
return number > 0.0 ? 1 : 2;
@@ -130,15 +131,30 @@
}
}
-static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial)
+int is_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;
+ }
+
+ return -1;
+}
+
+static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial, int num_faces, int *faces )
+{
BMEdge *edge;
BMLoop *loop;
BMIter edge_iter, face_iter;
float edge_length;
float poly_centres[2][3];
+ int k;
+ for( k = 0; k < num_faces; k++) printf("%d ", faces[k]);
+ printf("\n");
+
for(edge = BMIter_New(&edge_iter, bm, BM_EDGES_OF_MESH, bm ); edge; edge= BMIter_Step(&edge_iter))
{
/* if not boundary edge */
@@ -163,7 +179,21 @@
dz = poly_centres[0][2] - poly_centres[1][2];
edge_length = sqrt(dx*dx + dy*dy + dz*dz);
- autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
+ if(num_faces != -1){
+ int is_first_index = is_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){
+ printf("edge :%d %d", loop->f->head.index, loop->radial_next->f->head.index);
+ autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
+ }
+ }
+
+ }
+ else{
+ autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
+ }
}
}
@@ -173,51 +203,158 @@
}
+static int recursion_depth = 0;
+
+int generate_seam_recursive(BMesh *bm, int *fplus_p, int nplus_p, int *fminus_p, int nminus_p)
+{
+
+
+ AUTOSEAM_Adjacency adj;
+ AUTOSEAM_Adjacency adj_second;
+ int num_faces;
+ static int s, s2;
+ int *fplus, *fminus;
+ int *fplus2, *fminus2;
+
+ int nplus = nplus_p;
+ int nminus = nminus_p;
+
+ int nplus2, nminus2;
+
+ fplus = fplus_p;
+ fminus = fminus_p;
+
+
+ num_faces = BM_Count_Element(bm, BM_FACE);
+
+ while(recursion_depth < MAX_DEPTH)
+ {
+ if(!recursion_depth){
+
+ adj = autoseam_create_adjacency(num_faces);
+
+ autoseam_prepare_graph(bm);
+ autoseam_create_graph(adj, bm, 1, -1, NULL);
+ autoseam_generate_seam(adj);
+
+ s = autoseam_get_best_split(adj);
+
+ fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
+ fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
+
+ autoseam_get_split(adj, s, fplus, &nplus, fminus, &nminus);
+
+ /* mark the seam on the mesh */
+ autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
+
+ autoseam_delete_adjacency(adj);
+ recursion_depth++;
+ generate_seam_recursive(bm,fplus, nplus, fminus, nminus);
+
+
+ }
+
+ else{
+
+ adj = autoseam_create_adjacency(num_faces);
+
+ autoseam_create_graph(adj, bm, 1, nplus , fplus);
+ MEM_freeN(fplus);
+ autoseam_generate_seam(adj);
+
+ adj_second = autoseam_create_adjacency(num_faces);
+ autoseam_create_graph(adj_second, bm, 1, nminus , fminus);
+ MEM_freeN(fminus);
+ autoseam_generate_seam(adj_second);
+
+
+ s = autoseam_get_best_split(adj);
+
+ fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
+ fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
+
+ autoseam_get_split(adj, s, fplus, &nplus, fminus, &nminus);
+ autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
+ autoseam_delete_adjacency(adj);
+
+
+
+ s2 = autoseam_get_best_split(adj_second);
+
+ fplus2 = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus2");
+ fminus2 = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus2");
+
+ autoseam_get_split(adj_second, s2, fplus2, &nplus2, fminus2, &nminus2);
+ autoseam_mark_seam(bm, fplus2, nplus2, fminus2, nminus2);
+ autoseam_delete_adjacency(adj_second);
+
+
+ recursion_depth++;
+ generate_seam_recursive(bm,fplus, nplus, fminus, nminus);
+ generate_seam_recursive(bm,fplus2, nplus2, fminus2, nminus2);
+
+
+ //recursion_depth++;
+ //generate_seam_recursive(bm);
+
+
+
+ }
+
+ }
+
+ return 0;
+
+}
+
static int generate_seam_exec(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
Mesh *me= ((Mesh *)obedit->data);
BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
BMesh *bm = em->bm;
- AUTOSEAM_Adjacency adj;
+// AUTOSEAM_Adjacency adj;
- int s;
- int *fplus;
- int *fminus;
- int nplus = 0;
- int nminus = 0;
- int num_faces;
+// int s;
+// int *fplus;
+// int *fminus;
+// int nplus = 0;
+// int nminus = 0;
+// int num_faces;
me->drawflag |= ME_DRAWSEAMS;
- num_faces = BM_Count_Element(bm, BM_FACE);
+// num_faces = BM_Count_Element(bm, BM_FACE);
- adj = autoseam_create_adjacency(num_faces);
+// adj = autoseam_create_adjacency(num_faces);
+//
+// /* set initial indices, found out this is necessary, they get reset on operator redo */
+// autoseam_prepare_graph(bm);
+//
+// /* this creates the adjacency matrix */
+// autoseam_create_graph(adj, bm, 1, -1, NULL);
+//
+// /* calculate the eigenvalues and the actual seam */
+// autoseam_generate_seam(adj);
+//
+// /* retrieve the best seam */
+// s = autoseam_get_best_split(adj);
+//
+// fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
+// fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
+//
+// autoseam_get_split(adj, s, fplus, &nplus, fminus, &nminus);
+//
+// /* mark the seam on the mesh */
+// autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
+//
+// MEM_freeN(fplus);
+// MEM_freeN(fminus);
+//
+// autoseam_delete_adjacency(adj);
- /* set initial indices, found out this is necessary, they get reset on operator redo */
- autoseam_prepare_graph(bm);
+ generate_seam_recursive(bm,NULL, -1, NULL, -1);
+ recursion_depth = 0;
- /* this creates the adjacency matrix */
- autoseam_create_graph(adj, bm, 1);
-
- /* calculate the eigenvalues and the actual seam */
- autoseam_generate_seam(adj);
-
- /* retrieve the best seam */
- s = autoseam_get_best_split(adj);
-
- fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
- fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
-
- autoseam_get_split(adj, s, fplus, &nplus, fminus, &nminus);
-
- /* mark the seam on the mesh */
- autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
-
- MEM_freeN(fplus);
- MEM_freeN(fminus);
-
- autoseam_delete_adjacency(adj);
-
DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
More information about the Bf-blender-cvs
mailing list