Describe the bug
pcl::io::savePCDFileBinary doesn't perform a check to see if
(height * width ) == no_of_points
before saving the file. Consequently, attempting to open the resultant PCD file in most applications will fail.
In contrast, pcl::io::savePCDFileASCII does perform this check, and throws EXCEPTION : [pcl::PCDWriter::writeASCII] Number of points different than width * height!
Context
Issue occurs when attempting to save in binary format, if the width*height value is not equal to the number of points in the cloud.
The following code snippet from pcd_io.hpp demonstrates how the ASCII variant handles this.
if (cloud.width * cloud.height != cloud.points.size ())
{
throw pcl::IOException ("[pcl::PCDWriter::writeASCII] Number of points different than width * height!");
return (-1);
}
Expected behavior
Throw the above mentioned exception, same as the ASCII variant.
As a side note, would it make more sense for the PCDWriter to actually attempt to rectify this issue by changing the width, and perhaps inform the user with a warning, rather than throwing an exception?
To a general user, I feel like that may be more convenient, but of course I'm not well-versed enough with the library to think of any situation why an exception would be more useful.
Current Behavior
No error thrown, output file is corrupt. (at least in the sense that most viewers won't open it due to the mismatch)
To Reproduce
Screenshots/Code snippets
Your Environment (please complete the following information):
Possible Solution
Simply adding the above check to the PCDWriter::writeBinary method should fix the issue. I'd be happy to put in a PR.
Additional context
Please go ahead with a PR 馃槃
@haritha-j how did you end up with a point cloud where width x height doesn't equal pointcloud size in the first place?
@haritha-j how did you end up with a point cloud where width x height doesn't equal pointcloud size in the first place?
@larshg The short answer would be bad coding i guess :P
Basically I was directly manipulating the points vector of a point cloud to add / delete points, which of course changes the pointcloud size, but forgot to set the width at the end.
Well, it's a faulty API design. It provides direct access to the points container. :)
Maybe something to look into one day 馃槃
Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.