PCL库,如何访问组织好的点云?

7

我有一个非常简单的问题:

我有一个存储在pcl::PointCloud<pcl::PointXYZ>数据结构中的有序点云。

如果我没记错,有序点云应该存储在类似矩阵的结构中。

那么,我的问题是:是否有一种方法可以通过行列索引来访问这个结构?而不是像通常访问线性数组那样。

举个例子:

//data structure
pcl::PointCloud<pcl::PointXYZ> cloud;

//linearized access
cloud[j + cols*i] = ....

//matrix-like access
cloud.at(i,j) = ...

感谢您的选择。

3
cloud.at(column, row) 应该可以为你工作。你是否遇到了任何问题?你确定你的点云已经被组织好了吗 (cloud.isOrganized())? - Mark Loyman
2个回答

6
您可以使用()运算符访问这些点。
    //creating the cloud
    PointCloud<PointXYZ> organizedCloud;
    organizedCloud.width = 2;
    organizedCloud.height = 3;
    organizedCloud.is_dense = false;
    organizedCloud.points.resize(organizedCloud.height*organizedCloud.width);

    //setting random values
for(std::size_t i=0; i<organizedCloud.height; i++){
        for(std::size_t j=0; j<organizedCloud.width; j++){
            organizedCloud.at(i,j).x = 1024*rand() / (RAND_MAX + 1.0f);
            organizedCloud.at(i,j).y = 1024*rand() / (RAND_MAX + 1.0f);
            organizedCloud.at(i,j).z = 1024*rand() / (RAND_MAX + 1.0f);
        }
    }

    //display
    std::cout << "Organized Cloud" <<std:: endl; 

    for(std::size_t i=0; i<organizedCloud.height; i++){
        for(std::size_t j=0; j<organizedCloud.width; j++){
           std::cout << organizedCloud.at(i,j).x << organizedCloud.at(i,j).y  <<  organizedCloud.at(i,j).z << " - "; }
          std::cout << std::endl;
      }

1
谢谢回复,正是我想要的。不过函数签名是 const PointT & at(int column, int row) const,所以我认为 i 和 j 应该交换,也就是在你的例子中应该是 organizedCloud.at(j, i)。至少在我的测试中是这样的... - Germanunkol

-2

要访问这些点,请执行以下操作:

// create the cloud as a pointer
pcl::PointCloud<pcl::PointXYZ> cloud(new pcl::PointCloud<pcl::PointXYZ>);

假设你想要访问的元素编号为i

cloud->points[i].x将会给出该点的x坐标。

同样地,cloud->points[i].ycloud->points[i].z将分别给出该点的y和z坐标。


1
这并不适用于有组织的点云。问题是关于有组织的点云及其类似矩阵的结构的。 - metsburg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接