1

我使用 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循环?

4

1 回答 1

0

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

// 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();
于 2019-02-14T11:00:59.120 回答