Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 967
Federico Nardi Avatar asked Jun 18 '18 10:06

Federico Nardi


People also ask

What is an organized point cloud?

An organized point cloud resembles a 2-D matrix, with its data divided into rows and columns. The data is divided according to the spatial relationships between the points. As a result, the memory layout of an organized point cloud relates to the spatial layout represented by the xyz-coordinates of its points.

How do I see how many points I have on point cloud?

The number of points in a PCL point cloud is equal to the product of its width and height. By definition, an unorganized point cloud has height equal to 1. Therefore width is indeed equal to the number of points.


1 Answers

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;
      }
like image 86
badcode Avatar answered Sep 30 '22 17:09

badcode