diff --git a/CMakeLists.txt b/CMakeLists.txt index d832750163..aca1452f41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,51 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(ORB_SLAM2) -IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE Release) -ENDIF() - -MESSAGE("Build type: " ${CMAKE_BUILD_TYPE}) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native") - -# Check C++11 or C++0x support -include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) -CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) -if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - add_definitions(-DCOMPILEDWITHC11) - message(STATUS "Using flag -std=c++11.") -elseif(COMPILER_SUPPORTS_CXX0X) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") - add_definitions(-DCOMPILEDWITHC0X) - message(STATUS "Using flag -std=c++0x.") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +message("Build type: " ${CMAKE_BUILD_TYPE}) + +if(UNIX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native") + + # Check C++11 or C++0x support + include(CheckCXXCompilerFlag) + + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) + CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + add_definitions(-DCOMPILEDWITHC11) + message(STATUS "Using flag -std=c++11.") + elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + add_definitions(-DCOMPILEDWITHC0X) + message(STATUS "Using flag -std=c++0x.") + else() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + endif() else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + add_definitions(-DCOMPILEDWITHC11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif() -LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules) +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules) -find_package(OpenCV 2.4.3 REQUIRED) -find_package(Eigen3 3.1.0 REQUIRED) find_package(Pangolin REQUIRED) +find_package(OpenCV REQUIRED) +find_package(Eigen3 3.1.0 REQUIRED) -include_directories( -${PROJECT_SOURCE_DIR} -${PROJECT_SOURCE_DIR}/include -${EIGEN3_INCLUDE_DIR} -${Pangolin_INCLUDE_DIRS} -) - -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +# DBoW2 target +add_subdirectory(${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/) +# g2o target +add_subdirectory(${PROJECT_SOURCE_DIR}/Thirdparty/g2o/) -add_library(${PROJECT_NAME} SHARED +add_library(ORB_SLAM2 SHARED src/System.cc src/Tracking.cc src/LocalMapping.cc @@ -63,35 +67,60 @@ src/Initializer.cc src/Viewer.cc ) -target_link_libraries(${PROJECT_NAME} +target_include_directories(ORB_SLAM2 PUBLIC +${PROJECT_SOURCE_DIR} +${PROJECT_SOURCE_DIR}/include +${OpenCV_INCLUDE_DIRS} +${EIGEN3_INCLUDE_DIR} +${Pangolin_INCLUDE_DIR} +${PROJECT_BINARY_DIR} +) + +target_link_libraries(ORB_SLAM2 ${OpenCV_LIBS} ${EIGEN3_LIBS} ${Pangolin_LIBRARIES} -${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so -${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so +DBoW2 +g2o ) -# Build examples +include(GenerateExportHeader) +set_target_properties(ORB_SLAM2 PROPERTIES CXX_VISIBILITY_PRESET hidden) +set_target_properties(ORB_SLAM2 PROPERTIES VISIBILITY_INLINES_HIDDEN 1) +generate_export_header(ORB_SLAM2) + +install(TARGETS ORB_SLAM2 + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin + ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ORB_SLAM2/ + FILES_MATCHING PATTERN "*.h") +install(FILES ${PROJECT_BINARY_DIR}/orb_slam2_export.h + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ORB_SLAM2/) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D) +# Build examples add_executable(rgbd_tum Examples/RGB-D/rgbd_tum.cc) -target_link_libraries(rgbd_tum ${PROJECT_NAME}) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo) +target_link_libraries(rgbd_tum ORB_SLAM2) add_executable(stereo_kitti Examples/Stereo/stereo_kitti.cc) -target_link_libraries(stereo_kitti ${PROJECT_NAME}) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular) +target_link_libraries(stereo_kitti ORB_SLAM2) add_executable(mono_tum Examples/Monocular/mono_tum.cc) -target_link_libraries(mono_tum ${PROJECT_NAME}) - +target_link_libraries(mono_tum ORB_SLAM2) + add_executable(mono_kitti Examples/Monocular/mono_kitti.cc) -target_link_libraries(mono_kitti ${PROJECT_NAME}) +target_link_libraries(mono_kitti ORB_SLAM2) + +install(TARGETS + rgbd_tum + stereo_kitti + mono_tum + mono_kitti + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) diff --git a/Examples/Monocular/mono_kitti.cc b/Examples/Monocular/mono_kitti.cc index 665fd8c72f..c116189984 100644 --- a/Examples/Monocular/mono_kitti.cc +++ b/Examples/Monocular/mono_kitti.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -101,7 +102,7 @@ int main(int argc, char **argv) T = tframe-vTimestamps[ni-1]; if(ttrack #include #include +#include #include @@ -102,7 +103,7 @@ int main(int argc, char **argv) T = tframe-vTimestamps[ni-1]; if(ttrack #include #include +#include #include @@ -115,7 +116,7 @@ int main(int argc, char **argv) T = tframe-vTimestamps[ni-1]; if(ttrack #include #include +#include #include @@ -104,7 +105,7 @@ int main(int argc, char **argv) T = tframe-vTimestamps[ni-1]; if(ttrack #include +#include "dbow2_export.h" + namespace DBoW2 { /// Id of words @@ -53,7 +55,7 @@ enum ScoringType }; /// Vector of words to represent images -class BowVector: +class DBOW2_EXPORT BowVector: public std::map { public: diff --git a/Thirdparty/DBoW2/DBoW2/FClass.h b/Thirdparty/DBoW2/DBoW2/FClass.h index 13be53d753..c6455ddba9 100644 --- a/Thirdparty/DBoW2/DBoW2/FClass.h +++ b/Thirdparty/DBoW2/DBoW2/FClass.h @@ -14,6 +14,8 @@ #include #include +#include "dbow2_export.h" + namespace DBoW2 { /// Generic class to encapsulate functions to manage descriptors. @@ -22,7 +24,7 @@ namespace DBoW2 { * parameter F when creating Templated structures * (TemplatedVocabulary, TemplatedDatabase, ...) */ -class FClass +class DBOW2_EXPORT FClass { class TDescriptor; typedef const TDescriptor *pDescriptor; diff --git a/Thirdparty/DBoW2/DBoW2/FORB.cpp b/Thirdparty/DBoW2/DBoW2/FORB.cpp index 1f1990c2f7..b78c2d1ee2 100644 --- a/Thirdparty/DBoW2/DBoW2/FORB.cpp +++ b/Thirdparty/DBoW2/DBoW2/FORB.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include "FORB.h" diff --git a/Thirdparty/DBoW2/DBoW2/FORB.h b/Thirdparty/DBoW2/DBoW2/FORB.h index a39599f20e..5ff68dde42 100644 --- a/Thirdparty/DBoW2/DBoW2/FORB.h +++ b/Thirdparty/DBoW2/DBoW2/FORB.h @@ -15,11 +15,12 @@ #include #include "FClass.h" +#include "dbow2_export.h" namespace DBoW2 { /// Functions to manipulate ORB descriptors -class FORB: protected FClass +class DBOW2_EXPORT FORB: protected FClass { public: diff --git a/Thirdparty/DBoW2/DBoW2/FeatureVector.h b/Thirdparty/DBoW2/DBoW2/FeatureVector.h index 08a91def7c..04962174ae 100644 --- a/Thirdparty/DBoW2/DBoW2/FeatureVector.h +++ b/Thirdparty/DBoW2/DBoW2/FeatureVector.h @@ -15,10 +15,12 @@ #include #include +#include "dbow2_export.h" + namespace DBoW2 { /// Vector of nodes with indexes of local features -class FeatureVector: +class DBOW2_EXPORT FeatureVector: public std::map > { public: diff --git a/Thirdparty/DBoW2/DBoW2/ScoringObject.h b/Thirdparty/DBoW2/DBoW2/ScoringObject.h index 8d5b82192a..e2be440654 100644 --- a/Thirdparty/DBoW2/DBoW2/ScoringObject.h +++ b/Thirdparty/DBoW2/DBoW2/ScoringObject.h @@ -11,11 +11,12 @@ #define __D_T_SCORING_OBJECT__ #include "BowVector.h" +#include "dbow2_export.h" namespace DBoW2 { /// Base class of scoring functions -class GeneralScoring +class DBOW2_EXPORT GeneralScoring { public: /** @@ -71,22 +72,22 @@ class GeneralScoring } /// L1 Scoring object -class __SCORING_CLASS(L1Scoring, true, L1); +class DBOW2_EXPORT __SCORING_CLASS(L1Scoring, true, L1); /// L2 Scoring object -class __SCORING_CLASS(L2Scoring, true, L2); +class DBOW2_EXPORT __SCORING_CLASS(L2Scoring, true, L2); /// Chi square Scoring object -class __SCORING_CLASS(ChiSquareScoring, true, L1); +class DBOW2_EXPORT __SCORING_CLASS(ChiSquareScoring, true, L1); /// KL divergence Scoring object -class __SCORING_CLASS(KLScoring, true, L1); +class DBOW2_EXPORT __SCORING_CLASS(KLScoring, true, L1); /// Bhattacharyya Scoring object -class __SCORING_CLASS(BhattacharyyaScoring, true, L1); +class DBOW2_EXPORT __SCORING_CLASS(BhattacharyyaScoring, true, L1); /// Dot product Scoring object -class __SCORING_CLASS(DotProductScoring, false, L1); +class DBOW2_EXPORT __SCORING_CLASS(DotProductScoring, false, L1); #undef __SCORING_CLASS diff --git a/Thirdparty/DBoW2/DUtils/Random.h b/Thirdparty/DBoW2/DUtils/Random.h index 5115dc47c2..120a05c574 100644 --- a/Thirdparty/DBoW2/DUtils/Random.h +++ b/Thirdparty/DBoW2/DUtils/Random.h @@ -15,10 +15,12 @@ #include #include +#include "dbow2_export.h" + namespace DUtils { /// Functions to generate pseudo-random numbers -class Random +class DBOW2_EXPORT Random { public: class UnrepeatedRandomizer; @@ -109,7 +111,7 @@ class Random // --------------------------------------------------------------------------- /// Provides pseudo-random numbers with no repetitions -class Random::UnrepeatedRandomizer +class DBOW2_EXPORT Random::UnrepeatedRandomizer { public: diff --git a/Thirdparty/DBoW2/DUtils/Timestamp.h b/Thirdparty/DBoW2/DUtils/Timestamp.h index b92f89f872..a9fe805301 100644 --- a/Thirdparty/DBoW2/DUtils/Timestamp.h +++ b/Thirdparty/DBoW2/DUtils/Timestamp.h @@ -11,12 +11,15 @@ #define __D_TIMESTAMP__ #include + +#include "dbow2_export.h" + using namespace std; namespace DUtils { /// Timestamp -class Timestamp +class DBOW2_EXPORT Timestamp { public: diff --git a/Thirdparty/Pangolin/CMakeLists.txt b/Thirdparty/Pangolin/CMakeLists.txt new file mode 100644 index 0000000000..c94139517c --- /dev/null +++ b/Thirdparty/Pangolin/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.1) +project(PangolinBuild) + +include(ExternalProject) +set(COMMON_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_LINKER=${CMAKE_LINKER} +) + +find_package(GLEW REQUIRED) +find_package(PythonLibs 2.7 REQUIRED) + +set(PANGOLIN_CMAKE_ARGS ${COMMON_CMAKE_ARGS} + -DEIGEN3_INCLUDE_DIR=${EIGEN3_INCLUDE_DIR} + -DGLEW_INCLUDE_DIR=${GLEW_INCLUDE_DIR} + -DGLEW_LIBRARY=${GLEW_LIBRARY} + -DPYTHON_LIBRARY=${PYTHON_LIBRARY} + -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} + -DBUILD_SHARED_LIBS=True + -DCPP11_NO_BOOST=True + -DBUILD_PANGOLIN_VIDEO=True + -DBUILD_PANGOLIN_GUI=True + -DBUILD_EXAMPLES=False + -DBUILD_EXTERN_GLEW=False + -DBUILD_EXTERN_LIBJPEG=False + -DBUILD_EXTERN_LIBPNG=False) + +ExternalProject_Add(pangolin + URL https://github.com/stevenlovegrove/Pangolin/archive/v0.3.tar.gz + URL_HASH SHA256=8881c1102671ea99c241b273474ca7a5b3377fbde9c7d376253424c36d8ed678 + CMAKE_ARGS ${PANGOLIN_CMAKE_ARGS} + BINARY_DIR ${CMAKE_BINARY_DIR}/Pangolin-build) + +if(WIN32) + ExternalProject_Add_Step(pangolin pangolinExportInstall + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/Pangolin-prefix/src/Pangolin-build/src/include/pangolin/pangolin_export.h" + "${CMAKE_INSTALL_PREFIX}/include/pangolin/pangolin_export.h" + COMMENT "Install pangolin_export" + DEPENDEES install) +endif() diff --git a/Thirdparty/g2o/CMakeLists.txt b/Thirdparty/g2o/CMakeLists.txt index 5882a53ff2..c494f007c3 100644 --- a/Thirdparty/g2o/CMakeLists.txt +++ b/Thirdparty/g2o/CMakeLists.txt @@ -13,7 +13,11 @@ ENDIF() MESSAGE(STATUS "BUILD TYPE:" ${CMAKE_BUILD_TYPE}) -SET (G2O_LIB_TYPE SHARED) +IF(WIN32) + SET(G2O_LIB_TYPE STATIC) +ELSE() + SET(G2O_LIB_TYPE SHARED) +ENDIF() # There seems to be an issue with MSVC8 # see http://eigen.tuxfamily.org/bz/show_bug.cgi?id=83 @@ -22,16 +26,6 @@ if(MSVC90) message(STATUS "Disabling memory alignment for MSVC8") endif(MSVC90) -# Set the output directory for the build executables and libraries -IF(WIN32) - SET(g2o_LIBRARY_OUTPUT_DIRECTORY ${g2o_SOURCE_DIR}/bin CACHE PATH "Target for the libraries") -ELSE(WIN32) - SET(g2o_LIBRARY_OUTPUT_DIRECTORY ${g2o_SOURCE_DIR}/lib CACHE PATH "Target for the libraries") -ENDIF(WIN32) -SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${g2o_LIBRARY_OUTPUT_DIRECTORY}) -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${g2o_LIBRARY_OUTPUT_DIRECTORY}) -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${g2o_RUNTIME_OUTPUT_DIRECTORY}) - # Set search directory for looking for our custom CMake scripts to # look for SuiteSparse, QGLViewer, and Eigen3. LIST(APPEND CMAKE_MODULE_PATH ${g2o_SOURCE_DIR}/cmake_modules) @@ -43,8 +37,8 @@ IF(UNIX) ENDIF(UNIX) # For building the CHOLMOD / CSPARSE solvers -FIND_PACKAGE(BLAS REQUIRED) -FIND_PACKAGE(LAPACK REQUIRED) +FIND_PACKAGE(BLAS) +FIND_PACKAGE(LAPACK) # Eigen library parallelise itself, though, presumably due to performance issues # OPENMP is experimental. We experienced some slowdown with it @@ -61,9 +55,11 @@ ENDIF(OPENMP_FOUND AND G2O_USE_OPENMP) SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -march=native") -# activate warnings !!! -SET(g2o_C_FLAGS "${g2o_C_FLAGS} -Wall -W") -SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Wall -W") +if(UNIX) + # activate warnings !!! + SET(g2o_C_FLAGS "${g2o_C_FLAGS} -Wall -W") + SET(g2o_CXX_FLAGS "${g2o_CXX_FLAGS} -Wall -W") +endif() # specifying compiler flags SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${g2o_CXX_FLAGS}") @@ -176,3 +172,12 @@ g2o/stuff/string_tools.cpp g2o/stuff/property.cpp g2o/stuff/property.h ) + +# Set the output directory for the build executables and libraries +install(TARGETS g2o + RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin + ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) +install(DIRECTORY ${PROJECT_SOURCE_DIR} + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ORB_SLAM2/Thirdparty/ + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") diff --git a/Thirdparty/g2o/g2o/core/estimate_propagator.h b/Thirdparty/g2o/g2o/core/estimate_propagator.h index 6a16d11d3a..eb2a494afd 100644 --- a/Thirdparty/g2o/g2o/core/estimate_propagator.h +++ b/Thirdparty/g2o/g2o/core/estimate_propagator.h @@ -33,12 +33,7 @@ #include #include #include - -#ifdef _MSC_VER #include -#else -#include -#endif namespace g2o { @@ -135,7 +130,7 @@ namespace g2o { size_t operator ()(const OptimizableGraph::Vertex* v) const { return v->id();} }; - typedef std::tr1::unordered_map AdjacencyMap; + typedef std::unordered_map AdjacencyMap; public: EstimatePropagator(OptimizableGraph* g); diff --git a/Thirdparty/g2o/g2o/core/hyper_graph.h b/Thirdparty/g2o/g2o/core/hyper_graph.h index da6bb3d361..8b87c63953 100644 --- a/Thirdparty/g2o/g2o/core/hyper_graph.h +++ b/Thirdparty/g2o/g2o/core/hyper_graph.h @@ -34,13 +34,7 @@ #include #include #include - -#ifdef _MSC_VER #include -#else -#include -#endif - /** @addtogroup graph */ //@{ @@ -90,7 +84,7 @@ namespace g2o { typedef std::set EdgeSet; typedef std::set VertexSet; - typedef std::tr1::unordered_map VertexIDMap; + typedef std::unordered_map VertexIDMap; typedef std::vector VertexContainer; //! abstract Vertex, your types must derive from that one diff --git a/Thirdparty/g2o/g2o/core/marginal_covariance_cholesky.h b/Thirdparty/g2o/g2o/core/marginal_covariance_cholesky.h index e7dfce88f8..73401dbd01 100644 --- a/Thirdparty/g2o/g2o/core/marginal_covariance_cholesky.h +++ b/Thirdparty/g2o/g2o/core/marginal_covariance_cholesky.h @@ -32,13 +32,7 @@ #include #include - -#ifdef _MSC_VER #include -#else -#include -#endif - namespace g2o { @@ -50,7 +44,7 @@ namespace g2o { /** * hash struct for storing the matrix elements needed to compute the covariance */ - typedef std::tr1::unordered_map LookupMap; + typedef std::unordered_map LookupMap; public: MarginalCovarianceCholesky(); diff --git a/Thirdparty/g2o/g2o/core/matrix_operations.h b/Thirdparty/g2o/g2o/core/matrix_operations.h index 28e6fbefc7..a1082cf003 100644 --- a/Thirdparty/g2o/g2o/core/matrix_operations.h +++ b/Thirdparty/g2o/g2o/core/matrix_operations.h @@ -45,7 +45,7 @@ namespace g2o { } template<> - inline void axpy(const Eigen::MatrixXd& A, const Eigen::Map& x, int xoff, Eigen::Map& y, int yoff) + inline void axpy(const Eigen::MatrixXd& A, const Eigen::Map& x, int xoff, Eigen::Map& y, int yoff) { y.segment(yoff, A.rows()) += A * x.segment(xoff, A.cols()); } @@ -63,7 +63,7 @@ namespace g2o { } template<> - inline void atxpy(const Eigen::MatrixXd& A, const Eigen::Map& x, int xoff, Eigen::Map& y, int yoff) + inline void atxpy(const Eigen::MatrixXd& A, const Eigen::Map& x, int xoff, Eigen::Map& y, int yoff) { y.segment(yoff, A.cols()) += A.transpose() * x.segment(xoff, A.rows()); } diff --git a/Thirdparty/g2o/g2o/core/optimization_algorithm_factory.cpp b/Thirdparty/g2o/g2o/core/optimization_algorithm_factory.cpp index a9be96e834..9a7bc9ee9c 100644 --- a/Thirdparty/g2o/g2o/core/optimization_algorithm_factory.cpp +++ b/Thirdparty/g2o/g2o/core/optimization_algorithm_factory.cpp @@ -26,6 +26,7 @@ #include "optimization_algorithm_factory.h" +#include #include #include #include diff --git a/Thirdparty/g2o/g2o/core/robust_kernel.h b/Thirdparty/g2o/g2o/core/robust_kernel.h index 29e1394a0d..48634767f8 100644 --- a/Thirdparty/g2o/g2o/core/robust_kernel.h +++ b/Thirdparty/g2o/g2o/core/robust_kernel.h @@ -27,14 +27,9 @@ #ifndef G2O_ROBUST_KERNEL_H #define G2O_ROBUST_KERNEL_H -#ifdef _MSC_VER #include -#else -#include -#endif #include - namespace g2o { /** @@ -74,7 +69,7 @@ namespace g2o { protected: double _delta; }; - typedef std::tr1::shared_ptr RobustKernelPtr; + typedef std::shared_ptr RobustKernelPtr; } // end namespace g2o diff --git a/Thirdparty/g2o/g2o/core/sparse_block_matrix.hpp b/Thirdparty/g2o/g2o/core/sparse_block_matrix.hpp index 8dfa99c1b7..469ad83ac6 100644 --- a/Thirdparty/g2o/g2o/core/sparse_block_matrix.hpp +++ b/Thirdparty/g2o/g2o/core/sparse_block_matrix.hpp @@ -274,9 +274,9 @@ namespace g2o { if (destOffset > srcOffset) // only upper triangle break; // destVec += *a * srcVec (according to the sub-vector parts) - internal::axpy(*a, srcVec, srcOffset, destVec, destOffset); + internal::template axpy::SparseMatrixBlock>(*a, srcVec, srcOffset, destVec, destOffset); if (destOffset < srcOffset) - internal::atxpy(*a, srcVec, destOffset, destVec, srcOffset); + internal::template atxpy::SparseMatrixBlock>(*a, srcVec, destOffset, destVec, srcOffset); } } } @@ -305,7 +305,7 @@ namespace g2o { const typename SparseBlockMatrix::SparseMatrixBlock* a=it->second; int srcOffset = rowBaseOfBlock(it->first); // destVec += *a.transpose() * srcVec (according to the sub-vector parts) - internal::atxpy(*a, srcVec, srcOffset, destVec, destOffset); + internal::template atxpy::SparseMatrixBlock>(*a, srcVec, srcOffset, destVec, destOffset); } } diff --git a/Thirdparty/g2o/g2o/core/sparse_block_matrix_ccs.h b/Thirdparty/g2o/g2o/core/sparse_block_matrix_ccs.h index eb9042c218..3a95bdabe5 100644 --- a/Thirdparty/g2o/g2o/core/sparse_block_matrix_ccs.h +++ b/Thirdparty/g2o/g2o/core/sparse_block_matrix_ccs.h @@ -34,11 +34,7 @@ #include "../../config.h" #include "matrix_operations.h" -#ifdef _MSC_VER #include -#else -#include -#endif namespace g2o { @@ -122,7 +118,7 @@ namespace g2o { const SparseMatrixBlock* a = it->block; int srcOffset = rowBaseOfBlock(it->row); // destVec += *a.transpose() * srcVec (according to the sub-vector parts) - internal::atxpy(*a, srcVec, srcOffset, destVec, destOffset); + internal::template atxpy(*a, srcVec, srcOffset, destVec, destOffset); } } } @@ -223,7 +219,7 @@ namespace g2o { //! rows of the matrix int rows() const {return _rowBlockIndices.size() ? _rowBlockIndices.back() : 0;} - typedef std::tr1::unordered_map SparseColumn; + typedef std::unordered_map SparseColumn; SparseBlockMatrixHashMap(const std::vector& rowIndices, const std::vector& colIndices) : _rowBlockIndices(rowIndices), _colBlockIndices(colIndices) diff --git a/Thirdparty/g2o/g2o/core/sparse_block_matrix_diagonal.h b/Thirdparty/g2o/g2o/core/sparse_block_matrix_diagonal.h index 7b13b9f2f3..b658ea10b4 100644 --- a/Thirdparty/g2o/g2o/core/sparse_block_matrix_diagonal.h +++ b/Thirdparty/g2o/g2o/core/sparse_block_matrix_diagonal.h @@ -94,7 +94,7 @@ namespace g2o { int srcOffset = destOffset; const SparseMatrixBlock& A = _diagonal[i]; // destVec += *A.transpose() * srcVec (according to the sub-vector parts) - internal::axpy(A, srcVec, srcOffset, destVec, destOffset); + internal::template axpy(A, srcVec, srcOffset, destVec, destOffset); } } diff --git a/Thirdparty/g2o/g2o/stuff/string_tools.cpp b/Thirdparty/g2o/g2o/stuff/string_tools.cpp index 0a4f60a277..fef69667e4 100644 --- a/Thirdparty/g2o/g2o/stuff/string_tools.cpp +++ b/Thirdparty/g2o/g2o/stuff/string_tools.cpp @@ -97,7 +97,7 @@ std::string formatString(const char* fmt, ...) char* auxPtr = NULL; va_list arg_list; va_start(arg_list, fmt); - int numChar = vasprintf(&auxPtr, fmt, arg_list); + int numChar = vsprintf(auxPtr, fmt, arg_list); va_end(arg_list); string retString; if (numChar != -1) @@ -114,7 +114,7 @@ int strPrintf(std::string& str, const char* fmt, ...) char* auxPtr = NULL; va_list arg_list; va_start(arg_list, fmt); - int numChars = vasprintf(&auxPtr, fmt, arg_list); + int numChars = vsprintf(auxPtr, fmt, arg_list); va_end(arg_list); str = auxPtr; free(auxPtr); diff --git a/include/Converter.h b/include/Converter.h index 0002ad62c2..d5e514b3e2 100644 --- a/include/Converter.h +++ b/include/Converter.h @@ -27,10 +27,12 @@ #include"Thirdparty/g2o/g2o/types/types_six_dof_expmap.h" #include"Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h" +#include "orb_slam2_export.h" + namespace ORB_SLAM2 { -class Converter +class ORB_SLAM2_EXPORT Converter { public: static std::vector toDescriptorVector(const cv::Mat &Descriptors); diff --git a/include/Frame.h b/include/Frame.h index a6a8032f57..90f565c8d0 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -29,6 +29,7 @@ #include "ORBVocabulary.h" #include "KeyFrame.h" #include "ORBextractor.h" +#include "orb_slam2_export.h" #include @@ -40,7 +41,7 @@ namespace ORB_SLAM2 class MapPoint; class KeyFrame; -class Frame +class ORB_SLAM2_EXPORT Frame { public: Frame(); diff --git a/include/FrameDrawer.h b/include/FrameDrawer.h index 95c1df9d9e..f6ab011656 100644 --- a/include/FrameDrawer.h +++ b/include/FrameDrawer.h @@ -24,6 +24,7 @@ #include "Tracking.h" #include "MapPoint.h" #include "Map.h" +#include "orb_slam2_export.h" #include #include @@ -37,7 +38,7 @@ namespace ORB_SLAM2 class Tracking; class Viewer; -class FrameDrawer +class ORB_SLAM2_EXPORT FrameDrawer { public: FrameDrawer(Map* pMap); diff --git a/include/Initializer.h b/include/Initializer.h index 09b27a65bb..acc4b69935 100644 --- a/include/Initializer.h +++ b/include/Initializer.h @@ -22,13 +22,13 @@ #include #include "Frame.h" - +#include "orb_slam2_export.h" namespace ORB_SLAM2 { // THIS IS THE INITIALIZER FOR MONOCULAR SLAM. NOT USED IN THE STEREO OR RGBD CASE. -class Initializer +class ORB_SLAM2_EXPORT Initializer { typedef pair Match; diff --git a/include/KeyFrame.h b/include/KeyFrame.h index 67f4348273..212cdd2a93 100644 --- a/include/KeyFrame.h +++ b/include/KeyFrame.h @@ -28,6 +28,7 @@ #include "ORBextractor.h" #include "Frame.h" #include "KeyFrameDatabase.h" +#include "orb_slam2_export.h" #include @@ -40,7 +41,7 @@ class MapPoint; class Frame; class KeyFrameDatabase; -class KeyFrame +class ORB_SLAM2_EXPORT KeyFrame { public: KeyFrame(Frame &F, Map* pMap, KeyFrameDatabase* pKFDB); diff --git a/include/KeyFrameDatabase.h b/include/KeyFrameDatabase.h index fa3735762d..45d2050d11 100644 --- a/include/KeyFrameDatabase.h +++ b/include/KeyFrameDatabase.h @@ -28,6 +28,7 @@ #include "KeyFrame.h" #include "Frame.h" #include "ORBVocabulary.h" +#include "orb_slam2_export.h" #include @@ -39,7 +40,7 @@ class KeyFrame; class Frame; -class KeyFrameDatabase +class ORB_SLAM2_EXPORT KeyFrameDatabase { public: diff --git a/include/LocalMapping.h b/include/LocalMapping.h index 1361a5757a..74513da72b 100644 --- a/include/LocalMapping.h +++ b/include/LocalMapping.h @@ -26,6 +26,7 @@ #include "LoopClosing.h" #include "Tracking.h" #include "KeyFrameDatabase.h" +#include "orb_slam2_export.h" #include @@ -37,7 +38,7 @@ class Tracking; class LoopClosing; class Map; -class LocalMapping +class ORB_SLAM2_EXPORT LocalMapping { public: LocalMapping(Map* pMap, const float bMonocular); diff --git a/include/LoopClosing.h b/include/LoopClosing.h index b1736fed78..f79fc8a057 100644 --- a/include/LoopClosing.h +++ b/include/LoopClosing.h @@ -32,6 +32,7 @@ #include #include #include "Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h" +#include "orb_slam2_export.h" namespace ORB_SLAM2 { @@ -41,7 +42,7 @@ class LocalMapping; class KeyFrameDatabase; -class LoopClosing +class ORB_SLAM2_EXPORT LoopClosing { public: diff --git a/include/Map.h b/include/Map.h index 49ffab7374..317d4665a9 100644 --- a/include/Map.h +++ b/include/Map.h @@ -23,6 +23,8 @@ #include "MapPoint.h" #include "KeyFrame.h" +#include "orb_slam2_export.h" + #include #include @@ -35,7 +37,7 @@ namespace ORB_SLAM2 class MapPoint; class KeyFrame; -class Map +class ORB_SLAM2_EXPORT Map { public: Map(); diff --git a/include/MapDrawer.h b/include/MapDrawer.h index 83b282676d..b90c3a08ca 100644 --- a/include/MapDrawer.h +++ b/include/MapDrawer.h @@ -24,6 +24,7 @@ #include"Map.h" #include"MapPoint.h" #include"KeyFrame.h" +#include"orb_slam2_export.h" #include #include @@ -31,7 +32,7 @@ namespace ORB_SLAM2 { -class MapDrawer +class ORB_SLAM2_EXPORT MapDrawer { public: MapDrawer(Map* pMap, const string &strSettingPath); diff --git a/include/MapPoint.h b/include/MapPoint.h index 11568a504a..508c3c3eed 100644 --- a/include/MapPoint.h +++ b/include/MapPoint.h @@ -24,6 +24,7 @@ #include"KeyFrame.h" #include"Frame.h" #include"Map.h" +#include"orb_slam2_export.h" #include #include @@ -36,7 +37,7 @@ class Map; class Frame; -class MapPoint +class ORB_SLAM2_EXPORT MapPoint { public: MapPoint(const cv::Mat &Pos, KeyFrame* pRefKF, Map* pMap); diff --git a/include/ORBextractor.h b/include/ORBextractor.h index 66e8e7a547..f7d628b219 100644 --- a/include/ORBextractor.h +++ b/include/ORBextractor.h @@ -25,11 +25,12 @@ #include #include +#include "orb_slam2_export.h" namespace ORB_SLAM2 { -class ExtractorNode +class ORB_SLAM2_EXPORT ExtractorNode { public: ExtractorNode():bNoMore(false){} diff --git a/include/ORBmatcher.h b/include/ORBmatcher.h index ad881ee04a..595b9e1d6a 100644 --- a/include/ORBmatcher.h +++ b/include/ORBmatcher.h @@ -29,12 +29,12 @@ #include"MapPoint.h" #include"KeyFrame.h" #include"Frame.h" - +#include"orb_slam2_export.h" namespace ORB_SLAM2 { -class ORBmatcher +class ORB_SLAM2_EXPORT ORBmatcher { public: diff --git a/include/Optimizer.h b/include/Optimizer.h index 2c4378ed3b..155db8a143 100644 --- a/include/Optimizer.h +++ b/include/Optimizer.h @@ -26,6 +26,7 @@ #include "KeyFrame.h" #include "LoopClosing.h" #include "Frame.h" +#include "orb_slam2_export.h" #include "Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h" @@ -34,7 +35,7 @@ namespace ORB_SLAM2 class LoopClosing; -class Optimizer +class ORB_SLAM2_EXPORT Optimizer { public: void static BundleAdjustment(const std::vector &vpKF, const std::vector &vpMP, diff --git a/include/PnPsolver.h b/include/PnPsolver.h index f92544fc8f..e39ba8ac73 100644 --- a/include/PnPsolver.h +++ b/include/PnPsolver.h @@ -54,11 +54,12 @@ #include #include "MapPoint.h" #include "Frame.h" +#include "orb_slam2_export.h" namespace ORB_SLAM2 { -class PnPsolver { +class ORB_SLAM2_EXPORT PnPsolver { public: PnPsolver(const Frame &F, const vector &vpMapPointMatches); diff --git a/include/Sim3Solver.h b/include/Sim3Solver.h index 9af66cb26f..336d9bb138 100644 --- a/include/Sim3Solver.h +++ b/include/Sim3Solver.h @@ -26,13 +26,13 @@ #include #include "KeyFrame.h" - +#include "orb_slam2_export.h" namespace ORB_SLAM2 { -class Sim3Solver +class ORB_SLAM2_EXPORT Sim3Solver { public: diff --git a/include/System.h b/include/System.h index dec008c437..1b1b2fd074 100644 --- a/include/System.h +++ b/include/System.h @@ -35,6 +35,7 @@ #include "KeyFrameDatabase.h" #include "ORBVocabulary.h" #include "Viewer.h" +#include "orb_slam2_export.h" namespace ORB_SLAM2 { @@ -46,7 +47,7 @@ class Tracking; class LocalMapping; class LoopClosing; -class System +class ORB_SLAM2_EXPORT System { public: // Input sensor diff --git a/include/Tracking.h b/include/Tracking.h index 5aaa93ef26..0dd6589269 100644 --- a/include/Tracking.h +++ b/include/Tracking.h @@ -37,6 +37,7 @@ #include "Initializer.h" #include "MapDrawer.h" #include "System.h" +#include "orb_slam2_export.h" #include @@ -50,7 +51,7 @@ class LocalMapping; class LoopClosing; class System; -class Tracking +class ORB_SLAM2_EXPORT Tracking { public: diff --git a/include/Viewer.h b/include/Viewer.h index 251e223c54..9c563de04c 100644 --- a/include/Viewer.h +++ b/include/Viewer.h @@ -26,6 +26,7 @@ #include "MapDrawer.h" #include "Tracking.h" #include "System.h" +#include "orb_slam2_export.h" #include @@ -37,7 +38,7 @@ class FrameDrawer; class MapDrawer; class System; -class Viewer +class ORB_SLAM2_EXPORT Viewer { public: Viewer(System* pSystem, FrameDrawer* pFrameDrawer, MapDrawer* pMapDrawer, Tracking *pTracking, const string &strSettingPath); diff --git a/src/LocalMapping.cc b/src/LocalMapping.cc index 3dd2dce8ac..d6f5baa58d 100644 --- a/src/LocalMapping.cc +++ b/src/LocalMapping.cc @@ -23,7 +23,9 @@ #include "ORBmatcher.h" #include "Optimizer.h" -#include +#include +#include +#include namespace ORB_SLAM2 { @@ -91,7 +93,7 @@ void LocalMapping::Run() // Safe area to stop while(isStopped() && !CheckFinish()) { - usleep(3000); + std::this_thread::sleep_for(std::chrono::microseconds(3000)); } if(CheckFinish()) break; @@ -105,7 +107,7 @@ void LocalMapping::Run() if(CheckFinish()) break; - usleep(3000); + std::this_thread::sleep_for(std::chrono::microseconds(3000)); } SetFinish(); @@ -718,7 +720,7 @@ void LocalMapping::RequestReset() if(!mbResetRequested) break; } - usleep(3000); + std::this_thread::sleep_for(std::chrono::microseconds(3000)); } } diff --git a/src/LoopClosing.cc b/src/LoopClosing.cc index 6879125fdd..776859d6da 100644 --- a/src/LoopClosing.cc +++ b/src/LoopClosing.cc @@ -30,7 +30,7 @@ #include #include - +#include namespace ORB_SLAM2 { @@ -82,7 +82,7 @@ void LoopClosing::Run() if(CheckFinish()) break; - usleep(5000); + std::this_thread::sleep_for(std::chrono::microseconds(5000)); } SetFinish(); @@ -414,7 +414,7 @@ void LoopClosing::CorrectLoop() mbStopGBA = true; while(!isFinishedGBA()) - usleep(5000); + std::this_thread::sleep_for(std::chrono::microseconds(5000)); mpThreadGBA->join(); delete mpThreadGBA; @@ -423,7 +423,7 @@ void LoopClosing::CorrectLoop() // Wait until Local Mapping has effectively stopped while(!mpLocalMapper->isStopped()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); } // Ensure current keyframe is updated @@ -625,7 +625,7 @@ void LoopClosing::RequestReset() if(!mbResetRequested) break; } - usleep(5000); + std::this_thread::sleep_for(std::chrono::microseconds(5000)); } } @@ -663,7 +663,7 @@ void LoopClosing::RunGlobalBundleAdjustment(unsigned long nLoopKF) while(!mpLocalMapper->isStopped() && !mpLocalMapper->isFinished()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); } // Get Map Mutex diff --git a/src/MapPoint.cc b/src/MapPoint.cc index ec41ddbc8b..5976d605fc 100644 --- a/src/MapPoint.cc +++ b/src/MapPoint.cc @@ -271,16 +271,15 @@ void MapPoint::ComputeDistinctiveDescriptors() // Compute distances between them const size_t N = vDescriptors.size(); - - float Distances[N][N]; + float* Distances = new float[N*N]; for(size_t i=0;i vDists(Distances[i],Distances[i]+N); + vector vDists(Distances + i,Distances + i + N); sort(vDists.begin(),vDists.end()); int median = vDists[0.5*(N-1)]; @@ -299,7 +298,7 @@ void MapPoint::ComputeDistinctiveDescriptors() BestIdx = i; } } - + delete[] Distances; { unique_lock lock(mMutexFeatures); mDescriptor = vDescriptors[BestIdx].clone(); diff --git a/src/ORBextractor.cc b/src/ORBextractor.cc index 14be2efae5..31dc52fbf4 100644 --- a/src/ORBextractor.cc +++ b/src/ORBextractor.cc @@ -59,6 +59,7 @@ #include #include #include +#include #include "ORBextractor.h" diff --git a/src/ORBmatcher.cc b/src/ORBmatcher.cc index be31e8487e..7fa0f64e60 100644 --- a/src/ORBmatcher.cc +++ b/src/ORBmatcher.cc @@ -27,7 +27,7 @@ #include "Thirdparty/DBoW2/DBoW2/FeatureVector.h" -#include +#include using namespace std; diff --git a/src/System.cc b/src/System.cc index 739f541bc1..2fa1037f05 100644 --- a/src/System.cc +++ b/src/System.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include namespace ORB_SLAM2 { @@ -130,7 +132,7 @@ cv::Mat System::TrackStereo(const cv::Mat &imLeft, const cv::Mat &imRight, const // Wait until Local Mapping has effectively stopped while(!mpLocalMapper->isStopped()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); } mpTracker->InformOnlyTracking(true); @@ -175,7 +177,7 @@ cv::Mat System::TrackRGBD(const cv::Mat &im, const cv::Mat &depthmap, const doub // Wait until Local Mapping has effectively stopped while(!mpLocalMapper->isStopped()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); } mpTracker->InformOnlyTracking(true); @@ -220,7 +222,7 @@ cv::Mat System::TrackMonocular(const cv::Mat &im, const double ×tamp) // Wait until Local Mapping has effectively stopped while(!mpLocalMapper->isStopped()) { - usleep(1000); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); } mpTracker->InformOnlyTracking(true); @@ -275,7 +277,7 @@ void System::Shutdown() while(!mpLocalMapper->isFinished() || !mpLoopCloser->isFinished() || !mpViewer->isFinished() || mpLoopCloser->isRunningGBA()) { - usleep(5000); + std::this_thread::sleep_for(std::chrono::microseconds(5000)); } pangolin::BindToContext("ORB-SLAM2: Map Viewer"); diff --git a/src/Tracking.cc b/src/Tracking.cc index be6e12b935..d2f2111c5e 100644 --- a/src/Tracking.cc +++ b/src/Tracking.cc @@ -36,7 +36,8 @@ #include #include - +#include +#include using namespace std; @@ -1520,7 +1521,7 @@ void Tracking::Reset() cout << "System Reseting" << endl; while(!mpViewer->isStopped()) - usleep(3000); + std::this_thread::sleep_for(std::chrono::microseconds(3000)); // Reset Local Mapping cout << "Reseting Local Mapper..."; diff --git a/src/Viewer.cc b/src/Viewer.cc index 92fa8468cc..7513f80a41 100644 --- a/src/Viewer.cc +++ b/src/Viewer.cc @@ -22,6 +22,8 @@ #include #include +#include +#include namespace ORB_SLAM2 { @@ -156,7 +158,7 @@ void Viewer::Run() { while(isStopped()) { - usleep(3000); + std::this_thread::sleep_for(std::chrono::microseconds(3000)); } }