g2o
backbone_tree_action.cpp
Go to the documentation of this file.
1 #include <limits>
2 #include "g2o/core/factory.h"
3 #include "backbone_tree_action.h"
5 namespace g2o {
6 
7  using namespace std;
8 
9  BackBoneTreeAction::BackBoneTreeAction(SparseOptimizer* optimizer, std::string vertexTag, int level, int step):
10  _optimizer(optimizer),
11  _vertexTag(vertexTag),
12  _level(level),
13  _step(step) {
15  init();
16  }
17 
19  _vsMap.clear();
20  _vsMmap.clear();
21  _freeEdges.clear();
22  for (HyperGraph::EdgeSet::iterator it=_optimizer->edges().begin(); it!=_optimizer->edges().end(); it++){
24  if (e->level()==_level) {
25  _freeEdges.insert(e);
26  }
27  }
28  }
29 
31  HyperGraph::Vertex* vParent,
33  double distance){
34  int depth=(int) distance;
35  if (_factory->tag(v)!= _vertexTag)
36  return 0;
37  Star* parentStar=getStar(vParent);
38  if (! parentStar){
39  parentStar=new Star(_level+1,_optimizer);
40  addToMap(parentStar, vParent);
41  parentStar->_gauge.insert(vParent);
42  }
43  addToMap(parentStar,v);
44  fillStar(parentStar, e);
45 
46  // every _step levels you go down in the tree, create a new star
47  if (depth && ! (depth%_step )){
48  Star* star=new Star(_level+1, _optimizer);
49  addToMap(star,v);
50  star->_gauge.insert(v);
51  }
52  return 1;
53  }
54 
55 
58  VertexStarMap::iterator it=_vsMap.find(v);
59  if (it!=_vsMap.end())
60  it->second = s;
61  else
62  _vsMap.insert(make_pair(v,s));
63  _vsMmap.insert(make_pair(v,s));
64  s->_lowLevelVertices.insert(v);
65  }
66 
69  VertexStarMap::iterator it=_vsMap.find(v);
70  if (it==_vsMap.end())
71  return 0;
72  return it->second;
73  }
74 
77  HyperGraph::EdgeSet::iterator it=_freeEdges.find(e);
78  if (it!=_freeEdges.end()) {
79  _freeEdges.erase(it);
80  s->_lowLevelEdges.insert(e);
81  for (size_t i=0; i<e->vertices().size(); i++){
82  s->_lowLevelVertices.insert(e->vertices()[i]);
83  }
84  return true;
85  }
86  return false;
87  }
88 }
virtual double perform(HyperGraph::Vertex *v, HyperGraph::Vertex *vParent, HyperGraph::Edge *e, double distance)
static Factory * instance()
return the instance
Definition: factory.cpp:61
HyperGraph::EdgeSet _lowLevelEdges
edges in the lower level
Definition: star.h:58
VertexStarMultimap _vsMmap
int level() const
returns the level of the edge
SparseOptimizer * _optimizer
void init()
initializes the visit and clears the internal structures
const VertexContainer & vertices() const
Definition: hyper_graph.h:178
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition: factory.cpp:157
Definition: star.h:26
const EdgeSet & edges() const
Definition: hyper_graph.h:230
HyperGraph::VertexSet _lowLevelVertices
vertices that are fixed (center of the star)
Definition: star.h:66
HyperGraph::VertexSet _gauge
vertices that are fixed (center of the star)
Definition: star.h:64
Star * getStar(HyperGraph::Vertex *v)
A general case Vertex for optimization.
abstract Vertex, your types must derive from that one
Definition: hyper_graph.h:142
HyperGraph::EdgeSet _freeEdges
BackBoneTreeAction(SparseOptimizer *optimizer, std::string vertexTag, int level, int step)
void addToMap(Star *s, HyperGraph::Vertex *v)
bool fillStar(Star *s, HyperGraph::Edge *e_)
helper function that adds to a star an edge and all its vertices
yylloc step()