Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShMesh.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHUTIL_SHMESH_HPP
00028 #define SHUTIL_SHMESH_HPP
00029 
00030 #include <list>
00031 #include <map>
00032 #include <set>
00033 
00034 #include "sh.hpp"
00035 
00036 namespace ShUtil {
00037 
00070 template<typename VertexType, typename FaceType, typename EdgeType>
00071 struct ShMeshType {
00072   typedef VertexType Vertex;
00073   typedef FaceType Face;
00074   typedef EdgeType Edge;
00075 };
00076 
00077 template<typename M>
00078 struct ShMeshVertex {
00079   typedef typename M::Edge Edge;
00080   Edge *edge; //< Edge that starts at this vertex 
00081 
00083   ShMeshVertex();
00084 
00086   ShMeshVertex(const ShMeshVertex<M> &other);
00087 };
00088 
00089 template<typename M>
00090 struct ShMeshFace {
00091   typedef typename M::Edge Edge;
00092   Edge *edge; //< Edge in this face 
00093 
00095   ShMeshFace();
00096 
00098   ShMeshFace(const ShMeshFace<M> &other);
00099 };
00100 
00101 // A half-edge going from start to end that is part of face.
00102 template<typename M>
00103 struct ShMeshEdge {
00104   typedef typename M::Vertex Vertex;
00105   typedef typename M::Face Face;
00106   typedef typename M::Edge Edge;
00107   Vertex *start; //< Start vertex 
00108   Vertex *end;  //< End vertex
00109   Face *face; //< Face  
00110   Edge *sym; //< Edge paired with this edge.
00111   Edge *next; //< Next edge in the face 
00112   Edge *prev; //< Previous edge in the face
00113 
00115   ShMeshEdge();
00116 
00118   ShMeshEdge(const ShMeshEdge<M> &other);
00119 
00122   void setLinks(Vertex *s, Vertex *e, Face *f, 
00123       Edge *next, Edge *prev, Edge *sym);
00124 
00126   void setNext(Edge *n);
00127 
00129   void setPrev(Edge *p);
00130 
00132   void setSym(Edge *s);
00133 };
00134 
00135 
00137 template<typename M>
00138 class ShMesh {
00139   public:
00140     typedef M MeshType; 
00141     typedef typename M::Vertex Vertex; 
00142     typedef typename M::Edge Edge; 
00143     typedef typename M::Face Face; 
00144 
00145     typedef std::set<Vertex*> VertexSet;
00146     typedef std::set<Edge*> EdgeSet;
00147     typedef std::set<Face*> FaceSet;
00148     typedef std::list<Vertex*> VertexList;
00149 
00151     ShMesh();
00152 
00155     ShMesh(const ShMesh<M>& other);
00156 
00158     ~ShMesh();
00159 
00161     ShMesh<M>& operator=(const ShMesh<M>& other); 
00162 
00164     void clear();
00165 
00171     Face* addFace(const VertexList &vl);
00172 
00176     void removeFace(Face *f);
00177 
00182     template<typename VertLess>
00183     void mergeVertices();
00184 
00192     void mergeEdges();
00193 
00196     bool earTriangulate();
00197 
00198     VertexSet verts;
00199     EdgeSet edges;
00200     FaceSet faces;
00201 
00202   protected:
00203     typedef std::map<Vertex*, Vertex*> VertexMap;
00204     typedef std::map<Edge*, Edge*> EdgeMap;
00205     typedef std::map<Face*, Face*> FaceMap;
00206 
00207     // TODO this is a real hack...figure out how to do removeHalfEdge(e) in log or 
00208     // constant time without the incidence map for weird meshes 
00209     // (e.g. with articulation points).
00210     
00211     // On certain meshes, all edges incident to a vertex v can be found
00212     // by traversing v.edge->sym pointers, but this is not always
00213     // the case.
00214     typedef std::multimap<Vertex*, Edge*> IncidenceMap;
00215     typedef typename IncidenceMap::value_type Incidence;
00216     typedef typename IncidenceMap::iterator IncidenceIterator;
00217     typedef std::pair<typename IncidenceMap::iterator, 
00218               typename IncidenceMap::iterator> IncidenceRange;
00219 
00220     IncidenceMap m_incidences; // m_incidences[v] holds all edges e with e.start = v
00221 
00229     void removeHalfEdge(Edge *e);
00230 
00232     void insertHalfEdge(Edge *e);
00233 };
00234 
00235 
00236 }
00237 
00238 #include "ShMeshImpl.hpp"
00239 
00240 #endif

Generated on Mon Jan 24 18:36:33 2005 for Sh by  doxygen 1.4.1