Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用PCL的点云相交_C++_Point Cloud Library_Point Clouds - Fatal编程技术网

C++ 使用PCL的点云相交

C++ 使用PCL的点云相交,c++,point-cloud-library,point-clouds,C++,Point Cloud Library,Point Clouds,假设我有两个不同的pcl::PointCloud(尽管点类型并不重要),c1和c2 我想找到这两个点云的交点。 所谓交叉点,我指的是点云inter,其构造使得c1中的点pi插入inter中,如果(且仅当)点pj存在于c2中,并且 pi.x == pj.x && pi.y == pj.y && pi.z == pj.z 目前,我正在使用以下功能来实现这一点: #include <pcl/point_cloud.h> #include <pcl/p

假设我有两个不同的
pcl::PointCloud
(尽管点类型并不重要),
c1
c2

我想找到这两个点云的交点。 所谓交叉点,我指的是点云
inter
,其构造使得
c1
中的点
pi
插入
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;
}
#包括
#包括
使用名称空间pcl;
typedef PointXYZL PointLT;
typedef PointCloud PointLCloudT;
bool包含(PointLCloudT::Ptr c,PointLT p){
PointLCloudT::迭代器it=c->begin();
对于(;it!=c->end();++it){
如果(it->x==p.x&&it->y==p.y&&it->z==p.z)
返回true;
}
返回false;
}
点云::Ptr交叉点(点云::Ptr c1,
PointLCloudT::Ptr c2){
PointLCloudT::Ptr inter;
PointLCloudT::迭代器it=c1->begin();
对于(;it!=c1->end();++it){
如果(包含(c2,*它))
inter->push_back(*it);
}
返回间隔;
}
我想知道是否有一个标准的(可能更有效的)方法来做到这一点

我在网上找不到这方面的任何东西,但也许我遗漏了什么


谢谢。

如果您只查找精确匹配,而不是近似匹配,您只需将每个点云中的点放入一个
std::vector
,排序,然后使用
std::set_intersection
来识别匹配项。

包含的
函数中搜索点,可以通过使用高效的数据结构(如)来提高效率

另一种选择是在您的开发过程中尽早做好簿记工作,但我们需要更多地了解您在高水平上努力实现的目标,以帮助您实现这一目标


编辑:正如评论中指出的,KD树适合于近似的空间搜索,但询问者希望进行精确的点匹配。为此,哈希表(或其他一些基本的搜索数据结构)可能更有效。

谢谢。对于这种方法,我唯一关心的是它们可能有不同的标签,因此向量应该只包含三个要正确比较的空间坐标。这样做,我丢失了标签信息,我必须在原始的点云中检索它,我想再次遍历所有的点。向量可以包含原始点数据。你需要使用一个只使用坐标而忽略标签的自定义比较器。。。我会调查一下的,谢谢!这会加速事情的发展,但会有点过头。kD树不是精确点查询的良好结构。它是为近似点查询而设计的。我的高级任务是将点云的分割(由我们正在研究的算法计算)与给定的地面真实分割进行比较。@FrancescoV。不想偏离原来的实现,但是如果你要分割成两个以上的片段——特别是如果片段没有与来自地面真相的片段相关联的话,那么你应该考虑更多的形式化和强大的统计方法来测量发散。特别是,你说得对,斯奈夫特尔。散列将更直接、更快。我也在计算VOI,但我还想评估精确度和召回率(以及F分数);对于那些人,我需要十字路口。