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         MainWindow * mainWindow = new MainWindow();
00051     app->installEventFilter(mainWindow); // to catch FileOpen events.
00052     
00053     std::string database;
00054     for(int i=1; i<argc; ++i)
00055     {
00056         std::string value = uReplaceChar(argv[i], '~', UDirectory::homeDir());
00057         if(UFile::exists(value) &&
00058            UFile::getExtension(value).compare("db") == 0)
00059         {
00060             database = value;
00061             break;
00062         }
00063     }
00064 
00065         UINFO("Program started...");
00066 
00067         UEventsManager::addHandler(mainWindow);
00068 
00069         /* Start thread's task */
00070         if(mainWindow->isSavedMaximized())
00071         {
00072                 mainWindow->showMaximized();
00073         }
00074         else
00075         {
00076                 mainWindow->show();
00077         }
00078 
00079         RtabmapThread * rtabmap = new RtabmapThread(new Rtabmap());
00080         rtabmap->start(); // start it not initialized... will be initialized by event from the gui
00081         UEventsManager::addHandler(rtabmap);
00082     
00083     if(!database.empty())
00084     {
00085         QMetaObject::invokeMethod(mainWindow, "openDatabase", Qt::QueuedConnection, Q_ARG(QString, QString(database.c_str())));
00086     }
00087 
00088         // Now wait for application to finish
00089         app->connect( app, SIGNAL( lastWindowClosed() ),
00090                                 app, SLOT( quit() ) );
00091         app->exec();// MUST be called by the Main Thread
00092 
00093         /* Remove handlers */
00094         UEventsManager::removeHandler(mainWindow);
00095         UEventsManager::removeHandler(rtabmap);
00096 
00097         UINFO("Killing threads...");
00098         rtabmap->join(true);
00099 
00100         UINFO("Closing RTAB-Map...");
00101         delete rtabmap;
00102         delete mainWindow;
00103         delete app;
00104         UINFO("All done!");
00105 
00106     return 0;
00107 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:16