[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29693] branches/soc-2010-rohith291991/ intern/comiso/intern: Small modifications.
Rohith B V
rohith291991 at gmail.com
Fri Jun 25 18:32:57 CEST 2010
Revision: 29693
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29693
Author: rohith291991
Date: 2010-06-25 18:32:57 +0200 (Fri, 25 Jun 2010)
Log Message:
-----------
Small modifications. Tested the code. Seems to work for all completely closed, triangular meshes. Code to set facet constraints is yet to be integrated.
Modified Paths:
--------------
branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp
branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp
Modified: branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp 2010-06-25 13:44:47 UTC (rev 29692)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp 2010-06-25 16:32:57 UTC (rev 29693)
@@ -229,6 +229,8 @@
x2=mesh->verts[v3].co[0]-mesh->verts[v4].co[0];
y2=mesh->verts[v3].co[1]-mesh->verts[v4].co[1];
z2=mesh->verts[v3].co[2]-mesh->verts[v4].co[2];
+
+ //TODO calculate correct kappa
mesh->edges[mesh->faces[i].edges[j]].kappa=acos((x1*x2+y1*y2+z1*z2)/sqrt((x1*x1+y1*y1+z1*z1)*(x2*x2+y2*y2+z2*z2)));
totkappa+= mesh->edges[mesh->faces[i].edges[j]].kappa;
@@ -257,28 +259,29 @@
for (int i=0;i<totedge;i++)
{
- solver.mdata[t].i=i;
+ solver.mdata[t].i=i+totface;
solver.mdata[t].j=totface+mesh->edges[i].index;
solver.mdata[t].value=3.1415926*3.1415926*0.5*mesh->edges[i].p;
t++;
- solver.mdata[t].i=i;
+ solver.mdata[t].i=i+totface;
solver.mdata[t].j=mesh->edges[i].faces[0];
solver.mdata[t].value=mesh->faces[mesh->edges[i].faces[0]].theta*3.1415926;
t++;
- solver.mdata[t].i=i;
+ solver.mdata[t].i=i+totface;
solver.mdata[t].j=mesh->edges[i].faces[1];
solver.mdata[t].value=mesh->faces[mesh->edges[i].faces[1]].theta* -3.1415926;
t++;
- solver.mdata[t].i=i;
+ solver.mdata[t].i=i+totface;
solver.mdata[t].j=solver.n-1;
solver.mdata[t].value=mesh->edges[i].kappa * -3.1415926;
t++;
}
+solver.mnnz=t;
//set period jumps to be rounded
@@ -305,44 +308,55 @@
for(int i=0;i<totedge;i++)
{
- if(mesh->edges[i].flag & CE_MARKED)
+ if((mesh->edges[i].flag & CE_MARKED))
{
t++;
}
}
-
-
solver.c=t;
solver.cnnz=2*solver.c;
solver.cdata=(MValue *)MEM_mallocN(sizeof(MValue)*solver.cnnz, "cdata");
t=0;
+int c=0;
for(int i=0;i<totface;i++)
{
if(mesh->faces[i].flag & CF_CONSTRAINED)
{
- solver.cdata[t].i = i;
+ solver.cdata[t].i = c;
+ solver.cdata[t].j = i;
+ solver.cdata[t].value = 1;
+ t++;
+ solver.cdata[t].i = c;
solver.cdata[t].j = solver.n-1;
solver.cdata[t].value = mesh->faces[i].theta;
t++;
+ c++;
}
}
for(int i=0;i<totedge;i++)
{
- if(mesh->edges[i].flag & CE_MARKED)
+ if((mesh->edges[i].flag & CE_MARKED))
{
- solver.cdata[t].i = i + totface;
+ solver.cdata[t].i = c;
+ solver.cdata[t].j = i+totface;
+ solver.cdata[t].value = 1;
+ t++;
+ solver.cdata[t].i = c;
solver.cdata[t].j = solver.n-1;
solver.cdata[t].value = mesh->edges[i].p;
t++;
+ c++;
}
}
+solver.c=c;
+solver.cnnz=t;
solution = MISolve(solver,1e-7,10000,20);
@@ -359,6 +373,7 @@
}
+
if(0)
{
return 0;
Modified: branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp 2010-06-25 13:44:47 UTC (rev 29692)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp 2010-06-25 16:32:57 UTC (rev 29693)
@@ -1,202 +1,206 @@
-/*===========================================================================*\
-* *
-* CoMISo *
-* Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
-* www.rwth-graphics.de *
-* *
-*---------------------------------------------------------------------------*
-* This file is part of CoMISo. *
-* *
-* CoMISo 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 3 of the License, or *
-* (at your option) any later version. *
-* *
-* CoMISo 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 CoMISo. If not, see <http://www.gnu.org/licenses/>. *
-* *
-\*===========================================================================*/
-
-#include "../extern/comiso.h"
-#include "common.h"
-#include <vector>
-#include "ConstrainedSolver.h"
-#include "MISolver.h"
-#include "MEM_guardedalloc.h"
-
-/// function to extract the actual system Ax=b of linear equation from a B^tB matrix
-void extract_Axb( const MatrixXd& _B, MatrixXd& _A, std::vector<double>& _b)
- {
- int dimm = _B.rows();
- int dimn = _B.cols();
- int i;
- int j;
-
- MatrixXd Btcol;
- MatrixXd Bcol;
- VectorXd b;
- Btcol.resize(dimn, dimm);
- Bcol.resize(dimm, dimn);
- _A.resize( dimn, dimn);
- Bcol=MatrixXd(_B);
- Btcol=MatrixXd(Bcol.transpose());
- _A=MatrixXd((Btcol*Bcol));
-
- b.resize( dimn);
- b=_A.col(dimn-1);
- _b.resize(dimn-1);
-
- MatrixXd tA=_A;
-
- _A.resize( dimn-1, dimn-1);
-
- for(i=0;i<dimn-1;i++)
- {
- _b[i]=-1.0*b[i];
-
- for(j=0;j<dimn-1;j++)
- {
-
- _A(i,j)=tA(i,j);
-
- }
- }
-
- }
-
-/// 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)
- {
-
- for(int j=0 ;j<n-1;++j)
- {
- if( _B(i,j) != 0.0)
- std::cout << _B(i,j) << "*x" << j;
- else
- std::cout << "0";
- if(j < n-2 ) std::cout << " + ";
-
- }
- std::cout << " = " << _B(i,n-1) << std::endl;
-
- }
- }
-
-CVect Solve(MatrixXd B, MatrixXd C,std::vector<int> ids_to_round, double precision,int _numGauss=10000,int _numCG=20)
- {
-
- CVect result;
- MatrixXd A;
- std::vector<double> b;
-
- extract_Axb( B, A, b);
-
- // create a constrained solver
- ConstrainedSolver cs;
-
- // lets say we want to round the third variable
- std::vector< int > ids_to_elim;
-
- cs.make_constraints_independent( C, ids_to_round, ids_to_elim);
-
- // CSC matrix later initialized and used by solver
- 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());
-
- cs.eliminate_constraints( C, A, x, b, ids_to_round, ids_to_elim, new_idx, Acsc);
-
- // create solver
-
- MISolver miso;
- miso.solve( A, x, b, ids_to_round);
-
- 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]<<" ]";
-
- result.n=x.size();
- result.data=(double *)MEM_mallocN(sizeof(double)*result.n, "data");
-
- 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;
-
- printf("TESTSET\n");
- 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;
-
- }
-
- ids_to_round.resize(_data.nr);
-
- for(int k=0;k<_data.nr;k++)
- {
-
- ids_to_round[k]=_data.rdata[k];
-
- }
+/*===========================================================================*\
+* *
+* CoMISo *
+* Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
+* www.rwth-graphics.de *
+* *
+*---------------------------------------------------------------------------*
+* This file is part of CoMISo. *
+* *
+* CoMISo 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 3 of the License, or *
+* (at your option) any later version. *
+* *
+* CoMISo 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 CoMISo. If not, see <http://www.gnu.org/licenses/>. *
+* *
+\*===========================================================================*/
-
- result=Solve(B,C,ids_to_round,_precision,_numGauss,_numCG);
-
- return result;
-
- }
+#include "../extern/comiso.h"
+#include "common.h"
+#include <vector>
+#include "ConstrainedSolver.h"
+#include "MISolver.h"
+#include "MEM_guardedalloc.h"
+
+/// function to extract the actual system Ax=b of linear equation from a B^tB matrix
+void extract_Axb( const MatrixXd& _B, MatrixXd& _A, std::vector<double>& _b)
+ {
+ int dimm = _B.rows();
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list