[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39405] branches/soc-2011-avocado/blender: Removal of AutoseamUtility class,

shuvro sarker shuvro05 at gmail.com
Mon Aug 15 06:53:54 CEST 2011


Revision: 39405
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39405
Author:   shuvro
Date:     2011-08-15 04:53:53 +0000 (Mon, 15 Aug 2011)
Log Message:
-----------
Removal of AutoseamUtility class,
               Added two options for stretch calculation in the user interface

Modified Paths:
--------------
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.h
    branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h
    branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c

Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.cpp	2011-08-15 04:11:55 UTC (rev 39404)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.cpp	2011-08-15 04:53:53 UTC (rev 39405)
@@ -66,69 +66,8 @@
 }
 
 
-AutoseamUtility::AutoseamUtility()
-{
-	m_A <<  1.0f, 2.0f, 0.0f,
-			0.0f, 2.0f, 3.0f,
-			0.0f, 0.0f, 3.0f;
-	
-}
 
-static double row_sum(MatrixXd matrix, int dimension, int row_index) {
-	double result = 0.0 ;
 
-	for (int i = 0; i < dimension; i++) {
-		result += matrix(row_index, i);
-	}
-	return result ;
-}
 
 
 
-
-void AutoseamUtility::calculate_eigen(float **dual_matrix, int num_row, int num_col, float **eigen_vectors, float *eigen_values)
-{
-	int i,l,r_index,c_index;
-	dualMatrix.resize(num_row, num_col);
-	
-
-	for(c_index = 0; c_index < num_col; c_index++){
-		for(r_index = 0; r_index < num_row; r_index++){
-			if(dual_matrix[r_index][c_index] != 0.0){
-				dualMatrix(r_index, c_index) = dual_matrix[r_index][c_index];
-			}
-			else dualMatrix(r_index, c_index) = 0;
-		}
-	}
-	
-	for( l = 0; l < num_row; l++ ){
-		dualMatrix(l,l) = - row_sum(dualMatrix, num_row, l);
-	}
-
-	// we need to replace this portion with our eigen generation code
-	Eigen::EigenSolver<MatrixXd> es(dualMatrix);
-	
-	
-	
-	/**
-	 * Pack the calculated eigen vectors and eigen values to 
-	 * eigen_vectors and eigen_values.
-	 */
-	
-	for(i = 0; i < num_col; i++ )
-	{
-		int num_vectors = es.eigenvectors().cols();
-		int loop;
-		
-		eigen_values[i] = es.eigenvalues()[i].real();
-				
-		for(loop = 0; loop < num_vectors; loop++){
-			eigen_vectors[i][loop] = es.eigenvectors().col(i)[loop].real();
-			
-			
-		}
-		
-	}
-
-	
-}

Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.h	2011-08-15 04:11:55 UTC (rev 39404)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamUtility.h	2011-08-15 04:53:53 UTC (rev 39405)
@@ -41,20 +41,8 @@
 void depth_first_search(const MatrixXd& adjacency, int u, GraphNodeColor state[], float min_value);
 
 
-class AutoseamUtility
-{
-	public:
-		AutoseamUtility();
 
-		void calculate_eigen(float **dual_matrix, int num_row, int num_col, float **eigen_vectors, float *eigen_values);
 
-		Eigen::Matrix3f m_A;
-		Eigen::Vector3f m_x;
-		Eigen::MatrixXd dualMatrix;
 
-};
 
-
-
-
 #endif
\ No newline at end of file

Modified: branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp	2011-08-15 04:11:55 UTC (rev 39404)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp	2011-08-15 04:53:53 UTC (rev 39405)
@@ -37,25 +37,9 @@
 #include "AutoseamAdjacency.h"
 #include "autoseam_C_API.h"
 
-AUTOSEAM_UtilityClassHandle autoseam_create_utility()
-{
-	AutoseamUtility *utility = new AutoseamUtility();
-	return (AUTOSEAM_UtilityClassHandle) utility;
-}
 
