PCL中訪問點雲資料點的幾種方式
阿新 • • 發佈:2019-01-30
最近在看PCL的教程,發現對點雲中具體資料點的訪問也有好幾種方式,看著看著就會混淆了,所以,現將每種方式記錄下來,做個對比,方便隨時複習,溫故知新。
一、
第一種是在看《How to create a range image from a point cloud》教程時看到的,程式碼如下,這種方式是一種vector的賦值方式,首先將point資料push_back到pcl::PointXYZ型別的模板中,然後再用無序點雲的方式重新組織點雲資料。
pcl::PointCloud<pcl::PointXYZ> pointCloud; // Generate the data二、for (float y=-0.5f; y<=0.5f; y+=0.01f) { for (float z=-0.5f; z<=0.5f; z+=0.01f) { pcl::PointXYZ point; point.x = 2.0f - y; point.y = y; point.z = z; pointCloud.points.push_back(point); } } pointCloud.width = (uint32_t) pointCloud.points.size(); pointCloud.height = 1;
出處《Filtering a PointCloud using a PassThrough filter》,指標型類模板,採用“->points[i]”方式賦值。
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); // Fill in the cloud data未完待續。。。cloud->width = 5; cloud->height = 1; cloud->points.resize (cloud->width * cloud->height); for (size_t i = 0; i < cloud->points.size (); ++i) { cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); } std::cerr << "Cloud before filtering: " << std::endl; for (size_t i = 0; i < cloud->points.size (); ++i) std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << std::endl;