首页 > 解决方案 > PCL 库,如何访问有组织的点云?

问题描述

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

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

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

所以,我的问题是:有没有办法用行和列索引访问这个结构?而不是以通常的方式访问它,即作为线性数组。

举个例子:

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

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

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

谢谢。

标签: data-structurespoint-cloud-library

解决方案


您可以使用() operator

    //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;
      }

推荐阅读