c++ - 将 libigl 网格结果加载到 PCL PolygonMesh

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

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

最佳答案

颜色信息仍然缺失,但以下代码将格式从 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();

关于c++ - 将 libigl 网格结果加载到 PCL PolygonMesh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49968512/

相关文章:

matlab - 三角形网格上的最近点

mesh - 将比例应用于子弹碰撞体

c++ - 为使用 boost 的预开发库构建 C++ 包装器时 Unresolved external 问题

c++ - PCL OpenNI2Grabber 在没有查看器的情况下获取点云

c++ - 在 QT 对象类中声明一个 PCL 点云

c++ - 比较 2 个字节数组的函数

c# - TagLib# (C#) 和 TagLib (C++) 的长度差异

c++ - opengl vbo dma数组

c++ - 为什么有时需要将 C++ 模板函数定义放在头文件中?

c++ - 向 2D 对象添加 3D 效果 - DirectX