g2o
Loading...
Searching...
No Matches
backbone_tree_action.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, H. Strasdat, 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
28
29#include <limits>
30
32#include "g2o/core/factory.h"
33namespace g2o {
34
35using namespace std;
36
38 const std::string& vertexTag, int level,
39 int step)
40 : _optimizer(optimizer), _vertexTag(vertexTag), _level(level), _step(step) {
42 init();
43}
44
46 _vsMap.clear();
47 _vsMmap.clear();
48 _freeEdges.clear();
49 for (HyperGraph::EdgeSet::iterator it = _optimizer->edges().begin();
50 it != _optimizer->edges().end(); ++it) {
52 if (e->level() == _level) {
53 _freeEdges.insert(e);
54 }
55 }
56}
57
59 HyperGraph::Vertex* vParent,
60 HyperGraph::Edge* e, double distance) {
61 int depth = (int)distance;
62 if (_factory->tag(v) != _vertexTag) return 0;
63 Star* parentStar = getStar(vParent);
64 if (!parentStar) {
65 parentStar = new Star(_level + 1, _optimizer);
66 addToMap(parentStar, vParent);
67 parentStar->_gauge.insert(vParent);
68 }
69 addToMap(parentStar, v);
70 fillStar(parentStar, e);
71
72 // every _step levels you go down in the tree, create a new star
73 if (depth && !(depth % _step)) {
74 Star* star = new Star(_level + 1, _optimizer);
75 addToMap(star, v);
76 star->_gauge.insert(v);
77 }
78 return 1;
79}
80
83 VertexStarMap::iterator it = _vsMap.find(v);
84 if (it != _vsMap.end())
85 it->second = s;
86 else
87 _vsMap.insert(make_pair(v, s));
88 _vsMmap.insert(make_pair(v, s));
89 s->_lowLevelVertices.insert(v);
90}
91
94 VertexStarMap::iterator it = _vsMap.find(v);
95 if (it == _vsMap.end()) return 0;
96 return it->second;
97}
98
101 HyperGraph::EdgeSet::iterator it = _freeEdges.find(e);
102 if (it != _freeEdges.end()) {
103 _freeEdges.erase(it);
104 s->_lowLevelEdges.insert(e);
105 for (size_t i = 0; i < e->vertices().size(); i++) {
106 s->_lowLevelVertices.insert(e->vertices()[i]);
107 }
108 return true;
109 }
110 return false;
111}
112} // namespace g2o
static Factory * instance()
return the instance
Definition factory.cpp:46
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition factory.cpp:138
const VertexContainer & vertices() const
abstract Vertex, your types must derive from that one
const EdgeSet & edges() const
int level() const
returns the level of the edge
A general case Vertex for optimization.
Definition jet.h:876
yylloc step()
Star * getStar(HyperGraph::Vertex *v)
BackBoneTreeAction(SparseOptimizer *optimizer, const std::string &vertexTag, int level, int step)
virtual double perform(HyperGraph::Vertex *v, HyperGraph::Vertex *vParent, HyperGraph::Edge *e, double distance)
bool fillStar(Star *s, HyperGraph::Edge *e_)
helper function that adds to a star an edge and all its vertices
void addToMap(Star *s, HyperGraph::Vertex *v)
void init()
initializes the visit and clears the internal structures
HyperGraph::EdgeSet _freeEdges
HyperGraph::VertexSet _lowLevelVertices
vertices that are fixed (center of the star)
Definition star.h:95
HyperGraph::VertexSet _gauge
vertices that are fixed (center of the star)
Definition star.h:93
HyperGraph::EdgeSet _lowLevelEdges
edges in the lower level
Definition star.h:87