Revision: 38885
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38885
Author:   shuvro
Date:     2011-08-01 02:40:09 +0000 (Mon, 01 Aug 2011)
Log Message:
-----------
Code restructure and clean up. Class level and function level comments added in 
the EigenSolverArpack class.

Modified Paths:
--------------
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.h
    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/EigenSolverArpack.h

Modified: 
branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp     
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp     
2011-08-01 02:40:09 UTC (rev 38885)
@@ -112,8 +112,7 @@
 
 bool AutoseamAdjacency::generate_seam()
 {
-       
-       double *eigen_vectors;
+       eigen_vectors vectors;
        MatrixXd& a = m_adjacency;
        
        clear_eigenspaces();
@@ -127,13 +126,8 @@
                a(i,i) = -rowsum;
        }
        
-       //eigen_vectors = calculate_eigen_arpack();
-       
-
-       
-       
        EigenSolverArpack solver(matrix_dimension);
-       //solver.matrix =  a;
+       
        // We need to set up our matrix here.
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
@@ -143,9 +137,9 @@
                }
        }
        
-       eigen_vectors = solver.solve();
+       vectors = solver.solve();
        
-       if(a.rows() && a.cols() && eigen_vectors != NULL){
+       if(a.rows() && a.cols() && vectors.size()){
                
                int f = 0;
                bool found = false;
@@ -158,21 +152,7 @@
                        
                        if(fabs(solver.eigenvalue(f)) > THRESHOLD_ZERO){
                                
-                               int loop;
-                               //now construct a vector with the values
-                               std::vector<double> eig_vector = 
solver.eigenvector(f);
-                               Eigen::VectorXd eigen_vector = 
Eigen::VectorXd(matrix_dimension);
-                               
-                               for(loop = 0; loop < matrix_dimension; loop++){
-                                       
-                                       //eigen_vector(loop) = *(eigen_vectors 
+ f*matrix_dimension + loop);
-                                       eigen_vector(loop) = eig_vector[loop];
-                               }
-                               
-                               
-                               //AutoseamEigenspace* aes = new 
AutoseamEigenspace(evalues[n-f-1], es.eigenvectors().col(n-f-1));
-                               //AutoseamEigenspace* aes = new 
AutoseamEigenspace(eigen_values[f], eigen_vector);
-                               AutoseamEigenspace* aes = new 
AutoseamEigenspace(solver.eigenvalue(f), eigen_vector);
+                               AutoseamEigenspace* aes = new 
AutoseamEigenspace(solver.eigenvalue(f), solver.eigenvector(f));
                                // split Eigenspace into two subspaces F+ and 
F- where the ith entry in the eigenvector is positive/negative
                                aes->split();
                                aes->fill_adjacency(a, aplus, aminus);
@@ -191,11 +171,10 @@
                        f++;
                }
                
-               MEM_freeN(eigen_vectors);
+               
                return found;
        }
        
-       MEM_freeN(eigen_vectors);
        return 0;
 }
 

Modified: 
branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.cpp    
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.cpp    
2011-08-01 02:40:09 UTC (rev 38885)
@@ -31,7 +31,8 @@
 
 #define THRESHOLD_ZERO 0.0001
 
