diff --git a/ros2_numpy/point_cloud2.py b/ros2_numpy/point_cloud2.py index 0c1bfa5..fa65c58 100644 --- a/ros2_numpy/point_cloud2.py +++ b/ros2_numpy/point_cloud2.py @@ -37,6 +37,8 @@ __docformat__ = "restructuredtext en" +import sys + from .registry import converts_from_numpy, converts_to_numpy import array @@ -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): @@ -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: @@ -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 = \ diff --git a/ros2_numpy/registry.py b/ros2_numpy/registry.py index 57a071d..f2bf189 100644 --- a/ros2_numpy/registry.py +++ b/ros2_numpy/registry.py @@ -1,5 +1,5 @@ import functools -import collections +from collections.abc import Sequence _to_numpy = {} _from_numpy = {} @@ -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))