-void autoseam_delete_utility(AUTOSEAM_UtilityClassHandle handle)
-{
-	AutoseamUtility *utility = reinterpret_cast<AutoseamUtility*>(handle);
-	delete utility;
-}
 
-void autoseam_calculate_eigen(AUTOSEAM_UtilityClassHandle handle, float** vec, int dimension, float **eigen_vectors, float *eigen_values)
-{
-	AutoseamUtility *utility = reinterpret_cast<AutoseamUtility*>(handle);
-	utility->calculate_eigen(vec, dimension, dimension, eigen_vectors, eigen_values);
-}
 
-
 AUTOSEAM_Adjacency autoseam_create_adjacency(int dimension)
 {
 	AutoseamAdjacency *adj = new AutoseamAdjacency(dimension);

Modified: branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h	2011-08-15 04:11:55 UTC (rev 39404)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h	2011-08-15 04:53:53 UTC (rev 39405)
@@ -39,10 +39,7 @@
 AUTOSEAM_DECLARE_HANDLE(AUTOSEAM_UtilityClassHandle);
 AUTOSEAM_DECLARE_HANDLE(AUTOSEAM_Adjacency);
 
-AUTOSEAM_UtilityClassHandle autoseam_create_utility();
-void autoseam_delete_utility(AUTOSEAM_UtilityClassHandle handle);
 
-void autoseam_calculate_eigen(AUTOSEAM_UtilityClassHandle handle, float** vec, int dimension, float **eigen_vectors, float *eigen_values);
 	
 /* Laplacian Matrix */
 AUTOSEAM_Adjacency autoseam_create_adjacency(int dimension);

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-08-15 04:11:55 UTC (rev 39404)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c	2011-08-15 04:53:53 UTC (rev 39405)
@@ -63,12 +63,14 @@
 #include "autoseam_C_API.h"
 
 
+
+
 #define INF 999999
 
 static float min_value = INF;
 enum GraphNodeColor { White, Gray, Black };
 static void autoseam_clear_seam(BMesh *bm);
-static int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch);
+static int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch, int current_algo);
 static int find_element_in_array(int element, int *array, int num_array_element);
 
 
@@ -228,7 +230,7 @@
 	*component_size = *component_size + 1;
 }
 
-static int next_component(BMesh *bm, GHash *visithash, int recursion_depth, bContext *C)
+static int next_component(BMesh *bm, GHash *visithash, int recursion_depth, bContext *C, int stretch_type)
 {
 	GHash* component = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "autoseam_component");
 	AUTOSEAM_Adjacency adj;
@@ -289,7 +291,7 @@
 	autoseam_set_min_value(adj, min_value);
 	autoseam_set_map_default(adj);
 	
-	generate_seam_recursive(bm, adj, adj, recursion_depth, C, -1.0);
+	generate_seam_recursive(bm, adj, adj, recursion_depth, C, -1.0, stretch_type);
 	
 	BLI_ghash_free(component, NULL, NULL);
 	return 0;
@@ -297,20 +299,20 @@
 
 
 
-static void do_all_components(BMesh *bm, int recursion_depth, bContext *C) {
+static void do_all_components(BMesh *bm, int recursion_depth, bContext *C, int stretch_type) {
 	
 	GHash* visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "autoseam_visited");
 	int done = 0;
 	
 	while (!done) {
-		done = next_component(bm, visithash, recursion_depth, C);
+		done = next_component(bm, visithash, recursion_depth, C, stretch_type);
 	}
 	
 	BLI_ghash_free(visithash, NULL, NULL);
 }
 
 
