if __name__ == '__main__': # We'll open the visualizer by spawning it as a subprocess. vis_binary = os.path.join(os.path.dirname(sys.executable), "drake-visualizer") # The viewer will take some time to load before it is ready to receive # messages, so we'll wait until it sends its first status message. print "waiting for viewer to initialize" lc = lcm.LCM() lc.subscribe("DIRECTOR_TREE_VIEWER_RESPONSE", lambda c, d: None) vis_process = subprocess.Popen([vis_binary, '--testing', '--interactive']) # Wait for one LCM message to be received. lc.handle() vis = Visualizer("lines") vis["basic_line"].setgeometry(PolyLine([[0, 0, 0], [0, 0, 1]])) vis["arrow_end"].setgeometry(PolyLine([[.1, 0, 0], [.1, 0, 1]], end_head=True)) vis["arrow_start"].setgeometry(PolyLine([[-.1, 0, 0], [-.1, 0, 1]], start_head=True)) vis["loop"].setgeometry(PolyLine([[1, 0, 0], [1, 1, 0.5], [1, 0, 1]], closed=True)) vis["poly_arrow"].setgeometry(PolyLine([[0, 1, 0], [0, 1, 1], [-1, 1, 1]], start_head=True, end_head=True)) vis["colored_hairline"].setgeometry(GeometryData(PolyLine([[0, -1, 0], [0, -1, 1]], radius=0), color=[0, 0.2, 0.8, 0.5])) vis["sharp_arrow"].setgeometry(PolyLine([[-1, 0, 0.5], [-0.5, 0, 0.5]], end_head=True, head_length=0.2))
# We'll open the visualizer by spawning it as a subprocess. vis_binary = os.path.join(os.path.dirname(sys.executable), "drake-visualizer") # The viewer will take some time to load before it is ready to receive # messages, so we'll wait until it sends its first status message. print("waiting for viewer to initialize") lc = lcm.LCM() lc.subscribe("DIRECTOR_TREE_VIEWER_RESPONSE", lambda c, d: None) vis_process = subprocess.Popen([vis_binary, '--testing', '--interactive']) # Wait for one LCM message to be received. lc.handle() # We can provide an initial path if we want vis = Visualizer(path="/root/folder1") vis["boxes"].setgeometry( [GeometryData(Box([1, 1, 1]), color=np.hstack((np.random.rand(3), 0.5)), transform=transformations.translation_matrix([x, -2, 0])) for x in range(10)]) # Index into the visualizer to get a sub-tree. vis.__getitem__ is lazily # implemented, so these sub-visualizers come into being as soon as they're # asked for vis = vis["group1"] box_vis = vis["box"] sphere_vis = vis["sphere"]
# instead. vis_binary = os.path.join(os.path.dirname(sys.executable), "drake-visualizer") # The viewer will take some time to load before it is ready to receive # messages, so we'll wait until it sends its first status message. print "waiting for viewer to initialize" lc = lcm.LCM() lc.subscribe("DIRECTOR_TREE_VIEWER_RESPONSE", lambda c, d: None) vis_process = subprocess.Popen([vis_binary, '--testing', '--interactive']) # Wait for one LCM message to be received. lc.handle() # We can provide an initial path if we want vis = Visualizer(path="/root/folder1") vis["boxes"].setgeometry( [GeometryData(Box([1, 1, 1]), color=np.hstack((np.random.rand(3), 0.5)), transform=transformations.translation_matrix([x, -2, 0])) for x in range(10)]) # Index into the visualizer to get a sub-tree. vis.__getitem__ is lazily # implemented, so these sub-visualizers come into being as soon as they're # asked for vis = vis["group1"] box_vis = vis["box"] sphere_vis = vis["sphere"]