3737
3838__docformat__ = "restructuredtext en"
3939
40+ import sys
41+
4042from .registry import converts_from_numpy , converts_to_numpy
4143
4244import array
5961pftype_to_nptype = dict (type_mappings )
6062nptype_to_pftype = dict ((nptype , pftype ) for pftype , nptype in type_mappings )
6163
62- # sizes (in bytes) of PointField types
63- pftype_sizes = {PointField .INT8 : 1 ,
64- PointField .UINT8 : 1 ,
65- PointField .INT16 : 2 ,
66- PointField .UINT16 : 2 ,
67- PointField .INT32 : 4 ,
68- PointField .UINT32 : 4 ,
69- PointField .FLOAT32 : 4 ,
70- PointField .FLOAT64 : 8 }
7164
7265@converts_to_numpy (PointField , plural = True )
7366def fields_to_dtype (fields , point_step ):
@@ -87,7 +80,7 @@ def fields_to_dtype(fields, point_step):
8780 dtype = np .dtype ((dtype , f .count ))
8881
8982 np_dtype_list .append ((f .name , dtype ))
90- offset += pftype_sizes [f .datatype ] * f .count
83+ offset += pftype_to_nptype [f .datatype ]. itemsize * f .count
9184
9285 # might be extra padding between points
9386 while offset < point_step :
@@ -160,7 +153,7 @@ def array_to_pointcloud2(cloud_arr, stamp=None, frame_id=None):
160153 cloud_msg .height = cloud_arr .shape [0 ]
161154 cloud_msg .width = cloud_arr .shape [1 ]
162155 cloud_msg .fields = dtype_to_fields (cloud_arr .dtype )
163- cloud_msg .is_bigendian = False # assumption
156+ cloud_msg .is_bigendian = sys . byteorder != 'little'
164157 cloud_msg .point_step = cloud_arr .dtype .itemsize
165158 cloud_msg .row_step = cloud_msg .point_step * cloud_arr .shape [1 ]
166159 cloud_msg .is_dense = \
0 commit comments