g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
examples
g2o_hierarchical
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
27
#include "
backbone_tree_action.h
"
28
29
#include <limits>
30
31
#include "
edge_types_cost_function.h
"
32
#include "
g2o/core/factory.h
"
33
namespace
g2o
{
34
35
using namespace
std;
36
37
BackBoneTreeAction::BackBoneTreeAction
(
SparseOptimizer
* optimizer,
38
const
std::string& vertexTag,
int
level,
39
int
step
)
40
:
_optimizer
(optimizer),
_vertexTag
(vertexTag),
_level
(level),
_step
(
step
) {
41
_factory
=
Factory::instance
();
42
init
();
43
}
44
45
void
BackBoneTreeAction::init
() {
46
_vsMap
.clear();
47
_vsMmap
.clear();
48
_freeEdges
.clear();
49
for
(HyperGraph::EdgeSet::iterator it =
_optimizer
->edges().begin();
50
it !=
_optimizer
->edges().end(); ++it) {
51
OptimizableGraph::Edge
* e = (
OptimizableGraph::Edge
*)(*it);
52
if
(e->
level
() ==
_level
) {
53
_freeEdges
.insert(e);
54
}
55
}
56
}
57
58
double
BackBoneTreeAction::perform
(
HyperGraph::Vertex
* v,
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
81
void
BackBoneTreeAction::addToMap
(
Star
* s,
HyperGraph::Vertex
* v_) {
82
OptimizableGraph::Vertex
* v = (
OptimizableGraph::Vertex
*)v_;
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
92
Star
*
BackBoneTreeAction::getStar
(
HyperGraph::Vertex
* v_) {
93
OptimizableGraph::Vertex
* v = (
OptimizableGraph::Vertex
*)v_;
94
VertexStarMap::iterator it =
_vsMap
.find(v);
95
if
(it ==
_vsMap
.end())
return
0;
96
return
it->second;
97
}
98
99
bool
BackBoneTreeAction::fillStar
(
Star
* s,
HyperGraph::Edge
* e_) {
100
OptimizableGraph::Edge
* e = (
OptimizableGraph::Edge
*)e_;
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
backbone_tree_action.h
g2o::Factory::instance
static Factory * instance()
return the instance
Definition
factory.cpp:46
g2o::HyperGraph::Edge
Definition
hyper_graph.h:172
g2o::HyperGraph::Edge::vertices
const VertexContainer & vertices() const
Definition
hyper_graph.h:186
g2o::HyperGraph::Vertex
abstract Vertex, your types must derive from that one
Definition
hyper_graph.h:148
g2o::OptimizableGraph::Edge
Definition
optimizable_graph.h:417
g2o::OptimizableGraph::Edge::level
int level() const
returns the level of the edge
Definition
optimizable_graph.h:513
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::SparseOptimizer
Definition
sparse_optimizer.h:42
edge_types_cost_function.h
factory.h
g2o
Definition
dl_wrapper.cpp:55
step
yylloc step()
g2o::BackBoneTreeAction::getStar
Star * getStar(HyperGraph::Vertex *v)
Definition
backbone_tree_action.cpp:92
g2o::BackBoneTreeAction::_vsMmap
VertexStarMultimap _vsMmap
Definition
backbone_tree_action.h:102
g2o::BackBoneTreeAction::_optimizer
SparseOptimizer * _optimizer
Definition
backbone_tree_action.h:96
g2o::BackBoneTreeAction::_vertexTag
std::string _vertexTag
Definition
backbone_tree_action.h:97
g2o::BackBoneTreeAction::_factory
Factory * _factory
Definition
backbone_tree_action.h:104
g2o::BackBoneTreeAction::BackBoneTreeAction
BackBoneTreeAction(SparseOptimizer *optimizer, const std::string &vertexTag, int level, int step)
Definition
backbone_tree_action.cpp:37
g2o::BackBoneTreeAction::perform
virtual double perform(HyperGraph::Vertex *v, HyperGraph::Vertex *vParent, HyperGraph::Edge *e, double distance)
Definition
backbone_tree_action.cpp:58
g2o::BackBoneTreeAction::_vsMap
VertexStarMap _vsMap
Definition
backbone_tree_action.h:101
g2o::BackBoneTreeAction::_level
int _level
Definition
backbone_tree_action.h:98
g2o::BackBoneTreeAction::fillStar
bool fillStar(Star *s, HyperGraph::Edge *e_)
helper function that adds to a star an edge and all its vertices
Definition
backbone_tree_action.cpp:99
g2o::BackBoneTreeAction::addToMap
void addToMap(Star *s, HyperGraph::Vertex *v)
Definition
backbone_tree_action.cpp:81
g2o::BackBoneTreeAction::init
void init()
initializes the visit and clears the internal structures
Definition
backbone_tree_action.cpp:45
g2o::BackBoneTreeAction::_freeEdges
HyperGraph::EdgeSet _freeEdges
Definition
backbone_tree_action.h:103
g2o::BackBoneTreeAction::_step
int _step
Definition
backbone_tree_action.h:99
g2o::Star
Definition
star.h:54
g2o::Star::_lowLevelVertices
HyperGraph::VertexSet _lowLevelVertices
vertices that are fixed (center of the star)
Definition
star.h:95
g2o::Star::_gauge
HyperGraph::VertexSet _gauge
vertices that are fixed (center of the star)
Definition
star.h:93
g2o::Star::_lowLevelEdges
HyperGraph::EdgeSet _lowLevelEdges
edges in the lower level
Definition
star.h:87
Generated on
for g2o by
1.17.0