[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29668] branches/soc-2010-rohith291991: updates to direction field.

Rohith B V rohith291991 at gmail.com
Thu Jun 24 14:15:34 CEST 2010


Revision: 29668
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29668
Author:   rohith291991
Date:     2010-06-24 14:15:34 +0200 (Thu, 24 Jun 2010)

Log Message:
-----------
updates to direction field. Compiles but does not work yet.

Modified Paths:
--------------
    branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h
    branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp
    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/CMesh.h
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h	2010-06-24 10:17:51 UTC (rev 29667)
+++ branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h	2010-06-24 12:15:34 UTC (rev 29668)
@@ -30,6 +30,8 @@
 
 typedef struct CEdge{
 
+int faces[2];//Indices of all faces having this edge
+double kappa;//Correction angle between two adjacent faces
 int index; //Index of the edge
 int p;// Period Jump for v1-v2. For v2-v1 it is -p
 int flag; //Flag for various purposes (eg. Cut graph)

Modified: branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp	2010-06-24 10:17:51 UTC (rev 29667)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/CMesh.cpp	2010-06-24 12:15:34 UTC (rev 29668)
@@ -1,5 +1,6 @@
 #include "../extern/CMesh.h"
 #include <vector>
+#include <math.h>
 #include "MEM_guardedalloc.h"
 
 int generateVoronoiCells(CMesh* mesh)
@@ -52,7 +53,7 @@
 			{
 	
 				int nIndex=face->neighbors[k];
-				
+			
 				if(!(mesh->faces[nIndex].flag & CF_VISITED)||(mesh->faces[nIndex].group==face->group))
 				{
 
@@ -76,19 +77,69 @@
 
 				for(int l=0;l<mesh->numEdges;l++)
 				{
-					if((mesh->edges[l].v[0]==v[0]&&mesh->edges[l].v[1]==v[1])
-					   || (mesh->edges[l].v[0]==v[1]&&mesh->edges[l].v[1]==v[0] ))
-						{
-							mesh->edges[l].flag |= CE_MARKED;
-							mesh->edges[l].p=0;	
-						}
 					
+					if((mesh->edges[l].v[0]==v[0]&&mesh->edges[l].v[1]==v[1]))
+							{
+								face->edges[k]=mesh->edges[l].index;	
+								mesh->edges[l].faces[0]=index;
+								mesh->edges[l].faces[1]=nIndex;
+								mesh->edges[l].flag |= CE_MARKED;
+								mesh->edges[l].p=0;	
+
+							}
+							
+							else if((mesh->edges[l].v[0]==v[1]&&mesh->edges[l].v[1]==v[0] ))
+							{
+								face->edges[k]=mesh->edges[l].index;
+								mesh->edges[l].faces[1]=index;
+								mesh->edges[l].faces[0]=nIndex;
+								mesh->edges[l].flag |= CE_MARKED;
+								mesh->edges[l].p=0;	
+
+							}
+					
 				}
 
 
+					}
+				else
+					{
+				
+					int v[2];
+					int cv=0;
+					//Mark common vertices
+					for(int l=0;l<4;l++)
+						for(int k=0;k<4;k++)
+							if( (mesh->faces[index].v[l] == mesh->faces[nIndex].v[k])
+							&& mesh->faces[index].v[k]!=-1)
+							{
+								v[cv]=mesh->faces[index].v[l]; 
+								cv++;
+							}
+					
+						for(int l=0;l<mesh->numEdges;l++)
+						{
+							
+							if((mesh->edges[l].v[0]==v[0]&&mesh->edges[l].v[1]==v[1]))
+							{
+								face->edges[k]=mesh->edges[l].index;	
+								mesh->edges[l].faces[0]=index;
+								mesh->edges[l].faces[1]=nIndex;
+
+							}
+							
+							else if((mesh->edges[l].v[0]==v[1]&&mesh->edges[l].v[1]==v[0] ))
+							{
+								face->edges[k]=mesh->edges[l].index;
+								mesh->edges[l].faces[1]=index;
+								mesh->edges[l].faces[0]=nIndex;
+
+							}
+					
+						}
+					}
+
 				}
-
-			}
 			
 		}
 
