c++3dpoint-cloud-librarypoint-cloudsply-file-format

Detect if there is an error when importing a point cloud and display alert message without closing application PCL and C++


I am trying to import a point cloud into a program I have made with the PCL and C++ library. This program must be able to load different files and that, in case of encountering one that has some error at the time of having made its coding, it indicates that there has been an error but in no case makes the application break.

The header of a point cloud that right now is causing the program to break is as follows.

ply
format ascii 1.0
comment PCL generated
element vertex 88655
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
element camera 1
property float view_px
property float view_py
property float view_pz
property float x_axisx
property float x_axisy
property float x_axisz
property float y_axisx
property float y_axisy
property float y_axisz
property float z_axisx
property float z_axisy
property float z_axisz
property float focal
property float scalex
property float scaley
property float centerx
property float centery
property int viewportx
property int viewporty
property float k1
property float k2
end_header

And I'm trying to import the cloud as pcl::PointCloud<pcl::PointXYXRGB> and also as a pcl::PolygonMesh. In this case, the cloud does not have mesh information but as far as I was noticing with other clouds, the system is able to detect it and import it without any problem.

The code I'm using to import the files is:

std::string filepath = "cloud.ply";
// Load cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PolygonMesh::Ptr cloud_mesh (new pcl::PolygonMesh);

if (pcl::io::loadPLYFile(filepath_cloud, *cloud) == -1) {
  std::cerr << "Error reading cloud" << std::endl;
}
std::cout << "Reading cloud OK" << std::endl;

if (pcl::io::loadPolygonFilePLY(filepath_cloud, * cloud_mesh) == -1) {
  std::cerr << "Error reading cloud mesh" << std::endl;
}
std::cout << "Reading cloud mesh OK" << std::endl;

Whith this code I obtain these messages until the application crush:

[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:25: property 'float32 focal' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:26: property 'float32 scalex' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:27: property 'float32 scaley' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:28: property 'float32 centerx' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:29: property 'float32 centery' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply: property 'float32 k1' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply: property 'float32 k2' of element 'camera' is not handled
Reading cloud OK
Warning:  Can't find property 'vertex_indices' in element 'face'

So, what you can see is that, until the time comes to import it to pcl::PolygonMesh, no error occurs. What I want to manage is that, although it is not possible to be read as polygonmesh, the application does not close. In other words, to put the reading of pcl::PolygonMesh in a kind of try{} catch{} so that it simply reads the file if possible. But I don't know if that can be done or what, if it can be done, how it would have to be done.


Solution

  • Try pcl::io::loadPLYFile() (https://pointclouds.org/documentation/group__io.html#ga0cfc645cc531647728e16088b6342204) instead of pcl::io::loadPolygonFilePLY()