SimpleMesh.h

00001 /*************************************************************************************************
00002  *
00003  * Modeling and animation (TNM079) 2007
00004  * Code base for lab assignments. Copyright:
00005  *   Gunnar Johansson (gunnar.johansson@itn.liu.se)
00006  *   Ken Museth (ken.museth@itn.liu.se)
00007  *   Michael Bang Nielsen (bang@daimi.au.dk)
00008  *   Ola Nilsson (ola.nilsson@itn.liu.se)
00009  *   Andreas Sderstrm (andreas.soderstrom@itn.liu.se)
00010  *
00011  *************************************************************************************************/
00012 #ifndef __simplemesh_h__
00013 #define __simplemesh_h__
00014 
00015 #ifdef __APPLE__
00016 #include "GLUT/glut.h"
00017 #else
00018 #include "GL/glut.h"
00019 #endif
00020 #include "Mesh.h"
00021 
00022 #include <set>
00023 #include <map>
00024 #include <cassert>
00025 #include <limits>
00026 #include <algorithm>
00027 #include <cmath>
00028 #include <utility>
00029 
00030 #include "Vector3.h"
00031 
00032 struct MyEdge{
00033   MyEdge(unsigned int a, unsigned int b) : a(std::min(a, b)), b(std::max(a,b)) {}
00034   bool operator < (const MyEdge &eb) const {
00035     if (a<eb.a)
00036       return true;
00037     else if(a==eb.a)
00038       if(b<eb.b)
00039         return true;
00040     return false;
00041   }
00042   unsigned int a, b;
00043 };
00044 
00045 
00046 class SimpleMesh : public Mesh 
00047 {
00048 
00049 protected:
00050 
00051   struct Face 
00052   {
00053     unsigned int v1, v2, v3;
00054   };
00055 
00056   std::vector<Vector3<float> > mVerts;
00057   std::vector<Face> mFaces;
00058   std::vector<Vector3<float> > mNormals;
00059 
00060   std::map<Vector3<float>, unsigned int> mUniqueVerts;
00061 
00063   virtual bool addVertex(const Vector3<float>& v, unsigned int &indx);
00064   
00065   // Given a vertex, find all triangles that includes this vertex
00066   virtual bool findNeighbourTriangles(const unsigned int vertexIndex, std::vector<unsigned int>& foundTriangles) const;
00067   
00068 public: 
00069   SimpleMesh();
00070   ~SimpleMesh();
00071     
00073   virtual bool addTriangle(const Vector3<float> &v1, const Vector3<float> &v2, const Vector3<float> & v3);
00074     
00076   const std::vector<Vector3<float> >& getVerts() const { return mVerts; }
00077   const std::vector<Vector3<float> >& getNormals() const { return mNormals; }
00078   const std::vector<Face>& getTris() const { return mFaces; }
00079  
00080   // Methods for calculating normals
00081   virtual void calculateFaceNormals();
00082   virtual void calculateVertexNormals();  
00083   
00084   // Draw call
00085   virtual void draw();
00086   
00087     
00088   // Curvature calculation test
00089   float mMinCurv;
00090   float mMaxCurv;
00091   std::vector<float> curvatureArray;
00092   virtual float curvature(const unsigned int vertexIndex, const Vector3<float>& n);
00093   void calcCurv();
00094 };
00095 
00096 
00097 #endif

Generated on Fri Jul 20 23:57:42 2007 for HalfEdge by  doxygen 1.5.1