From b90f08eaeb5934ade5c9f1fd5272a294bdc8f8a6 Mon Sep 17 00:00:00 2001 From: Vladyslav Usenko Date: Tue, 28 Apr 2020 19:24:19 +0200 Subject: [PATCH] switch from tbb_hash to std::hash --- .../basalt/calibration/calibration_helper.h | 19 +++++++++++-------- include/basalt/calibration/cam_calib.h | 7 +++---- include/basalt/calibration/cam_imu_calib.h | 7 +++---- .../frame_to_frame_optical_flow.h | 4 +++- .../basalt/optical_flow/patch_optical_flow.h | 4 +++- include/basalt/utils/common_types.h | 5 +++-- include/basalt/vi_estimator/nfr_mapper.h | 6 ------ src/calibration/calibraiton_helper.cpp | 12 ++++-------- src/opt_flow.cpp | 3 ++- src/vio.cpp | 2 +- 10 files changed, 33 insertions(+), 36 deletions(-) diff --git a/include/basalt/calibration/calibration_helper.h b/include/basalt/calibration/calibration_helper.h index 49bb151..dcdf48f 100644 --- a/include/basalt/calibration/calibration_helper.h +++ b/include/basalt/calibration/calibration_helper.h @@ -69,20 +69,23 @@ struct CalibInitPoseData { EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; +using CalibCornerMap = tbb::concurrent_unordered_map>; + +using CalibInitPoseMap = + tbb::concurrent_unordered_map>; + class CalibHelper { public: - static void detectCorners( - const VioDatasetPtr& vio_data, - tbb::concurrent_unordered_map& calib_corners, - tbb::concurrent_unordered_map& - calib_corners_rejected); + static void detectCorners(const VioDatasetPtr& vio_data, + CalibCornerMap& calib_corners, + CalibCornerMap& calib_corners_rejected); static void initCamPoses( const Calibration::Ptr& calib, const Eigen::aligned_vector& aprilgrid_corner_pos_3d, - tbb::concurrent_unordered_map& calib_corners, - tbb::concurrent_unordered_map& - calib_init_poses); + CalibCornerMap& calib_corners, CalibInitPoseMap& calib_init_poses); static bool initializeIntrinsics( const Eigen::aligned_vector& corners, diff --git a/include/basalt/calibration/cam_calib.h b/include/basalt/calibration/cam_calib.h index bfd211f..34e4524 100644 --- a/include/basalt/calibration/cam_calib.h +++ b/include/basalt/calibration/cam_calib.h @@ -111,10 +111,9 @@ class CamCalib { VioDatasetPtr vio_dataset; // CalibrationPtr calib; - tbb::concurrent_unordered_map calib_corners; - tbb::concurrent_unordered_map - calib_corners_rejected; - tbb::concurrent_unordered_map calib_init_poses; + CalibCornerMap calib_corners; + CalibCornerMap calib_corners_rejected; + CalibInitPoseMap calib_init_poses; std::shared_ptr processing_thread; diff --git a/include/basalt/calibration/cam_imu_calib.h b/include/basalt/calibration/cam_imu_calib.h index e9ba471..94e8d1c 100644 --- a/include/basalt/calibration/cam_imu_calib.h +++ b/include/basalt/calibration/cam_imu_calib.h @@ -110,10 +110,9 @@ class CamImuCalib { VioDatasetPtr vio_dataset; - tbb::concurrent_unordered_map calib_corners; - tbb::concurrent_unordered_map - calib_corners_rejected; - tbb::concurrent_unordered_map calib_init_poses; + CalibCornerMap calib_corners; + CalibCornerMap calib_corners_rejected; + CalibInitPoseMap calib_init_poses; std::shared_ptr processing_thread; diff --git a/include/basalt/optical_flow/frame_to_frame_optical_flow.h b/include/basalt/optical_flow/frame_to_frame_optical_flow.h index ee46822..5e9c6ef 100644 --- a/include/basalt/optical_flow/frame_to_frame_optical_flow.h +++ b/include/basalt/optical_flow/frame_to_frame_optical_flow.h @@ -195,7 +195,9 @@ class FrameToFrameOpticalFlow : public OpticalFlowBase { init_vec.push_back(kv.second); } - tbb::concurrent_unordered_map result; + tbb::concurrent_unordered_map> + result; auto compute_func = [&](const tbb::blocked_range& range) { for (size_t r = range.begin(); r != range.end(); ++r) { diff --git a/include/basalt/optical_flow/patch_optical_flow.h b/include/basalt/optical_flow/patch_optical_flow.h index e5ed634..51ead8b 100644 --- a/include/basalt/optical_flow/patch_optical_flow.h +++ b/include/basalt/optical_flow/patch_optical_flow.h @@ -183,7 +183,9 @@ class PatchOpticalFlow : public OpticalFlowBase { init_vec.push_back(kv.second); } - tbb::concurrent_unordered_map result; + tbb::concurrent_unordered_map> + result; auto compute_func = [&](const tbb::blocked_range& range) { for (size_t r = range.begin(); r != range.end(); ++r) { diff --git a/include/basalt/utils/common_types.h b/include/basalt/utils/common_types.h index ec0365e..cc0c07e 100644 --- a/include/basalt/utils/common_types.h +++ b/include/basalt/utils/common_types.h @@ -109,7 +109,8 @@ struct KeypointsData { }; /// feature corners is a collection of { imageId => KeypointsData } -using Corners = tbb::concurrent_unordered_map; +using Corners = tbb::concurrent_unordered_map>; /// feature matches for an image pair struct MatchData { @@ -127,7 +128,7 @@ struct MatchData { /// feature matches is a collection of { (imageId, imageId) => MatchData } using Matches = tbb::concurrent_unordered_map< std::pair, MatchData, - tbb::tbb_hash>, + std::hash>, std::equal_to>, Eigen::aligned_allocator< std::pair, MatchData>>>; diff --git a/include/basalt/vi_estimator/nfr_mapper.h b/include/basalt/vi_estimator/nfr_mapper.h index 2781cc3..fba9252 100644 --- a/include/basalt/vi_estimator/nfr_mapper.h +++ b/include/basalt/vi_estimator/nfr_mapper.h @@ -57,12 +57,6 @@ class HashBow; class NfrMapper : public BundleAdjustmentBase { public: using Ptr = std::shared_ptr; - using Matches = tbb::concurrent_unordered_map< - std::pair, MatchData, - tbb::tbb_hash>, - std::equal_to>, - Eigen::aligned_allocator< - std::pair, MatchData>>>; template struct MapperLinearizeAbsReduce diff --git a/src/calibration/calibraiton_helper.cpp b/src/calibration/calibraiton_helper.cpp index 2597fc2..7a86ce2 100644 --- a/src/calibration/calibraiton_helper.cpp +++ b/src/calibration/calibraiton_helper.cpp @@ -97,11 +97,9 @@ bool estimateTransformation( return ransac.inliers_.size() > 8; } -void CalibHelper::detectCorners( - const VioDatasetPtr &vio_data, - tbb::concurrent_unordered_map &calib_corners, - tbb::concurrent_unordered_map - &calib_corners_rejected) { +void CalibHelper::detectCorners(const VioDatasetPtr &vio_data, + CalibCornerMap &calib_corners, + CalibCornerMap &calib_corners_rejected) { calib_corners.clear(); calib_corners_rejected.clear(); @@ -144,9 +142,7 @@ void CalibHelper::detectCorners( void CalibHelper::initCamPoses( const Calibration::Ptr &calib, const Eigen::aligned_vector &aprilgrid_corner_pos_3d, - tbb::concurrent_unordered_map &calib_corners, - tbb::concurrent_unordered_map - &calib_init_poses) { + CalibCornerMap &calib_corners, CalibInitPoseMap &calib_init_poses) { calib_init_poses.clear(); std::vector corners; diff --git a/src/opt_flow.cpp b/src/opt_flow.cpp index b824db2..2ebd769 100644 --- a/src/opt_flow.cpp +++ b/src/opt_flow.cpp @@ -83,7 +83,8 @@ basalt::VioDatasetPtr vio_dataset; basalt::VioConfig vio_config; basalt::OpticalFlowBase::Ptr opt_flow_ptr; -tbb::concurrent_unordered_map +tbb::concurrent_unordered_map> observations; tbb::concurrent_bounded_queue observations_queue; diff --git a/src/vio.cpp b/src/vio.cpp index c16a608..048a8ab 100644 --- a/src/vio.cpp +++ b/src/vio.cpp @@ -130,7 +130,7 @@ Eigen::aligned_vector gt_t_w_i; std::string marg_data_path; size_t last_frame_processed = 0; -tbb::concurrent_unordered_map timestamp_to_id; +tbb::concurrent_unordered_map> timestamp_to_id; std::mutex m; std::condition_variable cv;