HalfEdgeMesh.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 __HALF_EDGE_H__
00013 #define __HALF_EDGE_H__
00014 
00015 #include "Mesh.h"
00016 #include <map>
00017 #include <set>
00018 #include <queue>
00019 
00020 class HalfEdgeMesh : public Mesh 
00021 {
00022 public:
00023   HalfEdgeMesh();
00024   ~HalfEdgeMesh();
00025         
00027   virtual bool addTriangle(const Vector3<float> &v1, const Vector3<float> &v2, const Vector3<float> & v3);
00028 
00029 
00030   virtual float area() const;
00031 
00032   virtual float volume() const;
00033 
00034   virtual int genus() const;
00035 
00036   virtual float curvature(const unsigned int vertexIndex, const Vector3<float>& n);
00037 
00038 
00039   //caculate the face normals and store the 
00040   //resulting normal inside Face structure
00041   virtual void calculateFaceNormals();
00042 
00043   virtual void calculateVertexNormals();
00044 
00045   virtual void draw();
00046 
00047   //validate the mesh
00048   void validate();
00049 
00050   //merge all  the boundaries of the mesh
00051   void mergeAllBoundaries();
00052 
00053 protected:
00054 
00056   const static unsigned int BORDER;
00058   const static unsigned int UNINITIALIZED;
00059 
00060   struct HalfEdge 
00061   {
00062     HalfEdge() : vert(UNINITIALIZED), face(UNINITIALIZED), next(UNINITIALIZED), prev(UNINITIALIZED), pair(UNINITIALIZED) { }
00063     unsigned int vert;  // index into mVerts
00064     unsigned int face;   // index into mFaces
00065     unsigned int next;  // index into mEdges
00066     unsigned int prev;  // index into mEdges
00067     unsigned int pair;  // index into mEdges
00068   };
00069 
00070   struct Vertex 
00071   {
00072     Vertex() : edge(UNINITIALIZED) { }
00073     Vector3<float> vec;  // the vertex coordinates
00074          Vector3<float> v_normal; // vertex normal
00075     unsigned int edge; // index into mEdges
00076   };
00077 
00078   struct Face 
00079   {
00080     Face() : edge(UNINITIALIZED) { }
00081     unsigned int edge; // index into mEdges
00082     Vector3<float> normal; // the face normal
00083   };
00084 
00085   std::vector<HalfEdge> mEdges;
00086   std::vector<Vertex> mVerts;
00087   std::vector<Face> mFaces;
00088   std::vector<float> mCurvature;
00089 
00090   std::map<Vector3<float>, unsigned int> mUniqueVerts;
00091 
00093   virtual bool addVertex(const Vector3<float>& v, unsigned int &indx);
00094 
00095   bool addHalfEdgePair(unsigned int v1, unsigned int v2, unsigned int &indx1, unsigned int &indx2);
00096 
00097 
00098   //merge an edge into  the boundary of the mesh
00099   void mergeBoundaryEdge(unsigned int indx);
00100 
00101   
00102   // Given a vertex, find all triangles that includes this vertex
00103   virtual bool findNeighbourTriangles(const unsigned int vertexIndex, std::vector<unsigned int>& foundTriangles) const;
00104 
00105 };
00106 
00107 #endif

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