commit bcadc546038a17fd57228c87e2f5c4ce7074b51f Author: matlabbe Date: Thu Feb 17 01:47:00 2011 +0000 Initial commit git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@2 f169173b-cf89-36c8-b27e-44dbe73f0c83 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..cb6a5fe3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +####### DEPENDENCIES ####### +FIND_PACKAGE(UtiLite REQUIRED) +FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui REQUIRED ) +FIND_PACKAGE(OpenCV REQUIRED) + + +####### SOURCES ####### +ADD_SUBDIRECTORY( src ) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..9f805463 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,125 @@ + +### Qt Gui stuff ### +SET(headers_ui + ./ObjDeletionHandler.h +) + +#This will generate moc_* for Qt +QT4_WRAP_CPP(moc_srcs ${headers_ui}) + +SET(SRC_FILES + main.cpp + ${moc_srcs} +) + +SET(INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR} + ${UTILITE_INCLUDE_DIR} + ${OpenCV_INCLUDE_DIRS} +) + +INCLUDE(${QT_USE_FILE}) + +SET(LIBRARIES + ${UTILITE_LIBRARY} + ${QT_LIBRARIES} + ${OpenCV_LIBS} +) + +# Make sure the compiler can find include files from our library. +INCLUDE_DIRECTORIES(${INCLUDE_DIRS}) + +# For Apple set the icns file containing icons +IF(APPLE AND BUILD_AS_BUNDLE) + # set how it shows up in the Info.plist file + SET(MACOSX_BUNDLE_ICON_FILE ${PROJECT_NAME}.icns) + # set where in the bundle to put the icns file + SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + # include the icns file in the target + SET(SRC_FILES ${SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.icns) +ENDIF(APPLE AND BUILD_AS_BUNDLE) + +# Add exe icon resource +IF(WIN32) + IF( MINGW ) + # resource compilation for MinGW + ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/AppIco.o + COMMAND windres.exe -I${CMAKE_CURRENT_SOURCE_DIR} -i${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.rc + -o ${CMAKE_CURRENT_BINARY_DIR}/AppIco.o ) + SET(SRC_FILES ${SRC_FILES} ${CMAKE_CURRENT_BINARY_DIR}/AppIco.o) + ELSE( MINGW ) + SET(SRC_FILES ${SRC_FILES} ${PROJECT_NAME}.rc) + ENDIF( MINGW ) +ENDIF(WIN32) + +# Add binary +IF(APPLE AND BUILD_AS_BUNDLE) + ADD_EXECUTABLE(main_app MACOSX_BUNDLE ${SRC_FILES}) +ELSE() + ADD_EXECUTABLE(main_app WIN32 ${SRC_FILES}) +ENDIF() +TARGET_LINK_LIBRARIES(main_app corelib guilib ${LIBRARIES}) + +IF(APPLE AND BUILD_AS_BUNDLE) + SET_TARGET_PROPERTIES(main_app PROPERTIES + OUTPUT_NAME ${CMAKE_BUNDLE_NAME}) +ELSEIF(WIN32) + SET_TARGET_PROPERTIES(main_app PROPERTIES + OUTPUT_NAME ${PROJECT_NAME}) +ELSE() + SET_TARGET_PROPERTIES(main_app PROPERTIES + OUTPUT_NAME ${PROJECT_PREFIX}) +ENDIF() + +#--------------------------- +# Installation stuff +#--------------------------- +INSTALL(TARGETS main_app + RUNTIME DESTINATION bin COMPONENT runtime + BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime) + +IF(APPLE AND BUILD_AS_BUNDLE) +INSTALL(CODE "execute_process(COMMAND ln -s \"../MacOS/${CMAKE_BUNDLE_NAME}\" ${PROJECT_NAME} + WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)") +ENDIF(APPLE AND BUILD_AS_BUNDLE) + +SET(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}") +IF((APPLE AND BUILD_AS_BUNDLE) OR WIN32) + SET(plugin_dest_dir bin) + SET(qtconf_dest_dir bin) + IF(APPLE) + SET(plugin_dest_dir MacOS) + SET(qtconf_dest_dir Resources) + SET(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/${CMAKE_BUNDLE_NAME}") + ENDIF(APPLE) + + # Install needed Qt plugins by copying directories from the qt installation + # One can cull what gets copied by using 'REGEX "..." EXCLUDE' + INSTALL(DIRECTORY "${QT_PLUGINS_DIR}/imageformats" DESTINATION ${plugin_dest_dir}/plugins COMPONENT runtime) + + # install a qt.conf file + # this inserts some cmake code into the install script to write the file + SET(QT_CONF_FILE [Paths]\nPlugins=plugins) + IF(APPLE) + SET(QT_CONF_FILE [Paths]\nPlugins=MacOS/plugins) + ENDIF(APPLE) + INSTALL(CODE " + file(WRITE \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"${QT_CONF_FILE}\") + " COMPONENT runtime) + + # directories to look for dependencies + SET(DIRS ${QT_LIBRARY_DIRS} ${PROJECT_SOURCE_DIR}/bin) + + # Now the work of copying dependencies into the bundle/package + # The quotes are escaped and variables to use at install time have their $ escaped + # An alternative is the do a configure_file() on a script and use install(SCRIPT ...). + # Note that the image plugins depend on QtSvg and QtXml, and it got those copied + # over. + # To find dependencies, cmake use "otool" on Apple and "dumpbin" on Windows (make sure you have one of them). + install(CODE " + file(GLOB_RECURSE QTPLUGINS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/plugins/*${CMAKE_SHARED_LIBRARY_SUFFIX}\") + include(\"BundleUtilities\") + fixup_bundle(\"${APPS}\" \"\${QTPLUGINS}\" \"${DIRS}\") + " COMPONENT runtime) +ENDIF((APPLE AND BUILD_AS_BUNDLE) OR WIN32) + diff --git a/src/ObjDeletionHandler.h b/src/ObjDeletionHandler.h new file mode 100644 index 00000000..c49b8b8f --- /dev/null +++ b/src/ObjDeletionHandler.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke + * + * This file is part of RTAB-Map. + * + * RTAB-Map is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RTAB-Map is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RTAB-Map. If not, see . + */ + +#ifndef OBJDELETIONHANDLER_H_ +#define OBJDELETIONHANDLER_H_ + +#include "utilite/UEventsHandler.h" +#include "utilite/UEvent.h" +#include + +class ObjDeletionHandler : public QObject, public UEventsHandler +{ + Q_OBJECT + +public: + ObjDeletionHandler(int watchedId, QObject * receiver = 0, const char * member = 0) : _watchedId(watchedId) + { + if(receiver && member) + { + connect(this, SIGNAL(objDeletionEventReceived(int)), receiver, member); + } + } + virtual ~ObjDeletionHandler() {} + +signals: + void objDeletionEventReceived(int); + +protected: + virtual void handleEvent(UEvent * event) + { + if(event->getClassName().compare("ObjDeletedEvent") == 0 && + event->getCode() == _watchedId) + { + emit objDeletionEventReceived(_watchedId); + } + } +private: + int _watchedId; +}; + +#endif /* OBJDELETIONHANDLER_H_ */ diff --git a/src/RTAB-Map.icns b/src/RTAB-Map.icns new file mode 100644 index 00000000..8747cc5e Binary files /dev/null and b/src/RTAB-Map.icns differ diff --git a/src/RTAB-Map.ico b/src/RTAB-Map.ico new file mode 100644 index 00000000..eb277e91 Binary files /dev/null and b/src/RTAB-Map.ico differ diff --git a/src/RTAB-Map.rc b/src/RTAB-Map.rc new file mode 100644 index 00000000..08f859a8 --- /dev/null +++ b/src/RTAB-Map.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "CTABMap.ico" diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 00000000..6970067e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke + * + * This file is part of RTAB-Map. + * + * RTAB-Map is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RTAB-Map is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RTAB-Map. If not, see . + */ + +#include +#include +#include "utilite/UEventsManager.h" +#include "rtabmap/core/Rtabmap.h" +#include "rtabmap/gui/MainWindow.h" +#include +#include "utilite/UObjDeletionThread.h" +#include "ObjDeletionHandler.h" + +using namespace rtabmap; + +int main(int argc, char* argv[]) +{ + + /* Set logger type */ + ULogger::setType(ULogger::kTypeConsole); + ULogger::setLevel(ULogger::kDebug); // Disable log with level + + ULOGGER_INFO("Program started..."); + + /* Create tasks */ + Rtabmap * rtabmap = new Rtabmap(); + QApplication * app = new QApplication(argc, argv); + MainWindow * mainWindow = new MainWindow(); + + /* Add handlers to the EventsManager */ + UEventsManager::addHandler(mainWindow); + UEventsManager::addHandler(rtabmap); //thread + + /* Start thread's task */ + mainWindow->showNormal(); + + // 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); + + ULOGGER_INFO("Killing threads..."); + rtabmap->kill(); + + ULOGGER_INFO("Free memory..."); + + //Since we can't put the Rtabmap object in the MainWindow class, + //we pop up a message box indicating that the rtabmap object + // is being deleted (saving data to the database) + QMessageBox * msg = new QMessageBox(QMessageBox::Information, QObject::tr("RTAB-Map is closing..."), QObject::tr("The detector is saving the working memory to the database..."), QMessageBox::NoButton); + msg->setEnabled(false); + msg->setIconPixmap(QPixmap(":/images/RTAB-Map.ico")); + msg->setWindowIcon(QIcon(":/images/RTAB-Map.ico")); + ObjDeletionThread delThread(rtabmap); + ObjDeletionHandler handler(delThread.id(), app, SLOT(quit())); + UEventsManager::addHandler(&handler); + delThread.startDeletion(); + msg->show(); + app->exec(); + delete msg; + delete mainWindow; + delete app; + + ULOGGER_INFO("All done! Closing..."); + + return 0; +}