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

IO PolygonMesh to PLY output cannot support large polygons #6087

Open
mauricefallon opened this issue Jul 16, 2024 · 2 comments
Open

IO PolygonMesh to PLY output cannot support large polygons #6087

mauricefallon opened this issue Jul 16, 2024 · 2 comments
Labels

Comments

@mauricefallon
Copy link
Contributor

mauricefallon commented Jul 16, 2024

Describe the bug

When writing a PolygonMesh with large polygons, PCL doesnt properly encode the size of the vertex lists.

Very specifically these lines use uchar to store the size of the polygon:
https://github.com/PointCloudLibrary/pcl/blob/master/io/src/ply_io.cpp#L907C32-L907C51
https://github.com/PointCloudLibrary/pcl/blob/master/io/src/ply_io.cpp#L1520

When a polygon is bigger than 256 edges, this results in a ply file which cannot be read by PCL

This Possible Fix
When a polygon contains a large polygon, the simple fix is to change:
property list uchar int vertex_indices
to
property list uint int vertex_indices

PCL will then be able to read back in this ply file.
However, meshlab (for comparison) cannot load this ply file. VTK can parse it.

Your Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • PCL Versio: 1.12 with ROS2 / humble
@mauricefallon mauricefallon added kind: bug Type of issue status: triage Labels incomplete labels Jul 16, 2024
@mauricefallon
Copy link
Contributor Author

mauricefallon commented Jul 16, 2024

The existing header:
ply
format ascii 1.0
comment PCL generated
element vertex 1257
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property float nx
property float ny
property float nz
property float curvature
element face 8
property list uchar int vertex_indices
end_header

The header containing the fix:

ply
format ascii 1.0
comment PCL generated
element vertex 1257
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property float nx
property float ny
property float nz
property float curvature
element face 8
property list uint int vertex_indices
end_header

@mvieth
Copy link
Member

mvieth commented Jul 17, 2024

Interesting, I did not expect that someone would have faces with more than 255 vertices/edges.
https://github.com/PointCloudLibrary/pcl/blob/master/io/src/ply_io.cpp#L907C32-L907C51 I think this line is actually irrelevant because it is for a pcl::PCLPointCloud2, not a pcl::PolygonMesh and stores no indices. I am not sure though why that line is written at all, probably for compatibility with some ply readers.
However these lines would have to be adapted if uchar is changed to uint: https://github.com/PointCloudLibrary/pcl/blob/master/io/src/ply_io.cpp#L1707-L1713 (binary ply)

PCL will then be able to read back in this ply file.
However, meshlab (for comparison) cannot load this ply file. VTK can parse it.

So the best approach probably is to check whether any face/polygon has more than 255 vertices, if yes use uint (and maybe print a warning), if not use uchar as before.
Feel free to open a pull request.

@mvieth mvieth added module: io and removed status: triage Labels incomplete labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants