diff --git a/CMakeLists.txt b/CMakeLists.txt index a55d067f..4bb93e3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +option(BUILD_WITH_UBUNTU1804 OFF) + include(cmake/packages.cmake) include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}) diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 93094482..dc4adf32 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -70,14 +70,63 @@ include_directories(${yaml-cpp_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}/thirdparty/) include_directories(${PROJECT_SOURCE_DIR}/thirdparty/velodyne/include) -set(third_party_libs - ${catkin_LIBRARIES} - ${g2o_libs} - ${OpenCV_LIBS} - ${PCL_LIBRARIES} - ${Pangolin_LIBRARIES} - glog gflags - ${yaml-cpp_LIBRARIES} - yaml-cpp - tbb - ) +if(BUILD_WITH_UBUNTU1804) + function(extract_file filename extract_dir) + message(STATUS "Extract ${filename} to ${extract_dir} ...") + set(temp_dir ${extract_dir}) + if(EXISTS ${temp_dir}) + file(REMOVE_RECURSE ${temp_dir}) + endif() + file(MAKE_DIRECTORY ${temp_dir}) + execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvzf ${filename} + WORKING_DIRECTORY ${temp_dir}) + endfunction() + + set(TBB_ROOT_DIR ${PROJECT_SOURCE_DIR}/thirdparty/tbb/oneTBB-2019_U8/oneTBB-2019_U8) + set(TBB_BUILD_DIR "tbb_build_dir=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") + set(TBB_BUILD_PREFIX "tbb_build_prefix=tbb") + + extract_file(${PROJECT_SOURCE_DIR}/thirdparty/tbb/2019_U8.tar.gz ${PROJECT_SOURCE_DIR}/thirdparty/tbb/oneTBB-2019_U8) + + include(${TBB_ROOT_DIR}/cmake/TBBBuild.cmake) + + #message(STATUS "======TBB_BUILD_DIR = ${TBB_BUILD_DIR}") + #message(STATUS "======TBB_BUILD_PREFIX = ${TBB_BUILD_PREFIX}") + + tbb_build(TBB_ROOT ${TBB_ROOT_DIR} + compiler=gcc-9 + stdver=c++17 + ${TBB_BUILD_DIR} + ${TBB_BUILD_PREFIX} + CONFIG_DIR + TBB_DIR) + + find_package(TBB REQUIRED) + + include_directories(${PROJECT_SOURCE_DIR}/thirdparty/tbb/oneTBB-2019_U8/oneTBB-2019_U8/include) + link_directories(${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tbb_release) + + set(third_party_libs + ${catkin_LIBRARIES} + ${g2o_libs} + ${OpenCV_LIBS} + ${PCL_LIBRARIES} + ${Pangolin_LIBRARIES} + glog gflags + ${yaml-cpp_LIBRARIES} + yaml-cpp + TBB::tbb + ) +else() + set(third_party_libs + ${catkin_LIBRARIES} + ${g2o_libs} + ${OpenCV_LIBS} + ${PCL_LIBRARIES} + ${Pangolin_LIBRARIES} + glog gflags + ${yaml-cpp_LIBRARIES} + yaml-cpp + tbb + ) +endif () \ No newline at end of file diff --git a/readme.md b/readme.md index a5e17179..d80a5fae 100644 --- a/readme.md +++ b/readme.md @@ -64,9 +64,53 @@ ## 编译 - 本书推荐的编译环境是Ubuntu 20.04。更老的Ubuntu版本需要适配gcc编译器,主要是C++17标准。更新的Ubuntu则需要您自己安装对应的ROS版本。 -- 在编译本书代码之前,请编译安装本书thirdparty/下的三方库(如果您机器上没有安装的话)。 +- 在编译本书代码之前,请编译安装本书thirdparty/下的```g2o```以及以下三方库(如果您机器上没有安装的话) + - ROS Noetic (http://wiki.ros.org/noetic/Installation/Ubuntu) + - pcl-ros (如果没有选择安装 ```ros-noetic-desktop-full```): ```sudo apt install ros-noetic-pcl-ros``` + - velodyne-msgs (如果没有选择安装```ros-noetic-desktop-full```): ```sudo apt install ros-noetic-velodyne-msgs``` + - opencv: ```sudo apt install libopencv-dev``` + - glog: ```sudo apt install libgoogle-glog-dev``` + - eigen3: ```sudo apt install libeigen3-dev``` + - suitesparse: ```sudo apt install libsuitesparse-dev``` + - pcl: ```sudo apt install libpcl-dev``` + - yaml-cpp: ```sudo apt install libyaml-cpp-dev``` + - tbb: ```sudo apt install libbtbb-dev``` + - gmock: ```sudo apt install libgmock-dev``` + - 以下命令可以一次安装上面几个库: ```sudo apt install -y libopencv-dev libgoogle-glog-dev libeigen3-dev libsuitesparse-dev libpcl-dev libyaml-cpp-dev libbtbb-dev libgmock-dev``` + - Pangolin: https://github.com/stevenlovegrove/Pangolin - 之后,使用通常的cmake, make 方式就可以编译本书所有内容了。 +### 适配Ubuntu18.04 + +为了在Ubuntu18.04上编译运行,需要安装gcc-9,并且使用对应版本的TBB + +**安装gcc-9** +```bash +sudo add-apt-repository ppa:ubuntu-toolchain-r/test +sudo update-alternatives --remove-all gcc +sudo update-alternatives --remove-all g++ + +#命令最后的1和10是优先级,如果使用auto选择模式,系统将默认使用优先级高的 +sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 1 +sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 10 + +sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 1 +sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 10 +``` + +**检查版本** +```bash +g++ -v +``` + +**编译程序** +```bash +mkdir build +cd build +cmake .. -DBUILD_WITH_UBUNTU1804=ON +make -j8 +``` + ## TODO项 - 一部分插图需要授权 diff --git a/src/ch7/loam-like/feature_extraction.cc b/src/ch7/loam-like/feature_extraction.cc index 7ff0cbec..0b2182b2 100644 --- a/src/ch7/loam-like/feature_extraction.cc +++ b/src/ch7/loam-like/feature_extraction.cc @@ -21,7 +21,7 @@ void FeatureExtraction::Extract(FullCloudPtr pc_in, CloudPtr pc_out_edge, CloudP p.z = pt.z; p.intensity = pt.intensity; - scans_in_each_line[pt.ring]->emplace_back(p); + scans_in_each_line[pt.ring]->points.emplace_back(p); } // 处理曲率 diff --git a/thirdparty/tbb/2019_U8.tar.gz b/thirdparty/tbb/2019_U8.tar.gz new file mode 100644 index 00000000..5033dd68 Binary files /dev/null and b/thirdparty/tbb/2019_U8.tar.gz differ