问题
I'm working with PCL and a Mesh editor (MeshLab). I'm interested in importing my meshes to PCL to do some 3D processing.
I've a mesh model in ply format. When I load the model with the code:
PointCloud<PointXYZRGBA>::Ptr cloud (new PointCloud<PointXYZRGBA> ());
pcl::io::loadPLYFile<pcl::PointXYZRGBA>(argv[1], *cloud);
and I visualize it as a point cloud:
visualization::PCLVisualizer viewer ("Model");
viewer.addPointCloud (cloud,"model");
the geometry is different from loading and visualizing the mesh directly:
viewer.addModelFromPLYFile(argv[1], "model");
In the second case, I visualize the model exactly as I do with a Mesh editor, but in the first case I visualize a deformed version of it, i.e and sphere is like and ellipsoid. What is happening here? Maybe I should manually sample the mesh?
If I add the two models in the viewer, the difference is very evident, the point cloud is smaller than the mesh, and it has suffered some strange deformation (please, see attached image)
Thank you very much
(source: pcl-users.org)
回答1:
If someone is interested, here's the answer:
PointCloud<PointXYZRGBA>::Ptr cloud (new PointCloud<PointXYZRGBA> ());
pcl::PolygonMesh triangles;
pcl::io::loadPolygonFilePLY(argv[1], triangles);
pcl::fromROSMsg(triangles.cloud, *cloud);
This code opens a PLY file and converts it to a point cloud with the correct shape.
回答2:
I'm quite sure that it's a bug of PCL before 1.7.2, as disclaimed in the release notes and proved by my own experience:
Fixed a bug in PLYReader which lead to deformation of point clouds when displayed in CloudViewer or PCLVisualizer #879
If you don't upgrade, please add one line to fix the bug as follows:
if (pcl::io::loadPLYFile <pcl::PointXYZRGBNormal> (file, *cloud) == -1)
{
std::cout << "Cloud reading failed." << std::endl;
return (-1);
}
cloud->sensor_orientation_.setIdentity();
来源:https://stackoverflow.com/questions/17491042/difference-between-visualizing-a-mesh-and-its-point-cloud