GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/HMesh/ConnectivityKernel.h
00001 /* ----------------------------------------------------------------------- *
00002  * This file is part of GEL, www.imm.dtu.dk/GEL
00003  * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
00004  *
00005  * Principal authors:
00006  *  Christian Thode Larsen (thode2d@gmail.com)
00007  *  J. Andreas Baerentzen (jab@imm.dtu.dk)
00008  *
00009  * See LICENSE.txt for licensing information
00010  * ----------------------------------------------------------------------- */
00011 
00012 #ifndef __HMESH_CONNECTIVITY_KERNEL_H__
00013 #define __HMESH_CONNECTIVITY_KERNEL_H__
00014 
00015 #include <vector>
00016 #include <map>
00017 #include "ItemVector.h"
00018 #include "ItemID.h"
00019 
00020 namespace HMesh
00021 {
00022     typedef std::map<VertexID, VertexID> VertexIDRemap;
00023     typedef std::map<FaceID, FaceID> FaceIDRemap;
00024     typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;
00025 
00026     struct IDRemap
00027     {
00028         VertexIDRemap vmap;
00029         FaceIDRemap fmap;
00030         HalfEdgeIDRemap hmap;
00031     };
00032 
00033     struct Vertex
00034     { 
00035         HalfEdgeID out; 
00036     };
00037 
00038     struct Face
00039     { 
00040         HalfEdgeID last; 
00041     };
00042 
00043     struct HalfEdge
00044     {
00045         HalfEdgeID next;
00046         HalfEdgeID prev;
00047         HalfEdgeID opp;
00048         VertexID vert;
00049         FaceID face;
00050     };
00051 
00052     class ConnectivityKernel
00053     {
00054     public:
00056         VertexID add_vertex();
00058         FaceID add_face();
00060         HalfEdgeID add_halfedge();
00061 
00063         void remove_vertex(VertexID id);
00065         void remove_face(FaceID id);
00067         void remove_halfedge(HalfEdgeID id);
00068 
00070         void resize_vertices(size_t size);
00072         void resize_faces(size_t size);
00074         void resize_halfedges(size_t size);
00075 
00077         HalfEdgeID next(HalfEdgeID current) const;
00079         HalfEdgeID prev(HalfEdgeID current) const;
00081         HalfEdgeID opp(HalfEdgeID current) const;
00083         HalfEdgeID out(VertexID current) const;
00085         HalfEdgeID last(FaceID current) const;
00087         VertexID vert(HalfEdgeID id) const;
00089         FaceID face(HalfEdgeID id) const;
00090 
00092         void set_next(HalfEdgeID current, HalfEdgeID next);
00094         void set_prev(HalfEdgeID current, HalfEdgeID prev);
00096         void set_opp(HalfEdgeID current, HalfEdgeID opp);
00098         void set_out(VertexID current, HalfEdgeID out);
00100         void set_last(FaceID current, HalfEdgeID last);
00102         void set_vert(HalfEdgeID current, VertexID vert);
00104         void set_face(HalfEdgeID current, FaceID face);
00105 
00107         size_t active_vertices() const;
00109         size_t active_faces() const;
00111         size_t active_halfedges() const;
00112 
00114         size_t total_vertices() const;
00116         size_t total_faces() const;
00118         size_t total_halfedges() const;
00119 
00121         bool in_use(VertexID id) const;
00123         bool in_use(FaceID id) const;
00125         bool in_use(HalfEdgeID id) const;
00126 
00128         VertexID vertices_next(VertexID id, bool skip = true) const;
00130         HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
00132         FaceID faces_next(FaceID id, bool skip = true) const;
00133 
00135         VertexID vertices_prev(VertexID id, bool skip = true) const;
00137         HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
00139         FaceID faces_prev(FaceID id, bool skip = true) const;
00140 
00142         VertexID vertices_begin(bool skip = true) const;
00144         HalfEdgeID halfedges_begin(bool skip = true) const;
00146         FaceID faces_begin(bool skip = true) const;
00147 
00149         VertexID vertices_end() const;
00151         HalfEdgeID halfedges_end() const;
00153         FaceID faces_end() const;
00154 
00156         void cleanup(IDRemap& map);
00157 
00159         void clear();
00160 
00161     private:
00162         ItemVector<Vertex> vertices;
00163         ItemVector<Face> faces;
00164         ItemVector<HalfEdge> halfedges;
00165     };
00166 
00167     inline VertexID ConnectivityKernel::add_vertex()
00168     {
00169         vertices.add(Vertex());
00170         return VertexID(vertices.total_size() - 1);
00171     }
00172 
00173     inline FaceID ConnectivityKernel::add_face()
00174     {
00175         faces.add(Face());
00176         return FaceID(faces.total_size() - 1);
00177     }
00178 
00179     inline HalfEdgeID ConnectivityKernel::add_halfedge()
00180     {
00181         halfedges.add(HalfEdge());
00182         return HalfEdgeID(halfedges.total_size() - 1);
00183     }
00184 
00185 
00186 
00187 
00188     inline void ConnectivityKernel::remove_vertex(VertexID id)
00189     { vertices.remove(id.index); }
00190 
00191     inline void ConnectivityKernel::remove_face(FaceID id)
00192     { faces.remove(id.index); }
00193 
00194     inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
00195     { halfedges.remove(id.index); }
00196 
00197 
00198 
00199     inline void ConnectivityKernel::resize_vertices(size_t size)
00200     {  vertices.resize(size); }
00201 
00202     inline void ConnectivityKernel::resize_faces(size_t size)
00203     {  faces.resize(size); }
00204 
00205     inline void ConnectivityKernel::resize_halfedges(size_t size)
00206     {  halfedges.resize(size); }
00207 
00208 
00209     inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
00210     { return HalfEdgeID(halfedges[id.index].next); }
00211 
00212     inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
00213     { return HalfEdgeID(halfedges[id.index].prev); }
00214 
00215     inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
00216     { return HalfEdgeID(halfedges[id.index].opp); }
00217 
00218     inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
00219     { return HalfEdgeID(vertices[id.index].out); }
00220 
00221     inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
00222     { return HalfEdgeID(faces[id.index].last); }
00223 
00224     inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
00225     { return VertexID(halfedges[id.index].vert); }
00226 
00227     inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
00228     { return FaceID(halfedges[id.index].face); }
00229 
00230     inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
00231     { halfedges[id.index].next = next; }
00232 
00233     inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
00234     { halfedges[id.index].prev = prev; }
00235 
00236     inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
00237     {halfedges[id.index].opp = opp; }
00238 
00239     inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
00240     { vertices[id.index].out = out; }
00241 
00242     inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
00243     { faces[id.index].last = last; }
00244 
00245     inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
00246     { halfedges[id.index].vert = vert; }
00247 
00248     inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
00249     { halfedges[id.index].face = face; }
00250 
00251 
00252 
00253     inline size_t ConnectivityKernel::active_vertices() const
00254     { return vertices.active_size(); }
00255 
00256     inline size_t ConnectivityKernel::active_faces() const
00257     { return faces.active_size(); }
00258 
00259     inline size_t ConnectivityKernel::active_halfedges() const
00260     { return halfedges.active_size(); }
00261 
00262 
00263 
00264     inline size_t ConnectivityKernel::total_vertices() const
00265     { return vertices.total_size(); }
00266 
00267     inline size_t ConnectivityKernel::total_faces() const
00268     { return faces.total_size(); }
00269 
00270     inline size_t ConnectivityKernel::total_halfedges() const
00271     { return halfedges.total_size(); }
00272 
00273 
00274 
00275     inline bool ConnectivityKernel::in_use(VertexID id) const
00276     { return vertices.in_use(id.index); }
00277 
00278     inline bool ConnectivityKernel::in_use(FaceID id) const
00279     { return faces.in_use(id.index); }
00280 
00281     inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
00282     { return halfedges.in_use(id.index); }
00283 
00284 
00285 
00286     inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
00287     { return vertices.index_next(id.index, skip); }
00288 
00289     inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
00290     { return halfedges.index_next(id.index, skip); }
00291 
00292     inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
00293     { return faces.index_next(id.index, skip); }
00294 
00295     inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
00296     { return vertices.index_prev(id.index, skip); }
00297 
00298     inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
00299     { return halfedges.index_prev(id.index, skip); }
00300 
00301     inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
00302     { return faces.index_prev(id.index, skip); }
00303 
00304     inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
00305     { return vertices.index_begin(skip); }
00306 
00307     inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
00308     { return halfedges.index_begin(skip); }
00309 
00310     inline FaceID ConnectivityKernel::faces_begin(bool skip) const
00311     { return faces.index_begin(skip); }
00312 
00313     inline VertexID ConnectivityKernel::vertices_end() const
00314     { return vertices.index_end(); }
00315 
00316     inline HalfEdgeID ConnectivityKernel::halfedges_end() const
00317     { return halfedges.index_end(); }
00318 
00319     inline FaceID ConnectivityKernel::faces_end() const
00320     { return faces.index_end(); }
00321 
00322     inline void ConnectivityKernel::clear()
00323     {
00324         vertices.clear();
00325         faces.clear();
00326         halfedges.clear();
00327     }
00328 }
00329 
00330 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations