00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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; 
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; 
00093 
00095   ShMeshFace();
00096 
00098   ShMeshFace(const ShMeshFace<M> &other);
00099 };
00100 
00101 
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; 
00108   Vertex *end;  
00109   Face *face; 
00110   Edge *sym; 
00111   Edge *next; 
00112   Edge *prev; 
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     
00208     
00209     
00210     
00211     
00212     
00213     
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; 
00221 
00229     void removeHalfEdge(Edge *e);
00230 
00232     void insertHalfEdge(Edge *e);
00233 };
00234 
00235 
00236 }
00237 
00238 #include "ShMeshImpl.hpp"
00239 
00240 #endif