Highlight triangles, and draw points as spheres
authorDmitriy Morozov <morozov@cs.duke.edu>
Thu, 29 Jun 2006 09:29:01 -0400
changeset 7 8871c5317b90
parent 5 4928fc0f292d
child 8 2d94ef3aab03
Highlight triangles, and draw points as spheres
VEFViewer.cpp
VEFViewer.h
VEFViewer.pro
--- a/VEFViewer.cpp	Mon Jun 19 09:00:02 2006 -0400
+++ b/VEFViewer.cpp	Thu Jun 29 09:29:01 2006 -0400
@@ -1,6 +1,7 @@
 #include "VEFViewer.h"
 #include <QtDebug>
 #include <cstdio>
+#include "sphere.h"
 
 VEFViewer::VEFViewer(QWidget* parent): QGLViewer(parent)
 {
@@ -64,7 +65,6 @@
 	std::cout << "Center: " << center << std::endl;
 }
 
-// Draws a spiral
 void VEFViewer::draw()
 {
 	// GL_LIGHT0
@@ -238,7 +238,11 @@
 	if (!isVisible()) return;
 		
 	glColor3f(.5, .65, .65);
-	glCallList(display_list);
+
+	if (!isSphere())
+		glCallList(display_list);
+	else
+		glCallList(sphere_display_list);
 }
 void QVerticesLWI::drawWithNames(int offset) const
 {}
@@ -248,23 +252,39 @@
 {}
 
 QVerticesLWI::QVerticesLWI(QString name, FILE* file, VEFViewer* v): 
-	QDisplayListLWI(name)
+	QDisplayListLWI(name), isSphere_(false)
 {
+	// Read in vertices
+	Point p;
+	int result = fscanf(file, "%f %f %f", &p.x, &p.y, &p.z);
+	while(result != EOF)
+	{
+		vertices.push_back(p);
+		v->updateMinMax(p.x,p.y,p.z);
+		result = fscanf(file, "%f %f %f", &p.x, &p.y, &p.z);
+	}
+
+	// Create display list of points
 	display_list = glGenLists(1);
 	glNewList(display_list, GL_COMPILE);
 	glBegin(GL_POINTS);
-	
-		float x,y,z;
-		int result = fscanf(file, "%f %f %f", &x, &y, &z);
-		while(result != EOF)
-		{
-			glVertex3f(x,y,z);
-			v->updateMinMax(x,y,z);
-			result = fscanf(file, "%f %f %f", &x, &y, &z);
-		}
-
+		for (VertexContainer::const_iterator cur = vertices.begin(); cur != vertices.end(); ++cur)
+			glVertex3f(cur->x,cur->y,cur->z);
 	glEnd();
 	glEndList();
+
+	// Create display list of spheres
+	sphere_display_list = glGenLists(1);
+	glNewList(sphere_display_list, GL_COMPILE);
+	for (VertexContainer::const_iterator cur = vertices.begin(); cur != vertices.end(); ++cur)
+	{
+		XYZ c;
+		c.x = cur->x; c.y = cur->y; c.z = cur->z;
+		CreateSphere(c, .01, 6);
+	}
+	glEnd();
+	glEndList();
+
 }
 
 
@@ -302,6 +322,7 @@
 void QFacesLWI::drawWithNames(int offset) const
 {
 	if (!isVisible()) return;
+	if (isWireframe()) return;
 		
 	for (int i = 0; i < triangles.size(); i++)
 	{
@@ -322,6 +343,12 @@
 void QFacesLWI::highlight(int selected)
 {
 	highlighted = selected;
+	if (highlighted < 0) return;
+
+	const Triangle& t = triangles[highlighted];
+	std::cout << "Highlighted: (" << t.x0 << " " << t.y0 << " " << t.z0 << std::endl;
+	std::cout << "              " << t.x1 << " " << t.y1 << " " << t.z1 << std::endl;
+	std::cout << "              " << t.x2 << " " << t.y2 << " " << t.z2 << ")" << std::endl;
 }
 
 QFacesLWI::QFacesLWI(QString name, FILE* file, VEFViewer* v):
--- a/VEFViewer.h	Mon Jun 19 09:00:02 2006 -0400
+++ b/VEFViewer.h	Thu Jun 29 09:29:01 2006 -0400
@@ -80,14 +80,38 @@
 				
 };
 
+struct Point { float x,y,z; };
 class QVerticesLWI: public QDisplayListLWI
 {
+	Q_OBJECT
+		
 	public:
 		QVerticesLWI(QString name, FILE* file, VEFViewer* v);
 		virtual void draw() const;
 		virtual void drawWithNames(int offset) const;
 		virtual int numElements() const;
 		virtual void highlight(int selected);
+		virtual void setupMenu(QMenu& m) const
+		{
+			QDisplayListLWI::setupMenu(m);
+			
+			QAction* sphere_action= m.addAction("Sphere");
+			connect(sphere_action, SIGNAL(triggered()), this, SLOT(toggleSphere()));
+			sphere_action->setCheckable(true);
+			sphere_action->setChecked(isSphere());
+		}
+		
+		bool isSphere() const	{ return isSphere_; }
+	
+	public slots:
+		void toggleSphere()		{ isSphere_ = !isSphere_; }
+
+	private:
+		bool isSphere_;
+		GLuint sphere_display_list;
+
+		typedef 	std::vector<Point>		VertexContainer;
+		VertexContainer vertices;
 };
 
 class Triangle;
--- a/VEFViewer.pro	Mon Jun 19 09:00:02 2006 -0400
+++ b/VEFViewer.pro	Thu Jun 29 09:29:01 2006 -0400
@@ -2,8 +2,8 @@
 TARGET   = VEFViewer
 CONFIG  += qt opengl warn_on release thread
 
-HEADERS  = VEFViewer.h
-SOURCES  = VEFViewer.cpp main.cpp
+HEADERS  = VEFViewer.h sphere.h
+SOURCES  = VEFViewer.cpp sphere.cpp main.cpp
 FORMS   *= viewerInterface.Qt4.ui
 
 # The rest of this configuration file is pretty complex since it tries to automatically