-static int handle_separate_components(AUTOSEAM_Adjacency adj, int num_nodes, BMesh *bm, int recursion_depth, bContext *C)
+static int handle_separate_components(AUTOSEAM_Adjacency adj, int num_nodes, BMesh *bm, int recursion_depth, bContext *C, int stretch_type)
 {
 	int i, j, k;
 	int remaining_nodes = num_nodes;
@@ -363,7 +365,7 @@
 			}
 			
 			/* now call the recursive function for a single component*/
-			generate_seam_recursive(bm, connected_adjacency, adj, recursion_depth, C, -1.0);
+			generate_seam_recursive(bm, connected_adjacency, adj, recursion_depth, C, -1.0, stretch_type);
 			
 		}
 		
@@ -482,6 +484,11 @@
 	BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
 	BMesh *bm = em->bm;
 	
+	if(!ED_uvedit_ensure_uvs(C, scene, obedit)) {
+		//invalid case
+		return -1.0;
+	}
+	
 	ED_unwrap_lscm(scene, obedit, TRUE);
 	
 	for (i=0; i < em->tottri; i++) {
@@ -494,7 +501,7 @@
 	return max_stretch;
 }
 
-static int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch)
+static int generate_seam_recursive(BMesh *bm, AUTOSEAM_Adjacency adj, AUTOSEAM_Adjacency adj_big, int recursion_depth, bContext *C, float stretch, int current_algo)
 {
 	int s;
 	int i, j;
@@ -518,8 +525,14 @@
 	 */
 	else{
 		//float temp = total_stretch_of_mesh(C);
-		float temp = average_stretch_of_mesh(C);
+		float temp;
 		
+		if(current_algo == 1)
+			temp = maximum_stretch_of_mesh(C);
+		else
+			temp = average_stretch_of_mesh(C);
+
+		
 		/* stretch is increasing, so stop here*/
 		if(temp > stretch) {
 			
@@ -596,12 +609,12 @@
 	/* 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, stretch);
+		generate_seam_recursive(bm, adj_plus, adj_big, recursion_depth, C, stretch, current_algo);
 
 	}
 	if(nminus > 0){
 		//same is applicable for this part.
-		generate_seam_recursive(bm, adj_minus, adj_big, recursion_depth, C, stretch);
+		generate_seam_recursive(bm, adj_minus, adj_big, recursion_depth, C, stretch, current_algo);
 	}
 	
 	autoseam_delete_adjacency(adj);
@@ -620,6 +633,7 @@
 	int correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
 	int num_faces;
 	int is_live_unwrap = RNA_boolean_get(op->ptr, "live_unwrap");
+	int stretch_algo   = RNA_enum_get(op->ptr, "stretch_type"); 
 	
 	Scene *scene= CTX_data_scene(C);
 	Object *obedit= CTX_data_edit_object(C);
@@ -651,7 +665,7 @@
 	
 	/* This function will call the recusive function for each of the components of bmesh*/
 	//handle_separate_components(adj, num_faces, bm, maxdepth, C);
-	do_all_components(bm, maxdepth, C);
+	do_all_components(bm, maxdepth, C, stretch_algo);
 	
 	
 	
@@ -701,6 +715,13 @@
 		{1, "CONFORMAL", 0, "Conformal", ""},
 		{0, NULL, 0, NULL, NULL}};
 	
+	static EnumPropertyItem prop_stretch_algo_types[] = {
+		{1, "MAX", 0, "Maximum Stretch"},
+		{2, "AVERAGE", 0, "Average Stretch", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	
 	/* identifiers */
 	ot->name= "Generate Seam";
 	ot->idname= "MESH_OT_generate_seam";
@@ -713,13 +734,16 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
+	RNA_def_enum(ot->srna, "stretch_type", prop_stretch_algo_types, 1, "Stretch Type", "");
 	RNA_def_int(ot->srna, "depth", 3, 1, 6, "Recursion Depth", "Max. recursion depth", 0, 6);
 	RNA_def_boolean(ot->srna, "is_combinatorial", 0, "Combinatorial", "Consider actual face centers for calculation.");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list