-AutoseamEigenspace::AutoseamEigenspace(double eigenval, const Eigen::VectorXd& 
eigenvector)
+//AutoseamEigenspace::AutoseamEigenspace(double eigenval, const 
Eigen::VectorXd& eigenvector)
+AutoseamEigenspace::AutoseamEigenspace(double eigenval, const 
std::vector<double> eigenvector)
 : e(eigenval), v(eigenvector)
 {
 
@@ -114,6 +115,14 @@
 
 void AutoseamEigenspace::debug(std::ofstream& fout)
 {
+       int i, length_vector;
        fout << "Eigenvalue: " << e << std::endl;
-       fout << "Eigenvector: " << (Eigen::VectorXd)v << std::endl;
+       
+       fout << "Eigenvector: " ;
+       length_vector = v.size();
+       for (i = 0; i < length_vector; i++) {
+                       fout << v[i] << " ";
+       }
+       fout << std::endl;
+       
 }
\ No newline at end of file

Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.h      
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamEigenspace.h      
2011-08-01 02:40:09 UTC (rev 38885)
@@ -35,7 +35,8 @@
 class AutoseamEigenspace
 {
        public:
-               AutoseamEigenspace(double eigenval, const Eigen::VectorXd& 
eigenvector);
+               //AutoseamEigenspace(double eigenval, const Eigen::VectorXd& 
eigenvector);
+               AutoseamEigenspace(double eigenval, const std::vector<double> 
eigenvector);
                void split();
                void fill_adjacency(const Eigen::MatrixXd& adj, 
Eigen::MatrixXd& adj_plus, Eigen::MatrixXd& adj_minus);
                void get(int *fplus, unsigned int* nplus, int* fminus, unsigned 
int* nminus);
@@ -45,7 +46,8 @@
 
        private:
                double e;
-               Eigen::VectorXd v;
+               //Eigen::VectorXd v;
+               std::vector<double> v;
        
                std::vector<int> m_fplus;
                std::vector<int> m_fminus;

Modified: branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h     
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolver.h     
2011-08-01 02:40:09 UTC (rev 38885)
@@ -49,7 +49,7 @@
                SparseMatrix<double> sparse_matrix;
                EigenSolver(int dimension);
                virtual int num_eigenvalues();
-               virtual double * solve() = 0;    
+               virtual eigen_vectors solve() = 0;    
                virtual double eigenvalue(int n) = 0;
                virtual std::vector<double> eigenvector(int n) = 0;
        

Modified: 
branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp     
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.cpp     
2011-08-01 02:40:09 UTC (rev 38885)
@@ -26,6 +26,12 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+
+/**
+ * This class calculates eigen values and eigen vectors using the routines of
+ * the numerical library ARPACK.
+ */
+
 #include "EigenSolverArpack.h"
 #include "MEM_guardedalloc.h"
 #include <stdio.h>
@@ -50,11 +56,14 @@
 
 EigenSolverArpack::EigenSolverArpack(int dimension) : EigenSolver(dimension)
 {
-       //
-       // Allocate memories for eigenspace
-       
+               
 }
 
+/**
+ * Returns the nth eigen vector. n must be less than the number 
+ * of eigen vectors calculated. It will be avaiable to call after the
+ * execution of the solve function.
+ */
 std::vector<double> EigenSolverArpack::eigenvector(int n){
        
        if (n < eig_vectors.size()) {
@@ -66,12 +75,21 @@
        
 }
 
+/**
+ * Returns the nth eigen value. It will be avaiable to call after the
+ * execution of the solve function.
+ */
 double EigenSolverArpack:: eigenvalue(int n)
 {
        return eigen_values[n];
 }
 
-double * EigenSolverArpack:: solve()
+
+/**
+ * Calculates the eigen values and eigen vectors using ARPACK functions
+ * and returns a vector of eigen vectors
+ */
+eigen_vectors  EigenSolverArpack:: solve()
 {
        
 #ifdef WITH_ARPACK
@@ -127,27 +145,25 @@
        
        if (n > ldv) {
                printf(" ERROR with _SSIMP: N is greater than MAXN \n");
-               //goto L9000;
-               return NULL;
+               eig_vectors.clear();
+               return eig_vectors;
        }
        else if (nev > NUM_EIGEN_VAL) {
                printf(" ERROR with _SSIMP: NEV is greater than MAXNEV \n");
-               //goto L9000;
-               return NULL;
+               eig_vectors.clear();
+               return eig_vectors;
                
        }
        else if (ncv <= nev || ncv > n) {
                printf(" ERROR with _SSIMP: NCV is greater than MAXNCV \n");
-               // goto L9000;
-               return NULL;
+               eig_vectors.clear();
+               return eig_vectors;
        }
        
        
-       //vectors_size = matrix_dimension * nev;
        vectors_size = ldv * ncv;
        v            = (doublereal*)MEM_callocN(vectors_size * 
sizeof(doublereal), "eigen_vectors");
        workl        = (doublereal*)MEM_callocN((ncv*ncv + 8*ncv) * 
sizeof(doublereal), "workl");
-       //d__          = (doublereal*)MEM_callocN(2*matrix_dimension * 
sizeof(doublereal), "eigen_values");
        d__          = (doublereal*)MEM_callocN(2*ncv * sizeof(doublereal), 
"eigen_values");
        
        resid        = (doublereal*)MEM_callocN(matrix_dimension * 
sizeof(doublereal), "resid");
@@ -172,7 +188,6 @@
        iparam[6] = mode1;
        
        // main loop        
-       //L10:
        while (true) {
                
                
@@ -190,10 +205,7 @@
                
                if (ido == -1 || ido == 1) {
                        //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]);
-                       //goto L10;
                }
                else{
                        break;
@@ -267,11 +279,12 @@
                        MEM_freeN(workd);
                        MEM_freeN(workl);
                        MEM_freeN(select);
+                       MEM_freeN(v);
                        
                        
                        
                        // return the eigen vectors
-                       return v;
+                       return eig_vectors;
                        
                        
                }
@@ -285,10 +298,11 @@
        MEM_freeN(workd);
        MEM_freeN(workl);
        MEM_freeN(select);
+       MEM_freeN(v);
        
-       *v = NULL;
+       eig_vectors.clear();
        
-       return v;
+       return eig_vectors;
        
        
 #endif

Modified: branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.h       
2011-07-31 22:59:36 UTC (rev 38884)
+++ branches/soc-2011-avocado/blender/intern/autoseam/EigenSolverArpack.h       
2011-08-01 02:40:09 UTC (rev 38885)
@@ -40,7 +40,7 @@
                
                //Eigen::VectorXd eigen_values;
                EigenSolverArpack(int dimension);
-               double * solve();
+               eigen_vectors solve();
                double eigenvalue(int n);
                std::vector<double> eigenvector(int n);
                ~EigenSolverArpack();

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to