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

Support lowercase types (i, u, f) when reading PCD files #6930

Merged

Conversation

nicolaloi
Copy link
Contributor

@nicolaloi nicolaloi commented Aug 25, 2024

Type

Motivation and Context

Other libraries, like PCL, support both lowercase types (i, u, f) and their uppercase "official" counterpart (I, U, F) when loading PCD files. Currently, Open3D raises an error for lowercase types when using open3d.t.io, or loads a 0.0 value when using open3d.io, without any warning/error.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

Add support for lowercase types when reading PCD files by using std::toupper(type, std::locale()).

Testing

Trying to load pc_example.zip (notice TYPE f f f instead of TYPE F F F):

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z
SIZE 4 4 4
TYPE f f f
COUNT 1 1 1
WIDTH 4
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 4
DATA ascii
1.0 2.0 3.0
1.5 2.5 3.5
0.2 4.1 -9.3
7.1 8.3 -4.7

with script:

import open3d as o3d
import numpy as np

filename = "pc_example.pcd"

print("open3d.io:")
pcd = o3d.io.read_point_cloud(filename)
print(np.asarray(pcd.points))

print("\nopen3d.t.io:")
pcd = o3d.t.io.read_point_cloud(filename)
print(pcd.point.positions.numpy())
Before
open3d.io:
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]

open3d.t.io:
Traceback (most recent call last):
  File "/home/nicola/Desktop/test/open3d/pcd_types/test-script.py", line 13, in <module>
    pcd = o3d.t.io.read_point_cloud(filename)
RuntimeError: [Open3D Error] (open3d::core::Dtype open3d::t::io::GetDtypeFromPCDHeaderField(char, int)) /home/nicola/Open3D-support-2D/cpp/open3d/t/io/file_format/FilePCD.cpp:115: Unsupported data type.
After
open3d.io:
[[ 1.   2.   3. ]
 [ 1.5  2.5  3.5]
 [ 0.2  4.1 -9.3]
 [ 7.1  8.3 -4.7]]

open3d.t.io:
[[ 1.   2.   3. ]
 [ 1.5  2.5  3.5]
 [ 0.2  4.1 -9.3]
 [ 7.1  8.3 -4.7]]

@ssheorey ssheorey self-requested a review August 30, 2024 04:54
Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nicolaloi ! Looks good!

PS: To correctly convert an Open3D Tensor to numpy, use this:

print("\nopen3d.t.io:")
pcd = o3d.t.io.read_point_cloud(filename)
print(pcd.point.positions)   # To just print directly
print(pcd.point.positions.numpy())   # convert to numpy and print

@ssheorey ssheorey merged commit d18bb95 into isl-org:main Sep 4, 2024
36 of 39 checks passed
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

Successfully merging this pull request may close these issues.

Bug in displaying pcd files with lowercase written type
2 participants