2011-06-05 14:45:39 +00:00
|
|
|
/*
|
2016-07-17 21:57:10 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:00:55 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2015-03-16 19:51:22 +00:00
|
|
|
#include <QApplication>
|
2011-06-05 14:45:39 +00:00
|
|
|
#include <QtCore/QDir>
|
2013-04-30 20:16:01 +00:00
|
|
|
#include "rtabmap/utilite/UEventsManager.h"
|
2013-02-03 22:12:02 +00:00
|
|
|
#include "rtabmap/core/RtabmapThread.h"
|
2014-02-24 21:04:02 +00:00
|
|
|
#include "rtabmap/core/Rtabmap.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
#include "rtabmap/gui/MainWindow.h"
|
2015-03-16 19:51:22 +00:00
|
|
|
#include <QMessageBox>
|
2013-04-30 20:16:01 +00:00
|
|
|
#include "rtabmap/utilite/UObjDeletionThread.h"
|
2016-04-10 14:52:14 -04:00
|
|
|
#include "rtabmap/utilite/UFile.h"
|
|
|
|
|
#include "rtabmap/utilite/UConversion.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2023-03-16 19:27:54 -07:00
|
|
|
#include <vtkVersionMacros.h>
|
2021-05-23 17:21:12 -04:00
|
|
|
#include <vtkObject.h>
|
|
|
|
|
|
2023-03-25 22:41:28 -07:00
|
|
|
#if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION==9 && VTK_MINOR_VERSION >= 1)
|
|
|
|
|
#include <QVTKRenderWidget.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
using namespace rtabmap;
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
/* Set logger type */
|
|
|
|
|
ULogger::setType(ULogger::kTypeConsole);
|
2018-10-12 16:03:29 -04:00
|
|
|
ULogger::setLevel(ULogger::kWarning);
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2021-06-18 12:43:08 -04:00
|
|
|
#ifdef WIN32
|
2026-07-04 18:16:37 -07:00
|
|
|
// STA (single-threaded apartment) is required for the native file dialogs / File Explorer
|
|
|
|
|
// (see commit d75cc04, "Fixed File Explorer hanging (Qt 5.12)"). Do NOT switch to MTA
|
|
|
|
|
// (CoInitializeEx COINIT_MULTITHREADED): it deadlocks the
|
|
|
|
|
// native file dialogs.
|
2021-06-18 12:43:08 -04:00
|
|
|
CoInitialize(nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-25 22:41:28 -07:00
|
|
|
#if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION==9 && VTK_MINOR_VERSION >= 1)
|
|
|
|
|
// needed to ensure appropriate OpenGL context is created for VTK rendering.
|
|
|
|
|
QSurfaceFormat::setDefaultFormat(QVTKRenderWidget::defaultFormat());
|
|
|
|
|
#endif
|
2021-05-23 17:21:12 -04:00
|
|
|
|
2026-07-04 18:16:37 -07:00
|
|
|
// Recommended by VTK when using QVTKOpenGLNativeWidget (a QOpenGLWidget): let all VTK
|
|
|
|
|
// render widgets share a single OpenGL context, which is needed for correct rendering
|
|
|
|
|
// when render widgets live in / move across multiple top-level windows. Must be set
|
|
|
|
|
// before QApplication is constructed.
|
|
|
|
|
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
/* Create tasks */
|
|
|
|
|
QApplication * app = new QApplication(argc, argv);
|
2017-01-27 14:31:44 -05:00
|
|
|
app->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); // selectable message box
|
2016-11-16 17:39:17 -05:00
|
|
|
|
2018-08-14 14:21:44 -04:00
|
|
|
ParametersMap parameters = Parameters::parseArguments(argc, argv, false);
|
2011-06-05 14:45:39 +00:00
|
|
|
MainWindow * mainWindow = new MainWindow();
|
2016-04-10 14:52:14 -04:00
|
|
|
app->installEventFilter(mainWindow); // to catch FileOpen events.
|
|
|
|
|
|
|
|
|
|
std::string database;
|
|
|
|
|
for(int i=1; i<argc; ++i)
|
|
|
|
|
{
|
|
|
|
|
std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
|
|
|
|
|
if(UFile::exists(value) &&
|
|
|
|
|
UFile::getExtension(value).compare("db") == 0)
|
|
|
|
|
{
|
|
|
|
|
database = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2018-10-12 16:03:29 -04:00
|
|
|
printf("Program started...\n");
|
2015-01-30 15:30:57 -05:00
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
UEventsManager::addHandler(mainWindow);
|
|
|
|
|
|
|
|
|
|
/* Start thread's task */
|
2015-01-30 15:30:57 -05:00
|
|
|
if(mainWindow->isSavedMaximized())
|
|
|
|
|
{
|
|
|
|
|
mainWindow->showMaximized();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mainWindow->show();
|
|
|
|
|
}
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2014-02-24 21:04:02 +00:00
|
|
|
RtabmapThread * rtabmap = new RtabmapThread(new Rtabmap());
|
2013-01-10 20:29:01 +00:00
|
|
|
rtabmap->start(); // start it not initialized... will be initialized by event from the gui
|
|
|
|
|
UEventsManager::addHandler(rtabmap);
|
2016-04-10 14:52:14 -04:00
|
|
|
|
|
|
|
|
if(!database.empty())
|
|
|
|
|
{
|
2018-07-27 16:01:17 -04:00
|
|
|
mainWindow->openDatabase(database.c_str(), parameters);
|
2016-04-10 14:52:14 -04:00
|
|
|
}
|
2018-08-14 14:21:44 -04:00
|
|
|
else if(parameters.size())
|
|
|
|
|
{
|
|
|
|
|
mainWindow->updateParameters(parameters);
|
|
|
|
|
}
|
2011-06-09 02:56:31 +00:00
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
// Now wait for application to finish
|
|
|
|
|
app->connect( app, SIGNAL( lastWindowClosed() ),
|
|
|
|
|
app, SLOT( quit() ) );
|
|
|
|
|
app->exec();// MUST be called by the Main Thread
|
|
|
|
|
|
|
|
|
|
/* Remove handlers */
|
|
|
|
|
UEventsManager::removeHandler(mainWindow);
|
|
|
|
|
UEventsManager::removeHandler(rtabmap);
|
|
|
|
|
|
2012-03-03 01:46:30 +00:00
|
|
|
rtabmap->join(true);
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2018-10-12 16:03:29 -04:00
|
|
|
printf("Closing RTAB-Map...\n");
|
2015-01-30 15:30:57 -05:00
|
|
|
delete rtabmap;
|
2014-01-22 19:49:28 +00:00
|
|
|
delete mainWindow;
|
2011-06-05 14:45:39 +00:00
|
|
|
delete app;
|
2018-10-12 16:03:29 -04:00
|
|
|
printf("All done!\n");
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|