Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadPLYFile() does not support NaN values #1433

Closed
VictorLamoine opened this issue Nov 18, 2015 · 1 comment
Closed

loadPLYFile() does not support NaN values #1433

VictorLamoine opened this issue Nov 18, 2015 · 1 comment

Comments

@VictorLamoine
Copy link
Contributor

Test code

#include <pcl/common/common.h>
#include <pcl/console/parse.h>
#include <pcl/point_cloud.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>

int main(int argc, char* argv[])
{
  std::vector<int> ply_args = pcl::console::parse_file_extension_argument (argc, argv, ".ply");
  if (ply_args.size() != 1)
  {
    PCL_ERROR("Usage: %s input.ply\n", argv[0]);
    return -1;
  }

  PCL_INFO("Trying to loading %s\n", argv[ply_args[0]]);
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  if (pcl::io::loadPLYFile(argv[ply_args[0]], *cloud) != 0)
  {
    PCL_ERROR("Could not load %s\n", argv[ply_args[0]]);
    return -1;
  }

  PCL_INFO("The cloud is %s.\n", cloud->is_dense ? "dense" : "NOT dense");
  pcl::visualization::PCLVisualizer viewer;
  viewer.addPointCloud(cloud);
  viewer.spin();
  return 0;
}

File 1

ply
format ascii 1.0
comment VCGLIB generated
element vertex 4
property float x
property float y
property float z
element face 0
property list uchar int vertex_indices
end_header
4.23607 0 1.61803 
2.61803 2.61803 2.61803 
0 1.61803 4.23607 
0 -1.61803 4.23607 

File 2

ply
format ascii 1.0
comment VCGLIB generated
element vertex 4
property float x
property float y
property float z
element face 0
property list uchar int vertex_indices
end_header
4.23607 nan 1.61803 
2.61803 2.61803 2.61803 
0 1.61803 4.23607 
0 -1.61803 4.23607 

File 3

ply
format ascii 1.0
comment VCGLIB generated
element vertex 4
property float x
property float y
property float z
element face 0
property list uchar int vertex_indices
end_header
4.23607 NaN 1.61803 
2.61803 2.61803 2.61803 
0 1.61803 4.23607 
0 -1.61803 4.23607 

Output error:

Happens with file_2 and file_3

$ ./test_pcl_1 ~/file_2.ply 
[pcl::PLYReader] /home/victor/file_2.ply:9: property 'list uint8 int32 vertex_indices' of element 'face' is not handled
[pcl::PLYReader] /home/victor/file_2.ply:11: parse error
[pcl::PLYReader::read] problem parsing header!
[pcl::PLYReader::read] problem parsing header!
Could not load /home/victor/file_2.ply
@SergioRAgostinho
Copy link
Member

Traced the problem here.

The issue is that istream cannot properly parse the nan,inf and variants into the actual float variable.
http://stackoverflow.com/questions/11420263/is-it-possible-to-read-infinity-or-nan-values-using-input-streams
http://stackoverflow.com/questions/7477978/nan-ascii-i-o-with-visual-c

To handle it, the value needs to be extracted as a string followed by an explicit conversion attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants