Skip to content

Commit

Permalink
Merge pull request #8 from VladimirSvoboda/organized_pcd
Browse files Browse the repository at this point in the history
Fix loading of binary_compressed organized PCD
  • Loading branch information
urasakikeisuke authored May 15, 2024
2 parents 2dbfe96 + d6741b4 commit 1b393b8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pypcd4/pypcd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -300,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"
19 changes: 19 additions & 0 deletions tests/pcd/ascii_organized.pcd
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/pcd/binary_compressed_organized.pcd
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test/test_pypcd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -258,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")
Expand Down

5 comments on commit 1b393b8

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/pypcd4
   __init__.py20100% 
   _version.py11282%5–6
   pointcloud2.py591280%87–101
   pypcd4.py3793391%23–24, 107, 135, 188, 349–350, 572–594, 607–648, 658–659, 828, 848–849, 972, 975
TOTAL4514790% 

Tests Skipped Failures Errors Time
62 0 💤 0 ❌ 0 🔥 0.606s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/pypcd4
   __init__.py20100% 
   _version.py11282%5–6
   pointcloud2.py591280%87–101
   pypcd4.py3793391%23–24, 107, 135, 188, 349–350, 572–594, 607–648, 658–659, 828, 848–849, 972, 975
TOTAL4514790% 

Tests Skipped Failures Errors Time
62 0 💤 0 ❌ 0 🔥 0.621s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/pypcd4
   __init__.py20100% 
   _version.py11282%5–6
   pointcloud2.py591280%87–101
   pypcd4.py3793391%23–24, 107, 135, 188, 349–350, 572–594, 607–648, 658–659, 828, 848–849, 972, 975
TOTAL4514790% 

Tests Skipped Failures Errors Time
62 0 💤 0 ❌ 0 🔥 0.685s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/pypcd4
   __init__.py20100% 
   _version.py11282%5–6
   pointcloud2.py591280%87–101
   pypcd4.py3793391%23–24, 107, 135, 188, 349–350, 572–594, 607–648, 658–659, 828, 848–849, 972, 975
TOTAL4514790% 

Tests Skipped Failures Errors Time
62 0 💤 0 ❌ 0 🔥 0.635s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/pypcd4
   __init__.py20100% 
   _version.py11282%5–6
   pointcloud2.py591280%87–101
   pypcd4.py3793391%23–24, 107, 135, 188, 349–350, 572–594, 607–648, 658–659, 828, 848–849, 972, 975
TOTAL4514790% 

Tests Skipped Failures Errors Time
62 0 💤 0 ❌ 0 🔥 0.647s ⏱️

Please sign in to comment.