@@ -137,7 +188,7 @@
 //the variables are stored as all thetas followed by all period jumps
 
 
-//TODO makes constraints on face theta's and edge p's
+//TODO makes constraints on face theta's
 //call generateConstraints(CMesh* mesh) 
 
 
@@ -161,16 +212,39 @@
 		solver.mdata[t].value=-2;
 		t++;
 
-		//TODO totkappa+= something (calculate)
 
-		//TODO for each edge
-		//solver.mdata[t].i=i
-		//solver.mdata[t].j=totface+index of edge
-		//use *edges
-		//solver.mdata[t].value=+ or - pij * 3.1415926; depending on match
-		//t++;
+		double x1,x2,y1,y2,z1,z2;
+
+		int v1,v2,v3,v4;
+		v1=mesh->faces[i].v[0];
+		v2=mesh->faces[i].v[1];
+		v3=mesh->edges[mesh->faces[i].edges[j]].v[0];
+		v4=mesh->edges[mesh->faces[i].edges[j]].v[1];
+
+
+		x1=mesh->verts[v1].co[0]-mesh->verts[v2].co[0];
+		y1=mesh->verts[v1].co[1]-mesh->verts[v2].co[1];
+		z1=mesh->verts[v1].co[2]-mesh->verts[v2].co[2];
+
+		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];
 		
+		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;
 
+		solver.mdata[t].i=i;
+		solver.mdata[t].j=totface+mesh->faces[i].edges[j];
+		int sign=1;
+
+		if(mesh->edges[mesh->faces[i].edges[j]].faces[0]==i)
+			sign=1;
+		else
+			sign=-1;// <---- TODO check
+
+		solver.mdata[t].value=mesh->edges[mesh->faces[i].edges[j]].p * sign * 3.1415926; 
+		t++;
+		
 		}
 
 	solver.mdata[t].i=i;
@@ -180,7 +254,7 @@
 
 	}
 
-for (int i=0;i<solver.n-totface;i++)
+for (int i=0;i<totedge;i++)
 	{
 	
 	solver.mdata[t].i=i;
@@ -189,22 +263,23 @@
 	t++;
 
 	solver.mdata[t].i=i;
-	solver.mdata[t].j=0;// <-- dummy, change to index of face 1
-	solver.mdata[t].value=3.1415926;//<--- dummy, change to actual face 1's theta *3.1415926
+	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].j=0;// <-- dummy, change to index of face 2
-	solver.mdata[t].value=3.1415926;//<--- dummy, change to actual face 2's theta * -3.1415926
+	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].j=solver.n-1;
-	solver.mdata[t].value=0; //<--- dummy, change to kappa of edge * -3.1415926
+	solver.mdata[t].value=mesh->edges[i].kappa * -3.1415926;
 	t++;
 
 	}
 
+	
 
 //set period jumps to be rounded
 solver.nr=totedge;
@@ -215,7 +290,6 @@
     solver.rdata[a]=a+totface;	
 	}
 
-//TODO set constraint data
 
 t=0;
 
@@ -238,6 +312,8 @@
 
 	}
 
+
+
 solver.c=t;
 solver.cnnz=2*solver.c;
 solver.cdata=(MValue *)MEM_mallocN(sizeof(MValue)*solver.cnnz, "cdata");
@@ -267,6 +343,7 @@
 		}
 	}
 
+
 solution = MISolve(solver,1e-7,10000,20);
 
 for(int i=0;i<totface;i++)

Modified: branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp	2010-06-24 10:17:51 UTC (rev 29667)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/comiso.cpp	2010-06-24 12:15:34 UTC (rev 29668)
@@ -27,6 +27,7 @@
 #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)
@@ -134,7 +135,7 @@
 	std::cout<<x[x.size()-1]<<" ]";
 
 	result.n=x.size();
