g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
examples
g2o_hierarchical
edge_creator.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 "
edge_creator.h
"
28
29
#include <cassert>
30
31
#include "
g2o/core/factory.h
"
32
33
namespace
g2o
{
34
35
using namespace
std;
36
37
bool
EdgeCreator::addAssociation
(
const
std::string& vertexTypes,
38
const
std::string& edgeType,
39
const
std::vector<int>& parameterIds) {
40
EntryMap::iterator it =
_vertexToEdgeMap
.find(vertexTypes);
41
if
(it !=
_vertexToEdgeMap
.end())
42
it->second = edgeType;
43
else
44
_vertexToEdgeMap
.insert(
45
make_pair(vertexTypes,
EdgeCreatorEntry
(edgeType, parameterIds)));
46
return
true
;
47
}
48
49
bool
EdgeCreator::addAssociation
(
const
std::string& vertexTypes,
50
const
std::string& edgeType) {
51
return
addAssociation
(vertexTypes, edgeType, std::vector<int>());
52
}
53
54
bool
EdgeCreator::removeAssociation
(
const
std::string& vertexTypes) {
55
EntryMap::iterator it =
_vertexToEdgeMap
.find(vertexTypes);
56
if
(it ==
_vertexToEdgeMap
.end())
return
false
;
57
_vertexToEdgeMap
.erase(it);
58
return
true
;
59
}
60
61
OptimizableGraph::Edge
*
EdgeCreator::createEdge
(
62
std::vector<OptimizableGraph::Vertex*>& vertices) {
63
std::stringstream key;
64
Factory
* factory =
Factory::instance
();
65
for
(
size_t
i = 0; i < vertices.size(); i++) {
66
key << factory->
tag
(vertices[i]) <<
";"
;
67
}
68
EntryMap::iterator it =
_vertexToEdgeMap
.find(key.str());
69
if
(it ==
_vertexToEdgeMap
.end()) {
70
cerr <<
"no thing in factory: "
<< key.str() << endl;
71
return
0;
72
}
73
HyperGraph::HyperGraphElement
* element =
74
factory->
construct
(it->second._edgeTypeName);
75
if
(!element) {
76
cerr <<
"no thing can be created"
<< endl;
77
return
0;
78
}
79
OptimizableGraph::Edge
* e =
dynamic_cast<
OptimizableGraph::Edge
*
>
(element);
80
assert(it->second._parameterIds.size() == e->
numParameters
());
81
for
(
size_t
i = 0; i < it->second._parameterIds.size(); i++) {
82
if
(!e->
setParameterId
(i, it->second._parameterIds[i])) {
83
cerr <<
"no thing in good for setting params"
<< endl;
84
return
0;
85
}
86
}
87
assert(e);
88
for
(
size_t
i = 0; i < vertices.size(); i++) e->
vertices
()[i] = vertices[i];
89
return
e;
90
}
91
92
}
// namespace g2o
g2o::Factory
create vertices and edges based on TAGs in, for example, a file
Definition
factory.h:48
g2o::Factory::instance
static Factory * instance()
return the instance
Definition
factory.cpp:46
g2o::Factory::construct
HyperGraph::HyperGraphElement * construct(const std::string &tag) const
Definition
factory.cpp:129
g2o::Factory::tag
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition
factory.cpp:138
g2o::HyperGraph::Edge::vertices
const VertexContainer & vertices() const
Definition
hyper_graph.h:186
g2o::OptimizableGraph::Edge
Definition
optimizable_graph.h:417
g2o::OptimizableGraph::Edge::setParameterId
bool setParameterId(int argNum, int paramId)
Definition
optimizable_graph.cpp:125
g2o::OptimizableGraph::Edge::numParameters
size_t numParameters() const
Definition
optimizable_graph.h:539
edge_creator.h
factory.h
g2o
Definition
dl_wrapper.cpp:55
g2o::EdgeCreator::EdgeCreatorEntry
Definition
edge_creator.h:46
g2o::EdgeCreator::_vertexToEdgeMap
EntryMap _vertexToEdgeMap
Definition
edge_creator.h:96
g2o::EdgeCreator::addAssociation
bool addAssociation(const std::string &vertexTypes, const std::string &edgeType)
Definition
edge_creator.cpp:49
g2o::EdgeCreator::createEdge
OptimizableGraph::Edge * createEdge(std::vector< OptimizableGraph::Vertex * > &vertices)
Definition
edge_creator.cpp:61
g2o::EdgeCreator::removeAssociation
bool removeAssociation(const std::string &vertexTypes)
Definition
edge_creator.cpp:54
g2o::HyperGraph::HyperGraphElement
Definition
hyper_graph.h:80
Generated on
for g2o by
1.17.0