gpt4 book ai didi

c++ - 使用 PCL 的点云交集

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:02 24 4
gpt4 key购买 nike

假设我有两个不同的 pcl::PointCloud<pcl::PointXYZL> (尽管点类型并不重要),c1c2 .

我想找到这两个点云的交集。交集是指点云 inter构造成一个点 pi来自 c1插入 inter如果(且仅当)一个点 pj存在于 c2

pi.x == pj.x && pi.y == pj.y && pi.z == pj.z

目前我正在使用以下函数来实现这一点:

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

using namespace pcl;

typedef PointXYZL PointLT;
typedef PointCloud<PointLT> PointLCloudT;

bool contains(PointLCloudT::Ptr c, PointLT p) {
PointLCloudT::iterator it = c->begin();
for (; it != c->end(); ++it) {
if (it->x == p.x && it->y == p.y && it->z == p.z)
return true;
}
return false;
}

PointLCloudT::Ptr intersection(PointLCloudT::Ptr c1,
PointLCloudT::Ptr c2) {
PointLCloudT::Ptr inter;
PointLCloudT::iterator it = c1->begin();
for (; it != c1->end(); ++it) {
if (contains(c2, *it))
inter->push_back(*it);
}

return inter;
}

我想知道是否有一种标准(并且可能更有效)的方式来执行此操作?

我在 official documentation 中没有找到任何相关信息,但也许我遗漏了什么。

谢谢。

最佳答案

如果您只是寻找精确匹配,而不是近似匹配,您可以简单地将每个点云中的点放入 std::vector 中,对其进行排序,然后使用 std::set_intersection 以识别匹配项。

关于c++ - 使用 PCL 的点云交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31423598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com