Federico Nardi
Federico Nardi

Reputation: 510

PCL library, how to access to organized point clouds?

I have a very simple question:

I have an organized point cloud stored in a pcl::PointCloud<pcl::PointXYZ> data structure.

If I didn't get it wrong, organized point clouds should be stored in a matrix-like structure.

So, my question is: is there a way to access this structure with row and column index? Instead of accessing it in the usual way, i.e., as a linear array.

To make an example:

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

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

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

Thanks.

Upvotes: 7

Views: 6382

Answers (2)

badcode
badcode

Reputation: 610

You can accces the points with () 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;
      }

Upvotes: 6

Nithin Shrivatsav
Nithin Shrivatsav

Reputation: 11

To access the points do the following:

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

Let i be the element number which you want to access

cloud->points[i].x will give you the x-coordinate.

Similarly, cloud->points[i].y and cloud->points[i].z will give you the y and z coordinates.

Upvotes: -1

Related Questions