Go to the documentation of this file.00001 import roslib
00002 roslib.load_manifest('sensor_msgs')
00003 roslib.load_manifest('geometry_msgs')
00004 import rospy
00005
00006 from sensor_msgs.msg import PointCloud
00007 from geometry_msgs.msg import Point32
00008 from sensor_msgs.msg import ChannelFloat32
00009 import numpy as np
00010 import time
00011
00012
00013
00014
00015 def ros_pointcloud_to_np(ros_pointcloud):
00016 ''' ros PointCloud.pts -> 3xN numpy matrix
00017 '''
00018 return ros_pts_to_np(ros_pointcloud.points)
00019
00020
00021
00022
00023 def ros_pts_to_np(ros_pts):
00024 pts_list = []
00025 for p in ros_pts:
00026 pts_list.append([p.x,p.y,p.z])
00027
00028 return np.matrix(pts_list).T
00029
00030
00031
00032
00033 def np_points_to_ros(pts):
00034 p_list = []
00035 chlist = []
00036
00037
00038
00039 for p in pts.T:
00040 p_list.append(Point32(p[0,0],p[0,1],p[0,2]))
00041 chlist.append(0.)
00042
00043 ch = ChannelFloat32('t',chlist)
00044 pc = PointCloud()
00045 pc.points = p_list
00046 pc.channels = [ch]
00047 return pc
00048
00049