-	result.data=NULL; // malloc here 
+	result.data=(double *)MEM_mallocN(sizeof(double)*result.n, "data");
 
 	for(int k=0;k<result.n;k++)
 		{
@@ -153,12 +154,13 @@
 	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;
@@ -167,6 +169,7 @@
 		B(i,j) = _data.mdata[k].value;
 		}
 
+
 	C.resize(_data.c,_data.n);
 	C.setZero();
 
@@ -182,12 +185,15 @@
 
 		}
 
+	ids_to_round.resize(_data.nr);
+
 	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);
 

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-24 10:17:51 UTC (rev 29667)
+++ branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c	2010-06-24 12:15:34 UTC (rev 29668)
@@ -182,16 +182,28 @@
 			  if(count>=2)
 			   {
 				   if(cm.faces[i].neighbors==NULL)
+					   {
 					   cm.faces[i].neighbors=MEM_mallocN((sizeof(int)*(++cm.faces[i].numNeighbors)),"neighbors");
+					   cm.faces[i].edges=MEM_mallocN((sizeof(int)*(cm.faces[i].numNeighbors)),"edges");
+					   }
 				   else
-						cm.faces[i].neighbors=MEM_reallocN(cm.faces[i].neighbors,(sizeof(int)*(++cm.faces[i].numNeighbors)));
+					   {
+					   cm.faces[i].neighbors=MEM_reallocN(cm.faces[i].neighbors,(sizeof(int)*(++cm.faces[i].numNeighbors)));
+					   cm.faces[i].edges=MEM_reallocN(cm.faces[i].edges,(sizeof(int)*(cm.faces[i].numNeighbors)));
+					   }
 
 				   cm.faces[i].neighbors[cm.faces[i].numNeighbors-1]=cm.faces[j].index;
 					
 				   if(cm.faces[j].neighbors==NULL)
-					    cm.faces[j].neighbors=MEM_mallocN((sizeof(int)*(++cm.faces[j].numNeighbors)),"neighbors");
+					   {
+					   cm.faces[j].neighbors=MEM_mallocN((sizeof(int)*(++cm.faces[j].numNeighbors)),"neighbors");
+					   cm.faces[j].edges=MEM_mallocN((sizeof(int)*(cm.faces[j].numNeighbors)),"edges");
+					   }
 				   else
-						cm.faces[j].neighbors=MEM_reallocN(cm.faces[j].neighbors,(sizeof(int)*(++cm.faces[j].numNeighbors)));
+					   {
+					   cm.faces[j].neighbors=MEM_reallocN(cm.faces[j].neighbors,(sizeof(int)*(++cm.faces[j].numNeighbors)));
+					   cm.faces[j].edges=MEM_reallocN(cm.faces[j].edges,(sizeof(int)*(cm.faces[j].numNeighbors)));
+					   }
 
 				   cm.faces[j].neighbors[cm.faces[j].numNeighbors-1]=cm.faces[i].index;
 
@@ -217,12 +229,13 @@
 
 			cm.faces[3].flag |= CF_CONSTRAINED;
 			cm.faces[10].flag |= CF_CONSTRAINED;
-			cm.faces[25].flag |= CF_CONSTRAINED;
+/*			cm.faces[25].flag |= CF_CONSTRAINED;
 			cm.faces[50].flag |= CF_CONSTRAINED;
-			cm.faces[73].flag |= CF_CONSTRAINED;
+			cm.faces[73].flag |= CF_CONSTRAINED;*/
 			
 			generateVoronoiCells(&cm);
 
+			
 			for(a=0;a<totface;a++)
 				printf("Group no: %d\n",cm.faces[a].group);
 				
@@ -236,6 +249,7 @@
 					medge[a].flag |=ME_SHARP;
 					}
 
+			
 			generateDirectionField(&cm);
 			
 	// Extract face angles, period jumps and other relevant data from the mesh





More information about the Bf-blender-cvs mailing list