Go to the documentation of this file.00001 import roslib; roslib.load_manifest('python_msg_conversions')
00002
00003 def point_arrays_equal(points1, points2):
00004 if not points1.dtype == points2.dtype:
00005 return False
00006
00007 for field_name in points1.dtype.names:
00008 if not (points1[field_name] == points2[field_name]).all():
00009 return False
00010 return True
00011
00012 def test_roundtrip():
00013 from python_msg_conversions import pointclouds
00014 import numpy as np
00015
00016 npoints = 100
00017
00018 points_arr = np.zeros((npoints,), dtype=[
00019 ('x', np.float32),
00020 ('y', np.float32),
00021 ('z', np.float32),
00022 ('r', np.uint8),
00023 ('g', np.uint8),
00024 ('b', np.uint8)])
00025 points_arr['x'] = np.random.random((npoints,))
00026 points_arr['y'] = np.random.random((npoints,))
00027 points_arr['z'] = np.random.random((npoints,))
00028 points_arr['r'] = np.floor(np.random.random((npoints,))*255)
00029 points_arr['g'] = 0
00030 points_arr['b'] = 255
00031
00032 cloud_msg = pointclouds.array_to_pointcloud2(points_arr, merge_rgb=True)
00033 new_points_arr = pointclouds.pointcloud2_to_array(cloud_msg, split_rgb=True)
00034
00035 assert(point_arrays_equal(points_arr, new_points_arr))
00036