g2o
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 "main_window.h"
22 #include "stream_redirect.h"
23 
24 #include "gui_hyper_graph_action.h"
25 
26 #include "g2o/config.h"
28 #include "g2o/core/factory.h"
31 
33 
34 #include "g2o/stuff/command_args.h"
36 
37 #include <QApplication>
38 #include <QThread>
39 
40 namespace g2o {
41 
45 class SleepThread : public QThread
46 {
47  public: // make the proctected methods publicly available
48  using QThread::msleep;
49  using QThread::usleep;
50 };
51 
52 int RunG2OViewer::run(int argc, char** argv, CommandArgs& arg)
53 {
54  std::string inputFilename;
55  arg.paramLeftOver("graph-input", inputFilename, "", "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 viewer
64  StreamRedirect redirect(std::cerr, mw.plainTextEdit);
65 
66  // setting up the optimizer
67  SparseOptimizer* optimizer = new SparseOptimizer();
68  mw.viewer->graph = optimizer;
69 
70  // set up the GUI action
71  GuiHyperGraphAction guiHyperGraphAction;
72  guiHyperGraphAction.viewer = mw.viewer;
73  //optimizer->addPostIterationAction(&guiHyperGraphAction);
74  optimizer->addPreIterationAction(&guiHyperGraphAction);
75 
76  if (inputFilename.size() > 0) {
77  mw.loadFromFile(QString::fromStdString(inputFilename));
78  }
79 
80  QCoreApplication* myapp = QApplication::instance();
81  while (mw.isVisible()) {
82  guiHyperGraphAction.dumpScreenshots = mw.actionDump_Images->isChecked();
83  if (myapp)
84  myapp->processEvents();
85  SleepThread::msleep(10);
86  }
87 
88  delete optimizer;
89  return 0;
90 }
91 
92 } //end namespace
helper for calling usleep on any system using Qt
void updateRobustKernels()
Command line parsing of argc and argv.
Definition: command_args.h:46
bool loadFromFile(const QString &filename)
void updateDisplayedSolvers()
redirect a stream to a QPlainTextEdit
bool parseArgs(int argc, char **argv, bool exitOnError=true)
class G2O_CORE_API SparseOptimizer
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
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)
main window of the g2o viewer
Definition: main_window.h:40
bool addPreIterationAction(HyperGraphAction *action)
add an action to be executed before each iteration