slam_in_autonomous_driving icon indicating copy to clipboard operation
slam_in_autonomous_driving copied to clipboard

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

Open kevin-tiger opened this issue 1 year ago • 1 comments

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<size_t> 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<size_t> index(index_num); // std::vector<size_t> 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])); } ); }

kevin-tiger avatar May 31 '23 08:05 kevin-tiger