[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29414] branches/soc-2010-rohith291991: Made the C interface to Comiso, as well as have the tool giving out a DerivedMesh.

Rohith B V rohith291991 at gmail.com
Fri Jun 11 20:22:33 CEST 2010


Revision: 29414
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29414
Author:   rohith291991
Date:     2010-06-11 20:22:33 +0200 (Fri, 11 Jun 2010)

Log Message:
-----------
Made the C interface to Comiso, as well as have the tool giving out a DerivedMesh. Commented the parts remaining.

Modified Paths:
--------------
    branches/soc-2010-rohith291991/intern/comiso/extern/comiso.h
    branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp
    branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c

Modified: branches/soc-2010-rohith291991/intern/comiso/extern/comiso.h
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/extern/comiso.h	2010-06-11 17:56:10 UTC (rev 29413)
+++ branches/soc-2010-rohith291991/intern/comiso/extern/comiso.h	2010-06-11 18:22:33 UTC (rev 29414)
@@ -1,13 +1,44 @@
 #ifndef COMISO_API_H
 #define COMISO_API_H
 
+typedef struct MValue
+	{
+	int i;
+	int j;
+	double value;
+	
+	}MValue;
+
+typedef struct Comiso
+	{
+	
+	int m; //<--- Number of rows
+    int n; //<--- Number of columns
+	int c; //<--- Number of constraint rows
+	int mnnz; //<--- Number of non zero elements in mesh data
+	int cnnz; //<--- Number of non zero elements in constraint data
+	int nr; //<--- Number of variables to round
+
+	MValue* mdata; //<--- Mesh data 
+	MValue* cdata; //<--- Constraint data 
+	int *rdata; //<--- Indices to round
+    
+	}Comiso;
+
+typedef struct CVect
+	{
+    
+	int n; //<--- Number of elements
+	double *data; //<--- Solution data;
+	
+	}CVect;
+
 #ifdef __cplusplus
 extern "C"  {
 #endif
 
-int MISolve();
+	CVect MISolve(Comiso _data,double _precision,int _numGauss,int _numCG);
 
-
 #ifdef __cplusplus
  }
 #endif

Modified: branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp	2010-06-11 17:56:10 UTC (rev 29413)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp	2010-06-11 18:22:33 UTC (rev 29414)
@@ -22,45 +22,29 @@
 *                                                                           *
 \*===========================================================================*/ 
 
-
 #include "../extern/comiso.h"
 #include "common.h"
 #include <vector>
 #include "ConstrainedSolver.h"
 #include "MISolver.h"
 
-
-/// function to setup a random sparse row matrix of dimension _m x _n
-/// for the simplicity of this example only integer valued entries are used
-void random_sparse_row_matrix( SparseXdr& _B, int _m, int _n, double _density = 0.7)
-	{
-	_B.resize(_m, _n);
-
-	for( int i=0; i<_m; ++i)
-		for( int j=0; j<_n; ++j)
-			if( (rand()-1.0*_density*RAND_MAX)/RAND_MAX> 0) // for sparseness
-				_B.fill(i,j) = round(((rand()-0.4*RAND_MAX)/RAND_MAX)*10.0);
-
-
-	}
-
 /// function to extract the actual system Ax=b of linear equation from a B^tB matrix
-void extract_Axb( const SparseXdr& _B, MatrixXd& _A, std::vector<double>& _b)
+void extract_Axb( const MatrixXd& _B, MatrixXd& _A, std::vector<double>& _b)
 	{
 	int dimm = _B.rows();
 	int dimn = _B.cols();
 	int i;
 	int j;
 
-	SparseXdc Btcol;
-	SparseXdc Bcol;
+	MatrixXd Btcol;
+	MatrixXd Bcol;
 	VectorXd b;
 	Btcol.resize(dimn, dimm);
 	Bcol.resize(dimm, dimn);
 	_A.resize( dimn, dimn);
-	Bcol=SparseXdc(_B);
-	Btcol=SparseXdc(Bcol.transpose());
-	_A=SparseXdc((Btcol*Bcol)).toDense();
+	Bcol=MatrixXd(_B);
+	Btcol=MatrixXd(Bcol.transpose());
+	_A=MatrixXd((Btcol*Bcol));
 
 	b.resize( dimn);
 	b=_A.col(dimn-1);
@@ -85,32 +69,14 @@
 
 	}
 
