hyper_graph.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_AIS_HYPER_GRAPH_HH
28 #define G2O_AIS_HYPER_GRAPH_HH
29 
30 #include <map>
31 #include <set>
32 #include <bitset>
33 #include <cassert>
34 #include <vector>
35 #include <limits>
36 #include <cstddef>
37 
38 #ifdef _MSC_VER
39 #include <unordered_map>
40 #else
41 #include <tr1/unordered_map>
42 #endif
43 
44 
47 namespace g2o {
48 
58  class HyperGraph
59  {
60  public:
61 
71  HGET_NUM_ELEMS // keep as last elem
72  };
73 
74  typedef std::bitset<HyperGraph::HGET_NUM_ELEMS> GraphElemBitset;
75 
76  class Vertex;
77  class Edge;
78 
83  virtual ~HyperGraphElement() {}
87  virtual HyperGraphElementType elementType() const = 0;
88  };
89 
90  typedef std::set<Edge*> EdgeSet;
91  typedef std::set<Vertex*> VertexSet;
92 
93  typedef std::tr1::unordered_map<int, Vertex*> VertexIDMap;
94  typedef std::vector<Vertex*> VertexContainer;
95 
97  class Vertex : public HyperGraphElement {
98  public:
100  explicit Vertex(int id=-1);
101  virtual ~Vertex();
103  int id() const {return _id;}
104  virtual void setId( int newId) { _id=newId; }
106  const EdgeSet& edges() const {return _edges;}
108  EdgeSet& edges() {return _edges;}
109  virtual HyperGraphElementType elementType() const { return HGET_VERTEX;}
110  protected:
111  int _id;
112  EdgeSet _edges;
113  };
114 
119  class Edge : public HyperGraphElement {
120  public:
122  explicit Edge(int id = -1);
123  virtual ~Edge();
124 
128  virtual void resize(size_t size);
132  const VertexContainer& vertices() const { return _vertices;}
136  VertexContainer& vertices() { return _vertices;}
140  const Vertex* vertex(size_t i) const { assert(i < _vertices.size() && "index out of bounds"); return _vertices[i];}
144  Vertex* vertex(size_t i) { assert(i < _vertices.size() && "index out of bounds"); return _vertices[i];}
148  void setVertex(size_t i, Vertex* v) { assert(i < _vertices.size() && "index out of bounds"); _vertices[i]=v;}
149 
150  int id() const {return _id;}
151  void setId(int id);
152  virtual HyperGraphElementType elementType() const { return HGET_EDGE;}
153  protected:
154  VertexContainer _vertices;
155  int _id;
156  };
157 
158  public:
160  HyperGraph();
162  virtual ~HyperGraph();
163 
165  Vertex* vertex(int id);
167  const Vertex* vertex(int id) const;
168 
170  virtual bool removeVertex(Vertex* v);
172  virtual bool removeEdge(Edge* e);
174  virtual void clear();
175 
177  const VertexIDMap& vertices() const {return _vertices;}
179  VertexIDMap& vertices() {return _vertices;}
180 
182  const EdgeSet& edges() const {return _edges;}
184  EdgeSet& edges() {return _edges;}
185 
192  virtual bool addVertex(Vertex* v);
193 
198  virtual bool addEdge(Edge* e);
199 
204  virtual bool changeId(Vertex* v, int newId);
205 
206  protected:
207  VertexIDMap _vertices;
208  EdgeSet _edges;
209 
210  private:
211  // Disable the copy constructor and assignment operator
212  HyperGraph(const HyperGraph&) { }
213  HyperGraph& operator= (const HyperGraph&) { return *this; }
214  };
215 
216 } // end namespace
217 
219 
220 #endif
int id() const
returns the id
Definition: hyper_graph.h:103
const Vertex * vertex(size_t i) const
Definition: hyper_graph.h:140
std::vector< Vertex * > VertexContainer
Definition: hyper_graph.h:94
std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
Definition: hyper_graph.h:74
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:91
HyperGraphElementType
enum of all the types we have in our graphs
Definition: hyper_graph.h:65
virtual bool changeId(Vertex *v, int newId)
Definition: hyper_graph.cpp:89
Vertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
Definition: hyper_graph.cpp:60
void setVertex(size_t i, Vertex *v)
Definition: hyper_graph.h:148
virtual bool addEdge(Edge *e)
Definition: hyper_graph.cpp:99
const VertexIDMap & vertices() const
Definition: hyper_graph.h:177
HyperGraph & operator=(const HyperGraph &)
Definition: hyper_graph.h:213
virtual void setId(int newId)
Definition: hyper_graph.h:104
std::set< Edge * > EdgeSet
Definition: hyper_graph.h:90
Vertex * vertex(size_t i)
Definition: hyper_graph.h:144
virtual bool removeVertex(Vertex *v)
removes a vertex from the graph. Returns true on success (vertex was present)
const VertexContainer & vertices() const
Definition: hyper_graph.h:132
const EdgeSet & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
Definition: hyper_graph.h:106
const EdgeSet & edges() const
Definition: hyper_graph.h:182
VertexContainer & vertices()
Definition: hyper_graph.h:136
EdgeSet & edges()
Definition: hyper_graph.h:184
virtual void clear()
clears the graph and empties all structures.
virtual HyperGraphElementType elementType() const =0
abstract Vertex, your types must derive from that one
Definition: hyper_graph.h:97
virtual HyperGraphElementType elementType() const
Definition: hyper_graph.h:152
virtual bool addVertex(Vertex *v)
Definition: hyper_graph.cpp:76
VertexIDMap & vertices()
Definition: hyper_graph.h:179
VertexIDMap _vertices
Definition: hyper_graph.h:207
std::tr1::unordered_map< int, Vertex * > VertexIDMap
Definition: hyper_graph.h:93
virtual HyperGraphElementType elementType() const
Definition: hyper_graph.h:109
HyperGraph()
constructs an empty hyper graph
virtual bool removeEdge(Edge *e)
removes a vertex from the graph. Returns true on success (edge was present)
HyperGraph(const HyperGraph &)
Definition: hyper_graph.h:212
EdgeSet & edges()
returns the set of hyper-edges that are leaving/entering in this vertex
Definition: hyper_graph.h:108
int _id
unique id
Definition: hyper_graph.h:155
virtual ~HyperGraph()
destroys the hyper-graph and all the vertices of the graph
VertexContainer _vertices
Definition: hyper_graph.h:154


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47