gaoxiang12 / slam_in_autonomous_driving

《自动驾驶中的SLAM技术》对应开源代码
1.91k stars 467 forks source link

in src/ch5/bfnn.cc, the index may beyond the cloud size, when cloud2 size is smaller than cloud1. #83

Open kevin-tiger opened 1 year ago

kevin-tiger commented 1 year ago

in src/ch5/bfnn.cc, when the point size of cloud2 is smaller than cloud1, the cloud2->points[idx]) is not good here.

void bfnn_cloud(CloudPtr cloud1, CloudPtr cloud2, std::vector<std::pair<size_t, size_t>>& matches) { // 单线程版本 std::vector index(cloud1->size()); std::for_each(index.begin(), index.end(), [idx = 0](size_t& i) mutable { i = idx++; }); matches.resize(index.size()); std::for_each(std::execution::seq, index.begin(), index.end(), [&](auto idx) { matches[idx].second = idx; matches[idx].first = bfnn_point(cloud1, ToVec3f(cloud2->points[idx])); }); } may could simply modify like below: void bfnn_cloud(CloudPtr cloud1, CloudPtr cloud2, std::vector<std::pair<size_t, size_t>>& matches) { // 单线程版本 int cloud1_num = cloud1->size(); int cloud2_num = cloud2->size(); int index_num = cloud1_num < cloud2_num ? cloud1_num : cloud2_num; std::vector index(index_num); // std::vector index(cloud1->size()); std::for_each(index.begin(), index.end(), [idx = 0](size_t& i) mutable { i = idx++; }); matches.resize(index.size()); std::for_each(std::execution::seq, index.begin(), index.end(), [&](auto idx) { matches[idx].second = idx; matches[idx].first = bfnn_point(cloud1, ToVec3f(cloud2->points[idx])); } ); }

gaoxiang12 commented 1 year ago

thanks, fixed in recent commit.