Go to the documentation of this file.00001
00002
00003 import dynamic_reconfigure.server
00004 from geometry_msgs.msg import PolygonStamped
00005 from geometry_msgs.msg import Point32
00006 from jsk_recognition_msgs.msg import PolygonArray
00007 from jsk_recognition_msgs.msg import RectArray
00008 from jsk_topic_tools import ConnectionBasedTransport
00009 from jsk_recognition_utils.cfg import PolygonArrayToPolygonConfig
00010 import rospy
00011
00012
00013 class RectArrayToPolygonArray(ConnectionBasedTransport):
00014
00015 def __init__(self):
00016 super(RectArrayToPolygonArray, self).__init__()
00017 self.pub = self.advertise('~output', PolygonArray, queue_size=1)
00018 dynamic_reconfigure.server.Server(PolygonArrayToPolygonConfig,
00019 self._config_callback)
00020
00021 def subscribe(self):
00022 self.sub = rospy.Subscriber('~input', RectArray, self._convert)
00023
00024 def unsubscribe(self):
00025 self.sub.unregister()
00026
00027 def _config_callback(self, config, level):
00028 self.index = config.index
00029 return config
00030
00031 def _convert(self, msg):
00032 polys_msg = PolygonArray()
00033 polys_msg.header = msg.header
00034 for rect in msg.rects:
00035 poly_msg = PolygonStamped()
00036 poly_msg.header = msg.header
00037 pt0 = Point32(x=rect.x, y=rect.y)
00038 pt1 = Point32(x=rect.x + rect.width, y=rect.y + rect.height)
00039 poly_msg.polygon.points.append(pt0)
00040 poly_msg.polygon.points.append(pt1)
00041 polys_msg.polygons.append(poly_msg)
00042 self.pub.publish(polys_msg)
00043
00044
00045 if __name__ == '__main__':
00046 rospy.init_node('rect_array_to_polygon_array')
00047 RectArrayToPolygonArray()
00048 rospy.spin()