segment_array_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import numpy as np
00004 from scipy.spatial import ConvexHull
00005 
00006 import rospy
00007 from jsk_recognition_msgs.msg import Segment
00008 from jsk_recognition_msgs.msg import SegmentArray
00009 from geometry_msgs.msg import Point
00010 
00011 
00012 def main():
00013     rospy.init_node('segment_array_sample')
00014 
00015     pub = rospy.Publisher('~output', SegmentArray, queue_size=1)
00016     r = rospy.Rate(rospy.get_param('~rate', 1.0))
00017 
00018     segment_array = SegmentArray()
00019     segment_array.header.frame_id = rospy.get_param('~frame_id', 'map')
00020 
00021     N = 30
00022     while not rospy.is_shutdown():
00023         points = np.random.rand(N, 3)
00024         hull = ConvexHull(points)
00025         segment_array.header.stamp = rospy.Time.now()
00026         segment_array.segments = []
00027         for i in hull.simplices:
00028             a, b, c = points[i]
00029             segment_array.segments.extend(
00030                 [Segment(start_point=Point(a[0], a[1], a[2]),
00031                          end_point=Point(b[0], b[1], b[2])),
00032                  Segment(start_point=Point(b[0], b[1], b[2]),
00033                          end_point=Point(c[0], c[1], c[2])),
00034                  Segment(start_point=Point(a[0], a[1], a[2]),
00035                          end_point=Point(c[0], c[1], c[2])),
00036                 ])
00037         pub.publish(segment_array)
00038         r.sleep()
00039 
00040 
00041 if __name__ == '__main__':
00042     main()


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Wed May 1 2019 02:40:22