app/src/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
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 met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING 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 */
27 
28 #include <QApplication>
29 #include <QtCore/QDir>
32 #include "rtabmap/core/Rtabmap.h"
33 #include "rtabmap/gui/MainWindow.h"
34 #include <QMessageBox>
36 #include "rtabmap/utilite/UFile.h"
38 #include "ObjDeletionHandler.h"
39 
40 using namespace rtabmap;
41 
42 int main(int argc, char* argv[])
43 {
44  /* Set logger type */
47 
48  /* Create tasks */
49  QApplication * app = new QApplication(argc, argv);
50  app->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); // selectable message box
51 
52  ParametersMap parameters = Parameters::parseArguments(argc, argv, false);
53  MainWindow * mainWindow = new MainWindow();
54  app->installEventFilter(mainWindow); // to catch FileOpen events.
55 
56  std::string database;
57  for(int i=1; i<argc; ++i)
58  {
59  std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
60  if(UFile::exists(value) &&
61  UFile::getExtension(value).compare("db") == 0)
62  {
63  database = value;
64  }
65  }
66 
67  printf("Program started...\n");
68 
69  UEventsManager::addHandler(mainWindow);
70 
71  /* Start thread's task */
72  if(mainWindow->isSavedMaximized())
73  {
74  mainWindow->showMaximized();
75  }
76  else
77  {
78  mainWindow->show();
79  }
80 
82  rtabmap->start(); // start it not initialized... will be initialized by event from the gui
84 
85  if(!database.empty())
86  {
87  mainWindow->openDatabase(database.c_str(), parameters);
88  }
89  else if(parameters.size())
90  {
91  mainWindow->updateParameters(parameters);
92  }
93 
94  // Now wait for application to finish
95  app->connect( app, SIGNAL( lastWindowClosed() ),
96  app, SLOT( quit() ) );
97  app->exec();// MUST be called by the Main Thread
98 
99  /* Remove handlers */
100  UEventsManager::removeHandler(mainWindow);
102 
103  rtabmap->join(true);
104 
105  printf("Closing RTAB-Map...\n");
106  delete rtabmap;
107  delete mainWindow;
108  delete app;
109  printf("All done!\n");
110 
111  return 0;
112 }
static std::string homeDir()
Definition: UDirectory.cpp:355
void start()
Definition: UThread.cpp:122
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
Definition: Parameters.cpp:575
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
Some conversion functions.
std::string getExtension()
Definition: UFile.h:140
void openDatabase(const QString &path, const rtabmap::ParametersMap &overridedParameters=rtabmap::ParametersMap())
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
void updateParameters(const rtabmap::ParametersMap &parameters)
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:32
bool isSavedMaximized() const
Definition: MainWindow.h:105
QApplication * app
bool exists()
Definition: UFile.h:104
static void addHandler(UEventsHandler *handler)
static void removeHandler(UEventsHandler *handler)
void join(bool killFirst=false)
Definition: UThread.cpp:85
int main(int argc, char *argv[])


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59