-/// function to setup a random sparse constraint row matrix of dimension _c x _n
-/// for the simplicity of the example only -1, 0, 1 constraints are used
-
-void simple_constraint_row_matrix( MatrixXd& _C, int _c, int _n, double _distribution = 0.2)
-	{
-	_C.resize(_c, _n);
-
-	for( int i=0; i<_c; ++i)
-		for( int j=0; j<_n; ++j)
-			{
-			double randnum = (double(rand())/double(RAND_MAX));
-			if ( randnum < _distribution)
-				_C( i,j) = -1;
-			else if( randnum > (1.0-_distribution))
-				_C( i,j) = 1;
-			else
-				_C( i,j) = 0;
-			}
-	}
-
 /// function to print the equations corresponding to the matrices of an equation system
 template <class MatrixT >
 void print_equations( const MatrixT& _B)
 	{
+
 	int m =  _B.rows();
 	int n =  _B.cols();
+
 	for( int i = 0; i < m; ++i)
 		{
 
@@ -128,111 +94,104 @@
 		}
 	}
 
-extern "C" 
-int MISolve(void)
+CVect Solve(MatrixXd B, MatrixXd C,std::vector<int> ids_to_round, double precision,int _numGauss=10000,int _numCG=20)
 	{
 
-
-
-	int m = 9;
-	int n = 8+1;
-
-	SparseXdr B;
+	CVect result;
 	MatrixXd A;
-
-	random_sparse_row_matrix( B, m, n, 0.85);// <- Replace with actual matrix
 	std::vector<double> b;
+
 	extract_Axb( B, A, b);
 
-	A.setZero();
-	A(0,0)=42;
-	A(0,5)=8;
-	A(2,2)=1;
-	A(3,3)=1;
-	A(3,6)=3;
-	A(3,7)=-1;
-	A(4,4)=29;
-	A(5,0)=8;
-	A(5,5)=4;
-	A(6,3)=3;
-	A(6,6)=9;
-	A(6,7)=-3;
-	A(7,3)=-1;
-	A(7,6)=-3;
-	A(7,7)=2;
-
-	b[0]=-0;
-	b[1]=-0;
-	b[2]=5;
-	b[3]=-0;
-	b[4]=-0;
-	b[5]=-0;
-	b[6]=-0;
-	b[7]=-0;
-
-	int c = 5;
-	MatrixXd C;
-	simple_constraint_row_matrix( C, c, n);// <- Replace with actual matrix
-
-	C.setZero();
-	C(0,0)=1;
-	C(0,2)=1;
-	C(0,5)=1;
-	C(0,6)=1;
-	C(0,7)=-1;
-	C(0,8)=1;
-	C(1,8)=-1;
-	C(2,3)=-1;
-	C(2,4)=1;
-	C(2,5)=-1;
-	C(2,6)=-1;
-	C(3,0)=1;
-	C(3,1)=1;
-	C(4,1)=-1;
-	C(4,3)=-1;
-	C(4,5)=-1;
-	C(4,7)=-1;
-	C(4,8)=1;
-
 	// create a constrained solver
 	ConstrainedSolver cs;
-	// vector of indices to round (this is the mixed-integer part)
-	std::vector< int > ids_to_round;
+
 	// lets say we want to round the third variable
-	ids_to_round.push_back(2);
-	ids_to_round.push_back(4);
-	// vector of independent variables to be eliminated (computed by the make_constraints_independent function)
 	std::vector< int > ids_to_elim;
 
 	cs.make_constraints_independent( C, ids_to_round, ids_to_elim);
 
-	MatrixXd Ccpy( C );
-	MatrixXd Acpy( A );
-
 	// CSC matrix later initialized and used by solver
-	SparseXdc Acsc; 
+	SparseXdc Acsc; // Not used right now
 
 	// this re-indexing is also used by the solver, to know which variables are still there (!=-1) and which have been eliminated (=-1) it is setup by eliminate_constraints
 	std::vector< int > new_idx;
 	std::vector< double > x(b.size()); 
-	std::vector< double > b_cpy(b); 
 
-	cs.eliminate_constraints( Ccpy, Acpy, x, b, ids_to_round, ids_to_elim, new_idx, Acsc);
+	cs.eliminate_constraints( C, A, x, b, ids_to_round, ids_to_elim, new_idx, Acsc);
 
 	// create solver
 
 	MISolver miso;
-	miso.solve( Acpy, x, b, ids_to_round);
+	miso.solve( A, x, b, ids_to_round);
 
-	cs.restore_eliminated_vars( Ccpy,x, ids_to_elim, new_idx);
+	cs.restore_eliminated_vars( C,x, ids_to_elim, new_idx);
 
 	std::cout<<"[ ";
 	for(int l=0;l<x.size()-1;l++)
 		{
 		std::cout<<x[l]<<", ";
 		}
-		std::cout<<x[x.size()-1]<<" ]";
+	std::cout<<x[x.size()-1]<<" ]";
 
-	return -1;
+	result.n=x.size();
+	result.data=NULL; // malloc here 
+
+	for(int k=0;k<result.n;k++)
+		{
+		result.data[k]=x[k];
+		}
+
+	return result;
 	}
 
