From d695de49132488e5299c0e05ccdd6c7218708668 Mon Sep 17 00:00:00 2001 From: Vladimir Svoboda Date: Tue, 14 May 2024 15:50:26 +0200 Subject: [PATCH 1/2] Add test for loading organized ascii PCD --- tests/conftest.py | 4 ++++ tests/pcd/ascii_organized.pcd | 19 +++++++++++++++++++ tests/test/test_pypcd4.py | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/pcd/ascii_organized.pcd diff --git a/tests/conftest.py b/tests/conftest.py index 9deb5e1..552985a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -292,6 +292,10 @@ def xyzrgb_ascii_with_empty_points_path(): return f"{Path(__file__).resolve().parent}/pcd/ascii_with_empty_points.pcd" +@pytest.fixture +def xyzintensity_ascii_organized_path(): + return f"{Path(__file__).resolve().parent}/pcd/ascii_organized.pcd" + @pytest.fixture def xyzrgb_binary_path(): return f"{Path(__file__).resolve().parent}/pcd/binary.pcd" diff --git a/tests/pcd/ascii_organized.pcd b/tests/pcd/ascii_organized.pcd new file mode 100644 index 0000000..6f6b055 --- /dev/null +++ b/tests/pcd/ascii_organized.pcd @@ -0,0 +1,19 @@ +# .PCD v.7 - Point Cloud Data file format +VERSION .7 +FIELDS x y z intensity +SIZE 4 4 4 4 +TYPE F F F F +COUNT 1 1 1 1 +WIDTH 4 +HEIGHT 2 +VIEWPOINT 0 0 0 1 0 0 0 +POINTS 8 +DATA ascii +0.0 0.0 0.0 0.1 +0.0 0.0 1.0 0.2 +0.0 1.0 0.0 0.3 +0.0 1.0 1.0 0.4 +1.0 0.0 0.0 0.5 +1.0 0.0 1.0 0.6 +1.0 1.0 0.0 0.7 +1.0 1.0 1.0 0.8 diff --git a/tests/test/test_pypcd4.py b/tests/test/test_pypcd4.py index a8ed626..7377604 100644 --- a/tests/test/test_pypcd4.py +++ b/tests/test/test_pypcd4.py @@ -242,6 +242,14 @@ def test_load_xyzrgb_ascii_with_empty_points_pcd(xyzrgb_ascii_with_empty_points_ assert len(pc.pc_data) == pc.metadata.points +def test_load_xyzintensity_ascii_organized_pcd(xyzintensity_ascii_organized_path): + pc = PointCloud.from_path(xyzintensity_ascii_organized_path) + + assert pc.metadata.data == "ascii" + assert pc.pc_data.dtype.names == pc.metadata.fields + assert len(pc.pc_data) == pc.metadata.points + + def test_load_binary_pcd(xyzrgb_binary_path): pc = PointCloud.from_path(xyzrgb_binary_path) From d6741b4fdef9b05060a97b8111295aa78a2c6561 Mon Sep 17 00:00:00 2001 From: Vladimir Svoboda Date: Tue, 14 May 2024 15:55:40 +0200 Subject: [PATCH 2/2] Fix loading of binary_compressed organized PCD The patch fixes an issue where only the first line of data of an organized PCD was loaded. The size of an organised PCD is defined by both its width and its height, and the amount of points to load is defined by the number of points and not solely by its width. --- src/pypcd4/pypcd4.py | 4 ++-- tests/conftest.py | 4 ++++ tests/pcd/binary_compressed_organized.pcd | Bin 0 -> 4096 bytes tests/test/test_pypcd4.py | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/pcd/binary_compressed_organized.pcd diff --git a/src/pypcd4/pypcd4.py b/src/pypcd4/pypcd4.py index d56d20c..a31e8ea 100644 --- a/src/pypcd4/pypcd4.py +++ b/src/pypcd4/pypcd4.py @@ -191,10 +191,10 @@ def _parse_pc_data(fp: BinaryIO, metadata: MetaData) -> npt.NDArray: ) offset = 0 - pc_data = np.zeros(metadata.width, dtype=dtype) + pc_data = np.zeros(metadata.points, dtype=dtype) for name in dtype.names: # type: ignore dt: np.dtype = dtype[name] - bytes = dt.itemsize * metadata.width + bytes = dt.itemsize * metadata.points pc_data[name] = np.frombuffer(buffer[offset : (offset + bytes)], dtype=dt) offset += bytes else: diff --git a/tests/conftest.py b/tests/conftest.py index 552985a..aef329e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -304,3 +304,7 @@ def xyzrgb_binary_path(): @pytest.fixture def xyzrgb_binary_compressed_path(): return f"{Path(__file__).resolve().parent}/pcd/binary_compressed.pcd" + +@pytest.fixture +def xyzintensity_binary_compressed_organized_path(): + return f"{Path(__file__).resolve().parent}/pcd/binary_compressed_organized.pcd" diff --git a/tests/pcd/binary_compressed_organized.pcd b/tests/pcd/binary_compressed_organized.pcd new file mode 100644 index 0000000000000000000000000000000000000000..861d768c6e3d118545be7f6a90f8537c2fc63a3c GIT binary patch literal 4096 zcmeIuL283g5C-6vrXYPTx-6xeA4-=ENe#4{YJ!^jK%!Ke&~A!t3*XX&rf$x6r9=C9lD9)g-lI;RUkOf#qs}Rd%vko#oGoL-- zOwo+;i7;)$!w+)&qS*=KG|F=Bi8m9&Hr#)8O-$Nw-Fcb%7_{MYVfYq?+%mQXe zggJK|(Twzu8MKujdmbLRG4{v!h~i+Azkep{uT7Yy;exA-v0d{!jMWl5*=ejk?Ut;( zC|TV-AIT$DpGoqesvZxOt?r9Lh0IjkNZP)*)D%U*Rmawv1N2CM1W14cNPq-LfCNZ@ N1W14cNZ>yU`~kWlMlk>Y literal 0 HcmV?d00001 diff --git a/tests/test/test_pypcd4.py b/tests/test/test_pypcd4.py index 7377604..aaa1ca8 100644 --- a/tests/test/test_pypcd4.py +++ b/tests/test/test_pypcd4.py @@ -266,6 +266,14 @@ def test_load_binary_compressed_pcd(xyzrgb_binary_compressed_path): assert len(pc.pc_data) == pc.metadata.points +def test_load_binary_compressed_organized_pcd(xyzintensity_binary_compressed_organized_path): + pc = PointCloud.from_path(xyzintensity_binary_compressed_organized_path) + + assert pc.metadata.data == "binary_compressed" + assert pc.pc_data.dtype.names == pc.metadata.fields + assert len(pc.pc_data) == pc.metadata.points + + def test_from_points(): array = np.array([[1, 2, 3], [4, 5, 6]]) fields = ("x", "y", "z")