cellcomplex.h

Go to the documentation of this file.
00001 
00008 #ifndef CELLCOMPLEX_H
00009 #define CELLCOMPLEX_H
00010 
00011 
00012 #include <iostream>
00013 #include <cstddef>
00014 #include <vector>
00015 #include <queue>
00016 #include <deque>
00017 
00018 #include "globals.h"
00019 #include "hash_set.h"
00020 #include "hash_map.h"
00021 #include "hash_classes.h"
00022 #include "util.h"
00023 #include "celltuple.h"
00024 #include "persistance.h"
00025 
00026 
00097 template <class Vertex,class Edge,class Face,class Tuple>
00098 class CellComplex{
00099     public:
00100         CellComplex(PersistantStore&);
00101         virtual ~CellComplex();
00102 
00103         PersistantStore& get_store() const;
00104 
00105     private:
00106         /* copy and assignment constructors declared private to prevent use */
00107         CellComplex( const CellComplex<Vertex, Edge, Face, Tuple> &other);
00108 
00109         CellComplex<Vertex, Edge, Face, Tuple>&
00110         operator=(const CellComplex<Vertex, Edge, Face, Tuple> &other);
00111 
00112 
00113     protected:
00122         virtual void add_vertex(Vertex*);
00123         virtual void add_edge(Edge *e);
00124         virtual void add_face(Face*,Edge**,int,bool inverse_handed=false);
00125 
00126         virtual void delete_vertex(Vertex*);
00127         virtual void delete_edge(Edge*);
00128         virtual void delete_face(Face*);
00139         void trash_cell(Cell*);
00140         void keep_trash();
00141         void empty_trash();
00144     public:
00147         typedef PersistantHashSet<Vertex*> Vertex_Hash_T;
00148         typedef PersistantHashSet<Edge*> Edge_Hash_T;
00149         typedef PersistantHashSet<Face*> Face_Hash_T;
00150         typedef PersistantHashMap<std::pair<Vertex*,Edge*>,Vertex*,PairHasher<Vertex*,Edge*> > Switch0_Hash_T;
00151         typedef PersistantHashMap<Tuple,Edge*,TupleHasher<Tuple> > Switch1_Hash_T;
00152         typedef PersistantHashMap<std::pair<Edge*,Face*>,Face*,PairHasher<Edge*,Face*> > Switch2_Hash_T;
00153         typedef PersistantHashSet<Face*> Inverted_Hash_T;
00158         bool is_member(Vertex*) const;
00159         bool is_member(Edge*) const;
00160         bool is_member(Face*) const;
00161     bool is_inverse_handed(Face*) const;
00175         int lower(Edge *e, std::vector<Vertex*> &vs);
00176         int lower(Edge *e, std::list<Vertex*> &vs);
00177         int lower(Face *f, std::vector<Edge*> &es);
00178         int lower(Face *f, std::list<Edge*> &es);
00179 
00180         int upper(Edge *e, std::vector<Face*> &fs);
00181         int upper(Edge *e, std::list<Face*> &fs);
00182         int upper(Vertex *v, std::vector<Edge*> &es);
00183         int upper(Vertex *v, std::list<Edge*> &es);
00184 
00185         Vertex* get_opposite_vertex(Edge *e, Vertex *v);
00186         Face*   get_opposite_face(Edge *e, Face *f);
00187 
00188         void enqueue_faces(Vertex *vert, std::deque<Face*> &faces);
00189         void enqueue_edges(Vertex *vert, std::deque<Edge*> &edges);
00190 
00191         Edge* find_common_edge(Vertex *v0, Vertex *v1);
00192         Edge* find_common_edge(Face *f0, Face *f1);
00193 
00194         void find_adjacent_faces(Face *f, std::list<Face*> &faces);
00195         void find_adjacent_edges(Edge *e, std::list<Edge*> &edges);
00196 
00197         void find_adjacent_faces(Face *f, std::deque<Face*> &faces);
00198         void find_adjacent_edges(Edge *e, std::deque<Edge*> &edges);
00217         Tuple Switch(int,const Tuple&) const;
00218 
00219         Tuple get_tuple() const;
00220         Tuple get_tuple(Face*) const;
00221         Tuple get_tuple(Vertex*, Face*) const;
00222         Tuple get_tuple(Edge*, Face*) const;
00223         Tuple get_tuple(Vertex*) const;
00224         Tuple get_tuple(Edge*) const;
00225     Tuple get_tuple(Vertex *v, Edge *e) const;
00226 
00227 
00235         int switch_size(int) const;
00240         void print(std::ostream& os = std::cout) const;
00241         void print_statistics(std::ostream& os = std::cout) const;
00242 
00243         template<class V,class E,class F,class T>
00244         friend std::ostream& operator<<( std::ostream &stream, const CellComplex<V, E, F, T> &bm);
00248         int get_num_vertices() const { return vertexs.size(); }
00249         typename Vertex_Hash_T::iterator get_vertexs_begin() const;
00250         typename Vertex_Hash_T::iterator get_vertexs_end() const;
00251         typename Vertex_Hash_T::iterator get_vertices_begin() const {
00252             return get_vertexs_begin();
00253         }
00254         typename Vertex_Hash_T::iterator get_vertices_end() const {
00255             return get_vertexs_end();
00256         }
00257 
00258         int get_num_edges() const { return edges.size(); }
00259         typename Edge_Hash_T::iterator get_edges_begin() const;
00260         typename Edge_Hash_T::iterator get_edges_end() const;
00261 
00262         int get_num_faces() const { return faces.size(); }
00263         typename Face_Hash_T::iterator get_faces_begin() const;
00264         typename Face_Hash_T::iterator get_faces_end() const;
00275         Vertex *get_next_vertex(typename Vertex_Hash_T::iterator&) const;
00276         Edge *get_next_edge(typename Edge_Hash_T::iterator&) const;
00277         Face *get_next_face(typename Face_Hash_T::iterator&) const;
00281     private:
00282         Vertex_Hash_T vertexs; 
00283         Edge_Hash_T edges; 
00284         Face_Hash_T faces; 
00289         typedef PersistantHashSet<Cell*> Trash_T;
00290         Trash_T trash_;
00291         int keep_trash_;
00294         /* Independent of the trash mechanism: this handles deleting things
00295            allocated and undone, or not actually deleting things until a
00296            commit. */
00297         PersistantMemoryPool<Cell> pool_;
00298 
00299         Switch0_Hash_T switch0; 
00300         Switch1_Hash_T switch1; 
00301         Switch2_Hash_T switch2; 
00302         Inverted_Hash_T inverted_faces; 
00303 };
00304 
00305 template<class Vertex,class Edge,class Face,class Tuple>
00306 inline std::ostream& operator << (std::ostream &stream,
00307                            const CellComplex<Vertex, Edge, Face, Tuple> &cc)
00308 {
00309     cc.print_statistics(stream);
00310     return stream;
00311 }
00312 
00313 #endif

Generated on Mon May 24 09:53:30 2010 for TUMBLE by  doxygen 1.5.2