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 
39 #include <vtkObject.h>
40 
41 using namespace rtabmap;
42 
43 int main(int argc, char* argv[])
44 {
45  /* Set logger type */
48 
49 #ifdef WIN32
50  CoInitialize(nullptr);
51 #endif
52 
53 #if VTK_MAJOR_VERSION >= 8
54  vtkObject::GlobalWarningDisplayOff();
55 #endif
56 
57  /* Create tasks */
58  QApplication * app = new QApplication(argc, argv);
59  app->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); // selectable message box
60 
61  ParametersMap parameters = Parameters::parseArguments(argc, argv, false);
62  MainWindow * mainWindow = new MainWindow();
63  app->installEventFilter(mainWindow); // to catch FileOpen events.
64 
65  std::string database;
66  for(int i=1; i<argc; ++i)
67  {
68  std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
69  if(UFile::exists(value) &&
70  UFile::getExtension(value).compare("db") == 0)
71  {
72  database = value;
73  }
74  }
75 
76  printf("Program started...\n");
77 
78  UEventsManager::addHandler(mainWindow);
79 
80  /* Start thread's task */
81  if(mainWindow->isSavedMaximized())
82  {
83  mainWindow->showMaximized();
84  }
85  else
86  {
87  mainWindow->show();
88  }
89 
91  rtabmap->start(); // start it not initialized... will be initialized by event from the gui
93 
94  if(!database.empty())
95  {
96  mainWindow->openDatabase(database.c_str(), parameters);
97  }
98  else if(parameters.size())
99  {
100  mainWindow->updateParameters(parameters);
101  }
102 
103  // Now wait for application to finish
104  app->connect( app, SIGNAL( lastWindowClosed() ),
105  app, SLOT( quit() ) );
106  app->exec();// MUST be called by the Main Thread
107 
108  /* Remove handlers */
109  UEventsManager::removeHandler(mainWindow);
111 
112  rtabmap->join(true);
113 
114  printf("Closing RTAB-Map...\n");
115  delete rtabmap;
116  delete mainWindow;
117  delete app;
118  printf("All done!\n");
119 
120  return 0;
121 }
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:596
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
bool isSavedMaximized() const
Definition: MainWindow.h:107
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:33
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 Jan 23 2023 03:37:29