pcl三角面片拼接和PCL库的bug修复

PCL面片拼接代码如下,我使用的1.10.1PCL,这个版本的库存在问题会导致输出的结果错误,在cc会报错: An error occurred while loading ‘combined mesh’

    // 读取第一个PLY文件
    pcl::PolygonMesh mesh1;
    pcl::io::loadPLYFile("hole.ply", mesh1);

    // 读取第二个PLY文件
    pcl::PolygonMesh mesh2;
    pcl::io::loadPLYFile("no_hole.ply", mesh2);

        // 创建一个新的PolygonMesh
    pcl::PolygonMesh combinedMesh;
    pcl::PolygonMesh::concatenate(mesh1, mesh2, combinedMesh);


    // 将结果保存为PLY文件
    pcl::io::savePLYFile("combined_mesh.ply", combinedMesh);

在PolygonMesh.h中原始函数定义如下,其中计算point_offset 调用过晚,只需要把它剪切到
bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);之前即可

      bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);
      if (success == false) {
        return false;
      }
      // Make the resultant polygon mesh take the newest stamp
      mesh1.header.stamp = std::max(mesh1.header.stamp, mesh2.header.stamp);

      const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;
      std::transform(mesh2.polygons.begin (),
                     mesh2.polygons.end (),
                     std::back_inserter (mesh1.polygons),
                     [point_offset](auto polygon)
                     {
                        std::transform(polygon.vertices.begin (),
                                       polygon.vertices.end (),
                                       polygon.vertices.begin (),
                                       [point_offset](auto& point_idx)
                                       {
                                         return point_idx + point_offset;
                                       });
                        return polygon;
                      });

      return true;
  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值