[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38874] branches/soc-2011-avocado/blender/ intern/autoseam: Tablification of the code and some code clean up.

shuvro sarker shuvro05 at gmail.com
Sun Jul 31 09:03:02 CEST 2011


Revision: 38874
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38874
Author:   shuvro
Date:     2011-07-31 07:03:02 +0000 (Sun, 31 Jul 2011)
Log Message:
-----------
Tablification of the code and some code clean up.

Modified Paths:
--------------
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h
    branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h

Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp	2011-07-31 06:38:23 UTC (rev 38873)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp	2011-07-31 07:03:02 UTC (rev 38874)
@@ -44,7 +44,7 @@
 	m_index_map_vector.resize(dimension, -1);
 	mul_vec     = Eigen::VectorXd(dimension);
 	matrix_dimension = dimension;
-	//threshold_value = min_value;
+	
 }
 
 void AutoseamAdjacency::set(int row, int col, float value)
@@ -94,7 +94,7 @@
 
 void AutoseamAdjacency::set_mapping(int index, int value)
 {
-	//m_index_map[index] =  value;
+	
 	m_index_map_vector[index] = value;
 }
 
@@ -130,42 +130,32 @@
 	//eigen_vectors = calculate_eigen_arpack();
 	
 
-	// Need to modify the errors of the commented code.
 	
+	
 	EigenSolverArpack solver(matrix_dimension);
 	//solver.matrix =  a;
