[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38042] branches/soc-2011-avocado/blender: Handled meshes with separate parts.
shuvro sarker
shuvro05 at gmail.com
Sat Jul 2 18:41:01 CEST 2011
Revision: 38042
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38042
Author: shuvro
Date: 2011-07-02 16:41:01 +0000 (Sat, 02 Jul 2011)
Log Message:
-----------
Handled meshes with separate parts.
Modified Paths:
--------------
branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
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/intern/autoseam/AutoseamAdjacency.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp 2011-07-02 16:27:52 UTC (rev 38041)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp 2011-07-02 16:41:01 UTC (rev 38042)
@@ -23,7 +23,8 @@
int AutoseamAdjacency::get(int row, int col)
{
- return m_adjacency(row, col) > THRESHOLD_ZERO ? 1 : 0;
+ //return m_adjacency(row, col) > THRESHOLD_ZERO ? 1 : 0;
+ return m_adjacency(row, col);
}
void AutoseamAdjacency::set_map_default()
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-02 16:27:52 UTC (rev 38041)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c 2011-07-02 16:41:01 UTC (rev 38042)
@@ -27,40 +27,8 @@
*/
#include "autoseam_tools.h"
-#include "autoseam_C_API.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "WM_types.h"
-#include "RNA_types.h"
-#include "RNA_define.h"
-#include "RNA_access.h"
-#include "DNA_object_types.h"
-
-#include "BKE_material.h"
-#include "BKE_context.h"
-#include "BKE_customdata.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_cdderivedmesh.h"
-#include "BKE_depsgraph.h"
-#include "BKE_global.h"
-#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_bmesh.h"
-#include "BKE_report.h"
-#include "BKE_tessmesh.h"
-#include "BKE_main.h"
-
-#include "ED_screen.h"
-#include "MEM_guardedalloc.h"
-#include "WM_api.h"
-
-#define INF 999999
-
-static float min_value = INF;
-
int get_sign(float number){
return number > 0.0 ? 1 : 2;
}
@@ -211,7 +179,93 @@
}
}
+void depth_first_search(const AUTOSEAM_Adjacency adjacency, int u, enum GraphNodeColor state[], int* num_nodes, int *component, int *component_size, int *remaining_nodes)
+{
+ int v;
+ state[u] = Gray;
+ for (v = 0; v < *num_nodes; v++) {
+ if (u != v) {
+ double value = autoseam_get_value(adjacency, u, v);
+
+ /* Here mean value is global variable for a specific mesh. */
+ if ((value >= min_value) && state[v] == White) {
+ depth_first_search(adjacency, v, state, num_nodes, component, component_size, remaining_nodes);
+ }
+ }
+ }
+ /* 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;
+}
+int handle_separate_components(AUTOSEAM_Adjacency adj, int num_nodes, BMesh *bm, int recursion_depth)
+{
+ int i, j, k;
+ int remaining_nodes = num_nodes;
+ int component_count = 0;
+ int *component;
+ int component_size;
+ AUTOSEAM_Adjacency connected_adjacency;
+
+ enum GraphNodeColor *node_state = (enum GraphNodeColor*)MEM_callocN(num_nodes*sizeof(enum GraphNodeColor), "graph_nodes");
+ component = (int*)MEM_callocN(num_nodes*sizeof(int), "component");
+
+ /* initialization of the mesh*/
+ for(i = 0; i < num_nodes; i++){
+ node_state[i] = White;
+ }
+
+ while(remaining_nodes){
+
+ /* initialize component before each call of dfs */
+ component_size = 0;
+ for(i = 0; i < num_nodes; i++){
+ component[i] = -1; // initialize with invalid index
+ }
+
+ /* find a white node */
+ for(i = 0; i < num_nodes; i++){
+ if(node_state[i] == White) break;
+ }
+
+ /*there is another unvisited component in the mesh*/
+ if(i < num_nodes){
+
+ depth_first_search(adj, i , node_state, &num_nodes, component, &component_size, &remaining_nodes);
+ /* when depth_first_search returns for each index we have component size and one
+ * connected component each time. */
+
+ component_count++;
+ connected_adjacency = autoseam_create_adjacency(component_size);
+ autoseam_set_min_value(connected_adjacency, min_value);
+
+ /* prepare the adjacency matrix for the connected component */
+ for(j = 0; j < component_size; j++){
+ autoseam_set_mapping(connected_adjacency, j, component[j]);
+
+ for(k = 0; k < component_size; k++){
+ if(autoseam_is_adjacent(adj, component[j], component[k])){
+ autoseam_set_adjacent(connected_adjacency, j, k, autoseam_get_value(adj, component[j], component[k]));
+ }
+ }
+ }
+
+ /* now call the recursive function for a single component*/
+ generate_seam_recursive(bm, connected_adjacency, adj, recursion_depth);
+
+ }
+
+ }
+
+ /* after all the calls, free the allocated memories */
+ MEM_freeN(component);
+ MEM_freeN(node_state);
+ autoseam_delete_adjacency(adj);
+ return 0;
+}
int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth)
{
int s;
@@ -272,7 +326,6 @@
for(j = i+1; j < nminus; j++){
if(autoseam_is_adjacent(adj_big, fminus[i], fminus[j])){
- //printf("value is %d and %d range: %d\n",i,j, nminus);
autoseam_set_adjacent(adj_minus, i, j, autoseam_get_value(adj_big, fminus[i], fminus[j]));
}
@@ -307,35 +360,38 @@
BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
BMesh *bm = em->bm;
AUTOSEAM_Adjacency adj;
- AUTOSEAM_Adjacency adj_big;
+ //AUTOSEAM_Adjacency adj_big;
int maxdepth= RNA_int_get(op->ptr, "depth");
int is_combinatorial = RNA_boolean_get(op->ptr, "is_combinatorial");
int num_faces;
-
+
me->drawflag |= ME_DRAWSEAMS;
num_faces = BM_Count_Element(bm, BM_FACE);
adj = autoseam_create_adjacency(num_faces);
- adj_big = autoseam_create_adjacency(num_faces);
+ //adj_big = 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, is_combinatorial, -1, NULL, 1);
- autoseam_create_graph(adj_big, bm, is_combinatorial, -1, NULL, 1);
+ //autoseam_create_graph(adj_big, bm, is_combinatorial, -1, NULL, 1);
+
autoseam_set_min_value(adj, min_value);
- autoseam_set_min_value(adj_big, min_value);
+ //autoseam_set_min_value(adj_big, min_value);
/* clear if any seam already exists. */
autoseam_clear_seam(bm);
autoseam_set_map_default(adj);
- generate_seam_recursive(bm, adj, adj_big, maxdepth);
+ //generate_seam_recursive(bm, adj, adj_big, maxdepth);
+ /* This function will call the recusive function for each of the components of bmesh*/
+ handle_separate_components(adj, num_faces, bm, maxdepth);
- autoseam_delete_adjacency(adj_big);
+ //autoseam_delete_adjacency(adj_big);
/*reset the min_value*/
min_value = INF;
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-02 16:27:52 UTC (rev 38041)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.h 2011-07-02 16:41:01 UTC (rev 38042)
@@ -30,10 +30,48 @@
#define AUTOSEAM_TOOLS_H
#include "bmesh.h"
+#include "autoseam_C_API.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "WM_types.h"
+#include "RNA_types.h"
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+#include "DNA_object_types.h"
+
+#include "BKE_material.h"
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_bmesh.h"
+#include "BKE_report.h"
+#include "BKE_tessmesh.h"
+#include "BKE_main.h"
+
+#include "ED_screen.h"
+#include "MEM_guardedalloc.h"
+#include "WM_api.h"
+
+#define INF 999999
+
+static float min_value = INF;
+enum GraphNodeColor { White, Gray, Black };
+
+
void calculate_eigen(float **dual_graph, int dimension, float **eigen_vectors, float *eigen_valuess);
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);
+
+
#endif
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list