一、點雲的創建與訪問
第一種,是一種vector的賦值方式,將point數據push_back到pcl::PointXYZ類型的模板中。
1 pcl::PointCloud<pcl::PointXYZ> pointCloud; 2 pcl::PointXYZ point; 3 point.x = 2.0f - y; 4 point.y = y; 5 point.z = z; 6 pointCloud.points.push_back(point);
訪問:PointXYZ 成員:float x,y,z;表示了xyz3D信息,可以通過points[i].data[0]或points[i].x訪問點X的坐標值。
第二種,指針型類模板,采用“->points[i]”方式賦值。
1 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); 2 for (int i = 0; i < cloud->points.size (); ++i) 3 { 4 cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); 5 cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); 6 cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); 7 }
二、點雲的轉換
//創建
pcl::PointCloud<pcl::PointXYZ> cloud;//點雲對象
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudPtr
(new pcl::PointCloud<pcl::PointXYZ>);//點雲指針對象
//轉換
cloud = * cloudPtr; cloudPtr = cloud.makeShared();