[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37183] branches/soc-2011-avocado/blender: Dummy Implementation of Laplacian Matrix from dual graph and Calculation of Eigen Space for that Laplacian Matrix is done .

shuvro sarker shuvro05 at gmail.com
Sat Jun 4 18:16:25 CEST 2011


Revision: 37183
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37183
Author:   shuvro
Date:     2011-06-04 16:16:25 +0000 (Sat, 04 Jun 2011)
Log Message:
-----------
Dummy Implementation of Laplacian Matrix from dual graph and Calculation of Eigen Space for that Laplacian Matrix is done. Currently the Dense module ofEigen3 is used for Eigen related calculations. This will be changed later.

Modified Paths:
--------------
    branches/soc-2011-avocado/blender/intern/autoseam/CMakeLists.txt
    branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.cpp
    branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.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/blenkernel/BKE_demo.h
    branches/soc-2011-avocado/blender/source/blender/blenkernel/intern/demo.c
    branches/soc-2011-avocado/blender/source/blender/editors/mesh/bmesh_tools.c

Modified: branches/soc-2011-avocado/blender/intern/autoseam/CMakeLists.txt
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/CMakeLists.txt	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/intern/autoseam/CMakeLists.txt	2011-06-04 16:16:25 UTC (rev 37183)
@@ -33,6 +33,8 @@
 	autoseam_C_API.cpp
 	DummyClass.h
 	autoseam_C_API.h
+    CoreFunctions.c
+    CoreFunctions.h
 )
 
 blender_add_lib(bf_intern_autoseam "${SRC}" "${INC}")

Modified: branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.cpp	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.cpp	2011-06-04 16:16:25 UTC (rev 37183)
@@ -1,3 +1,5 @@
+#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET 
+
 #include <Eigen/Core>
 #include <Eigen/Dense>
 #include <Eigen/Eigenvalues> 
@@ -6,6 +8,7 @@
 #include "DummyClass.h"
 
 using Eigen::MatrixXd;
+using Eigen::SparseMatrix;
 
 
 DummyClass::DummyClass()
@@ -15,6 +18,17 @@
 			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 DummyClass::solve3x3(float *vec)
 {
 	Eigen::Vector3f b;
@@ -28,22 +42,25 @@
     std::cout << m << std::endl;
     
     
+   /* 
     MatrixXd A = MatrixXd::Random(6,6);
+    
+
     std::cout << "Here is a random 6x6 matrix, A:" << std::endl << A << std::endl << std::endl;
     
     Eigen::EigenSolver<MatrixXd> es(A);
     std::cout << "The eigenvalues of A are:" << std::endl << es.eigenvalues() << std::endl;
     std::cout << "The matrix of eigenvectors, V, is:" << std::endl << es.eigenvectors() << std::endl << std::endl;
     
-    /*Eigen::complex<double> lambda = es.eigenvalues()[0];
+    Eigen::complex<double> lambda = es.eigenvalues()[0];
     std::cout << "Consider the first eigenvalue, lambda = " << lambda << std::endl;
     Eigen::VectorXcd v = es.eigenvectors().col(0);
     std::cout << "If v is the corresponding eigenvector, then lambda * v = " << std::endl << lambda * v << std::endl;
-    std::cout << "... and A * v = " << std::endl << A.cast<complex<double> >() * v << std::endl << std::endl;*/
+    std::cout << "... and A * v = " << std::endl << A.cast<complex<double> >() * v << std::endl << std::endl;
     
     Eigen::MatrixXcd D = es.eigenvalues().asDiagonal();
     Eigen::MatrixXcd V = es.eigenvectors();
-    std::cout << "Finally, V * D * V^(-1) = " <<     std::endl << V * D * V.inverse() <<     std::endl;
+    std::cout << "Finally, V * D * V^(-1) = " <<     std::endl << V * D * V.inverse() <<     std::endl;*/
 
 }
 
@@ -54,3 +71,40 @@
 	vec[2] = m_x[2];
 }
 
+
+void DummyClass::calculate_eigen(float **dual_matrix, int num_row, int num_col)
+{
+    int r_index,c_index;
+    dualMatrix.resize(num_row, num_col);
+    
+    /* we can print the matrix here to have a look */
+    
+    /* the argument dual_matrix will not be provided as 2d array later, the data 
+     structure will be improved for efficiency. */
+    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]){
+                dualMatrix(r_index, c_index) = dual_matrix[r_index][c_index];
+            }
+            else dualMatrix(r_index, c_index) = 0;
+        }
+    }
+    
+    for(int l = 0; l < num_row; l++ ){
+        dualMatrix(l,l) = - row_sum(dualMatrix, num_row, l);
+    }
+    
+   Eigen::EigenSolver<MatrixXd> es(dualMatrix);
+   std::cout << "The eigenvalues of A are:" << std::endl << es.eigenvalues() << std::endl;
+    
+    
+   /* Now display the values. */
+    
+    for(int i = 0; i < num_col; i++ )
+    {
+        std::cout << "Column "  << i << ": value " << es.eigenvalues()[i] << std::endl;
+        std::cout << "Column "  << i << ": vector " << es.eigenvectors().col(i) << std::endl;
+    }
+
+    
+}

Modified: branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.h	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/intern/autoseam/DummyClass.h	2011-06-04 16:16:25 UTC (rev 37183)
@@ -2,7 +2,10 @@
 #define DUMMY_CLASS_H_INCLUDED
 
 #include <Eigen/Core>
+#include <Eigen/Sparse>
 
