├── README.md
├── camera_model
├── CMakeLists.txt
├── cmake
│ └── FindEigen.cmake
├── include
│ └── camodocal
│ │ ├── calib
│ │ └── CameraCalibration.h
│ │ ├── camera_models
│ │ ├── Camera.h
│ │ ├── CameraFactory.h
│ │ ├── CataCamera.h
│ │ ├── CostFunctionFactory.h
│ │ ├── EquidistantCamera.h
│ │ ├── PinholeCamera.h
│ │ └── ScaramuzzaCamera.h
│ │ ├── chessboard
│ │ ├── Chessboard.h
│ │ ├── ChessboardCorner.h
│ │ ├── ChessboardQuad.h
│ │ └── Spline.h
│ │ ├── gpl
│ │ ├── EigenQuaternionParameterization.h
│ │ ├── EigenUtils.h
│ │ └── gpl.h
│ │ └── sparse_graph
│ │ └── Transform.h
├── instruction
├── package.xml
├── readme.md
└── src
│ ├── calib
│ └── CameraCalibration.cc
│ ├── camera_models
│ ├── Camera.cc
│ ├── CameraFactory.cc
│ ├── CataCamera.cc
│ ├── CostFunctionFactory.cc
│ ├── EquidistantCamera.cc
│ ├── PinholeCamera.cc
│ └── ScaramuzzaCamera.cc
│ ├── chessboard
│ └── Chessboard.cc
│ ├── gpl
│ ├── EigenQuaternionParameterization.cc
│ └── gpl.cc
│ ├── intrinsic_calib.cc
│ └── sparse_graph
│ └── Transform.cc
├── config
├── mynteye_leishen_indoor.yaml
├── mynteye_leishen_outdoor.yaml
├── vils_odom.rviz
└── vils_rviz_config.rviz
├── feature_tracker_
├── CMakeLists.txt
├── cmake
│ └── FindEigen.cmake
├── package.xml
└── src
│ ├── feature_tracker.cpp
│ ├── feature_tracker.h
│ ├── feature_tracker_node.cpp
│ ├── parameters.cpp
│ ├── parameters.h
│ └── tic_toc.h
├── fig
├── cover.png
├── device.png
└── results.png
├── lidar_compensator
├── CMakeLists.txt
├── cmake
│ ├── FindGflags.cmake
│ └── FindGlog.cmake
├── package.xml
└── src
│ ├── CircularBuffer.h
│ ├── PointProcessor.cc
│ ├── PointProcessor.h
│ ├── TicToc.h
│ ├── common_ros.h
│ ├── math_utils.h
│ └── processor_node.cc
├── lidar_mapping
├── CMakeLists.txt
├── include
│ ├── aloam_velodyne
│ │ ├── common.h
│ │ └── tic_toc.h
│ ├── fast_gicp
│ │ ├── cuda
│ │ │ ├── brute_force_knn.cuh
│ │ │ ├── compute_derivatives.cuh
│ │ │ ├── compute_mahalanobis.cuh
│ │ │ ├── covariance_estimation.cuh
│ │ │ ├── covariance_regularization.cuh
│ │ │ ├── fast_vgicp_cuda.cuh
│ │ │ ├── find_voxel_correspondences.cuh
│ │ │ ├── gaussian_voxelmap.cuh
│ │ │ ├── ndt_compute_derivatives.cuh
│ │ │ ├── ndt_cuda.cuh
│ │ │ └── vector3_hash.cuh
│ │ ├── fast_gicp.hpp
│ │ ├── fast_gicp_st.hpp
│ │ ├── fast_vgicp.hpp
│ │ ├── gicp
│ │ │ ├── experimental
│ │ │ │ ├── fast_gicp_mp.hpp
│ │ │ │ └── fast_gicp_mp_impl.hpp
│ │ │ ├── fast_gicp.hpp
│ │ │ ├── fast_gicp_st.hpp
│ │ │ ├── fast_vgicp.hpp
│ │ │ ├── fast_vgicp_cuda.hpp
│ │ │ ├── fast_vgicp_voxel.hpp
│ │ │ ├── gicp_settings.hpp
│ │ │ ├── impl
│ │ │ │ ├── fast_gicp_impl.hpp
│ │ │ │ ├── fast_gicp_st_impl.hpp
│ │ │ │ ├── fast_vgicp_cuda_impl.hpp
│ │ │ │ ├── fast_vgicp_impl.hpp
│ │ │ │ └── lsq_registration_impl.hpp
│ │ │ └── lsq_registration.hpp
│ │ ├── ndt
│ │ │ ├── impl
│ │ │ │ └── ndt_cuda_impl.hpp
│ │ │ ├── ndt_cuda.hpp
│ │ │ └── ndt_settings.hpp
│ │ └── so3
│ │ │ └── so3.hpp
│ ├── global_mapping
│ │ ├── Pose6D.h
│ │ ├── Quaternion.h
│ │ ├── Vector3.h
│ │ └── util.h
│ ├── ikd_Tree
│ │ ├── ikd_Tree.cpp
│ │ └── ikd_Tree.h
│ └── scancontext
│ │ ├── KDTreeVectorOfVectorsAdaptor.h
│ │ ├── Scancontext.cpp
│ │ ├── Scancontext.h
│ │ └── nanoflann.hpp
├── launch
│ └── map.launch
├── package.xml
└── src
│ ├── globalMappingIkdTree.cpp
│ ├── globalMappingOcTree.cpp
│ ├── lidarFactor.hpp
│ ├── localMapping.cpp
│ └── scanRegistration.cpp
└── vils_estimator
├── CMakeLists.txt
├── cmake
└── FindEigen.cmake
├── launch
├── mynteye_leishen_indoor.launch
├── mynteye_leishen_odom.launch
└── mynteye_leishen_outdoor.launch
├── package.xml
└── src
├── estimator.cpp
├── estimator.h
├── estimator_node.cpp
├── factor
├── imu_factor.h
├── integration_base.h
├── marginalization_factor.cpp
├── marginalization_factor.h
├── pose_local_parameterization.cpp
├── pose_local_parameterization.h
├── projection_factor.cpp
├── projection_factor.h
├── projection_td_factor.cpp
└── projection_td_factor.h
├── feature_manager.cpp
├── feature_manager.h
├── initial
├── initial_aligment.cpp
├── initial_alignment.h
├── initial_ex_rotation.cpp
├── initial_ex_rotation.h
├── initial_sfm.cpp
├── initial_sfm.h
├── solve_5pts.cpp
└── solve_5pts.h
├── lidar_backend.cpp
├── lidar_backend.h
├── lidar_frontend.cpp
├── lidar_frontend.h
├── lidar_functions
├── cov_func_point_to_point.h
├── fast_gicp-master.zip
└── fast_gicp
│ ├── .clang-format
│ ├── .gitignore
│ ├── .gitmodules
│ ├── .travis.yml
│ └── include
│ └── fast_gicp
│ ├── cuda
│ ├── brute_force_knn.cuh
│ ├── compute_derivatives.cuh
│ ├── compute_mahalanobis.cuh
│ ├── covariance_estimation.cuh
│ ├── covariance_regularization.cuh
│ ├── fast_vgicp_cuda.cuh
│ ├── find_voxel_correspondences.cuh
│ ├── gaussian_voxelmap.cuh
│ ├── ndt_compute_derivatives.cuh
│ ├── ndt_cuda.cuh
│ └── vector3_hash.cuh
│ ├── gicp
│ ├── experimental
│ │ ├── fast_gicp_mp.hpp
│ │ └── fast_gicp_mp_impl.hpp
│ ├── fast_gicp.hpp
│ ├── fast_gicp_st.hpp
│ ├── fast_vgicp.hpp
│ ├── fast_vgicp_cuda.hpp
│ ├── fast_vgicp_voxel.hpp
│ ├── gicp_settings.hpp
│ ├── impl
│ │ ├── fast_gicp_impl.hpp
│ │ ├── fast_gicp_st_impl.hpp
│ │ ├── fast_vgicp_cuda_impl.hpp
│ │ ├── fast_vgicp_impl.hpp
│ │ └── lsq_registration_impl.hpp
│ └── lsq_registration.hpp
│ ├── ndt
│ ├── impl
│ │ └── ndt_cuda_impl.hpp
│ ├── ndt_cuda.hpp
│ └── ndt_settings.hpp
│ └── so3
│ └── so3.hpp
├── parameters.cpp
├── parameters.h
└── utility
├── CameraPoseVisualization.cpp
├── CameraPoseVisualization.h
├── tic_toc.h
├── utility.cpp
├── utility.h
├── visualization.cpp
└── visualization.h
/README.md:
--------------------------------------------------------------------------------
1 | # mVIL-Fusion
2 | Monocular Visual-Inertial-LiDAR Simultaneous Localization and Mapping in Challenging Environments
3 | ## 1. Introduction
4 |
5 | ### 1.1 Video
6 |
7 |
9 |
10 |
11 | ### 1.2 Dataset
12 | #### Device
13 |
14 |
15 | - MYNTEYE-D120 VI sensor https://www.mynteye.com/pages/mynt-eye-d
16 | - LeiShen-C16 3d spinning LiDAR https://www.leishen-lidar.com/
17 | #### Topic:
18 | - imu_topic: `/mynteye/imu/data_raw` 200hz
19 | - image_topic: `/mynteye/left/image_mono` 30hz
20 | - lidar_topic: `/lslidar_point_cloud` 10hz
21 | #### Description
22 | | Name | Size |
23 | | :-----| ----: |
24 | | 3indoor.bag | 6.0G |
25 | | outdoor.bag | 9.1G |
26 | #### Download:
27 | - Link:https://pan.baidu.com/s/1ERiMsiewaP9C9_nWbJS-9w?pwd=h9m9
28 | - Pin:h9m9
29 | ## 2. Usage
30 | ### 2.1 Build
31 | ```
32 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test
33 | sudo apt-get update
34 | sudo apt-get install gcc-7 g++-7
35 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
36 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50 --slave /usr/bin/g++ g++ /usr/bin/g++-7
37 |
38 | cd ~/catkin_ws/src
39 | git clone https://github.com/Stan994265/mVIL-Fusion
40 | cd ../
41 | catkin_make -j1
42 | source ~/catkin_ws/devel/setup.bash
43 | ```
44 | ### 2.2 Run Demo
45 | ```
46 | For indoor:
47 | roslaunch vils_estimator mynteye_leishen_indoor.launch
48 | rosbag play ~/3indoor.bag
49 |
50 | For outdoor:
51 | roslaunch vils_estimator mynteye_leishen_outdoor.launch
52 | rosbag play ~/outdoor.bag
53 |
54 | For odometry only:
55 | (Comment line "#define FOR_GLOBAL" in lidar_mapping/src/localMapping.cpp.)
56 | roslaunch vils_estimator mynteye_leishen_odom.launch
57 | ```
58 | ### 2.3. Save Results
59 | If you want to save global map, set the onboard parameter of the .launch file to 1.
60 |
61 |
62 |
--------------------------------------------------------------------------------
/camera_model/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(camera_model)
3 |
4 | set(CMAKE_BUILD_TYPE "Release")
5 | set(CMAKE_CXX_FLAGS "-std=c++11")
6 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fPIC")
7 |
8 | find_package(catkin REQUIRED COMPONENTS
9 | roscpp
10 | std_msgs
11 | )
12 |
13 | find_package(Boost REQUIRED COMPONENTS filesystem program_options system)
14 | include_directories(${Boost_INCLUDE_DIRS})
15 |
16 | find_package(OpenCV REQUIRED)
17 |
18 | # set(EIGEN_INCLUDE_DIR "/usr/local/include/eigen3")
19 | find_package(Ceres REQUIRED)
20 | include_directories(${CERES_INCLUDE_DIRS})
21 |
22 |
23 | catkin_package(
24 | INCLUDE_DIRS include
25 | LIBRARIES camera_model
26 | CATKIN_DEPENDS roscpp std_msgs
27 | # DEPENDS system_lib
28 | )
29 |
30 | include_directories(
31 | ${catkin_INCLUDE_DIRS}
32 | )
33 |
34 | include_directories("include")
35 |
36 |
37 | add_executable(Calibration
38 | src/intrinsic_calib.cc
39 | src/chessboard/Chessboard.cc
40 | src/calib/CameraCalibration.cc
41 | src/camera_models/Camera.cc
42 | src/camera_models/CameraFactory.cc
43 | src/camera_models/CostFunctionFactory.cc
44 | src/camera_models/PinholeCamera.cc
45 | src/camera_models/CataCamera.cc
46 | src/camera_models/EquidistantCamera.cc
47 | src/camera_models/ScaramuzzaCamera.cc
48 | src/sparse_graph/Transform.cc
49 | src/gpl/gpl.cc
50 | src/gpl/EigenQuaternionParameterization.cc)
51 |
52 | add_library(camera_model
53 | src/chessboard/Chessboard.cc
54 | src/calib/CameraCalibration.cc
55 | src/camera_models/Camera.cc
56 | src/camera_models/CameraFactory.cc
57 | src/camera_models/CostFunctionFactory.cc
58 | src/camera_models/PinholeCamera.cc
59 | src/camera_models/CataCamera.cc
60 | src/camera_models/EquidistantCamera.cc
61 | src/camera_models/ScaramuzzaCamera.cc
62 | src/sparse_graph/Transform.cc
63 | src/gpl/gpl.cc
64 | src/gpl/EigenQuaternionParameterization.cc)
65 |
66 | target_link_libraries(Calibration ${Boost_LIBRARIES} ${OpenCV_LIBS} ${CERES_LIBRARIES})
67 | target_link_libraries(camera_model ${Boost_LIBRARIES} ${OpenCV_LIBS} ${CERES_LIBRARIES})
68 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/calib/CameraCalibration.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERACALIBRATION_H
2 | #define CAMERACALIBRATION_H
3 |
4 | #include
5 |
6 | #include "camodocal/camera_models/Camera.h"
7 |
8 | namespace camodocal
9 | {
10 |
11 | class CameraCalibration
12 | {
13 | public:
14 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
15 | CameraCalibration();
16 |
17 | CameraCalibration(Camera::ModelType modelType,
18 | const std::string& cameraName,
19 | const cv::Size& imageSize,
20 | const cv::Size& boardSize,
21 | float squareSize);
22 |
23 | void clear(void);
24 |
25 | void addChessboardData(const std::vector& corners);
26 |
27 | bool calibrate(void);
28 |
29 | int sampleCount(void) const;
30 | std::vector >& imagePoints(void);
31 | const std::vector >& imagePoints(void) const;
32 | std::vector >& scenePoints(void);
33 | const std::vector >& scenePoints(void) const;
34 | CameraPtr& camera(void);
35 | const CameraConstPtr camera(void) const;
36 |
37 | Eigen::Matrix2d& measurementCovariance(void);
38 | const Eigen::Matrix2d& measurementCovariance(void) const;
39 |
40 | cv::Mat& cameraPoses(void);
41 | const cv::Mat& cameraPoses(void) const;
42 |
43 | void drawResults(std::vector& images) const;
44 |
45 | void writeParams(const std::string& filename) const;
46 |
47 | bool writeChessboardData(const std::string& filename) const;
48 | bool readChessboardData(const std::string& filename);
49 |
50 | void setVerbose(bool verbose);
51 |
52 | private:
53 | bool calibrateHelper(CameraPtr& camera,
54 | std::vector& rvecs, std::vector& tvecs) const;
55 |
56 | void optimize(CameraPtr& camera,
57 | std::vector& rvecs, std::vector& tvecs) const;
58 |
59 | template
60 | void readData(std::ifstream& ifs, T& data) const;
61 |
62 | template
63 | void writeData(std::ofstream& ofs, T data) const;
64 |
65 | cv::Size m_boardSize;
66 | float m_squareSize;
67 |
68 | CameraPtr m_camera;
69 | cv::Mat m_cameraPoses;
70 |
71 | std::vector > m_imagePoints;
72 | std::vector > m_scenePoints;
73 |
74 | Eigen::Matrix2d m_measurementCovariance;
75 |
76 | bool m_verbose;
77 | };
78 |
79 | }
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/camera_models/CameraFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERAFACTORY_H
2 | #define CAMERAFACTORY_H
3 |
4 | #include
5 | #include
6 |
7 | #include "camodocal/camera_models/Camera.h"
8 |
9 | namespace camodocal
10 | {
11 |
12 | class CameraFactory
13 | {
14 | public:
15 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
16 | CameraFactory();
17 |
18 | static boost::shared_ptr instance(void);
19 |
20 | CameraPtr generateCamera(Camera::ModelType modelType,
21 | const std::string& cameraName,
22 | cv::Size imageSize) const;
23 |
24 | CameraPtr generateCameraFromYamlFile(const std::string& filename);
25 |
26 | private:
27 | static boost::shared_ptr m_instance;
28 | };
29 |
30 | }
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/camera_models/CostFunctionFactory.h:
--------------------------------------------------------------------------------
1 | #ifndef COSTFUNCTIONFACTORY_H
2 | #define COSTFUNCTIONFACTORY_H
3 |
4 | #include
5 | #include
6 |
7 | #include "camodocal/camera_models/Camera.h"
8 |
9 | namespace ceres
10 | {
11 | class CostFunction;
12 | }
13 |
14 | namespace camodocal
15 | {
16 |
17 | enum
18 | {
19 | CAMERA_INTRINSICS = 1 << 0,
20 | CAMERA_POSE = 1 << 1,
21 | POINT_3D = 1 << 2,
22 | ODOMETRY_INTRINSICS = 1 << 3,
23 | ODOMETRY_3D_POSE = 1 << 4,
24 | ODOMETRY_6D_POSE = 1 << 5,
25 | CAMERA_ODOMETRY_TRANSFORM = 1 << 6
26 | };
27 |
28 | class CostFunctionFactory
29 | {
30 | public:
31 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
32 | CostFunctionFactory();
33 |
34 | static boost::shared_ptr instance(void);
35 |
36 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
37 | const Eigen::Vector3d& observed_P,
38 | const Eigen::Vector2d& observed_p,
39 | int flags) const;
40 |
41 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
42 | const Eigen::Vector3d& observed_P,
43 | const Eigen::Vector2d& observed_p,
44 | const Eigen::Matrix2d& sqrtPrecisionMat,
45 | int flags) const;
46 |
47 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
48 | const Eigen::Vector2d& observed_p,
49 | int flags, bool optimize_cam_odo_z = true) const;
50 |
51 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
52 | const Eigen::Vector2d& observed_p,
53 | const Eigen::Matrix2d& sqrtPrecisionMat,
54 | int flags, bool optimize_cam_odo_z = true) const;
55 |
56 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
57 | const Eigen::Vector3d& odo_pos,
58 | const Eigen::Vector3d& odo_att,
59 | const Eigen::Vector2d& observed_p,
60 | int flags, bool optimize_cam_odo_z = true) const;
61 |
62 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& camera,
63 | const Eigen::Quaterniond& cam_odo_q,
64 | const Eigen::Vector3d& cam_odo_t,
65 | const Eigen::Vector3d& odo_pos,
66 | const Eigen::Vector3d& odo_att,
67 | const Eigen::Vector2d& observed_p,
68 | int flags) const;
69 |
70 | ceres::CostFunction* generateCostFunction(const CameraConstPtr& cameraLeft,
71 | const CameraConstPtr& cameraRight,
72 | const Eigen::Vector3d& observed_P,
73 | const Eigen::Vector2d& observed_p_left,
74 | const Eigen::Vector2d& observed_p_right) const;
75 |
76 | private:
77 | static boost::shared_ptr m_instance;
78 | };
79 |
80 | }
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/chessboard/Chessboard.h:
--------------------------------------------------------------------------------
1 | #ifndef CHESSBOARD_H
2 | #define CHESSBOARD_H
3 |
4 | #include
5 | #include
6 |
7 | namespace camodocal
8 | {
9 |
10 | // forward declarations
11 | class ChessboardCorner;
12 | typedef boost::shared_ptr ChessboardCornerPtr;
13 | class ChessboardQuad;
14 | typedef boost::shared_ptr ChessboardQuadPtr;
15 |
16 | class Chessboard
17 | {
18 | public:
19 | Chessboard(cv::Size boardSize, cv::Mat& image);
20 |
21 | void findCorners(bool useOpenCV = false);
22 | const std::vector& getCorners(void) const;
23 | bool cornersFound(void) const;
24 |
25 | const cv::Mat& getImage(void) const;
26 | const cv::Mat& getSketch(void) const;
27 |
28 | private:
29 | bool findChessboardCorners(const cv::Mat& image,
30 | const cv::Size& patternSize,
31 | std::vector& corners,
32 | int flags, bool useOpenCV);
33 |
34 | bool findChessboardCornersImproved(const cv::Mat& image,
35 | const cv::Size& patternSize,
36 | std::vector& corners,
37 | int flags);
38 |
39 | void cleanFoundConnectedQuads(std::vector& quadGroup, cv::Size patternSize);
40 |
41 | void findConnectedQuads(std::vector& quads,
42 | std::vector& group,
43 | int group_idx, int dilation);
44 |
45 | // int checkQuadGroup(std::vector& quadGroup,
46 | // std::vector& outCorners,
47 | // cv::Size patternSize);
48 |
49 | void labelQuadGroup(std::vector& quad_group,
50 | cv::Size patternSize, bool firstRun);
51 |
52 | void findQuadNeighbors(std::vector& quads, int dilation);
53 |
54 | int augmentBestRun(std::vector& candidateQuads, int candidateDilation,
55 | std::vector& existingQuads, int existingDilation);
56 |
57 | void generateQuads(std::vector& quads,
58 | cv::Mat& image, int flags,
59 | int dilation, bool firstRun);
60 |
61 | bool checkQuadGroup(std::vector& quads,
62 | std::vector& corners,
63 | cv::Size patternSize);
64 |
65 | void getQuadrangleHypotheses(const std::vector< std::vector >& contours,
66 | std::vector< std::pair >& quads,
67 | int classId) const;
68 |
69 | bool checkChessboard(const cv::Mat& image, cv::Size patternSize) const;
70 |
71 | bool checkBoardMonotony(std::vector& corners,
72 | cv::Size patternSize);
73 |
74 | bool matchCorners(ChessboardQuadPtr& quad1, int corner1,
75 | ChessboardQuadPtr& quad2, int corner2) const;
76 |
77 | cv::Mat mImage;
78 | cv::Mat mSketch;
79 | std::vector mCorners;
80 | cv::Size mBoardSize;
81 | bool mCornersFound;
82 | };
83 |
84 | }
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/chessboard/ChessboardCorner.h:
--------------------------------------------------------------------------------
1 | #ifndef CHESSBOARDCORNER_H
2 | #define CHESSBOARDCORNER_H
3 |
4 | #include
5 | #include
6 |
7 | namespace camodocal
8 | {
9 |
10 | class ChessboardCorner;
11 | typedef boost::shared_ptr ChessboardCornerPtr;
12 |
13 | class ChessboardCorner
14 | {
15 | public:
16 | ChessboardCorner() : row(0), column(0), needsNeighbor(true), count(0) {}
17 |
18 | float meanDist(int &n) const
19 | {
20 | float sum = 0;
21 | n = 0;
22 | for (int i = 0; i < 4; ++i)
23 | {
24 | if (neighbors[i].get())
25 | {
26 | float dx = neighbors[i]->pt.x - pt.x;
27 | float dy = neighbors[i]->pt.y - pt.y;
28 | sum += sqrt(dx*dx + dy*dy);
29 | n++;
30 | }
31 | }
32 | return sum / std::max(n, 1);
33 | }
34 |
35 | cv::Point2f pt; // X and y coordinates
36 | int row; // Row and column of the corner
37 | int column; // in the found pattern
38 | bool needsNeighbor; // Does the corner require a neighbor?
39 | int count; // number of corner neighbors
40 | ChessboardCornerPtr neighbors[4]; // pointer to all corner neighbors
41 | };
42 |
43 | }
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/chessboard/ChessboardQuad.h:
--------------------------------------------------------------------------------
1 | #ifndef CHESSBOARDQUAD_H
2 | #define CHESSBOARDQUAD_H
3 |
4 | #include
5 |
6 | #include "camodocal/chessboard/ChessboardCorner.h"
7 |
8 | namespace camodocal
9 | {
10 |
11 | class ChessboardQuad;
12 | typedef boost::shared_ptr ChessboardQuadPtr;
13 |
14 | class ChessboardQuad
15 | {
16 | public:
17 | ChessboardQuad() : count(0), group_idx(-1), edge_len(FLT_MAX), labeled(false) {}
18 |
19 | int count; // Number of quad neighbors
20 | int group_idx; // Quad group ID
21 | float edge_len; // Smallest side length^2
22 | ChessboardCornerPtr corners[4]; // Coordinates of quad corners
23 | ChessboardQuadPtr neighbors[4]; // Pointers of quad neighbors
24 | bool labeled; // Has this corner been labeled?
25 | };
26 |
27 | }
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/gpl/EigenQuaternionParameterization.h:
--------------------------------------------------------------------------------
1 | #ifndef EIGENQUATERNIONPARAMETERIZATION_H
2 | #define EIGENQUATERNIONPARAMETERIZATION_H
3 |
4 | #include "ceres/local_parameterization.h"
5 |
6 | namespace camodocal
7 | {
8 |
9 | class EigenQuaternionParameterization : public ceres::LocalParameterization
10 | {
11 | public:
12 | virtual ~EigenQuaternionParameterization() {}
13 | virtual bool Plus(const double* x,
14 | const double* delta,
15 | double* x_plus_delta) const;
16 | virtual bool ComputeJacobian(const double* x,
17 | double* jacobian) const;
18 | virtual int GlobalSize() const { return 4; }
19 | virtual int LocalSize() const { return 3; }
20 |
21 | private:
22 | template
23 | void EigenQuaternionProduct(const T z[4], const T w[4], T zw[4]) const;
24 | };
25 |
26 |
27 | template
28 | void
29 | EigenQuaternionParameterization::EigenQuaternionProduct(const T z[4], const T w[4], T zw[4]) const
30 | {
31 | zw[0] = z[3] * w[0] + z[0] * w[3] + z[1] * w[2] - z[2] * w[1];
32 | zw[1] = z[3] * w[1] - z[0] * w[2] + z[1] * w[3] + z[2] * w[0];
33 | zw[2] = z[3] * w[2] + z[0] * w[1] - z[1] * w[0] + z[2] * w[3];
34 | zw[3] = z[3] * w[3] - z[0] * w[0] - z[1] * w[1] - z[2] * w[2];
35 | }
36 |
37 | }
38 |
39 | #endif
40 |
41 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/gpl/gpl.h:
--------------------------------------------------------------------------------
1 | #ifndef GPL_H
2 | #define GPL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace camodocal
9 | {
10 |
11 | template
12 | const T clamp(const T& v, const T& a, const T& b)
13 | {
14 | return std::min(b, std::max(a, v));
15 | }
16 |
17 | double hypot3(double x, double y, double z);
18 | float hypot3f(float x, float y, float z);
19 |
20 | template
21 | const T normalizeTheta(const T& theta)
22 | {
23 | T normTheta = theta;
24 |
25 | while (normTheta < - M_PI)
26 | {
27 | normTheta += 2.0 * M_PI;
28 | }
29 | while (normTheta > M_PI)
30 | {
31 | normTheta -= 2.0 * M_PI;
32 | }
33 |
34 | return normTheta;
35 | }
36 |
37 | double d2r(double deg);
38 | float d2r(float deg);
39 | double r2d(double rad);
40 | float r2d(float rad);
41 |
42 | double sinc(double theta);
43 |
44 | template
45 | const T square(const T& x)
46 | {
47 | return x * x;
48 | }
49 |
50 | template
51 | const T cube(const T& x)
52 | {
53 | return x * x * x;
54 | }
55 |
56 | template
57 | const T random(const T& a, const T& b)
58 | {
59 | return static_cast(rand()) / RAND_MAX * (b - a) + a;
60 | }
61 |
62 | template
63 | const T randomNormal(const T& sigma)
64 | {
65 | T x1, x2, w;
66 |
67 | do
68 | {
69 | x1 = 2.0 * random(0.0, 1.0) - 1.0;
70 | x2 = 2.0 * random(0.0, 1.0) - 1.0;
71 | w = x1 * x1 + x2 * x2;
72 | }
73 | while (w >= 1.0 || w == 0.0);
74 |
75 | w = sqrt((-2.0 * log(w)) / w);
76 |
77 | return x1 * w * sigma;
78 | }
79 |
80 | unsigned long long timeInMicroseconds(void);
81 |
82 | double timeInSeconds(void);
83 |
84 | void colorDepthImage(cv::Mat& imgDepth,
85 | cv::Mat& imgColoredDepth,
86 | float minRange, float maxRange);
87 |
88 | bool colormap(const std::string& name, unsigned char idx,
89 | float& r, float& g, float& b);
90 |
91 | std::vector bresLine(int x0, int y0, int x1, int y1);
92 | std::vector bresCircle(int x0, int y0, int r);
93 |
94 | void fitCircle(const std::vector& points,
95 | double& centerX, double& centerY, double& radius);
96 |
97 | std::vector intersectCircles(double x1, double y1, double r1,
98 | double x2, double y2, double r2);
99 |
100 | void LLtoUTM(double latitude, double longitude,
101 | double& utmNorthing, double& utmEasting,
102 | std::string& utmZone);
103 | void UTMtoLL(double utmNorthing, double utmEasting,
104 | const std::string& utmZone,
105 | double& latitude, double& longitude);
106 |
107 | long int timestampDiff(uint64_t t1, uint64_t t2);
108 |
109 | }
110 |
111 | #endif
112 |
--------------------------------------------------------------------------------
/camera_model/include/camodocal/sparse_graph/Transform.h:
--------------------------------------------------------------------------------
1 | #ifndef TRANSFORM_H
2 | #define TRANSFORM_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace camodocal
9 | {
10 |
11 | class Transform
12 | {
13 | public:
14 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
15 |
16 | Transform();
17 | Transform(const Eigen::Matrix4d& H);
18 |
19 | Eigen::Quaterniond& rotation(void);
20 | const Eigen::Quaterniond& rotation(void) const;
21 | double* rotationData(void);
22 | const double* const rotationData(void) const;
23 |
24 | Eigen::Vector3d& translation(void);
25 | const Eigen::Vector3d& translation(void) const;
26 | double* translationData(void);
27 | const double* const translationData(void) const;
28 |
29 | Eigen::Matrix4d toMatrix(void) const;
30 |
31 | private:
32 | Eigen::Quaterniond m_q;
33 | Eigen::Vector3d m_t;
34 | };
35 |
36 | }
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/camera_model/instruction:
--------------------------------------------------------------------------------
1 | rosrun camera_model Calibration -w 8 -h 11 -s 70 -i ~/bag/PX/calib/
2 |
--------------------------------------------------------------------------------
/camera_model/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | camera_model
4 | 0.0.0
5 | The camera_model package
6 |
7 |
8 |
9 |
10 | dvorak
11 |
12 |
13 |
14 |
15 |
16 | TODO
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | catkin
43 | roscpp
44 | std_msgs
45 | roscpp
46 | std_msgs
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/camera_model/readme.md:
--------------------------------------------------------------------------------
1 | part of [camodocal](https://github.com/hengli/camodocal)
2 |
3 | [Google Ceres](http://ceres-solver.org) is needed.
4 |
5 | # Calibration:
6 |
7 | Use [intrinsic_calib.cc](https://github.com/dvorak0/camera_model/blob/master/src/intrinsic_calib.cc) to calibrate your camera.
8 |
9 | # Undistortion:
10 |
11 | See [Camera.h](https://github.com/dvorak0/camera_model/blob/master/include/camodocal/camera_models/Camera.h) for general interface:
12 |
13 | - liftProjective: Lift points from the image plane to the projective space.
14 | - spaceToPlane: Projects 3D points to the image plane (Pi function)
15 |
16 |
--------------------------------------------------------------------------------
/camera_model/src/gpl/EigenQuaternionParameterization.cc:
--------------------------------------------------------------------------------
1 | #include "camodocal/gpl/EigenQuaternionParameterization.h"
2 |
3 | #include
4 |
5 | namespace camodocal
6 | {
7 |
8 | bool
9 | EigenQuaternionParameterization::Plus(const double* x,
10 | const double* delta,
11 | double* x_plus_delta) const
12 | {
13 | const double norm_delta =
14 | sqrt(delta[0] * delta[0] + delta[1] * delta[1] + delta[2] * delta[2]);
15 | if (norm_delta > 0.0)
16 | {
17 | const double sin_delta_by_delta = (sin(norm_delta) / norm_delta);
18 | double q_delta[4];
19 | q_delta[0] = sin_delta_by_delta * delta[0];
20 | q_delta[1] = sin_delta_by_delta * delta[1];
21 | q_delta[2] = sin_delta_by_delta * delta[2];
22 | q_delta[3] = cos(norm_delta);
23 | EigenQuaternionProduct(q_delta, x, x_plus_delta);
24 | }
25 | else
26 | {
27 | for (int i = 0; i < 4; ++i)
28 | {
29 | x_plus_delta[i] = x[i];
30 | }
31 | }
32 | return true;
33 | }
34 |
35 | bool
36 | EigenQuaternionParameterization::ComputeJacobian(const double* x,
37 | double* jacobian) const
38 | {
39 | jacobian[0] = x[3]; jacobian[1] = x[2]; jacobian[2] = -x[1]; // NOLINT
40 | jacobian[3] = -x[2]; jacobian[4] = x[3]; jacobian[5] = x[0]; // NOLINT
41 | jacobian[6] = x[1]; jacobian[7] = -x[0]; jacobian[8] = x[3]; // NOLINT
42 | jacobian[9] = -x[0]; jacobian[10] = -x[1]; jacobian[11] = -x[2]; // NOLINT
43 | return true;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/camera_model/src/sparse_graph/Transform.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | namespace camodocal
4 | {
5 |
6 | Transform::Transform()
7 | {
8 | m_q.setIdentity();
9 | m_t.setZero();
10 | }
11 |
12 | Transform::Transform(const Eigen::Matrix4d& H)
13 | {
14 | m_q = Eigen::Quaterniond(H.block<3,3>(0,0));
15 | m_t = H.block<3,1>(0,3);
16 | }
17 |
18 | Eigen::Quaterniond&
19 | Transform::rotation(void)
20 | {
21 | return m_q;
22 | }
23 |
24 | const Eigen::Quaterniond&
25 | Transform::rotation(void) const
26 | {
27 | return m_q;
28 | }
29 |
30 | double*
31 | Transform::rotationData(void)
32 | {
33 | return m_q.coeffs().data();
34 | }
35 |
36 | const double* const
37 | Transform::rotationData(void) const
38 | {
39 | return m_q.coeffs().data();
40 | }
41 |
42 | Eigen::Vector3d&
43 | Transform::translation(void)
44 | {
45 | return m_t;
46 | }
47 |
48 | const Eigen::Vector3d&
49 | Transform::translation(void) const
50 | {
51 | return m_t;
52 | }
53 |
54 | double*
55 | Transform::translationData(void)
56 | {
57 | return m_t.data();
58 | }
59 |
60 | const double* const
61 | Transform::translationData(void) const
62 | {
63 | return m_t.data();
64 | }
65 |
66 | Eigen::Matrix4d
67 | Transform::toMatrix(void) const
68 | {
69 | Eigen::Matrix4d H;
70 | H.setIdentity();
71 | H.block<3,3>(0,0) = m_q.toRotationMatrix();
72 | H.block<3,1>(0,3) = m_t;
73 |
74 | return H;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/feature_tracker_/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(feature_tracker_)
3 |
4 | set(CMAKE_BUILD_TYPE "Release")
5 | set(CMAKE_CXX_FLAGS "-std=c++11")
6 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")
7 |
8 | find_package(catkin REQUIRED COMPONENTS
9 | roscpp
10 | std_msgs
11 | sensor_msgs
12 | cv_bridge
13 | camera_model
14 | tf
15 | )
16 | find_package(PCL REQUIRED)
17 | find_package(OpenCV REQUIRED)
18 |
19 | catkin_package()
20 |
21 | # include_directories(
22 | # ${catkin_INCLUDE_DIRS}
23 | # ${PCL_INCLUDE_DIRS}
24 | # )
25 | set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
26 | find_package(Eigen3)
27 | include_directories(
28 | ${catkin_INCLUDE_DIRS}
29 | ${EIGEN3_INCLUDE_DIR}
30 | ${PCL_INCLUDE_DIRS}
31 | )
32 |
33 | add_executable(feature_tracker_
34 | src/feature_tracker_node.cpp
35 | src/parameters.cpp
36 | src/feature_tracker.cpp
37 | )
38 |
39 | target_link_libraries(feature_tracker_ ${catkin_LIBRARIES} ${OpenCV_LIBS} ${PCL_LIBRARIES})
40 |
--------------------------------------------------------------------------------
/feature_tracker_/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | feature_tracker_
4 | 0.0.0
5 | The feature_tracker_package
6 |
7 |
8 |
9 |
10 | dvorak
11 |
12 |
13 |
14 |
15 |
16 | TODO
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | catkin
43 | roscpp
44 | camera_model
45 | message_generation
46 | roscpp
47 | camera_model
48 | message_runtime
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/feature_tracker_/src/parameters.cpp:
--------------------------------------------------------------------------------
1 | #include "parameters.h"
2 |
3 | std::string IMAGE_TOPIC;
4 | std::string IMU_TOPIC;
5 | std::string LIDAR_TOPIC;
6 | std::vector CAM_NAMES;
7 | std::string FISHEYE_MASK;
8 | int MAX_CNT;
9 | int MIN_DIST;
10 | int WINDOW_SIZE;
11 | int FREQ;
12 | double F_THRESHOLD;
13 | int SHOW_TRACK;
14 | int STEREO_TRACK;
15 | int EQUALIZE;
16 | int ROW;
17 | int COL;
18 | int FOCAL_LENGTH;
19 | int FISHEYE;
20 | bool PUB_THIS_FRAME;
21 | int SHOW_LIDAR2CAM;
22 | int LIDAR2CAM;
23 |
24 | Eigen::Matrix3d RLC;
25 | Eigen::Vector3d TLC;
26 | Eigen::Matrix4f TransFormLC;
27 |
28 | template
29 | T readParam(ros::NodeHandle &n, std::string name)
30 | {
31 | T ans;
32 | if (n.getParam(name, ans))
33 | {
34 | ROS_INFO_STREAM("Loaded " << name << ": " << ans);
35 | }
36 | else
37 | {
38 | ROS_ERROR_STREAM("Failed to load " << name);
39 | n.shutdown();
40 | }
41 | return ans;
42 | }
43 |
44 | void readParameters(ros::NodeHandle &n)
45 | {
46 | std::string config_file;
47 | config_file = readParam(n, "config_file");
48 | cv::FileStorage fsSettings(config_file, cv::FileStorage::READ);
49 | if(!fsSettings.isOpened())
50 | {
51 | std::cerr << "ERROR: Wrong path to settings" << std::endl;
52 | }
53 | std::string VINS_FOLDER_PATH = readParam(n, "vils_folder");
54 |
55 | {
56 | cv::Mat cv_RLC, cv_TLC;
57 | fsSettings["gt_rlc"] >> cv_RLC;
58 | fsSettings["gt_tlc"] >> cv_TLC;
59 | Eigen::Matrix3d eigen_RLC;
60 | Eigen::Vector3d eigen_TLC;
61 | cv::cv2eigen(cv_RLC, eigen_RLC);
62 | cv::cv2eigen(cv_TLC, eigen_TLC);
63 | Eigen::Quaterniond QLC(eigen_RLC);
64 | eigen_RLC = QLC.normalized();
65 | RLC = eigen_RLC;
66 | TLC = eigen_TLC;
67 | TransFormLC.setIdentity();
68 | TransFormLC.block<3, 3>(0, 0) = RLC.cast();
69 | TransFormLC.block<3, 1>(0, 3) = TLC.cast();
70 | }
71 |
72 | fsSettings["image_topic"] >> IMAGE_TOPIC;
73 | fsSettings["imu_topic"] >> IMU_TOPIC;
74 | fsSettings["lidar_topic"] >> LIDAR_TOPIC;
75 | MAX_CNT = fsSettings["max_cnt"];
76 | MIN_DIST = fsSettings["min_dist"];
77 | ROW = fsSettings["image_height"];
78 | COL = fsSettings["image_width"];
79 | FREQ = fsSettings["freq"];
80 | F_THRESHOLD = fsSettings["F_threshold"];
81 | SHOW_TRACK = fsSettings["show_track"];
82 | EQUALIZE = fsSettings["equalize"];
83 | FISHEYE = fsSettings["fisheye"];
84 | SHOW_LIDAR2CAM = fsSettings["show_lidar2cam"];
85 | LIDAR2CAM = fsSettings["add_lidar2cam"];
86 |
87 | if (FISHEYE == 1)
88 | FISHEYE_MASK = VINS_FOLDER_PATH + "config/fisheye_mask.jpg";
89 | CAM_NAMES.push_back(config_file);
90 |
91 | WINDOW_SIZE = 20;
92 | STEREO_TRACK = false;
93 | FOCAL_LENGTH = 460;
94 | PUB_THIS_FRAME = false;
95 |
96 | if (FREQ == 0)
97 | FREQ = 100;
98 |
99 | fsSettings.release();
100 |
101 |
102 | }
103 |
104 | float pointDistance(PointType p)
105 | {
106 | return sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
107 | }
108 |
109 |
110 | float pointDistance(PointType p1, PointType p2)
111 | {
112 | return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z));
113 | }
114 |
115 |
--------------------------------------------------------------------------------
/feature_tracker_/src/parameters.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 |
58 | using namespace std;
59 |
60 | extern int ROW;
61 | extern int COL;
62 | extern int FOCAL_LENGTH;
63 | const int NUM_OF_CAM = 1;
64 |
65 |
66 | extern std::string IMAGE_TOPIC;
67 | extern std::string IMU_TOPIC;
68 | extern std::string LIDAR_TOPIC;
69 | extern std::string FISHEYE_MASK;
70 | extern std::vector CAM_NAMES;
71 | extern int MAX_CNT;
72 | extern int MIN_DIST;
73 | extern int WINDOW_SIZE;
74 | extern int FREQ;
75 | extern double F_THRESHOLD;
76 | extern int SHOW_TRACK;
77 | extern int STEREO_TRACK;
78 | extern int EQUALIZE;
79 | extern int FISHEYE;
80 | extern bool PUB_THIS_FRAME;
81 | extern int SHOW_LIDAR2CAM;
82 | extern int LIDAR2CAM;
83 |
84 |
85 | extern Eigen::Matrix3d RLC;
86 | extern Eigen::Vector3d TLC;
87 | extern Eigen::Matrix4f TransFormLC;
88 |
89 | void readParameters(ros::NodeHandle &n);
90 |
91 | typedef pcl::PointXYZI PointType;
92 | float pointDistance(PointType p);
93 | float pointDistance(PointType p1, PointType p2);
94 | void publishCloud(ros::Publisher *thisPub, pcl::PointCloud::Ptr thisCloud, ros::Time thisStamp, std::string thisFrame);
--------------------------------------------------------------------------------
/feature_tracker_/src/tic_toc.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | class TicToc
8 | {
9 | public:
10 | TicToc()
11 | {
12 | tic();
13 | }
14 |
15 | void tic()
16 | {
17 | start = std::chrono::system_clock::now();
18 | }
19 |
20 | double toc()
21 | {
22 | end = std::chrono::system_clock::now();
23 | std::chrono::duration elapsed_seconds = end - start;
24 | return elapsed_seconds.count() * 1000;
25 | }
26 |
27 | private:
28 | std::chrono::time_point start, end;
29 | };
30 |
--------------------------------------------------------------------------------
/fig/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Stan994265/mVIL-Fusion/3dcb644e34f5c5908b46c78fb87505e9a800e803/fig/cover.png
--------------------------------------------------------------------------------
/fig/device.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Stan994265/mVIL-Fusion/3dcb644e34f5c5908b46c78fb87505e9a800e803/fig/device.png
--------------------------------------------------------------------------------
/fig/results.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Stan994265/mVIL-Fusion/3dcb644e34f5c5908b46c78fb87505e9a800e803/fig/results.png
--------------------------------------------------------------------------------
/lidar_compensator/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(lidar_compensator)
3 |
4 | set(CMAKE_BUILD_TYPE "Release")
5 | set(CMAKE_CXX_FLAGS "-std=c++11")
6 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")
7 |
8 | find_package(catkin REQUIRED COMPONENTS
9 | dynamic_reconfigure
10 | geometry_msgs
11 | message_generation
12 | message_runtime
13 | nav_msgs
14 | pcl_conversions
15 | pcl_ros
16 | rosbag
17 | roscpp
18 | rospy
19 | sensor_msgs
20 | std_msgs
21 | tf
22 | tf_conversions
23 | )
24 |
25 |
26 | find_package(OpenCV REQUIRED)
27 | include_directories(${OpenCV_INCLUDE_DIR})
28 | find_package(Eigen3 REQUIRED)
29 | include_directories(${EIGEN3_INCLUDE_DIR})
30 | find_package(PCL REQUIRED)
31 | include_directories(${PCL_INCLUDE_DIRS})
32 |
33 |
34 | catkin_package()
35 |
36 | include_directories(
37 | ${catkin_INCLUDE_DIRS}
38 | )
39 |
40 | add_executable(lidar_compensator
41 | src/PointProcessor.cc
42 | src/processor_node.cc
43 | )
44 |
45 | target_link_libraries(lidar_compensator ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBRARIES})
46 |
--------------------------------------------------------------------------------
/lidar_compensator/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | lidar_compensator
4 | 0.0.0
5 | The lidar_feature package
6 | wy
7 |
8 | TODO
9 |
10 | catkin
11 | dynamic_reconfigure
12 | geometry_msgs
13 | message_generation
14 | nav_msgs
15 | pcl_conversions
16 | pcl_ros
17 | rosbag
18 | roscpp
19 | rospy
20 | sensor_msgs
21 | std_msgs
22 | tf
23 | tf_conversions
24 |
25 |
--------------------------------------------------------------------------------
/lidar_compensator/src/CircularBuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef CIRCULARBUFFER_H_
2 | #define CIRCULARBUFFER_H_
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | template
9 | class CircularBuffer
10 | {
11 | public:
12 | CircularBuffer(const size_t &capacity = 200)
13 | : capacity_(capacity),
14 | size_(0),
15 | start_idx_(0)
16 | {
17 | buffer_ = new T[capacity];
18 | };
19 |
20 | ~CircularBuffer()
21 | {
22 | delete[] buffer_;
23 | buffer_ = NULL;
24 | }
25 |
26 | void Reset(size_t capacity = 1)
27 | {
28 | delete[] buffer_;
29 | buffer_ = NULL;
30 |
31 | capacity_ = capacity;
32 | size_ = 0;
33 | start_idx_ = 0;
34 | buffer_ = new T[capacity];
35 | }
36 |
37 | /** \brief Retrieve the buffer size.
38 | *
39 | * @return the buffer size
40 | */
41 | const size_t &size()
42 | {
43 | return size_;
44 | }
45 |
46 | /** \brief Retrieve the buffer capacity.
47 | *
48 | * @return the buffer capacity
49 | */
50 | const size_t &capacity()
51 | {
52 | return capacity_;
53 | }
54 |
55 | /** \brief Ensure that this buffer has at least the required capacity.
56 | *
57 | * @param req_apacity the minimum required capacity
58 | */
59 | void EnsureCapacity(const int &req_apacity)
60 | {
61 | if (req_apacity > 0 && capacity_ < req_apacity)
62 | {
63 | // create new buffer and copy (valid) entries
64 | T *new_buffer = new T[req_apacity];
65 | for (size_t i = 0; i < size_; i++)
66 | {
67 | new_buffer[i] = (*this)[i];
68 | }
69 |
70 | // switch buffer pointers and delete old buffer
71 | T *old_buffer = buffer_;
72 | buffer_ = new_buffer;
73 | start_idx_ = 0;
74 |
75 | delete[] old_buffer;
76 | }
77 | }
78 |
79 | /** \brief Check if the buffer is empty.
80 | *
81 | * @return true if the buffer is empty, false otherwise
82 | */
83 | bool empty()
84 | {
85 | return size_ == 0;
86 | }
87 |
88 | /** \brief Retrieve the i-th element of the buffer.
89 | *
90 | *
91 | * @param i the buffer index
92 | * @return the element at the i-th position as no-constant
93 | */
94 | T &operator[](const size_t &i)
95 | {
96 | return buffer_[(start_idx_ + i) % capacity_];
97 | }
98 |
99 | /** \brief Retrieve the i-th element of the buffer.
100 | *
101 | *
102 | * @param i the buffer index
103 | * @return the element at the i-th position
104 | */
105 | const T &operator[](const size_t &i) const
106 | {
107 | return buffer_[(start_idx_ + i) % capacity_];
108 | }
109 |
110 | /** \brief Retrieve the first (oldest) element of the buffer.
111 | *
112 | * @return the first element
113 | */
114 | const T &first() const
115 | {
116 | return buffer_[start_idx_];
117 | }
118 |
119 | T &first()
120 | {
121 | return buffer_[start_idx_];
122 | }
123 |
124 | /** \brief Retrieve the last (latest) element of the buffer.
125 | *
126 | * @return the last element
127 | */
128 | const T &last() const
129 | {
130 | size_t idx = size_ == 0 ? 0 : (start_idx_ + size_ - 1) % capacity_;
131 | return buffer_[idx];
132 | }
133 |
134 | T &last()
135 | {
136 | size_t idx = size_ == 0 ? 0 : (start_idx_ + size_ - 1) % capacity_;
137 | return buffer_[idx];
138 | }
139 |
140 | /** \brief Push a new element to the buffer.
141 | *
142 | * If the buffer reached its capacity, the oldest element is overwritten.
143 | *
144 | * @param element the element to push
145 | */
146 | void push(const T &element)
147 | {
148 | if (size_ < capacity_)
149 | {
150 | buffer_[size_] = element;
151 | ++size_;
152 | }
153 | else
154 | {
155 | buffer_[start_idx_] = element;
156 | start_idx_ = (start_idx_ + 1) % capacity_;
157 | }
158 | }
159 |
160 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
161 |
162 | private:
163 | size_t capacity_; ///< buffer capacity
164 | size_t size_; ///< current buffer size
165 | size_t start_idx_; ///< current start index
166 | T *buffer_; ///< internal element buffer
167 | };
168 |
169 | #endif // CIRCULARBUFFER_H_
170 |
--------------------------------------------------------------------------------
/lidar_compensator/src/PointProcessor.h:
--------------------------------------------------------------------------------
1 | #ifndef POINTPROCESSOR_H_
2 | #define POINTPROCESSOR_H_
3 |
4 | #include
5 |
6 | #include
7 |
8 | #include "common_ros.h"
9 | // #include "TicToc.h"
10 | #include "CircularBuffer.h"
11 | #include "math_utils.h"
12 | #include
13 |
14 | using namespace std;
15 | typedef pcl::PointXYZI PointT;
16 | typedef typename pcl::PointCloud PointCloud;
17 | typedef typename pcl::PointCloud::Ptr PointCloudPtr;
18 | typedef typename pcl::PointCloud::ConstPtr PointCloudConstPtr;
19 | typedef std::pair IndexRange;
20 |
21 | // adapted from LOAM
22 | /** Point label options. */
23 | enum PointLabel
24 | {
25 | CORNER_SHARP = 2, ///< sharp corner point
26 | CORNER_LESS_SHARP = 1, ///< less sharp corner point
27 | SURFACE_LESS_FLAT = 0, ///< less flat surface point
28 | SURFACE_FLAT = -1 ///< flat surface point
29 | };
30 |
31 | struct PointProcessorConfig
32 | {
33 | bool deskew = false;
34 | double scan_period = 0.1;
35 | int num_scan_subregions = 8;
36 | int num_curvature_regions = 5;
37 | float surf_curv_th = 1.0;
38 | int max_corner_sharp = 3;
39 | int max_corner_less_sharp = 10 * max_corner_sharp;
40 | int max_surf_flat = 4;
41 | float less_flat_filter_size = 0.2;
42 |
43 | string capture_frame_id = "/laser_link"; // /laser_link /velodyne /base_link
44 |
45 | double rad_diff = 0.2;
46 |
47 | bool infer_start_ori_ = false;
48 | };
49 |
50 | class PointProcessor
51 | {
52 |
53 | public:
54 | PointProcessor();
55 | PointProcessor(float lower_bound, float upper_bound, int num_rings, bool uneven = false);
56 |
57 | // WARNING: is it useful to separate Process and SetInputCloud?
58 | // void Process(const PointCloudConstPtr &cloud_in, PointCloud &cloud_out);
59 | void Process();
60 |
61 | void PointCloudHandler(const sensor_msgs::PointCloud2ConstPtr &raw_points_msg);
62 |
63 | void SetupConfig(PointProcessorConfig config)
64 | {
65 | config_ = config;
66 | }
67 |
68 | void SetupRos(ros::NodeHandle &nh);
69 |
70 | void SetInputCloud(const PointCloudConstPtr &cloud_in, ros::Time time_in = ros::Time::now());
71 |
72 | void PointToRing();
73 | void PointToRing(const PointCloudConstPtr &cloud_in,
74 | vector &ring_out,
75 | vector &intensity_out);
76 |
77 | inline int ElevationToRing(float rad)
78 | {
79 | double in = (RadToDeg(rad) - lower_bound_) * factor_ + 0.5;
80 | return int((RadToDeg(rad) - lower_bound_) * factor_ + 0.5);
81 | }
82 |
83 | void ExtractFeaturePoints();
84 |
85 | void PublishResults();
86 |
87 | // TODO: not necessary data?
88 | vector laser_scans;
89 | vector intensity_scans;
90 | vector scan_ranges;
91 |
92 | protected:
93 | ros::Time sweep_start_;
94 | ros::Time scan_time_;
95 |
96 | float lower_bound_;
97 | float upper_bound_;
98 | int num_rings_;
99 | float factor_;
100 | PointProcessorConfig config_;
101 | // TicToc tic_toc_;
102 |
103 | PointCloudConstPtr cloud_ptr_;
104 | PointCloud cloud_in_rings_;
105 |
106 | PointCloud corner_points_sharp_;
107 | PointCloud corner_points_less_sharp_;
108 | PointCloud surface_points_flat_;
109 | PointCloud surface_points_less_flat_;
110 |
111 | // the following will be assigened or resized
112 | vector scan_ring_mask_;
113 | vector > curvature_idx_pairs_; // in subregion
114 | vector subregion_labels_; ///< point label buffer
115 |
116 | void Reset(const ros::Time &scan_time, const bool &is_new_sweep = true);
117 | void PrepareRing(const PointCloud &scan);
118 | void PrepareSubregion(const PointCloud &scan, const size_t idx_start, const size_t idx_end);
119 | void MaskPickedInRing(const PointCloud &scan, const size_t in_scan_idx);
120 |
121 | ros::Subscriber sub_raw_points_; ///< input cloud message subscriber
122 |
123 | ros::Publisher pub_full_cloud_; ///< full resolution cloud message publisher
124 | ros::Publisher pub_corner_points_sharp_; ///< sharp corner cloud message publisher
125 | ros::Publisher pub_corner_points_less_sharp_; ///< less sharp corner cloud message publisher
126 | ros::Publisher pub_surf_points_flat_; ///< flat surface cloud message publisher
127 | ros::Publisher pub_surf_points_less_flat_; ///< less flat surface cloud message publisher
128 |
129 | bool is_ros_setup_ = false;
130 |
131 | bool uneven_ = false;
132 |
133 | private:
134 | float start_ori_, end_ori_;
135 | CircularBuffer start_ori_buf1_{10};
136 | CircularBuffer start_ori_buf2_{10};
137 | };
138 |
139 | #endif //POINTPROCESSOR_H_
140 |
--------------------------------------------------------------------------------
/lidar_compensator/src/TicToc.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of LIO-mapping.
3 | *
4 | * Copyright (C) 2019 Haoyang Ye ,
5 | * Robotics and Multiperception Lab (RAM-LAB ),
6 | * The Hong Kong University of Science and Technology
7 | *
8 | * For more information please see
9 | * or .
10 | * If you use this code, please cite the respective publications as
11 | * listed on the above websites.
12 | *
13 | * LIO-mapping is free software: you can redistribute it and/or modify
14 | * it under the terms of the GNU General Public License as published by
15 | * the Free Software Foundation, either version 3 of the License, or
16 | * (at your option) any later version.
17 | *
18 | * LIO-mapping is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | * GNU General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU General Public License
24 | * along with LIO-mapping. If not, see .
25 | */
26 |
27 | //
28 | // Created by hyye on 3/14/18.
29 | //
30 |
31 | #ifndef LIO_TICTOC_H
32 | #define LIO_TICTOC_H
33 |
34 | #include
35 | #include
36 | #include
37 |
38 | class TicToc {
39 | public:
40 | TicToc() {
41 | Tic();
42 | }
43 |
44 | void Tic() {
45 | start_ = std::chrono::system_clock::now();
46 | }
47 |
48 | double Toc() {
49 | end_ = std::chrono::system_clock::now();
50 | elapsed_seconds_ = end_ - start_;
51 | return elapsed_seconds_.count() * 1000;
52 | }
53 |
54 | double GetLastStop() {
55 | return elapsed_seconds_.count() * 1000;
56 | }
57 |
58 | private:
59 | std::chrono::time_point start_, end_;
60 | std::chrono::duration elapsed_seconds_;
61 | };
62 |
63 | #endif //LIO_TICTOC_H
64 |
--------------------------------------------------------------------------------
/lidar_compensator/src/common_ros.h:
--------------------------------------------------------------------------------
1 | #ifndef COMMON_ROS_H_
2 | #define COMMON_ROS_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | template
10 | inline void PublishCloudMsg(ros::Publisher &publisher,
11 | const pcl::PointCloud &cloud,
12 | const ros::Time &stamp,
13 | std::string frame_id)
14 | {
15 | sensor_msgs::PointCloud2 msg;
16 | pcl::toROSMsg(cloud, msg);
17 | msg.header.stamp = stamp;
18 | msg.header.frame_id = frame_id;
19 | publisher.publish(msg);
20 | }
21 |
22 | #endif //COMMON_ROS_H_
23 |
--------------------------------------------------------------------------------
/lidar_compensator/src/processor_node.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "PointProcessor.h"
10 | #include "TicToc.h"
11 | using namespace std;
12 |
13 | int main(int argc, char **argv)
14 | {
15 |
16 | ros::init(argc, argv, "point_processor");
17 |
18 | ros::NodeHandle nh("~");
19 |
20 | int sensor_type;
21 | double rad_diff;
22 | bool infer_start_ori;
23 | nh.param("sensor_type", sensor_type, 16);
24 | nh.param("rad_diff", rad_diff, 0.2);
25 | nh.param("infer_start_ori", infer_start_ori, false);
26 | double scan_period;
27 | nh.param("scan_period", scan_period, 0.1);
28 |
29 | PointProcessor processor; // Default sensor_type is 16
30 |
31 | if (sensor_type == 32)
32 | {
33 | processor = PointProcessor(-30.67f, 10.67f, 32);
34 | }
35 | else if (sensor_type == 64)
36 | {
37 | processor = PointProcessor(-24.9f, 2, 64);
38 | }
39 | else if (sensor_type == 320)
40 | {
41 | processor = PointProcessor(-25, 15, 32, true);
42 | }
43 |
44 | PointProcessorConfig config;
45 | config.rad_diff = rad_diff;
46 | config.infer_start_ori_ = infer_start_ori;
47 | config.scan_period = scan_period;
48 | processor.SetupConfig(config);
49 | processor.SetupRos(nh);
50 | ros::Rate r(100);
51 | // while (ros::ok())
52 | // {
53 | // ros::spinOnce();
54 | // r.sleep();
55 | // }
56 | ros::AsyncSpinner spinner(1);
57 | spinner.start();
58 | ros::waitForShutdown();
59 |
60 | return 0;
61 | }
--------------------------------------------------------------------------------
/lidar_mapping/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(vils_mapping)
3 |
4 | set(CMAKE_BUILD_TYPE "Release")
5 | # set(CMAKE_CXX_FLAGS "-std=c++11")
6 | set(CMAKE_CXX_STANDARD 17)
7 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -pthread")
8 |
9 | find_package(catkin REQUIRED COMPONENTS
10 | geometry_msgs
11 | nav_msgs
12 | sensor_msgs
13 | roscpp
14 | rospy
15 | rosbag
16 | std_msgs
17 | image_transport
18 | cv_bridge
19 | tf
20 | )
21 |
22 | #find_package(Eigen3 REQUIRED)
23 | find_package(PCL REQUIRED)
24 | find_package(OpenCV REQUIRED)
25 | find_package(Ceres REQUIRED)
26 |
27 | find_package(OpenMP REQUIRED)
28 | find_package(GTSAM REQUIRED QUIET)
29 | find_package(Boost REQUIRED COMPONENTS timer)
30 | include_directories(
31 | include
32 | ${catkin_INCLUDE_DIRS}
33 | ${PCL_INCLUDE_DIRS}
34 | ${CERES_INCLUDE_DIRS}
35 | ${OpenCV_INCLUDE_DIRS}
36 | ${GTSAM_INCLUDE_DIR}
37 | )
38 |
39 | catkin_package(
40 | CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy std_msgs
41 | DEPENDS EIGEN3 PCL
42 | INCLUDE_DIRS include
43 | )
44 |
45 |
46 | add_executable(feature src/scanRegistration.cpp)
47 | target_link_libraries(feature ${catkin_LIBRARIES} ${PCL_LIBRARIES})
48 |
49 | add_executable(local src/localMapping.cpp)
50 | target_link_libraries(local ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${CERES_LIBRARIES})
51 |
52 | include_directories(${PROJECT_SOURCE_DIR}/fast_gicp)
53 |
54 | add_executable(global_ikdtree
55 | src/globalMappingIkdTree.cpp
56 | include/ikd_Tree/ikd_Tree.cpp
57 | include/scancontext/Scancontext.cpp
58 | )
59 | target_compile_options(global_ikdtree
60 | PRIVATE ${OpenMP_CXX_FLAGS}
61 | )
62 |
63 | target_link_libraries(global_ikdtree
64 | ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenMP_CXX_FLAGS}
65 | # gtsam ${PROJECT_SOURCE_DIR}/include/fast_gicp/libfast_gicp.a
66 | gtsam ${PROJECT_SOURCE_DIR}/../vils_estimator/src/lidar_functions/fast_gicp/build/libfast_gicp.a
67 | )
68 |
69 | add_executable(global_octree
70 | src/globalMappingOcTree.cpp
71 | include/scancontext/Scancontext.cpp
72 | )
73 | target_compile_options(global_octree
74 | PRIVATE ${OpenMP_CXX_FLAGS}
75 | )
76 | target_link_libraries(global_octree
77 | ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenMP_CXX_FLAGS}
78 | #gtsam ${PROJECT_SOURCE_DIR}/include/fast_gicp/libfast_gicp.a
79 | gtsam ${PROJECT_SOURCE_DIR}/../vils_estimator/src/lidar_functions/fast_gicp/build/libfast_gicp.a
80 | )
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/lidar_mapping/include/aloam_velodyne/common.h:
--------------------------------------------------------------------------------
1 | // This is an advanced implementation of the algorithm described in the following paper:
2 | // J. Zhang and S. Singh. LOAM: Lidar Odometry and Mapping in Real-time.
3 | // Robotics: Science and Systems Conference (RSS). Berkeley, CA, July 2014.
4 |
5 | // Modifier: Tong Qin qintonguav@gmail.com
6 | // Shaozu Cao saozu.cao@connect.ust.hk
7 |
8 | // Copyright 2013, Ji Zhang, Carnegie Mellon University
9 | // Further contributions copyright (c) 2016, Southwest Research Institute
10 | // All rights reserved.
11 | //
12 | // Redistribution and use in source and binary forms, with or without
13 | // modification, are permitted provided that the following conditions are met:
14 | //
15 | // 1. Redistributions of source code must retain the above copyright notice,
16 | // this list of conditions and the following disclaimer.
17 | // 2. Redistributions in binary form must reproduce the above copyright notice,
18 | // this list of conditions and the following disclaimer in the documentation
19 | // and/or other materials provided with the distribution.
20 | // 3. Neither the name of the copyright holder nor the names of its
21 | // contributors may be used to endorse or promote products derived from this
22 | // software without specific prior written permission.
23 | //
24 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | // POSSIBILITY OF SUCH DAMAGE.
35 |
36 | #pragma once
37 |
38 | #include
39 |
40 | #include
41 |
42 | typedef pcl::PointXYZI PointType;
43 |
44 | inline double rad2deg(double radians)
45 | {
46 | return radians * 180.0 / M_PI;
47 | }
48 |
49 | inline double deg2rad(double degrees)
50 | {
51 | return degrees * M_PI / 180.0;
52 | }
53 |
54 | struct Pose6D
55 | {
56 | double x;
57 | double y;
58 | double z;
59 | double roll;
60 | double pitch;
61 | double yaw;
62 | };
--------------------------------------------------------------------------------
/lidar_mapping/include/aloam_velodyne/tic_toc.h:
--------------------------------------------------------------------------------
1 | // Author: Tong Qin qintonguav@gmail.com
2 | // Shaozu Cao saozu.cao@connect.ust.hk
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | class TicToc
11 | {
12 | public:
13 | TicToc()
14 | {
15 | tic();
16 | }
17 |
18 | void tic()
19 | {
20 | start = std::chrono::system_clock::now();
21 | }
22 |
23 | double toc()
24 | {
25 | end = std::chrono::system_clock::now();
26 | std::chrono::duration elapsed_seconds = end - start;
27 | return elapsed_seconds.count() * 1000;
28 | }
29 |
30 | private:
31 | std::chrono::time_point start, end;
32 | };
33 |
34 | class TicTocV2
35 | {
36 | public:
37 | TicTocV2()
38 | {
39 | tic();
40 | }
41 |
42 | TicTocV2( bool _disp )
43 | {
44 | disp_ = _disp;
45 | tic();
46 | }
47 |
48 | void tic()
49 | {
50 | start = std::chrono::system_clock::now();
51 | }
52 |
53 | void toc( std::string _about_task )
54 | {
55 | end = std::chrono::system_clock::now();
56 | std::chrono::duration elapsed_seconds = end - start;
57 | double elapsed_ms = elapsed_seconds.count() * 1000;
58 |
59 | if( disp_ )
60 | {
61 | std::cout.precision(3); // 10 for sec, 3 for ms
62 | std::cout << _about_task << ": " << elapsed_ms << " msec." << std::endl;
63 | }
64 | }
65 |
66 | private:
67 | std::chrono::time_point start, end;
68 | bool disp_ = false;
69 | };
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/brute_force_knn.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_CUDA_BRUTE_FORCE_KNN_CUH
2 | #define FAST_GICP_CUDA_BRUTE_FORCE_KNN_CUH
3 |
4 | #include
5 |
6 | #include
7 |
8 | namespace fast_gicp {
9 | namespace cuda {
10 |
11 | void brute_force_knn_search(const thrust::device_vector& source, const thrust::device_vector& target, int k, thrust::device_vector>& k_neighbors, bool do_sort=false);
12 |
13 | }
14 | } // namespace fast_gicp
15 |
16 |
17 | #endif
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/compute_derivatives.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_CUDA_COMPUTE_DERIVATIVES_CUH
2 | #define FAST_GICP_CUDA_COMPUTE_DERIVATIVES_CUH
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | namespace fast_gicp {
10 | namespace cuda {
11 |
12 | double compute_derivatives(
13 | const thrust::device_vector& src_points,
14 | const thrust::device_vector& src_covs,
15 | const GaussianVoxelMap& voxelmap,
16 | const thrust::device_vector>& voxel_correspondences,
17 | const thrust::device_ptr& linearized_x_ptr,
18 | const thrust::device_ptr& x_ptr,
19 | Eigen::Matrix* H,
20 | Eigen::Matrix* b);
21 | }
22 | } // namespace fast_gicp
23 |
24 | #endif
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/compute_mahalanobis.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_CUDA_COMPUTE_MAHALANOBIS_CUH
2 | #define FAST_GICP_CUDA_COMPUTE_MAHALANOBIS_CUH
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | namespace fast_gicp {
11 | namespace cuda {
12 |
13 | void compute_mahalanobis(
14 | const thrust::device_vector& src_points,
15 | const thrust::device_vector& src_covs,
16 | const GaussianVoxelMap& voxelmap,
17 | const thrust::device_vector& voxel_correspondences,
18 | const Eigen::Isometry3f& linearized_x,
19 | thrust::device_vector& mahalanobis
20 | );
21 |
22 | }
23 | } // namespace fast_gicp
24 |
25 | #endif
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/covariance_estimation.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_CUDA_COVARIANCE_ESTIMATION_CUH
2 | #define FAST_GICP_CUDA_COVARIANCE_ESTIMATION_CUH
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace fast_gicp {
9 | namespace cuda {
10 |
11 | void covariance_estimation(const thrust::device_vector& points, int k, const thrust::device_vector& k_neighbors, thrust::device_vector& covariances);
12 |
13 | void covariance_estimation_rbf(const thrust::device_vector& points, double kernel_width, double max_dist, thrust::device_vector& covariances);
14 | }
15 | } // namespace fast_gicp
16 |
17 | #endif
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/covariance_regularization.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_CUDA_COVARIANCE_REGULARIZATION_CUH
2 | #define FAST_GICP_CUDA_COVARIANCE_REGULARIZATION_CUH
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace fast_gicp {
9 | namespace cuda {
10 |
11 | void covariance_regularization(thrust::device_vector& means, thrust::device_vector& covs, RegularizationMethod method);
12 |
13 | } // namespace cuda
14 | } // namespace fast_gicp
15 |
16 | #endif
--------------------------------------------------------------------------------
/lidar_mapping/include/fast_gicp/cuda/fast_vgicp_cuda.cuh:
--------------------------------------------------------------------------------
1 | #ifndef FAST_GICP_FAST_VGICP_CUDA_CORE_CUH
2 | #define FAST_GICP_FAST_VGICP_CUDA_CORE_CUH
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | namespace thrust {
12 |
13 | template
14 | class pair;
15 |
16 | template
17 | class device_allocator;
18 |
19 | template
20 | class device_vector;
21 | } // namespace thrust
22 |
23 | namespace fast_gicp {
24 | namespace cuda {
25 |
26 | class GaussianVoxelMap;
27 |
28 | class FastVGICPCudaCore {
29 | public:
30 | using Points = thrust::device_vector>;
31 | using Indices = thrust::device_vector>;
32 | using Matrices = thrust::device_vector>;
33 | using Correspondences = thrust::device_vector, thrust::device_allocator>>;
34 | using VoxelCoordinates = thrust::device_vector>;
35 |
36 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
37 | FastVGICPCudaCore();
38 | ~FastVGICPCudaCore();
39 |
40 | void set_resolution(double resolution);
41 | void set_kernel_params(double kernel_width, double kernel_max_dist);
42 | void set_neighbor_search_method(fast_gicp::NeighborSearchMethod method, double radius);
43 |
44 | void swap_source_and_target();
45 | void set_source_cloud(const std::vector>& cloud);
46 | void set_target_cloud(const std::vector>& cloud);
47 |
48 | void set_source_neighbors(int k, const std::vector& neighbors);
49 | void set_target_neighbors(int k, const std::vector& neighbors);
50 | void find_source_neighbors(int k);
51 | void find_target_neighbors(int k);
52 |
53 | void calculate_source_covariances(RegularizationMethod method);
54 | void calculate_target_covariances(RegularizationMethod method);
55 |
56 | void calculate_source_covariances_rbf(RegularizationMethod method);
57 | void calculate_target_covariances_rbf(RegularizationMethod method);
58 |
59 | void get_source_covariances(std::vector>& covs) const;
60 | void get_target_covariances(std::vector>& covs) const;
61 |
62 | void get_voxel_num_points(std::vector& num_points) const;
63 | void get_voxel_means(std::vector>& means) const;
64 | void get_voxel_covs(std::vector>& covs) const;
65 | void get_voxel_correspondences(std::vector>& correspondences) const;
66 |
67 | void create_target_voxelmap();
68 |
69 | void update_correspondences(const Eigen::Isometry3d& trans);
70 |
71 | double compute_error(const Eigen::Isometry3d& trans, Eigen::Matrix* H, Eigen::Matrix* b) const;
72 |
73 | public:
74 | double resolution;
75 | double kernel_width;
76 | double kernel_max_dist;
77 | std::unique_ptr offsets;
78 |
79 | std::unique_ptr source_points;
80 | std::unique_ptr target_points;
81 |
82 | std::unique_ptr source_neighbors;
83 | std::unique_ptr target_neighbors;
84 |
85 | std::unique_ptr source_covariances;
86 | std::unique_ptr