83 string outputFilename;
90 arg.
param(
"batch", batchEachN, 100,
"solve by a batch Cholesky after inserting N nodes");
91 arg.
param(
"update", updateEachN, 10,
"update the graph after inserting N nodes");
92 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
93 arg.
param(
"g", vis,
false,
"gnuplot visualization");
94 arg.
param(
"o", outputFilename,
"",
"output the final graph");
95 arg.
param(
"i", inputFilename,
"",
"input file (default g2o format), if not given read via stdin");
105 slamInterface.setUpdateGraphEachN(updateEachN);
106 slamInterface.setBatchSolveEachN(batchEachN);
108 cerr <<
"Updating every " << updateEachN << endl;
109 cerr <<
"Batch step every " << batchEachN << endl;
111 if (inputFilename.size() > 0) {
112 vector<EdgeInformation> edgesFromGraph;
116 _putenv_s(
"G2O_ENABLE_TICTOC",
"1");
118 setenv(
"G2O_ENABLE_TICTOC",
"1", 1);
122 int graphDimension = 0;
123 cerr <<
"Parsing " << inputFilename <<
" ... ";
125 ifstream ifs(inputFilename.c_str());
127 cerr <<
"Failure to open " << inputFilename << endl;
130 stringstream currentLine;
131 while (
readLine(ifs, currentLine)) {
133 currentLine >>
token;
134 if (token ==
"EDGE_SE2") {
138 currentLine >> currentEdge.
fromId >> currentEdge.
toId;
142 for (
int i = 0; i < 6; ++i)
144 }
else if (token ==
"EDGE_SE3:QUAT") {
148 currentLine >> currentEdge.
fromId >> currentEdge.
toId;
150 for (
size_t i = 0; i < currentEdge.
measurement.size(); ++i)
153 for (
size_t i = 0; i < currentEdge.
information.size(); ++i)
157 assert(graphDimension > 0);
160 cerr <<
"done." << endl;
164 bool freshlySolved =
false;
166 slamInterface.addNode(
"", 0, graphDimension, vector<double>());
167 for (vector<EdgeInformation>::const_iterator it = edgesFromGraph.begin(); it != edgesFromGraph.end(); ++it) {
170 if (minNodeId > lastNode) {
172 lastNode = minNodeId;
173 freshlySolved =
true;
176 switch (solverState) {
177 case G2oSlamInterface::SOLVED:
180 case G2oSlamInterface::SOLVED_BATCH:
181 cout <<
"b " << optimizer.
vertices().size() << endl;
190 freshlySolved =
false;
192 if (! freshlySolved) {
195 switch (solverState) {
196 case G2oSlamInterface::SOLVED:
199 case G2oSlamInterface::SOLVED_BATCH:
200 cout <<
"b " << optimizer.
vertices().size() << endl;
211 while (parserInterface.parseCommand(cin)) {}
214 if (outputFilename.size() > 0) {
215 cerr <<
"Saving " << outputFilename << endl;
216 optimizer.
save(outputFilename.c_str());
Command line parsing of argc and argv.
SlamParser::Parser::token token
top-level interface to the parser
const VertexIDMap & vertices() const
bool parseArgs(int argc, char **argv, bool exitOnError=true)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
void setVerbose(bool verbose)
double tictoc(const char *algorithmPart)
Profile the timing of certain parts of your algorithm.
void setForceStopFlag(bool *flag)
int readLine(std::istream &is, std::stringstream ¤tLine)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
Sort Edges for inserting them sequentially.