pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[io] .PCD format does not support empty point clouds

Open kaesesahnetorte opened this issue 2 years ago • 2 comments

Current Behavior When trying to save an empty point cloud as .pcd file, pcl::io::savePCDFileASCII() throws pcl::IOException with Note: Input point cloud has no data!

Expected / desired behavior When trying to save an empty point cloud as .pcd file, pcl::io::savePCDFileASCII() gives a warning, but saves the file.

Argumentation Use Case A: I have a depth sensor, that surveys the sky, and could have frames with only infinite ranges. I want to be able to save all the frames, regardless of whether they are empty or not.

Use Case B: I want to label certain points of point cloud x.pcd. I want to save the labeled points as a partial point cloud in x_label.pcd. If x.pcd does not contain a point that should hold the label, x_label.pcd should be an empty .pcd file.

kaesesahnetorte avatar Jun 30 '22 09:06 kaesesahnetorte

I guess this is something we can think about. It would be possible to again have an empty cloud after saving and loading from PCD file. Important is that the user is informed about this (via the warning). Would you expect the file to look e.g. like this?

VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 0
HEIGHT 0
VIEWPOINT 0 0 0 1 0 0 0
POINTS 0
DATA ascii

Of course we have to make sure that the saving and loading functions can work with this

mvieth avatar Jun 30 '22 11:06 mvieth

Thank you for your quick feedback! Yes, I think this file layout looks appropriate.

kaesesahnetorte avatar Jun 30 '22 12:06 kaesesahnetorte

@mvieth May I work on this ticket? I'm thinking of making changes to writeASCII, writeBinary, writeBinaryCompressed and PCDReader.

bottlenome avatar Aug 24 '22 05:08 bottlenome

@mvieth May I work on this ticket?

@bottlenome That would be great!

I'm thinking of making changes to writeASCII, writeBinary, writeBinaryCompressed and PCDReader.

Sounds reasonable. Here is an idea for a test, could be added to test/io/test_io.cpp:

TEST (PCL, EmptyCloudToPCD)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  pcl::io::savePCDFileASCII("ascii.pcd", cloud);
  pcl::PointCloud<pcl::PointXYZ> cloud_in1;
  cloud_in1.width = 10; // Make sure loadPCDFile overwrites this
  pcl::io::loadPCDFile("ascii.pcd", cloud_in1);
  remove("ascii.pcd");
  EXPECT_EQ(cloud.width, cloud_in1.width);

  pcl::io::savePCDFileBinary("binary.pcd", cloud);
  pcl::PointCloud<pcl::PointXYZ> cloud_in2;
  cloud_in2.width = 10; // Make sure loadPCDFile overwrites this
  pcl::io::loadPCDFile("binary.pcd", cloud_in2);
  remove("binary.pcd");
  EXPECT_EQ(cloud.width, cloud_in2.width);
}

mvieth avatar Aug 24 '22 16:08 mvieth

@mvieth https://github.com/PointCloudLibrary/pcl/pull/5400 Created a pull request. This is the first pull request in my life. I have read the Contribution Guide, but if there is anything strange, please point it out to me.

bottlenome avatar Aug 25 '22 07:08 bottlenome