diff --git a/CMakeLists.txt b/CMakeLists.txt index 491193ba..bf3b85f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,9 @@ set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH IF(APPLE) OPTION(BUILD_AS_BUNDLE "Set to ON to build as bundle (DragNDrop)" OFF) ENDIF(APPLE) +OPTION(BUILD_APP "Build main application" ON) +OPTION(BUILD_TOOLS "Build tools" ON) +OPTION(BUILD_EXAMPLES "Build examples" ON) ####### DEPENDENCIES ####### @@ -135,6 +138,20 @@ option(WITH_FLYCAPTURE2 "Include FlyCapture2/Triclops support" ON) FIND_PACKAGE(OpenCV REQUIRED QUIET) FIND_PACKAGE(PCL 1.7 REQUIRED QUIET) FIND_PACKAGE(ZLIB REQUIRED QUIET) + +# OpenMP ("-fopenmp" should be added for flann included in PCL) +# the gcc-4.2.1 coming with MacOS X is not compatible with the OpenMP pragmas we use, so disabling OpenMP for it +if((NOT APPLE) OR (NOT CMAKE_COMPILER_IS_GNUCXX) OR (GCC_VERSION VERSION_GREATER 4.2.1) OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + find_package(OpenMP) +endif() +if(OPENMP_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + message (STATUS "Found OpenMP") +else(OPENMP_FOUND) + message (STATUS "Not found OpenMP") +endif() + IF(OpenCV_FOUND) MESSAGE(STATUS "Found OpenCV: ${OpenCV_INCLUDE_DIRS}") ENDIF(OpenCV_FOUND) @@ -272,13 +289,19 @@ ADD_SUBDIRECTORY( corelib ) IF(Qt5_FOUND OR (QT4_FOUND AND QT_QTCORE_FOUND AND QT_QTGUI_FOUND)) ADD_SUBDIRECTORY( guilib ) - ADD_SUBDIRECTORY( app ) + IF(BUILD_APP) + ADD_SUBDIRECTORY( app ) + ENDIF(BUILD_APP) ELSEIF(WITH_QT) MESSAGE(WARNING "Qt not found, the GUI lib and the stand-alone application will not be compiled...") ENDIF() -ADD_SUBDIRECTORY( tools ) -ADD_SUBDIRECTORY( examples ) +IF(BUILD_TOOLS) + ADD_SUBDIRECTORY( tools ) +ENDIF(BUILD_TOOLS) +IF(BUILD_EXAMPLES) + ADD_SUBDIRECTORY( examples ) +ENDIF(BUILD_EXAMPLES) ####################### # Uninstall target, for "make uninstall" @@ -303,7 +326,11 @@ set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/corelib/include" "${PROJECT_SOURCE_DIR}/guilib/include" "${PROJECT_SOURCE_DIR}/utilite/include") set(CONF_LIB_DIR "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") -set(CONF_WITH_GUI ${WITH_QT}) +IF(QT4_FOUND OR Qt5_FOUND) + set(CONF_WITH_GUI ON) +ELSE() + set(CONF_WITH_GUI OFF) +ENDIF() configure_file(RTABMapConfig.cmake.in "${PROJECT_BINARY_DIR}/RTABMapConfig.cmake" @ONLY) @@ -412,6 +439,9 @@ MESSAGE(STATUS "Info :") MESSAGE(STATUS " Version : ${RTABMAP_VERSION}") MESSAGE(STATUS " CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") MESSAGE(STATUS " CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") +MESSAGE(STATUS " BUILD_APP = ${BUILD_APP}") +MESSAGE(STATUS " BUILD_TOOLS = ${BUILD_TOOLS}") +MESSAGE(STATUS " BUILD_EXAMPLES = ${BUILD_EXAMPLES}") IF(NOT WIN32) # see comment above for the BUILD_SHARED_LIBS option on Windows MESSAGE(STATUS " BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}") diff --git a/corelib/include/rtabmap/core/CameraRGBD.h b/corelib/include/rtabmap/core/CameraRGBD.h index f39a2516..5f23a2b5 100644 --- a/corelib/include/rtabmap/core/CameraRGBD.h +++ b/corelib/include/rtabmap/core/CameraRGBD.h @@ -35,9 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "rtabmap/core/Camera.h" #include "rtabmap/core/CameraRGB.h" -#include -#include - #include namespace openni diff --git a/corelib/src/CMakeLists.txt b/corelib/src/CMakeLists.txt index b0b79314..304b37a2 100644 --- a/corelib/src/CMakeLists.txt +++ b/corelib/src/CMakeLists.txt @@ -223,12 +223,24 @@ SET(RESOURCES_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/DatabaseSchema_sql.h ) +IF(ANDROID) +IF(NOT URESOURCEGENERATOR) + MESSAGE( FATAL_ERROR "URESOURCEGENERATOR is not defined (it should point out on \"uresourcegenerator\" application created by a non-Android build), CMake will exit." ) +ENDIF(NOT URESOURCEGENERATOR) +ADD_CUSTOM_COMMAND( + OUTPUT ${RESOURCES_HEADERS} + COMMAND ${URESOURCEGENERATOR} -n rtabmap -p ${CMAKE_CURRENT_BINARY_DIR} ${RESOURCES} + COMMENT "[Creating resources]" + DEPENDS ${R} +) +ELSE() ADD_CUSTOM_COMMAND( OUTPUT ${RESOURCES_HEADERS} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/uresourcegenerator -n rtabmap -p ${CMAKE_CURRENT_BINARY_DIR} ${RESOURCES} COMMENT "[Creating resources]" DEPENDS ${R} uresourcegenerator ) +ENDIF() #################################### # Generate resources files END diff --git a/corelib/src/CameraRGB.cpp b/corelib/src/CameraRGB.cpp index 7841c651..8b31d97f 100644 --- a/corelib/src/CameraRGB.cpp +++ b/corelib/src/CameraRGB.cpp @@ -437,7 +437,6 @@ std::vector CameraImages::filenames() const SensorData CameraImages::captureImage() { - double actualDelay = 0.0; if(syncImageRateWithStamps_ && _captureDelay>0.0) { int sleepTime = (1000*_captureDelay - 1000.0f*_captureTimer.getElapsedTime()); @@ -460,8 +459,6 @@ SensorData CameraImages::captureImage() } } - actualDelay = 1.0/(_captureTimer.getElapsedTime()); - // Add precision at the cost of a small overhead while(_captureTimer.getElapsedTime() < _captureDelay-0.000001) { diff --git a/corelib/src/CameraRGBD.cpp b/corelib/src/CameraRGBD.cpp index 8db8b78f..a2da0845 100644 --- a/corelib/src/CameraRGBD.cpp +++ b/corelib/src/CameraRGBD.cpp @@ -42,6 +42,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef HAVE_OPENNI #include #include +#include +#include #endif #ifdef WITH_FREENECT diff --git a/corelib/src/Features2d.cpp b/corelib/src/Features2d.cpp index de178ad7..ae34b434 100644 --- a/corelib/src/Features2d.cpp +++ b/corelib/src/Features2d.cpp @@ -40,7 +40,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU #include +#endif #else #include #endif @@ -891,11 +893,19 @@ void ORB::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kFASTNonmaxSuppression(), nonmaxSuppresion_); #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0) { UWARN("GPU version of ORB not available! Using CPU version instead..."); gpu_ = false; } +#else + if(gpu_) + { + UWARN("GPU version of ORB not available (OpenCV not built with gpu/cuda module)! Using CPU version instead..."); + gpu_ = false; + } +#endif #else #ifndef HAVE_OPENCV_CUDAFEATURES2D if(gpu_) @@ -913,8 +923,12 @@ void ORB::parseParameters(const ParametersMap & parameters) if(gpu_) { #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU _gpuOrb = cv::Ptr(new CV_ORB_GPU(this->getMaxFeatures(), scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_)); _gpuOrb->setFastParams(fastThreshold_, nonmaxSuppresion_); +#else + UFATAL("not supposed to be here"); +#endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D UFATAL("not implemented"); @@ -945,9 +959,13 @@ std::vector ORB::generateKeypointsImpl(const cv::Mat & image, cons if(gpu_) { #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU cv::gpu::GpuMat imgGpu(imgRoi); cv::gpu::GpuMat maskGpu(maskRoi); (*_gpuOrb.obj)(imgGpu, maskGpu, keypoints); +#else + UERROR("Cannot use ORBGPU because OpenCV is not built with gpu module."); +#endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D UFATAL("not implemented"); @@ -974,17 +992,10 @@ cv::Mat ORB::generateDescriptorsImpl(const cv::Mat & image, std::vector FAST::generateKeypointsImpl(const cv::Mat & image, con if(gpu_) { #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU cv::gpu::GpuMat imgGpu(imgRoi); cv::gpu::GpuMat maskGpu(maskRoi); (*_gpuFast.obj)(imgGpu, maskGpu, keypoints); +#else + UERROR("Cannot use FAST GPU because OpenCV is not built with gpu module."); +#endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D UFATAL("not implemented"); diff --git a/corelib/src/VWDictionary.cpp b/corelib/src/VWDictionary.cpp index 3fb1f6e9..02e0f569 100644 --- a/corelib/src/VWDictionary.cpp +++ b/corelib/src/VWDictionary.cpp @@ -462,24 +462,33 @@ void VWDictionary::setNNStrategy(NNStrategy strategy) if(strategy!=kNNUndef) { #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU if(strategy == kNNBruteForceGPU && !cv::gpu::getCudaEnabledDeviceCount()) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; } #else + if(strategy == kNNBruteForceGPU) + { + UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but OpenCV is not built with GPU/cuda module! Doing \"kNNBruteForce\" instead."); + strategy = kNNBruteForce; + } +#endif +#else +#if HAVE_OPENCV_CUDAFEATURES2D if(strategy == kNNBruteForceGPU && !cv::cuda::getCudaEnabledDeviceCount()) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; } -#endif -#ifndef HAVE_OPENCV_CUDAFEATURES2D +#else if(strategy == kNNBruteForceGPU) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but OpenCV cudafeatures2d module is not found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; } +#endif #endif if(RTABMAP_NONFREE == 0 && strategy == kNNFlannKdTree) @@ -832,6 +841,7 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, { bruteForce = true; #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU cv::gpu::GpuMat newDescriptorsGpu(descriptors); cv::gpu::GpuMat lastDescriptorsGpu(_dataTree); if(type==CV_8U) @@ -844,6 +854,9 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, cv::gpu::BruteForceMatcher_GPU > gpuMatcher; gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else + UERROR("Cannot use brute Force GPU because OpenCV is not built with gpu module."); +#endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D cv::cuda::GpuMat newDescriptorsGpu(descriptors); @@ -859,6 +872,8 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, gpuMatcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_L2); gpuMatcher->knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else + UERROR("Cannot use brute Force GPU because OpenCV is not built with cuda module."); #endif #endif } @@ -1068,6 +1083,7 @@ std::vector VWDictionary::findNN(const std::list & vws) const { bruteForce = true; #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU cv::gpu::GpuMat newDescriptorsGpu(query); cv::gpu::GpuMat lastDescriptorsGpu(_dataTree); if(type==CV_8U) @@ -1080,6 +1096,9 @@ std::vector VWDictionary::findNN(const std::list & vws) const cv::gpu::BruteForceMatcher_GPU > gpuMatcher; gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else + UERROR("Cannot use brute Force GPU because OpenCV is not built with gpu module."); +#endif #else #ifdef HAVE_OPENCV_CUDAFEATURES2D cv::cuda::GpuMat newDescriptorsGpu(query); @@ -1095,6 +1114,8 @@ std::vector VWDictionary::findNN(const std::list & vws) const gpuMatcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_L2); gpuMatcher->knnMatchAsync(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else + UERROR("Cannot use brute Force GPU because OpenCV is not built with cuda module."); #endif #endif } diff --git a/corelib/src/util3d_surface.cpp b/corelib/src/util3d_surface.cpp index 723f5697..2692c90d 100644 --- a/corelib/src/util3d_surface.cpp +++ b/corelib/src/util3d_surface.cpp @@ -36,7 +36,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include + +#ifndef DISABLE_VTK #include +#endif namespace rtabmap { @@ -367,11 +370,16 @@ void adjustNormalsToViewPoints( pcl::PolygonMesh::Ptr meshDecimation(const pcl::PolygonMesh::Ptr & mesh, float factor) { + pcl::PolygonMesh::Ptr output(new pcl::PolygonMesh); +#ifndef DISABLE_VTK pcl::MeshQuadricDecimationVTK mqd; mqd.setTargetReductionFactor(factor); mqd.setInputMesh(mesh); - pcl::PolygonMesh::Ptr output(new pcl::PolygonMesh); mqd.process (*output); +#else + UWARN("RTAB-Map is not built with VTK module so mesh decimation cannot be used!"); + *output = *mesh; +#endif return output; } diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp index bf256461..8fc04249 100644 --- a/guilib/src/PreferencesDialog.cpp +++ b/guilib/src/PreferencesDialog.cpp @@ -77,10 +77,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU #include +#endif #else +#ifdef HAVE_OPENCV_CUDAFEATURES2D #include #endif +#endif using namespace rtabmap; @@ -104,11 +108,12 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : bool haveCuda = false; #if CV_MAJOR_VERSION < 3 +#ifdef HAVE_OPENCV_GPU haveCuda = cv::gpu::getCudaEnabledDeviceCount() != 0; +#endif #else +#ifdef HAVE_OPENCV_CUDAFEATURES2D haveCuda = cv::cuda::getCudaEnabledDeviceCount() != 0; -#ifndef HAVE_OPENCV_CUDAFEATURES2D - haveCuda = false; #endif #endif if(!haveCuda) diff --git a/utilite/CMakeLists.txt b/utilite/CMakeLists.txt index bbf7987d..cefea048 100644 --- a/utilite/CMakeLists.txt +++ b/utilite/CMakeLists.txt @@ -1,9 +1,9 @@ SET(UTILITE_VERSION "0.3.0") ADD_DEFINITIONS(-DUTILITE_VERSION="${UTILITE_VERSION}") -IF(UNIX) +if(UNIX AND NOT ANDROID) FIND_PACKAGE(Pthreads REQUIRED) -ENDIF(UNIX) +ENDIF(UNIX AND NOT ANDROID) ADD_SUBDIRECTORY( src ) ADD_SUBDIRECTORY( resource_generator ) \ No newline at end of file diff --git a/utilite/include/rtabmap/utilite/Posix/UThreadC.h b/utilite/include/rtabmap/utilite/Posix/UThreadC.h index 2ae11f6d..e773c55f 100644 --- a/utilite/include/rtabmap/utilite/Posix/UThreadC.h +++ b/utilite/include/rtabmap/utilite/Posix/UThreadC.h @@ -84,9 +84,10 @@ class UThreadC static void Exit() { pthread_exit(0); } - +#ifndef ANDROID static void TestCancel() { pthread_testcancel(); } +#endif static Handle Self() { return (Handle)pthread_self(); } @@ -163,8 +164,10 @@ class UThreadC static int Join( Handle H ) { return pthread_join(H,0); } +#ifndef ANDROID static int Kill( Handle H ) { return pthread_cancel(H); } +#endif static int Detach( Handle H ) { return pthread_detach(H); } @@ -180,6 +183,7 @@ class UThreadC Thread_T Data(I.Data); S_Create().release(); +#ifndef ANDROID if ( I.Flags & 1 /*CancelEnable*/ ) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); @@ -193,6 +197,7 @@ class UThreadC { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); } +#endif if ( I.Owner ) I.Owner->ThreadMain(Data); @@ -237,8 +242,10 @@ class UThreadC static void Exit() { pthread_exit(0); } +#ifndef ANDROID static void TestCancel() { pthread_testcancel(); } +#endif static Handle Self() { return (Handle)pthread_self(); } @@ -347,8 +354,10 @@ class UThreadC static int Join( Handle H ) { return pthread_join(H,0); } +#ifndef ANDROID static int Kill( Handle H ) { return pthread_cancel(H); } +#endif static int Detach( Handle H ) { return pthread_detach(H); } @@ -363,6 +372,7 @@ class UThreadC Instance I(*Param); S_Create().release(); +#ifndef ANDROID if ( I.Flags & 1 /*CancelEnable*/ ) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); @@ -376,6 +386,7 @@ class UThreadC { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL); } +#endif if ( I.Owner ) I.Owner->ThreadMain(); diff --git a/utilite/include/rtabmap/utilite/UThread.h b/utilite/include/rtabmap/utilite/UThread.h index e37c8861..041e1c37 100644 --- a/utilite/include/rtabmap/utilite/UThread.h +++ b/utilite/include/rtabmap/utilite/UThread.h @@ -245,8 +245,10 @@ private: //Methods from UThread class hided static int Join( Handle H ) { return UThreadC::Join(H); } +#ifndef ANDROID static int Kill( Handle H ) { return UThreadC::Kill(H); } +#endif static int Detach( Handle H ) { return UThreadC::Detach(H); } diff --git a/utilite/src/UDirectory.cpp b/utilite/src/UDirectory.cpp index 9173e8b4..d24f542f 100644 --- a/utilite/src/UDirectory.cpp +++ b/utilite/src/UDirectory.cpp @@ -29,7 +29,6 @@ #include #include #include - #include #include #include #include