+
+
 class DummyClass
 {
 	public:
@@ -10,13 +13,15 @@
 		
 		void solve3x3(float *vec);
 		void get_solution(float *vec);
-	private:
+        void calculate_eigen(float **dual_matrix, int num_row, int num_col);
+	//private:
 		Eigen::Matrix3f m_A;
 		Eigen::Vector3f m_x;
+        Eigen::MatrixXd dualMatrix;
+        
+        //Eigen::SparseMatrix<double,RowMajor> m2(1000,2000);
     
 
-    
-    
 };
 
 #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-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp	2011-06-04 16:16:25 UTC (rev 37183)
@@ -24,4 +24,10 @@
 {
 	DummyClass *dummy = reinterpret_cast<DummyClass*>(handle);
 	dummy->get_solution(vec);
+}
+
+void autoseam_calculate_eigen(AUTOSEAM_DummyClassHandle handle, float** vec, int dimension)
+{
+	DummyClass *dummy = reinterpret_cast<DummyClass*>(handle);
+	dummy->calculate_eigen(vec, dimension, dimension);
 }
\ No newline at end of file

Modified: branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h	2011-06-04 16:16:25 UTC (rev 37183)
@@ -17,6 +17,8 @@
 void autoseam_solve3x3(AUTOSEAM_DummyClassHandle handle, float* vec);
 void autoseam_get_solution(AUTOSEAM_DummyClassHandle handle, float* vec);
 
+void autoseam_calculate_eigen(AUTOSEAM_DummyClassHandle handle, float** vec, int dimension);
+
 #ifdef __cplusplus
 }
 #endif 

Modified: branches/soc-2011-avocado/blender/source/blender/blenkernel/BKE_demo.h
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/blenkernel/BKE_demo.h	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/source/blender/blenkernel/BKE_demo.h	2011-06-04 16:16:25 UTC (rev 37183)
@@ -1,6 +1,10 @@
 #ifndef BKE_DEMO_H
 #define BKE_DEMO_H
 
+#include "bmesh.h"
+
 void BKE_use_autoseam();
+void calculate_eigen(float **dual_graph, int dimension);
 
+
 #endif
\ No newline at end of file

Modified: branches/soc-2011-avocado/blender/source/blender/blenkernel/intern/demo.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/blenkernel/intern/demo.c	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/source/blender/blenkernel/intern/demo.c	2011-06-04 16:16:25 UTC (rev 37183)
@@ -1,8 +1,11 @@
-// This is just a demo file to show usage of the autoseam library from within C
-// - comment added for test commit
+/* This is just a demo file to show usage of the autoseam library from within C
+ - comment added for test commit*/
 
 #include "autoseam_C_API.h"
+#include <stdio.h>
+#include <stdlib.h>
 
+
 void BKE_use_autoseam()
 {
 	float vec_in[3] = { 1.0f, 0.0f, 1.0f };
@@ -12,4 +15,32 @@
 	autoseam_get_solution(handle, vec_result);
 	autoseam_delete_dummyclass(handle);
 
-}
\ No newline at end of file
+}
+
+void calculate_eigen(float **dual_graph, int dimension)
+{
+    int i,j;
+    
+    int k;
+    
+    float **array = (float **) malloc(dimension* sizeof(float *));
+    
+    for(k = 0; k < dimension; k++ ){
+        array[k] = (float *) malloc(dimension * sizeof(float));
+    }
+
+    
+    for(i = 0; i < dimension; i++){
+        for(j = 0; j< dimension; j++){
+            array[i][j] = dual_graph[i][j];
+            printf("%.2f ",array[i][j]);
+        }
+        printf("\n");
+    }
+    AUTOSEAM_DummyClassHandle handle = autoseam_create_dummyclass();
+    autoseam_calculate_eigen(handle, array, dimension);
+}
+
+
+
+

Modified: branches/soc-2011-avocado/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/editors/mesh/bmesh_tools.c	2011-06-04 16:11:49 UTC (rev 37182)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/bmesh_tools.c	2011-06-04 16:16:25 UTC (rev 37183)
@@ -25,6 +25,7 @@
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
@@ -101,6 +102,9 @@
 
 #include "editbmesh_bvh.h"
 
+
+
+
 static void add_normal_aligned(float *nor, float *add)
 {
 	if( INPR(nor, add) < -0.9999f)
@@ -1227,6 +1231,8 @@
 	RNA_def_boolean(ot->srna, "inclusive", 0, "Inclusive", "Selects geometry around selected geometry, occording to selection mode");	
 }
 
+
+
 static int compute_dual_graph(BMesh *bm)
 {
     BMEdge *eed;
@@ -1234,10 +1240,26 @@
     BMLoop *l;
     //int count = 0;
     
-    float dummy_dual_graph[1000][1000];
+    
+//    float dummy_dual_graph[10][10];
     int i,face_index[2];
     
+    //float dummy_dual_graph[10][10];
+    int k,m;
     
+    float **dummy_dual_graph = (float **) malloc(10* sizeof(float *));
+    
+    for(k = 0; k < 10; k++ ){
+        dummy_dual_graph[k] = (float *) malloc(10 * sizeof(float));
+    }    
+    
+    for(k = 0; k < 10; k++){
+        for(m = 0; m < 10; m++){
+            dummy_dual_graph[k][m] = 0.0f;
+        }
+    }
+
+    
     for(eed = BMIter_New(&iter, bm, BM_EDGES_OF_MESH, bm ); eed; eed= BMIter_Step(&iter)) 
     {
         /* if not boundary edge */
@@ -1247,9 +1269,10 @@
             i = 0;
             
             BM_ITER(l, &iter2, bm, BM_LOOPS_OF_EDGE, eed) {
-                printf("%d ", l->f->head.index);
+                
                 face_index[i++] = l->f->head.index;
             }
+            printf("%d %d", face_index[0], face_index[1]);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list