Open kevin-tiger opened 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])); } ); }
thanks, fixed in recent commit.
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]));
}
);
}