I am currently using the Point Cloud Library (PCL) in order to do some work with point clouds. Now I need to compute a mesh for some point cloud and thought that the best thing to do is to use Meshlab. So far so good, my problem is that my point cloud has labels, i.e. it is of the following form:
pcl::PointCloud<pcl::PointXYZRGBL> cloud;
Important: I cannot omit the labels, I have to know after the mesh is computed, which point of the mesh has which label. Later, after some manipulation etc. I save this cloud via
pcl::io::savePLYFileBinary(writePath, *cloud);
which works fine IF the cloud is of type
pcl::PointCloud<pcl::PointXYZRGB> cloud;
but does not work for the first case. Does anyone have some idea what I could do to be able to still get a PLY file which contains labels and can be loaded into Meshlab?
Thanks all!
As MeshLab is not able to open your labeled points cloud, I'd suggest to:
Export your point cloud to a format readable by MeshLab (for example, the pcl::PointCloud<pcl::PointXYZRGB>
you mentioned).
Reconstruct the triangle mesh using an interpolating method such as a ball pivoting. The interpolating method is necessary in order to preserve the original points as the vertices of the mesh. When you've finished, save the mesh.
Load the mesh at match the vertices with your original point cloud so you can recover the labels and any other associated attribute. In the quick test I've made even the vertices order matches the points' one.
Update
You mentioned in a comment that you were using the Screened Poisson Reconstruction. This method uses input points as positional constraints to improve the precision of the method, but it is still an approximating method, so output vertices are not guaranteed to match input points (and probably won't do).
You can either switch to an interpolating method (if noise and outliers allow you), or to find the closest point for each vertex (using a 1-NN, as you are doing now) to label vertices.
Above is valid for all discrete values. You should also adjust other values, such as color, to better match the reconstruction (vertices not matching points). To do so you can interpolate the corresponding value from the k-NN.