PCLPointCloud2和PointCloud<T>记录

简介

  • PCLPointCloud2 :以连续内存形式存储,非常适合序列化传输
    ros中有关点云的消息类型是PCLPointCloud2的,这是一个更为通用的数据结构,能够存储各种类型的点云数据,不仅限于 XYZ 或 XYZRGB 等常见的格式。并且可以选择要在其中存储哪些字段,例如仅 XYZ、XYZ + 法线、XYZ + 颜色等。当然灵活的代价就是非常不直观,得搞清楚传来的点云到底是什么。
  • PointCloud:如果指定了类型,会有一些更高效和方便的操作,比如直接对某一字段进行访问。
    缺点就是无法选择存储或者删除某一字段。

二者之间的转换非常方便,pcl中提供了相应的接口

template <typename PointT> 
void fromPCLPointCloud2 (const pcl::PCLPointCloud2& msg, pcl::PointCloud<PointT>& cloud);

template <typename PointT> 
void toPCLPointCloud2 (const pcl::PointCloud<PointT>& cloud, pcl::PCLPointCloud2& msg);

用途

目前有关PCLPointCloud2,除了经常用在ros中以外,最常见的一个用途是用来查询传入的点云是否包含某个字段,比如下面这段pcl示例代码中的一部分:

pcl::PCLPointCloud2 input_pointcloud2;
if (pcl::io::loadPCDFile(pcd_filename, input_pointcloud2))
{
    
    
    PCL_ERROR("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str());
    return (3);
}
pcl::fromPCLPointCloud2(input_pointcloud2, *input_cloud_ptr);
if (!ignore_provided_normals)
{
    
    
    if (pcl::getFieldIndex(input_pointcloud2, "normal_x") >= 0)
    {
    
    
        pcl::fromPCLPointCloud2(input_pointcloud2, *input_normals_ptr);
        has_normals = true;

        //NOTE Supposedly there was a bug in old PCL versions that the orientation was not set correctly when recording clouds. This is just a workaround.
        if (input_normals_ptr->sensor_orientation_.w() == 0)
        {
    
    
            input_normals_ptr->sensor_orientation_.w() = 1;
            input_normals_ptr->sensor_orientation_.x() = 0;
            input_normals_ptr->sensor_orientation_.y() = 0;
            input_normals_ptr->sensor_orientation_.z() = 0;
        }
    }
    else
        PCL_WARN("Could not find normals in pcd file. Normals will be calculated. This only works for single-camera-view pointclouds.\n");
}

猜你喜欢

转载自blog.csdn.net/weixin_44368569/article/details/134116150
今日推荐