00001 import roslib
00002 roslib.load_manifest('pcl_ros')
00003 import rospy
00004 import random
00005 
00006 from pcl.msg import PointIndices
00007 
00008 rospy.init_node('test_mask_indices')
00009 
00010 pub_indices = rospy.Publisher("/camera/depth/indices", PointIndices, latch=True)
00011 
00012 def getindices(startx, starty, width, height, xstep=1, ystep=1):
00013     """
00014     Deliciously inefficient...
00015     """
00016     out = []
00017     for v in range(starty, starty + height, ystep):
00018         for u in range(startx, startx + width, xstep):
00019             out.append(v * 640 + u)
00020     return out
00021 
00022 startx = 0
00023 starty = 0
00024 xinc = 20
00025 width = 200
00026 width_min = 100
00027 width_max = 300
00028 height = 200
00029 xstep = 1
00030 ystep = 1
00031 vx = 10
00032 vy = 10
00033 indices1 = getindices(0,0,640,480,10,10)
00034 while not rospy.is_shutdown():
00035     ax = random.uniform(-0.5,0.5)
00036     ay = random.uniform(-0.5,0.5)
00037     vx = vx + ax
00038     vy = vy + ay
00039     startx = startx + vx
00040     starty = starty + vy
00041     if starty + height >= 479 or starty <= 0:
00042         vy = -vy
00043 
00044     if startx >= 640 - width or startx <= 0:
00045         vx = -vx
00046     startx = max(0,min(640-width,startx))
00047     starty = max(0,min(480-height,starty))
00048     indices = indices1 + getindices(startx, starty, width, height, xstep, ystep)
00049     
00050     rospy.loginfo('Publishing indices.. First index = %d, Last = %d, N = %d, startx = %d, starty = %d' 
00051                   % (indices[0], indices[-1], len(indices), startx, starty))
00052     pub_indices.publish(PointIndices(indices=indices))
00053     rospy.sleep(0.1)
00054