PCL library, how to access to organized point clouds?
Asked Answered
C

2

7

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.

Corset answered 18/6, 2018 at 10:21 Comment(1)
cloud.at(column, row) should have worked for you. Did you encounter any issues with it? Are you sure that your cloud is organized (cloud.isOrganized())?Unimproved
T
6

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;
      }
Toast answered 22/3, 2020 at 11:31 Comment(1)
Thanks for the reply, just what I was looking for. However the function signature is const PointT & at (int column, int row) const, so I think i and j should be switched, i.e. it should be organizedCloud.at( j, i ) in your example. At least that's how it works in my test...Entirety
W
-1

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.

Worldbeater answered 19/10, 2018 at 16:19 Comment(1)
That is not specific to organized pointclouds. The question was about organized clouds and their matrix like structure.Wennerholn

© 2022 - 2024 — McMap. All rights reserved.