Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake clean up; modern g2o and mrpt targets #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# for in-tree builds:
build
3rdparty/DBoW2/lib/*
3rdparty/line_descriptor/lib/*
lib/*


# for qtcreator IDE
CMakeLists.txt.user*

4 changes: 2 additions & 2 deletions 3rdparty/line_descriptor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

include_directories( include ${OpenCV_INCLUDE_DIRS} )
list(APPEND LINK_LIBS ${OpenCV_LIBS} )
file(GLOB_RECURSE all_include_files RELATIVE "${CMAKE_SOURCE_DIR}" *.h *.hpp)
file(GLOB_RECURSE all_include_files RELATIVE "${PROJECT_SOURCE_DIR}" *.h *.hpp)

link_directories(${CMAKE_SOURCE_DIR}/src/)
file(GLOB_RECURSE all_source_files RELATIVE "${CMAKE_SOURCE_DIR}src/" *.cpp )
file(GLOB_RECURSE all_source_files RELATIVE "${PROJECT_SOURCE_DIR}src/" *.cpp )

add_custom_target( linedesc_includes DEPENDS ${all_include_files} SOURCES ${all_source_files} )

Expand Down
75 changes: 38 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
project( PL-SLAM )

project(PL-SLAM)
cmake_minimum_required(VERSION 2.7)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")

add_subdirectory(3rdparty/line_descriptor)
add_subdirectory(3rdparty/DBoW2)

set(HAS_MRPT ON CACHE BOOL "Build the PointGrey Bumblebee2 SVO application that employs the MRPT library")

find_package(OpenCV 3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS regex thread system filesystem)
find_package(G2O REQUIRED)
find_package(Boost REQUIRED COMPONENTS regex thread system filesystem)
find_package(g2o REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(yaml-cpp REQUIRED CONFIG PATHS ${YAML_PATHS}) # YAML library

# MRPT library (optional, only with representation purposes)
if(HAS_MRPT)
find_package(MRPT 1.9.9 REQUIRED opengl gui hwdrivers)
add_definitions(-DHAS_MRPT)
endif()

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
endif()
link_directories(${OpenCV_LIBS_DIR})
include_directories(${OpenCV2_INCLUDE_DIRS})

# Odometry library (Future TODO: integrate with this library)
SET( StVO_LIBRARY "" CACHE FILEPATH "Visual Odometry Library" )
SET( StVO_INCLUDE_DIR "" CACHE PATH "Visual Odometry Include folder" )

set(DEFAULT_HAS_MRPT ON)
set(HAS_MRPT ${DEFAULT_HAS_MRPT} CACHE BOOL "Build the PointGrey Bumblebee2 SVO application that employs the MRPT library")

SET(BUILD_SHARED_LIBS ON)
SET(CMAKE_MODULE_PATH $ENV{CMAKE_MODULE_PATH})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -mtune=native -march=native")

add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)

# MRPT library (optional, only with representation purposes)
if(HAS_MRPT)
FIND_PACKAGE(MRPT REQUIRED base opengl gui hwdrivers)
set(MRPT_DONT_USE_DBG_LIBS 1) #use release libraries for linking even if "Debug" CMake build
add_definitions(-DHAS_MRPT)
endif(HAS_MRPT)


# YAML library
FIND_PACKAGE(yaml-cpp REQUIRED CONFIG PATHS ${YAML_PATHS})

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

SET(G2O_LIBS g2o_cli g2o_ext_freeglut_minimal g2o_simulator g2o_solver_slam2d_linear g2o_types_icp g2o_types_slam2d g2o_core g2o_interface g2o_solver_csparse g2o_solver_structure_only g2o_types_sba g2o_types_slam3d g2o_csparse_extension g2o_opengl_helper g2o_solver_dense g2o_stuff g2o_types_sclam2d g2o_parser g2o_solver_pcg g2o_types_data g2o_types_sim3 cxsparse g2o_ext_csparse cholmod )
SET(G2O_LIBS
g2o::core
g2o::types_slam2d
g2o::types_slam3d
g2o::solver_cholmod
)

# Include dirs
include_directories(
Expand All @@ -55,36 +58,34 @@ include_directories(
${PROJECT_SOURCE_DIR}/3rdparty/DBoW2/include/
${PROJECT_SOURCE_DIR}/3rdparty/line_descriptor/include/
${G2O_INCLUDE_DIR}
${g2o_INCLUDE_DIR}
/usr/include/suitesparse # for cholmod
)


# Set link libraries
list(APPEND LINK_LIBS
${OpenCV_LIBS}
${Boost_LIBRARIES}
${YAML_CPP_LIBRARIES}
${G2O_LIBS}
${PROJECT_SOURCE_DIR}/../stvo-pl/lib/libstvo.so
${PROJECT_SOURCE_DIR}/3rdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/3rdparty/line_descriptor/lib/liblinedesc.so
DBoW2
linedesc
)

# Set source files
if(HAS_MRPT)
list(APPEND SOURCEFILES
src/mapHandler.cpp
src/mapFeatures.cpp
src/keyFrame.cpp
src/slamConfig.cpp
src/slamScene.cpp
)
else()
list(APPEND SOURCEFILES
src/mapHandler.cpp
src/mapFeatures.cpp
src/keyFrame.cpp
src/slamConfig.cpp
)

# Set source files
if(HAS_MRPT)
list(APPEND SOURCEFILES
src/slamScene.cpp
)
endif()

# List all files (headers) contained by StVO-PL library
Expand All @@ -96,17 +97,17 @@ add_custom_target( plslam_includes DEPENDS ${all_include_files} SOURCES ${all_in
# Create StVO-PL library
add_library(plslam SHARED ${SOURCEFILES})

if(HAS_MRPT)
target_link_libraries(plslam ${LINK_LIBS} ${MRPT_LIBS} )
else()
target_link_libraries(plslam ${LINK_LIBS})

if(HAS_MRPT)
target_link_libraries(plslam ${MRPT_LIBS} ${MRPT_LIBRARIES})
endif()

# Applications
if(HAS_MRPT)
add_executable ( plslam_dataset app/plslam_dataset.cpp )
target_link_libraries( plslam_dataset plslam )
endif(HAS_MRPT)
add_executable ( plslam_dataset app/plslam_dataset.cpp )
target_link_libraries( plslam_dataset plslam )
endif()



Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Please do not hesitate to contact the authors if you have any further questions.
## 1. Prerequisites and dependencies

### OpenCV 3.x.x
It can be easily found at http://opencv.org.
It can be easily found at http://opencv.org.

### Eigen3 (tested with 3.2.92)
http://eigen.tuxfamily.org
Expand All @@ -61,19 +61,23 @@ sudo apt-get install libyaml-cpp-dev
```

### stvo-pl
It can be found at:
It can be found at:
```
https://github.com/rubengooj/stvo-pl
```

### MRPT
In case of using the provided representation class.
Download and install instructions can be found at: http://www.mrpt.org/
### MRPT (>=v1.9.9)
Optional: Enables the provided visualization class.

#### Known Issues:
If working with the most recent versions of the MRPT library you might find some issues due to hard refactoring, for which we recommend to use this version instead (the last one we tested):
1) Only for Ubuntu 16.04 Xenial: upgrade gcc. Instructions [here](https://gist.github.com/jlblancoc/99521194aba975286c80f93e47966dc5).
2) For any Ubuntu version older than 20.04 Focal:
```
sudo add-apt-repository ppa:joseluisblancoc/mrpt
sudo apt-get update
```
https://github.com/MRPT/mrpt/tree/0c3d605c3cbf5f2ffb8137089e43ebdae5a55de3
3) Everyone: Install mrpt libraries:
```
sudo apt-get install libmrpt-dev
```

### Line Descriptor
Expand Down Expand Up @@ -106,4 +110,3 @@ A full command would be:
./plslam_dataset kitti/00 -c ../config/config_kitti.yaml -o 100 -s 2 -n 1000

where we are processing the sequence 00 from the KITTI dataset (in our dataset folders) with the custom config file, with an offset *-c* allowing to skip the first 100 images, a parameter *-s* to consider only one every 2 images, and a parameter *-n* to only consider 1000 input pairs.

16 changes: 0 additions & 16 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
echo "Building 3rdparty/line_descriptor ... "
cd 3rdparty/line_descriptor
mkdir build
cd build
cmake ..
make -j8
cd ../../../

echo "Building 3rdparty/DBoW2 ... "
cd 3rdparty/DBoW2
mkdir build
cd build
cmake ..
make -j8
cd ../../../

echo "Uncompressing vocabulary ..."
cd vocabulary
tar -xf voc.tar.gz
Expand Down
29 changes: 14 additions & 15 deletions include/slamScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ using namespace std;
#include <mrpt/opengl.h>
#include <mrpt/opengl/CPointCloudColoured.h>
#include <mrpt/gui.h>
#include <mrpt/utils/CConfigFile.h>
#include <mrpt/utils/CConfigFileBase.h>
#include <mrpt/config/CConfigFile.h>
#include <mrpt/config/CConfigFileBase.h>
using namespace mrpt;
using namespace mrpt::gui;
using namespace mrpt::poses;
using namespace mrpt::utils;
using namespace mrpt::config;
using namespace mrpt::math;
using namespace mrpt::opengl;

Expand Down Expand Up @@ -89,20 +89,19 @@ class slamScene{
CPose3D getPoseXYZ(VectorXd x);

CDisplayWindow3D* win;
COpenGLScenePtr theScene;
COpenGLViewportPtr image, legend, help;
opengl::CSetOfObjectsPtr bbObj, bbObj1, srefObj, srefObj1, gtObj, srefObjGT, elliObjL, elliObjP;
opengl::CEllipsoidPtr elliObj;
opengl::CFrustumPtr frustObj, frustObj1;
opengl::CAxisPtr axesObj;

opengl::CSetOfLinesPtr lineObj, lineObj_local, kfsLinesObj, voLinesObj;
opengl::CPointCloudPtr pointObj, pointObj_local;
opengl::CSetOfObjectsPtr kfsObj;
COpenGLScene::Ptr theScene;
COpenGLViewport::Ptr image, legend, help;
opengl::CSetOfObjects::Ptr bbObj, bbObj1, srefObj, srefObj1, gtObj, srefObjGT, elliObjL, elliObjP;
opengl::CEllipsoid::Ptr elliObj;
opengl::CFrustum::Ptr frustObj, frustObj1;
opengl::CAxis::Ptr axesObj;

opengl::CSetOfLines::Ptr lineObj, lineObj_local, kfsLinesObj, voLinesObj;
opengl::CPointCloud::Ptr pointObj, pointObj_local;
opengl::CSetOfObjects::Ptr kfsObj;

float sbb, saxis, srad, sref, sline, sfreq, szoom, selli, selev, sazim, sfrust, slinef;
CVectorDouble v_aux, v_aux_, v_aux1, v_aux1_, v_auxgt, gt_aux_, v_auxgt_;
CVectorFixedDouble<6> v_aux, v_aux_, v_aux1, v_aux1_, v_auxgt, gt_aux_, v_auxgt_;
CPose3D pose, pose_0, pose_gt, pose_ini, ellPose, pose1, change, frustumL_, frustumR_;
Matrix4d x_ini;
mrptKeyModifier kmods;
Expand All @@ -116,7 +115,7 @@ class slamScene{
float time;
string img, img_legend, img_help;
CMatrixFloat lData, pData;
CImage img_mrpt_legend, img_mrpt_image, img_mrpt_help;
mrpt::img::CImage img_mrpt_legend, img_mrpt_image, img_mrpt_help;

float b, sigmaP, sigmaL, f, cx, cy, bsigmaL, bsigmaP;

Expand Down
16 changes: 8 additions & 8 deletions src/mapHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3962,10 +3962,10 @@ bool MapHandler::loopClosureOptimizationEssGraphG2O()
// define G2O variables
g2o::SparseOptimizer optimizer;
optimizer.setVerbose(true);
g2o::BlockSolver_6_3::LinearSolverType* linearSolver;
linearSolver = new g2o::LinearSolverCholmod<g2o::BlockSolver_6_3::PoseMatrixType>();
g2o::BlockSolver_6_3* solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);

std::unique_ptr<g2o::BlockSolver_6_3::LinearSolverType> linearSolver (new g2o::LinearSolverCholmod<g2o::BlockSolver_6_3::PoseMatrixType>());
std::unique_ptr<g2o::BlockSolver_6_3> solver_ptr (new g2o::BlockSolver_6_3(std::move(linearSolver)));
g2o::OptimizationAlgorithmLevenberg * solver = new g2o::OptimizationAlgorithmLevenberg(std::move(solver_ptr));
solver->setUserLambdaInit(1e-10);
optimizer.setAlgorithm(solver);

Expand Down Expand Up @@ -4188,10 +4188,10 @@ bool MapHandler::loopClosureOptimizationCovGraphG2O()
// define G2O variables
g2o::SparseOptimizer optimizer;
optimizer.setVerbose(false);
g2o::BlockSolver_6_3::LinearSolverType* linearSolver;
linearSolver = new g2o::LinearSolverCholmod<g2o::BlockSolver_6_3::PoseMatrixType>();
g2o::BlockSolver_6_3* solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);

std::unique_ptr<g2o::BlockSolver_6_3::LinearSolverType> linearSolver (new g2o::LinearSolverCholmod<g2o::BlockSolver_6_3::PoseMatrixType>());
std::unique_ptr<g2o::BlockSolver_6_3> solver_ptr (new g2o::BlockSolver_6_3(std::move(linearSolver)));
g2o::OptimizationAlgorithmLevenberg * solver = new g2o::OptimizationAlgorithmLevenberg(std::move(solver_ptr));
solver->setUserLambdaInit(1e-10);
optimizer.setAlgorithm(solver);

Expand Down
Loading