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.
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With