point_cloud_utils.py
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 ## PointCloud  -> 3xN np matrix
00013 # @param ros_pointcloud - robot_msgs/PointCloud
00014 # @return 3xN np matrix
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 ## list of Point32 points  -> 3xN np matrix
00021 # @param ros_points - Point32[ ] (for e.g. from robot_msgs/PointCloud or Polygon3D)
00022 # @return 3xN np matrix
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 ## 3xN np matrix -> ros PointCloud
00031 # @param pts - 3xN np matrix
00032 # @return PointCloud as defined in robot_msgs/msg/PointCloud.msg
00033 def np_points_to_ros(pts):
00034     p_list = []
00035     chlist = []
00036 
00037 #    p_list = [Point32(p[0,0], p[0,1], p[0,2]) for p in pts.T]
00038 #    chlist = np.zeros(pts.shape[1]).tolist()
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 


rfid_datacapture
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 12:11:16