00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHUTIL_SHMESH_HPP
00025 #define SHUTIL_SHMESH_HPP
00026
00027 #include <list>
00028 #include <map>
00029 #include <set>
00030
00031 #include "sh.hpp"
00032
00033 namespace ShUtil {
00034
00067 template<typename VertexType, typename FaceType, typename EdgeType>
00068 struct ShMeshType {
00069 typedef VertexType Vertex;
00070 typedef FaceType Face;
00071 typedef EdgeType Edge;
00072 };
00073
00074 template<typename M>
00075 struct ShMeshVertex {
00076 typedef typename M::Edge Edge;
00077 Edge *edge;
00078
00080 ShMeshVertex();
00081
00083 ShMeshVertex(const ShMeshVertex<M> &other);
00084 };
00085
00086 template<typename M>
00087 struct ShMeshFace {
00088 typedef typename M::Edge Edge;
00089 Edge *edge;
00090
00092 ShMeshFace();
00093
00095 ShMeshFace(const ShMeshFace<M> &other);
00096 };
00097
00098
00099 template<typename M>
00100 struct ShMeshEdge {
00101 typedef typename M::Vertex Vertex;
00102 typedef typename M::Face Face;
00103 typedef typename M::Edge Edge;
00104 Vertex *start;
00105 Vertex *end;
00106 Face *face;
00107 Edge *sym;
00108 Edge *next;
00109 Edge *prev;
00110
00112 ShMeshEdge();
00113
00115 ShMeshEdge(const ShMeshEdge<M> &other);
00116
00119 void setLinks(Vertex *s, Vertex *e, Face *f,
00120 Edge *next, Edge *prev, Edge *sym);
00121
00123 void setNext(Edge *n);
00124
00126 void setPrev(Edge *p);
00127
00129 void setSym(Edge *s);
00130 };
00131
00132
00134 template<typename M>
00135 class ShMesh {
00136 public:
00137 typedef M MeshType;
00138 typedef typename M::Vertex Vertex;
00139 typedef typename M::Edge Edge;
00140 typedef typename M::Face Face;
00141
00142 typedef std::set<Vertex*> VertexSet;
00143 typedef std::set<Edge*> EdgeSet;
00144 typedef std::set<Face*> FaceSet;
00145 typedef std::list<Vertex*> VertexList;
00146
00148 ShMesh();
00149
00152 ShMesh(const ShMesh<M>& other);
00153
00155 ~ShMesh();
00156
00158 ShMesh<M>& operator=(const ShMesh<M>& other);
00159
00161 void clear();
00162
00168 Face* addFace(const VertexList &vl);
00169
00173 void removeFace(Face *f);
00174
00179 template<typename VertLess>
00180 void mergeVertices();
00181
00189 void mergeEdges();
00190
00193 bool earTriangulate();
00194
00195 VertexSet verts;
00196 EdgeSet edges;
00197 FaceSet faces;
00198
00199 protected:
00200 typedef std::map<Vertex*, Vertex*> VertexMap;
00201 typedef std::map<Edge*, Edge*> EdgeMap;
00202 typedef std::map<Face*, Face*> FaceMap;
00203
00204
00205
00206
00207
00208
00209
00210
00211 typedef std::multimap<Vertex*, Edge*> IncidenceMap;
00212 typedef typename IncidenceMap::value_type Incidence;
00213 typedef typename IncidenceMap::iterator IncidenceIterator;
00214 typedef std::pair<typename IncidenceMap::iterator,
00215 typename IncidenceMap::iterator> IncidenceRange;
00216
00217 IncidenceMap m_incidences;
00218
00226 void removeHalfEdge(Edge *e);
00227
00229 void insertHalfEdge(Edge *e);
00230 };
00231
00232
00233 }
00234
00235 #include "ShMeshImpl.hpp"
00236
00237 #endif