Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

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

Open nicolaloi opened this issue 1 year ago • 0 comments

Type

  • [ ] Bug fix (non-breaking change which fixes an issue): Fixes #
  • [x] New feature (non-breaking change which adds functionality). Resolves #6925
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

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:

  • [x] I have run python util/check_style.py --apply to apply Open3D code style to my code.
  • [x] This PR changes Open3D behavior or adds new functionality.
    • [ ] Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is updated accordingly.
    • [x] I have added or updated C++ and / or Python unit tests OR included test results (e.g. screenshots or numbers) here.
  • [x] I will follow up and update the code if CI fails.
  • [x] 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(np.asarray(pcd.point.positions))
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
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8c0]
  2
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8c4]
  3
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8c8]]
 [1.5
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8cc]
  2.5
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8d0]
  3.5
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8d4]]
 [0.2
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8d8]
  4.1
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8dc]
  -9.3
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8e0]]
 [7.1
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8e4]
  8.3
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8e8]
  -4.7
  Tensor[shape={}, stride={}, Float32, CPU:0, 0x1f4b8ec]]]

nicolaloi avatar Aug 25 '24 14:08 nicolaloi