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 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHUTIL_SHMESH_HPP
00021 #define SHUTIL_SHMESH_HPP
00022 
00023 #include <list>
00024 #include <map>
00025 #include <set>
00026 
00027 #include "sh.hpp"
00028 
00029 namespace ShUtil {
00030 
00063 template<typename VertexType, typename FaceType, typename EdgeType>
00064 struct ShMeshType {
00065   typedef VertexType Vertex;
00066   typedef FaceType Face;
00067   typedef EdgeType Edge;
00068 };
00069 
00070 template<typename M>
00071 struct ShMeshVertex {
00072   typedef typename M::Edge Edge;
00073   Edge *edge; //< Edge that starts at this vertex 
00074 
00076   ShMeshVertex();
00077 
00079   ShMeshVertex(const ShMeshVertex<M> &other);
00080 };
00081 
00082 template<typename M>
00083 struct ShMeshFace {
00084   typedef typename M::Edge Edge;
00085   Edge *edge; //< Edge in this face 
00086 
00088   ShMeshFace();
00089 
00091   ShMeshFace(const ShMeshFace<M> &other);
00092 };
00093 
00094 // A half-edge going from start to end that is part of face.
00095 template<typename M>
00096 struct ShMeshEdge {
00097   typedef typename M::Vertex Vertex;
00098   typedef typename M::Face Face;
00099   typedef typename M::Edge Edge;
00100   Vertex *start; //< Start vertex 
00101   Vertex *end;  //< End vertex
00102   Face *face; //< Face  
00103   Edge *sym; //< Edge paired with this edge.
00104   Edge *next; //< Next edge in the face 
00105   Edge *prev; //< Previous edge in the face
00106 
00108   ShMeshEdge();
00109 
00111   ShMeshEdge(const ShMeshEdge<M> &other);
00112 
00115   void setLinks(Vertex *s, Vertex *e, Face *f, 
00116       Edge *next, Edge *prev, Edge *sym);
00117 
00119   void setNext(Edge *n);
00120 
00122   void setPrev(Edge *p);
00123 
00125   void setSym(Edge *s);
00126 };
00127 
00128 
00130 template<typename M>
00131 class ShMesh {
00132   public:
00133     typedef M MeshType; 
00134     typedef typename M::Vertex Vertex; 
00135     typedef typename M::Edge Edge; 
00136     typedef typename M::Face Face; 
00137 
00138     typedef std::set<Vertex*> VertexSet;
00139     typedef std::set<Edge*> EdgeSet;
00140     typedef std::set<Face*> FaceSet;
00141     typedef std::list<Vertex*> VertexList;
00142 
00144     ShMesh();
00145 
00148     ShMesh(const ShMesh<M>& other);
00149 
00151     ~ShMesh();
00152 
00154     ShMesh<M>& operator=(const ShMesh<M>& other); 
00155 
00157     void clear();
00158 
00164     Face* addFace(const VertexList &vl);
00165 
00169     void removeFace(Face *f);
00170 
00175     template<typename VertLess>
00176     void mergeVertices();
00177 
00185     void mergeEdges();
00186 
00189     bool earTriangulate();
00190 
00191     VertexSet verts;
00192     EdgeSet edges;
00193     FaceSet faces;
00194 
00195   protected:
00196     typedef std::map<Vertex*, Vertex*> VertexMap;
00197     typedef std::map<Edge*, Edge*> EdgeMap;
00198     typedef std::map<Face*, Face*> FaceMap;
00199 
00200     // TODO this is a real hack...figure out how to do removeHalfEdge(e) in log or 
00201     // constant time without the incidence map for weird meshes 
00202     // (e.g. with articulation points).
00203     
00204     // On certain meshes, all edges incident to a vertex v can be found
00205     // by traversing v.edge->sym pointers, but this is not always
00206     // the case.
00207     typedef std::multimap<Vertex*, Edge*> IncidenceMap;
00208     typedef typename IncidenceMap::value_type Incidence;
00209     typedef typename IncidenceMap::iterator IncidenceIterator;
00210     typedef std::pair<typename IncidenceMap::iterator, 
00211               typename IncidenceMap::iterator> IncidenceRange;
00212 
00213     IncidenceMap m_incidences; // m_incidences[v] holds all edges e with e.start = v
00214 
00222     void removeHalfEdge(Edge *e);
00223 
00225     void insertHalfEdge(Edge *e);
00226 };
00227 
00228 
00229 }
00230 
00231 #include "ShMeshImpl.hpp"
00232 
00233 #endif

Generated on Thu Jul 28 17:33:04 2005 for Sh by  doxygen 1.4.3-20050530