Fra*_* V. 5 c++ point-clouds point-cloud-library
假设我有两个不同的pcl::PointCloud<pcl::PointXYZL>(尽管点类型并不重要),c1并且c2.
我想找到这两个点云的交集。inter通过交集,我的意思是构建的
点云pi,如果(且仅当)一个点存在于和中,则c1插入一个点interpjc2
pi.x == pj.x && pi.y == pj.y && pi.z == pj.z
Run Code Online (Sandbox Code Playgroud)
目前我正在使用以下函数来实现此目的:
#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;
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一个标准(并且可能更有效)的方法来做到这一点?
我在官方文档中没有找到任何关于此的信息,但也许我遗漏了一些东西。
谢谢。
如果您只是寻找精确匹配,而不是近似匹配,您可以简单地将每个点云中的点放入 a 中std::vector,对其进行排序,然后用于std::set_intersection识别匹配。