g2o
Loading...
Searching...
No Matches
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
33namespace g2o {
34
35using namespace std;
36
37bool 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
49bool EdgeCreator::addAssociation(const std::string& vertexTypes,
50 const std::string& edgeType) {
51 return addAssociation(vertexTypes, edgeType, std::vector<int>());
52}
53
54bool 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
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 }
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
create vertices and edges based on TAGs in, for example, a file
Definition factory.h:48
static Factory * instance()
return the instance
Definition factory.cpp:46
HyperGraph::HyperGraphElement * construct(const std::string &tag) const
Definition factory.cpp:129
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition factory.cpp:138
const VertexContainer & vertices() const
bool setParameterId(int argNum, int paramId)
Definition jet.h:876
EntryMap _vertexToEdgeMap
bool addAssociation(const std::string &vertexTypes, const std::string &edgeType)
OptimizableGraph::Edge * createEdge(std::vector< OptimizableGraph::Vertex * > &vertices)
bool removeAssociation(const std::string &vertexTypes)