g2o
Loading...
Searching...
No Matches
run_g2o_viewer.cpp
Go to the documentation of this file.
1// g2o - General Graph Optimization
2// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3//
4// This file is part of g2o.
5//
6// g2o is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// g2o is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with g2o. If not, see <http://www.gnu.org/licenses/>.
18
19#include "run_g2o_viewer.h"
20
21#include <QApplication>
22#include <QThread>
23
25#include "g2o/config.h"
26#include "g2o/core/factory.h"
33#include "main_window.h"
34#include "stream_redirect.h"
35
36namespace g2o {
37
41class SleepThread : public QThread {
42 public: // make the protected methods publicly available
43 using QThread::msleep;
44 using QThread::usleep;
45};
46
47int RunG2OViewer::run(int argc, char** argv, CommandArgs& arg) {
48 std::string inputFilename;
49 std::string loadLookup;
50 arg.param("renameTypes", loadLookup, "",
51 "create a lookup for loading types into other types,\n\t "
52 "TAG_IN_FILE=INTERNAL_TAG_FOR_TYPE,TAG2=INTERNAL2\n\t e.g., "
53 "VERTEX_CAM=VERTEX_SE3:EXPMAP");
54 arg.paramLeftOver("graph-input", inputFilename, "",
55 "graph file which will be processed", true);
56 arg.parseArgs(argc, argv);
57
58 MainWindow mw;
61 mw.show();
62
63 // redirect the output that normally goes to cerr to the textedit in the
64 // viewer
65 StreamRedirect redirect(std::cerr, mw.plainTextEdit);
66
67 // setting up the optimizer
68 SparseOptimizer* optimizer = new SparseOptimizer();
69 // Loading the input data
70 if (loadLookup.size() > 0) {
71 optimizer->setRenamedTypesFromString(loadLookup);
72 }
73 mw.viewer->graph = optimizer;
74
75 // set up the GUI action
76 GuiHyperGraphAction guiHyperGraphAction;
77 guiHyperGraphAction.viewer = mw.viewer;
78 // optimizer->addPostIterationAction(&guiHyperGraphAction);
79 optimizer->addPreIterationAction(&guiHyperGraphAction);
80
81 if (inputFilename.size() > 0) {
82 mw.loadFromFile(QString::fromStdString(inputFilename));
83 }
84
85 QCoreApplication* myapp = QApplication::instance();
86 while (mw.isVisible()) {
87 guiHyperGraphAction.dumpScreenshots = mw.actionDump_Images->isChecked();
88 if (myapp) myapp->processEvents();
89 SleepThread::msleep(10);
90 }
91
92 delete optimizer;
93 return 0;
94}
95
96} // namespace g2o
main window of the g2o viewer
Definition main_window.h:40
void updateDisplayedSolvers()
bool loadFromFile(const QString &filename)
void updateRobustKernels()
redirect a stream to a QPlainTextEdit
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
action which calls an GUI update after each iteration
G2oQGLViewer * viewer
the viewer which visualizes the graph
static int run(int argc, char **argv, CommandArgs &arg)
helper for calling usleep on any system using Qt
bool addPreIterationAction(HyperGraphAction *action)
add an action to be executed before each iteration
void setRenamedTypesFromString(const std::string &types)