g2o
Loading...
Searching...
No Matches
example_slam_interface.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, 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 <iostream>
30using namespace std;
31
33
34bool ExampleSlamInterface::addNode(const std::string& tag, int id,
35 int dimension,
36 const std::vector<double>& values) {
37 cerr << "ADDING NODE " << tag << " id=" << id << " dim=" << dimension;
38 if (values.size()) {
39 cerr << "\tpose=";
40 for (size_t i = 0; i < values.size(); ++i) cerr << " " << values[i];
41 }
42 cerr << endl;
43
44 // store the values
45 if (values.size() == 0)
46 _vertices[id] = make_pair(tag, std::vector<double>(dimension));
47 else
48 _vertices[id] = make_pair(tag, values);
49
50 return true;
51}
52
53bool ExampleSlamInterface::addEdge(const std::string& tag, int id,
54 int dimension, int v1, int v2,
55 const std::vector<double>& measurement,
56 const std::vector<double>& information) {
57 cerr << "ADDING EDGE " << tag << " id=" << id << " dim=" << dimension << " ("
58 << v1 << " <-> " << v2 << ")"
59 << " measurement=";
60 for (size_t i = 0; i < measurement.size(); ++i) cerr << " " << measurement[i];
61 cerr << " information=";
62 for (size_t i = 0; i < information.size(); ++i) cerr << " " << information[i];
63 cerr << endl;
64 return true;
65}
66
67bool ExampleSlamInterface::fixNode(const std::vector<int>& nodes) {
68 cerr << "FIXING NODE";
69 for (size_t i = 0; i < nodes.size(); ++i) cerr << " " << nodes[i];
70 cerr << endl;
71 return true;
72}
73
74bool ExampleSlamInterface::queryState(const std::vector<int>& nodes) {
75 cerr << "QUERY STATE";
76 for (size_t i = 0; i < nodes.size(); ++i) cerr << " " << nodes[i];
77 cerr << endl;
78
79 // actually output the values to the evaluator
80 // If a SLAM algorithm is running we would need to copy its estimate
81 if (nodes.size() == 0) {
82 // print all nodes
83 for (std::map<int,
84 std::pair<std::string, std::vector<double> > >::const_iterator
85 it = _vertices.begin();
86 it != _vertices.end(); ++it) {
87 cout << it->second.first << " " << it->first;
88 const vector<double>& values = it->second.second;
89 for (size_t j = 0; j < values.size(); ++j) cout << " " << values[j];
90 cout << endl;
91 }
92 } else {
93 for (size_t i = 0; i < nodes.size(); ++i) {
94 std::map<int,
95 std::pair<std::string, std::vector<double> > >::const_iterator
96 it = _vertices.find(nodes[i]);
97 if (it != _vertices.end()) {
98 cout << it->second.first << " " << it->first;
99 const vector<double>& values = it->second.second;
100 for (size_t j = 0; j < values.size(); ++j) cout << " " << values[j];
101 cout << endl;
102 }
103 }
104 }
105
106 return true;
107}
108
110 cerr << "SOLVE STATE" << endl;
111 return true;
112}
bool addNode(const std::string &tag, int id, int dimension, const std::vector< double > &values)
std::map< int, std::pair< std::string, std::vector< double > > > _vertices
bool addEdge(const std::string &tag, int id, int dimension, int v1, int v2, const std::vector< double > &measurement, const std::vector< double > &information)
bool fixNode(const std::vector< int > &nodes)
bool queryState(const std::vector< int > &nodes)
Definition jet.h:876