Skip to content

Commit

Permalink
Merge branch 'pr4' into rolling
Browse files Browse the repository at this point in the history
  • Loading branch information
tpanzarella committed May 16, 2022
2 parents c21b523 + b008191 commit 78f1ebf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 4 additions & 11 deletions ros2_numpy/point_cloud2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

__docformat__ = "restructuredtext en"

import sys

from .registry import converts_from_numpy, converts_to_numpy

import array
Expand All @@ -59,15 +61,6 @@
pftype_to_nptype = dict(type_mappings)
nptype_to_pftype = dict((nptype, pftype) for pftype, nptype in type_mappings)

# sizes (in bytes) of PointField types
pftype_sizes = {PointField.INT8: 1,
PointField.UINT8: 1,
PointField.INT16: 2,
PointField.UINT16: 2,
PointField.INT32: 4,
PointField.UINT32: 4,
PointField.FLOAT32: 4,
PointField.FLOAT64: 8}

@converts_to_numpy(PointField, plural=True)
def fields_to_dtype(fields, point_step):
Expand All @@ -87,7 +80,7 @@ def fields_to_dtype(fields, point_step):
dtype = np.dtype((dtype, f.count))

np_dtype_list.append((f.name, dtype))
offset += pftype_sizes[f.datatype] * f.count
offset += pftype_to_nptype[f.datatype].itemsize * f.count

# might be extra padding between points
while offset < point_step:
Expand Down Expand Up @@ -160,7 +153,7 @@ def array_to_pointcloud2(cloud_arr, stamp=None, frame_id=None):
cloud_msg.height = cloud_arr.shape[0]
cloud_msg.width = cloud_arr.shape[1]
cloud_msg.fields = dtype_to_fields(cloud_arr.dtype)
cloud_msg.is_bigendian = False # assumption
cloud_msg.is_bigendian = sys.byteorder != 'little'
cloud_msg.point_step = cloud_arr.dtype.itemsize
cloud_msg.row_step = cloud_msg.point_step*cloud_arr.shape[1]
cloud_msg.is_dense = \
Expand Down
4 changes: 2 additions & 2 deletions ros2_numpy/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
import collections
from collections.abc import Sequence

_to_numpy = {}
_from_numpy = {}
Expand All @@ -21,7 +21,7 @@ def numpify(msg, *args, **kwargs):
return

conv = _to_numpy.get((msg.__class__, False))
if not conv and isinstance(msg, collections.Sequence):
if not conv and isinstance(msg, Sequence):
if not msg:
raise ValueError("Cannot determine the type of an empty Collection")
conv = _to_numpy.get((msg[0].__class__, True))
Expand Down

0 comments on commit 78f1ebf

Please sign in to comment.