-    // We need to set up our matrix here.
-    
-    //logic: if any member of a is non-zero then push it into the matrix
-    for (int i = 0; i < n; i++) {
-        for (int j = 0; j < n; j++) {
-            if(fabs(a(i,j)) > VALUE_ZERO){
-                solver.sparse_matrix(i,j) = a(i,j);
-            }
-        }
-    }
-    
+	// We need to set up our matrix here.
+	for (int i = 0; i < n; i++) {
+		for (int j = 0; j < n; j++) {
+			if(fabs(a(i,j)) > VALUE_ZERO){
+				solver.sparse_matrix(i,j) = a(i,j);
+			}
+		}
+	}
+	
 	eigen_vectors = solver.calculate_eigen_space();
 	
 	if(a.rows() && a.cols() && eigen_vectors != NULL){
 		
-		//Eigen::SelfAdjointEigenSolver<MatrixXd> es(a);
-		//Eigen::VectorXd evalues(es.eigenvalues());
 		int f = 0;
 		bool found = false;
 
 		MatrixXd aplus;
 		MatrixXd aminus;
 	
-		//while ( (f < num_eigen_values)) {
+
 		while ( (f < solver.num_eigen_vectors)) {
-			// Eigenvalues seem to be sorted largest to smallest, we need the 30 smallest
-			// in the future only those will be calculated by the algorithm (if we use ARPACK)
 			
-			//if(fabs(eigen_values[n-f-1]) > 0.0005){
-			//if(fabs(eigen_values[f]) > 0.0005){
-			
-			printf("eigen values: %f\n", fabs(solver.eigen_values[f]));
 			if(fabs(solver.eigen_values[f]) > THRESHOLD_ZERO){
 				
 				int loop;
@@ -185,7 +175,7 @@
 				aes->split();
 				aes->fill_adjacency(a, aplus, aminus);
 			
-				// printf("four values are: %d %d %d %d", aplus.rows(), aplus.cols(), aminus.rows(), aminus.cols());
+				
 				// We filter out eigenspaces that give non-connected F+ and F- as in the paper
 				if ((is_graph_connected(aplus, threshold_value) && is_graph_connected(aminus, threshold_value))) {
 					m_eigenspaces.push_back(aes);

Modified: branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.cpp	2011-07-31 06:38:23 UTC (rev 38873)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.cpp	2011-07-31 07:03:02 UTC (rev 38874)
@@ -33,7 +33,7 @@
 EigenSolver::EigenSolver(int dimension)
 {
 	matrix_dimension  = dimension;
-    sparse_matrix     = SparseMatrix<double> (dimension);
+	sparse_matrix     = SparseMatrix<double> (dimension);
 	
 }
 

Modified: branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h	2011-07-31 06:38:23 UTC (rev 38873)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h	2011-07-31 07:03:02 UTC (rev 38874)
@@ -40,10 +40,10 @@
 		
 	
 	public:
-        int  num_eigen_vectors;
-        SparseMatrix<double> sparse_matrix;
+		int  num_eigen_vectors;
+		SparseMatrix<double> sparse_matrix;
 		EigenSolver(int dimension);
-        virtual double * calculate_eigen_space() = 0;        // Declared it as pure virtual, so that subclasses must have to implement this.
+		virtual double * calculate_eigen_space() = 0;        // Declared it as pure virtual, so that subclasses must have to implement this.
 		~EigenSolver();
 		
 	

Modified: branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp	2011-07-31 06:38:23 UTC (rev 38873)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp	2011-07-31 07:03:02 UTC (rev 38874)
@@ -53,30 +53,6 @@
 	
 }
 
-/*int EigenSolverArpack:: mul_matrix_vector(int dimension, double *vec, double * result)
-{
-	int i;
-	Eigen::VectorXd output(dimension);
-	Eigen::VectorXd mul_vec(dimension);
-	
-	//printf("the dimesion passed here : %d\n The output values are: \n", dimension);
-	
-	for(i = 0; i < dimension; i++){
-		//printf("%lf ", *(vec + i));
-		mul_vec(i) = *(vec + i);
-	}
-	
-	output = matrix * mul_vec;
-	
-	//pack the values into result
-	for(i = 0; i < dimension; i++){
-		//printf("%lf ", output(i));
-		*(result + i) = output(i);
-	}
-	
-	return 0;
-	
-}*/
 
 
 double * EigenSolverArpack:: calculate_eigen_space()
@@ -200,7 +176,7 @@
 			//perform matrix-vector multiplication
 			//av_(&nx, &workd[ipntr[0] - 1], &workd[ipntr[1] - 1]);
 			//mul_matrix_vector(n, &workd[ipntr[0] - 1], &workd[ipntr[1] - 1]);
-            sparse_matrix.mul_matrix_vector(n, &workd[ipntr[0] - 1], &workd[ipntr[1] - 1]);
+			sparse_matrix.mul_matrix_vector(n, &workd[ipntr[0] - 1], &workd[ipntr[1] - 1]);
 			//goto L10;
 		}
 		else{

Modified: branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h	2011-07-31 06:38:23 UTC (rev 38873)
+++ branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h	2011-07-31 07:03:02 UTC (rev 38874)
@@ -1,3 +1,32 @@
+/* $Id: SparseMatrix.h 38873 2011-07-31 06:38:23Z shuvro $ 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2011 by Shuvro Sarker.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Shuvro Sarker
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+
 #ifndef _SPARSE_MATRIX_H
 #define	_SPARSE_MATRIX_H
 
@@ -15,98 +44,98 @@
 class SparseMatrix
 {
 public:
-    typedef std::map<size_t, std::map<size_t , T> > mat_t;
-    typedef typename mat_t::iterator row_iter;
-    typedef std::map<size_t, T> col_t;
-    typedef typename col_t::iterator col_iter;
-    
-    SparseMatrix(){};
-    SparseMatrix(size_t i){ m=i; n=i; }
-    SparseMatrix(size_t i, size_t j){ m=i; n=j; }
+	typedef std::map<size_t, std::map<size_t , T> > mat_t;
+	typedef typename mat_t::iterator row_iter;
+	typedef std::map<size_t, T> col_t;
+	typedef typename col_t::iterator col_iter;
+	
+	SparseMatrix(){};
+	SparseMatrix(size_t i){ m=i; n=i; }
+	SparseMatrix(size_t i, size_t j){ m=i; n=j; }
 
-    inline
-    T& operator()(size_t i, size_t j)
-    {
-        if(i>=m || j>=n) throw;
-        return mat[i][j];
-    }
-    inline
-    T operator()(size_t i, size_t j) const
-    {
-        if(i>=m || j>=n) throw;
-        return mat[i][j];
-    }
+	inline
+	T& operator()(size_t i, size_t j)
+	{
+		if(i>=m || j>=n) throw;
+		return mat[i][j];
+	}
+	inline
+	T operator()(size_t i, size_t j) const
+	{
+		if(i>=m || j>=n) throw;
+		return mat[i][j];
+	}
 
-    /**
-     * Multiplies vector x with matrix m and returns
-     * the result as a vector.
-     */
-    std::vector<T> operator*(const std::vector<T>& x)
-    {  
-        if(this->m != x.size()) throw;
-        
-        std::vector<T> y(this->m);
-        T sum;
-        
-        row_iter ii;
-        col_iter jj;
-        
-        for(ii=this->mat.begin(); ii!=this->mat.end(); ii++){
-            sum=0;
-            for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){
-                sum += (*jj).second * x[(*jj).first];
-            }
-            y[(*ii).first]=sum;
-        }
-        
-        return y;
-    }
-    
-    /**
-     * Multiplies input_vector of length dimension with matrix m and stores
-     * it in result. Both the input_vector and the result need to be a valid
-     * pointer of type T
-     */
-    void mul_matrix_vector(int dimension, T *input_vector, T * result)
-    {
-        if(this->m != dimension) throw;
-        
-        T sum;
-        
-        row_iter ii;
-        col_iter jj;
-        
-        for(ii=this->mat.begin(); ii!=this->mat.end(); ii++){
-            sum=0;
-            for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){
-                sum += (*jj).second *  input_vector[(*jj).first];
-            }
-            result[(*ii).first]=sum;
-        }
-    
-    }
+	/**
+	 * Multiplies vector x with matrix m and returns
+	 * the result as a vector.
+	 */
+	std::vector<T> operator*(const std::vector<T>& x)
+	{  
+		if(this->m != x.size()) throw;
+		
+		std::vector<T> y(this->m);
+		T sum;
+		
+		row_iter ii;
+		col_iter jj;
+		
+		for(ii=this->mat.begin(); ii!=this->mat.end(); ii++){
+			sum=0;
+			for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){
+				sum += (*jj).second * x[(*jj).first];
+			}
+			y[(*ii).first]=sum;
+		}
+		
+		return y;
+	}
+	
+	/**
+	 * Multiplies input_vector of length dimension with matrix m and stores
+	 * it in result. Both the input_vector and the result need to be a valid
+	 * pointer of type T
+	 */
+	void mul_matrix_vector(int dimension, T *input_vector, T * result)
+	{
+		if(this->m != dimension) throw;
+		
+		T sum;
+		
+		row_iter ii;
+		col_iter jj;
+		
+		for(ii=this->mat.begin(); ii!=this->mat.end(); ii++){
+			sum=0;
+			for(jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++){

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list