【问题标题】:Loading libigl mesh result into the PCL PolygonMesh将 libigl 网格结果加载到 PCL PolygonMesh
【发布时间】:2018-10-02 18:10:19
【问题描述】:

我使用 libigl 做了一些网格处理,结果存储如下:

MatrixXd V;
MatrixXi F;
Matrix<unsigned char, Dynamic, Dynamic> C;

我可以使用以下命令将这些数据保存为 PLY 文件:

 igl::writePLY("out.ply", V, F, C, false);

但我想使用 PCL 查看器将其可视化。类似于下面的代码:

pcl::PolygonMesh::Ptr mesh(new pcl::PolygonMesh);

//  Here is what I need to do in between! --> converting V,F,C from libigl mesh into PCL mesh format.
// .....

pcl::visualization::PCLVisualizer viewer;
viewer.addPolygonMesh(*mesh);
viewer.spin();

您知道如何将顶点和面值转换/加载为 pcl 网格格式吗?也许是一个 for 循环?

【问题讨论】:

    标签: c++ mesh point-cloud-library ply libigl


    【解决方案1】:

    颜色信息仍然缺失,但以下代码将格式从 libigl 转换为 PCL。也就是说,libigl 有一个viewer,您可以使用它。

    // load the mesh
    Eigen::MatrixXd V;
    Eigen::MatrixXi F;
    igl::readPLY("input.ply", V, F);
    
    pcl::PolygonMesh::Ptr polymesh (new pcl::PolygonMesh);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr mesh_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
    
    mesh_cloud->points.resize(V.rows());
    for (int i=0; i<V.rows(); i++)
    {
        mesh_cloud->points[i].x = V(i, 0);
        mesh_cloud->points[i].y = V(i, 1);
        mesh_cloud->points[i].z = V(i, 2);
    }
    pcl::toPCLPointCloud2( *mesh_cloud, polymesh->cloud );
    
    polymesh->polygons.resize(F.rows());
    for (int i=0; i<F.rows(); i++)
    {
        polymesh->polygons[i].vertices.resize(3);
        polymesh->polygons[i].vertices[0] = F(i, 0);
        polymesh->polygons[i].vertices[1] = F(i, 1);
        polymesh->polygons[i].vertices[2] = F(i, 2);
    }
    
    pcl::visualization::PCLVisualizer viewer;
    viewer.setBackgroundColor (1, 1, 1);
    viewer.addPolygonMesh(*polymesh);
    viewer.spin();
    

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多