86int main(
int argc,
char** argv) {
88 string outputFilename;
95 arg.
param(
"batch", batchEachN, 100,
96 "solve by a batch Cholesky after inserting N nodes");
97 arg.
param(
"update", updateEachN, 10,
98 "update the graph after inserting N nodes");
99 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
100 arg.
param(
"g", vis,
false,
"gnuplot visualization");
101 arg.
param(
"o", outputFilename,
"",
"output the final graph");
102 arg.
param(
"i", inputFilename,
"",
103 "input file (default g2o format), if not given read via stdin");
116 cerr <<
"Updating every " << updateEachN << endl;
117 cerr <<
"Batch step every " << batchEachN << endl;
119 if (inputFilename.size() > 0) {
120 vector<EdgeInformation> edgesFromGraph;
123#if defined _MSC_VER || defined __MINGW32__
124 _putenv_s(
"G2O_ENABLE_TICTOC",
"1");
126 setenv(
"G2O_ENABLE_TICTOC",
"1", 1);
130 int graphDimension = 0;
131 cerr <<
"Parsing " << inputFilename <<
" ... ";
133 ifstream ifs(inputFilename.c_str());
135 cerr <<
"Failure to open " << inputFilename << endl;
138 stringstream currentLine;
139 while (
readLine(ifs, currentLine)) {
141 currentLine >>
token;
142 if (
token ==
"EDGE_SE2") {
146 currentLine >> currentEdge.
fromId >> currentEdge.
toId;
151 for (
int i = 0; i < 6; ++i) currentLine >> currentEdge.
information[i];
152 }
else if (
token ==
"EDGE_SE3:QUAT") {
156 currentLine >> currentEdge.
fromId >> currentEdge.
toId;
158 for (
size_t i = 0; i < currentEdge.
measurement.size(); ++i)
161 for (
size_t i = 0; i < currentEdge.
information.size(); ++i)
165 assert(graphDimension > 0);
166 sort(edgesFromGraph.begin(), edgesFromGraph.end(),
169 cerr <<
"done." << endl;
175 slamInterface.
addNode(
"", 0, graphDimension, vector<double>());
176 for (vector<EdgeInformation>::const_iterator it = edgesFromGraph.begin();
177 it != edgesFromGraph.end(); ++it) {
180 if (minNodeId > lastNode) {
182 lastNode = minNodeId;
198 if (outputFilename.size() > 0) {
199 cerr <<
"Saving " << outputFilename << endl;
200 optimizer.
save(outputFilename.c_str());
bool addEdge(const std::string &tag, int id, int dimension, int v1, int v2, const std::vector< double > &measurement, const std::vector< double > &information)