+extern "C" 
+CVect MISolve(Comiso _data,double _precision=1e-7,int _numGauss=10000,int _numCG=20)
+	{
+
+	CVect result;
+	MatrixXd B;
+	MatrixXd C;
+	// vector of indices to round (this is the mixed-integer part)
+	std::vector< int > ids_to_round;
+
+	B.resize(_data.m,_data.n);
+	B.setZero();
+
+	int nnz=_data.mnnz;
+
+	for( int k=0; k<nnz; ++k)
+		{
+		int i=_data.mdata[k].i;
+		int j=_data.mdata[k].j;
+
+		B(i,j) = _data.mdata[k].value;
+		}
+
+	C.resize(_data.c,_data.n);
+	C.setZero();
+
+	nnz=_data.cnnz;
+
+	for( int k=0; k<nnz; ++k)
+		{
+
+		int i=_data.cdata[k].i;
+		int j=_data.cdata[k].j;
+
+		C(i,j) = _data.cdata[k].value;
+
+		}
+
+	for(int k=0;k<_data.nr;k++)
+		{
+
+		ids_to_round[k]=_data.rdata[k];
+
+		}
+
+	result=Solve(B,C,ids_to_round,_precision,_numGauss,_numCG);
+
+	return result;
+
+	}

Modified: branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c
===================================================================
--- branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c	2010-06-11 17:56:10 UTC (rev 29413)
+++ branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c	2010-06-11 18:22:33 UTC (rev 29414)
@@ -60,6 +60,8 @@
   int useRenderParams, int isFinalCalc)
 {
   
+	Comiso solver;
+	CVect solution;
 	QuadrangulateModifierData *dmd = (QuadrangulateModifierData*) md;
 	DerivedMesh *dm = derivedData, *result = NULL;
 	MVert *mvert;
@@ -74,22 +76,51 @@
 
 //--------------Quadrangulate Tool--------------//
 
-	//------Test code-----//
-
 	numTris = 0;
 
-	MISolve();
-
 	for (a=0; a<totface; a++) 
 	{
 		MFace *mf = &mface[a];
 		numTris++;
 		if (mf->v4) numTris++;
 	}
+	
 
+	solver.m=numTris;
+	solver.n=numTris+1;
 
+	solver.c=0; // This will be set later
+
+
+	//TODO
+
+	// Extract face angles, period jumps and other relevant data from the mesh
+	
+
+	//Set up constraint and mesh matrices and ids to round
+
+    // USE BLENDER MEM FUNCS
+
+	// Fill solver.mdata
+
+	// Fill solver.cdata
+
+	// Fill solver.rdata
+
+	//solution=MISolve(solver,1e-7,10000,20); // Numerical params may change
+
+	//Generate cross field
+
+	//Calculate quadrangulation from cross field
+
+	//Calculate mesh from solution
+
+	//set result DerivedMesh
+	result=dm; // <--- for now
+
 //-------------------End Tool------------------//
 
+	//TODO
 	//------Error conditions-----//
 
 		if(0) 
@@ -99,7 +130,7 @@
 	}
     
 
-	return NULL;
+	return result;
 }
 
 





More information about the Bf-blender-cvs mailing list