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 <vtkVersionMacros.h>
40 #include <vtkObject.h>
41 
42 #if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION==9 && VTK_MINOR_VERSION >= 1)
43 #include <QVTKRenderWidget.h>
44 #endif
45 
46 using namespace rtabmap;
47 
48 int main(int argc, char* argv[])
49 {
50  /* Set logger type */
53 
54 #ifdef WIN32
55  CoInitialize(nullptr);
56 #endif
57 
58 #if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION==9 && VTK_MINOR_VERSION >= 1)
59  // needed to ensure appropriate OpenGL context is created for VTK rendering.
60  QSurfaceFormat::setDefaultFormat(QVTKRenderWidget::defaultFormat());
61 #endif
62 
63  /* Create tasks */
64  QApplication * app = new QApplication(argc, argv);
65  app->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); // selectable message box
66 
67  ParametersMap parameters = Parameters::parseArguments(argc, argv, false);
68  MainWindow * mainWindow = new MainWindow();
69  app->installEventFilter(mainWindow); // to catch FileOpen events.
70 
71  std::string database;
72  for(int i=1; i<argc; ++i)
73  {
74  std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
75  if(UFile::exists(value) &&
76  UFile::getExtension(value).compare("db") == 0)
77  {
78  database = value;
79  }
80  }
81 
82  printf("Program started...\n");
83 
84  UEventsManager::addHandler(mainWindow);
85 
86  /* Start thread's task */
87  if(mainWindow->isSavedMaximized())
88  {
89  mainWindow->showMaximized();
90  }
91  else
92  {
93  mainWindow->show();
94  }
95 
97  rtabmap->start(); // start it not initialized... will be initialized by event from the gui
99 
100  if(!database.empty())
101  {
102  mainWindow->openDatabase(database.c_str(), parameters);
103  }
104  else if(parameters.size())
105  {
106  mainWindow->updateParameters(parameters);
107  }
108 
109  // Now wait for application to finish
110  app->connect( app, SIGNAL( lastWindowClosed() ),
111  app, SLOT( quit() ) );
112  app->exec();// MUST be called by the Main Thread
113 
114  /* Remove handlers */
115  UEventsManager::removeHandler(mainWindow);
117 
118  rtabmap->join(true);
119 
120  printf("Closing RTAB-Map...\n");
121  delete rtabmap;
122  delete mainWindow;
123  delete app;
124  printf("All done!\n");
125 
126  return 0;
127 }
rtabmap::MainWindow
Definition: MainWindow.h:82
compare
bool compare
UEventsManager::removeHandler
static void removeHandler(UEventsHandler *handler)
Definition: UEventsManager.cpp:41
rtabmap::MainWindow::updateParameters
void updateParameters(const rtabmap::ParametersMap &parameters)
Definition: MainWindow.cpp:5387
rtabmap::Parameters::parseArguments
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
Definition: Parameters.cpp:599
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
rtabmap::MainWindow::openDatabase
void openDatabase(const QString &path, const rtabmap::ParametersMap &overridedParameters=rtabmap::ParametersMap())
Definition: MainWindow.cpp:5530
rtabmap::ParametersMap
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
RtabmapThread.h
UDirectory::homeDir
static std::string homeDir()
Definition: UDirectory.cpp:355
app
QApplication * app
Definition: tools/DataRecorder/main.cpp:59
UConversion.h
Some conversion functions.
UFile::getExtension
std::string getExtension()
Definition: UFile.h:140
UEventsManager::addHandler
static void addHandler(UEventsHandler *handler)
Definition: UEventsManager.cpp:28
UObjDeletionThread.h
Rtabmap.h
ULogger::kWarning
@ kWarning
Definition: ULogger.h:252
rtabmap_netvlad.argv
argv
Definition: rtabmap_netvlad.py:15
ULogger::setType
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
uReplaceChar
std::string UTILITE_EXPORT uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:33
MainWindow.h
rtabmap::MainWindow::isSavedMaximized
bool isSavedMaximized() const
Definition: MainWindow.h:110
rtabmap::Rtabmap
Definition: Rtabmap.h:54
UFile.h
rtabmap
Definition: CameraARCore.cpp:35
UFile::exists
bool exists()
Definition: UFile.h:104
UEventsManager.h
value
value
i
int i
main
int main(int argc, char *argv[])
Definition: app/src/main.cpp:48
rtabmap::RtabmapThread
Definition: RtabmapThread.h:51


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:11