简体   繁体   中英

Loading libigl mesh result into the PCL PolygonMesh

I did some mesh processing using libigl and results are stored as below:

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

I can save these data as PLY file using the command below:

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

But I want to visualize it using PCL viewer. something similar to the code below:

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();

Do you know how to convert/load the vertex and face value into the pcl mesh format? maybe a for-loop?

The color information is still missing, but the following code convert the format from libigl into PCL. That said, libigl has a viewer that you could use instead.

// 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM