PCL中访问点云数据点的几种方式

    最近在看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;

未完待续。。。









猜你喜欢

转载自blog.csdn.net/sinat_23853639/article/details/80305327