From 9189cf69d99615181b98e35a808fa53d47713254 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vladim=C3=ADr=20Ulman?= <ulman@mpi-cbg.de>
Date: Mon, 10 Oct 2016 17:05:57 +0200
Subject: [PATCH] Added various surface visualizations, keys M,V,Q...

---
 src/graphics.cpp | 108 +++++++++++++++++++++++++++++++++++------------
 src/main.cpp     |   4 +-
 2 files changed, 82 insertions(+), 30 deletions(-)

diff --git a/src/graphics.cpp b/src/graphics.cpp
index 3ec144a..b69de74 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -46,6 +46,10 @@ float zoom = 1.0;
 bool MouseActive = false;
 int last_x = 0, last_y = 0;
 
+bool showWholeMesh=true;
+bool showVertexSurface=false;
+bool showQuadricSurface=false;
+
 
 ///manage \e count steps of the simulation and then print and draw
 void step(int count)
@@ -107,24 +111,73 @@ void displayAxes(void)
 
 
 int VertexID=10;
-void ActiveMesh::displayMesh(void)
+int vertexLevels=5;
+void ActiveMesh::displayVertexAndNeigs(void)
 {
-	glColor3f(0.8f,0.8f,0.8f);
+	//determine some reasonable number of nearest neighbors
+	std::vector< std::vector<size_t> > neigsLeveled;
+	ulm::getVertexNeighbours(*this,VertexID,vertexLevels,neigsLeveled);
+
+	//make it flat...
+	std::vector<size_t> neigs;
+	for (unsigned int l=0; l < neigsLeveled.size(); ++l)
+		for (unsigned int i=0; i < neigsLeveled[l].size(); ++i)
+			neigs.push_back(neigsLeveled[l][i]);
+	neigsLeveled.clear();
 
 	/*
-	for (unsigned int i=0; i < ID.size(); i+=3)
-	{
-		//glBegin(GL_TRIANGLES);
-		glBegin(GL_LINE_LOOP);
-		glNormal3f(norm[i/3].x,norm[i/3].y,norm[i/3].z);
-		glVertex3f(Pos[ID[i+0]].x,Pos[ID[i+0]].y,Pos[ID[i+0]].z);
-		glVertex3f(Pos[ID[i+1]].x,Pos[ID[i+1]].y,Pos[ID[i+1]].z);
-		glVertex3f(Pos[ID[i+2]].x,Pos[ID[i+2]].y,Pos[ID[i+2]].z);
-		glEnd();
-	}
+	std::vector<size_t> neigs;
+	ulm::getVertexImmediateNeighbours(*this,VertexID,neigs);
 	*/
 
-	//long unsigned int* id=&ID.front();
+	glPointSize(3.0f);
+	glBegin(GL_POINTS);
+
+	// centre vertex:
+	glColor3f(0.0f,0.0f,1.0f);
+	glVertex3f(Pos[VertexID].x,Pos[VertexID].y,Pos[VertexID].z);
+
+	// neigs:
+	glColor3f(1.0f,0.0f,0.0f);
+	for (unsigned int i=1; i < neigs.size(); ++i)
+		glVertex3f(Pos[neigs[i]].x,Pos[neigs[i]].y,Pos[neigs[i]].z);
+
+	glEnd();
+}
+
+void ActiveMesh::displayQuadricSurface(void)
+{
+	//get surface params
+	float surf_coeff[10];
+	CalcQuadricSurface_Taubin(VertexID,surf_coeff);
+
+	glPointSize(2.0f);
+	glBegin(GL_POINTS);
+	glColor3f(0.0f,1.0f,0.0f);
+
+	//do the rendering
+	//hmm... figure out some iteration model..
+	//perhaps from surrounding points some interpolation
+
+	//FOR CYCLE BEGIN
+		Vector3F point;
+		//say we have x,y,z -> point
+
+		//adapt the point
+		GetClosestPointOnQuadricSurface(point,surf_coeff);
+
+		//display the point
+		glVertex3f(point.x,point.y,point.z);
+
+	//FOR CYCLE END
+
+	glEnd();
+}
+
+void ActiveMesh::displayMesh(void)
+{
+	glColor3f(0.8f,0.8f,0.8f);
+
 	long unsigned int* id=ID.data();
 	for (unsigned int i=0; i < ID.size(); i+=3)
 	{
@@ -136,20 +189,6 @@ void ActiveMesh::displayMesh(void)
 		glVertex3f(Pos[*id].x,Pos[*id].y,Pos[*id].z); ++id;
 		glEnd();
 	}
-
-	std::vector<size_t> neigs;
-	ulm::getVertexImmediateNeighbours(*this,VertexID,neigs);
-
-	glPointSize(4.0f);
-	glBegin(GL_POINTS);
-	// centre vertex:
-	glColor3f(0.0f,0.0f,1.0f);
-	glVertex3f(Pos[VertexID].x,Pos[VertexID].y,Pos[VertexID].z);
-	// neigs:
-	glColor3f(1.0f,0.0f,0.0f);
-	for (unsigned int i=0; i < neigs.size(); ++i)
-		glVertex3f(Pos[neigs[i]].x,Pos[neigs[i]].y,Pos[neigs[i]].z);
-	glEnd();
 }
 
 
@@ -170,7 +209,10 @@ void display(void)
 
 	displayFrame();
 	displayAxes();
-	mesh.displayMesh();
+
+	if (showWholeMesh) mesh.displayMesh();
+	if (showVertexSurface) mesh.displayVertexAndNeigs();
+	if (showQuadricSurface) mesh.displayQuadricSurface();
 
 	glFlush();
 	glutSwapBuffers();
@@ -303,6 +345,16 @@ void keyboard(unsigned char key, int mx, int my)
 				glutPostRedisplay();
 				break;
 
+			case 'M':
+				showWholeMesh^=true;
+				break;
+			case 'V':
+				showVertexSurface^=true;
+				break;
+			case 'Q':
+				showQuadricSurface^=true;
+				break;
+
 			case 'i': //inspect a cell
 				GetSceneViewSize(windowSizeX,windowSizeY, xVisF,xVisT,yVisF,yVisT);
 				sx=(float)mx              /(float)windowSizeX * (xVisT-xVisF) + xVisF;
diff --git a/src/main.cpp b/src/main.cpp
index 8859286..60ac239 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,8 +34,10 @@ int main(void)
 	mesh.CenterMesh(params.sceneCentre);
 
 	//work with mesh
+/*
 	float surf_coeff[10];
 	mesh.CalcQuadricSurface_Taubin(10,surf_coeff);
+*/
 
 /*
 	//render mesh
@@ -50,11 +52,9 @@ int main(void)
 	mask.SaveImage("mesh.ics");
 */
 
-/*
 	initializeGL();
 	loopGL();
 	closeGL();
-*/
 
 	return(0);
 }
-- 
GitLab