main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include <QApplication>
00029 #include <QtCore/QDir>
00030 #include "rtabmap/utilite/UEventsManager.h"
00031 #include "rtabmap/core/RtabmapThread.h"
00032 #include "rtabmap/core/Rtabmap.h"
00033 #include "rtabmap/gui/MainWindow.h"
00034 #include <QMessageBox>
00035 #include "rtabmap/utilite/UObjDeletionThread.h"
00036 #include "rtabmap/utilite/UFile.h"
00037 #include "rtabmap/utilite/UConversion.h"
00038 #include "ObjDeletionHandler.h"
00039 
00040 using namespace rtabmap;
00041 
00042 int main(int argc, char* argv[])
00043 {
00044         /* Set logger type */
00045         ULogger::setType(ULogger::kTypeConsole);
00046         ULogger::setLevel(ULogger::kInfo);
00047 
00048         /* Create tasks */
00049         QApplication * app = new QApplication(argc, argv);
00050         app->setStyleSheet("QMessageBox { messagebox-text-interaction-flags: 5; }"); // selectable message box
00051 
00052         ParametersMap parameters = Parameters::parseArguments(argc, argv, false);
00053         MainWindow * mainWindow = new MainWindow();
00054     app->installEventFilter(mainWindow); // to catch FileOpen events.
00055     
00056     std::string database;
00057     for(int i=1; i<argc; ++i)
00058     {
00059         std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
00060         if(UFile::exists(value) &&
00061            UFile::getExtension(value).compare("db") == 0)
00062         {
00063             database = value;
00064             break;
00065         }
00066     }
00067 
00068         UINFO("Program started...");
00069 
00070         UEventsManager::addHandler(mainWindow);
00071 
00072         /* Start thread's task */
00073         if(mainWindow->isSavedMaximized())
00074         {
00075                 mainWindow->showMaximized();
00076         }
00077         else
00078         {
00079                 mainWindow->show();
00080         }
00081 
00082         RtabmapThread * rtabmap = new RtabmapThread(new Rtabmap());
00083         rtabmap->start(); // start it not initialized... will be initialized by event from the gui
00084         UEventsManager::addHandler(rtabmap);
00085     
00086     if(!database.empty())
00087     {
00088         mainWindow->openDatabase(database.c_str(), parameters);
00089     }
00090     else if(parameters.size())
00091     {
00092         mainWindow->updateParameters(parameters);
00093     }
00094 
00095         // Now wait for application to finish
00096         app->connect( app, SIGNAL( lastWindowClosed() ),
00097                                 app, SLOT( quit() ) );
00098         app->exec();// MUST be called by the Main Thread
00099 
00100         /* Remove handlers */
00101         UEventsManager::removeHandler(mainWindow);
00102         UEventsManager::removeHandler(rtabmap);
00103 
00104         UINFO("Killing threads...");
00105         rtabmap->join(true);
00106 
00107         UINFO("Closing RTAB-Map...");
00108         delete rtabmap;
00109         delete mainWindow;
00110         delete app;
00111         UINFO("All done!");
00112 
00113     return 0;
00114 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20