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  break;
65  }
66  }
67 
68  UINFO("Program started...");
69 
70  UEventsManager::addHandler(mainWindow);
71 
72  /* Start thread's task */
73  if(mainWindow->isSavedMaximized())
74  {
75  mainWindow->showMaximized();
76  }
77  else
78  {
79  mainWindow->show();
80  }
81 
83  rtabmap->start(); // start it not initialized... will be initialized by event from the gui
85 
86  if(!database.empty())
87  {
88  mainWindow->openDatabase(database.c_str(), parameters);
89  }
90  else if(parameters.size())
91  {
92  mainWindow->updateParameters(parameters);
93  }
94 
95  // Now wait for application to finish
96  app->connect( app, SIGNAL( lastWindowClosed() ),
97  app, SLOT( quit() ) );
98  app->exec();// MUST be called by the Main Thread
99 
100  /* Remove handlers */
101  UEventsManager::removeHandler(mainWindow);
103 
104  UINFO("Killing threads...");
105  rtabmap->join(true);
106 
107  UINFO("Closing RTAB-Map...");
108  delete rtabmap;
109  delete mainWindow;
110  delete app;
111  UINFO("All done!");
112 
113  return 0;
114 }
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:543
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
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
static RTABMapApp 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[])
#define UINFO(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31