5 from sensor_msgs.msg
import PointCloud2, PointField, Image
6 from ros_numpy
import numpy_msg
10 points_arr = np.zeros((npoints,), dtype=[
17 points_arr[
'x'] = np.random.random((npoints,))
18 points_arr[
'y'] = np.random.random((npoints,))
19 points_arr[
'z'] = np.random.random((npoints,))
20 points_arr[
'r'] = np.floor(np.random.random((npoints,))*255) 28 PointField(name=
'x', offset=0, count=1, datatype=PointField.FLOAT32),
29 PointField(name=
'y', offset=4, count=1, datatype=PointField.FLOAT32)
35 conv_fields = ros_numpy.msgify(PointField, dtype, plural=
True)
36 self.assertSequenceEqual(fields, conv_fields,
'dtype->Pointfield Failed with simple values')
38 conv_dtype = ros_numpy.numpify(fields, point_step=8)
39 self.assertSequenceEqual(dtype, conv_dtype,
'dtype->Pointfield Failed with simple values')
43 PointField(name=
'x', offset=0, count=1, datatype=PointField.FLOAT32),
44 PointField(name=
'y', offset=4, count=1, datatype=PointField.FLOAT32),
45 PointField(name=
'vectors', offset=8, count=3, datatype=PointField.FLOAT32)
51 (
'vectors', np.float32, (3,))
54 conv_fields = ros_numpy.msgify(PointField, dtype, plural=
True)
55 self.assertSequenceEqual(fields, conv_fields,
'dtype->Pointfield with inner dimensions')
57 conv_dtype = ros_numpy.numpify(fields, point_step=8)
58 self.assertEqual(dtype, conv_dtype,
'Pointfield->dtype with inner dimensions')
64 cloud_msg = ros_numpy.msgify(PointCloud2, points_arr)
65 new_points_arr = ros_numpy.numpify(cloud_msg)
67 np.testing.assert_equal(points_arr, new_points_arr)
72 cloud_msg = ros_numpy.msgify(
numpy_msg(PointCloud2), points_arr)
73 new_points_arr = ros_numpy.numpify(cloud_msg)
75 np.testing.assert_equal(points_arr, new_points_arr)
77 if __name__ ==
'__main__':
def test_convert_dtype_inner(self)
def test_convert_dtype(self)
def test_roundtrip_numpy(self)
def makeArray(self, npoints)