def show(animate=False, axis=np.array([0., 0., 1.]), clf=True, **kwargs): """Display the current figure and enable interaction. Parameters ---------- animate : bool Whether or not to animate the scene. axis : (3,) float or None If present, the animation will rotate about the given axis in world coordinates. Otherwise, the animation will rotate in azimuth. clf : bool If true, the Visualizer is cleared after showing the figure. kwargs : dict Other keyword arguments for the SceneViewer instance. """ x = SceneViewer(Visualizer3D._scene, size=Visualizer3D._init_size, animate=animate, animate_axis=axis, save_directory=Visualizer3D._save_directory, **kwargs) if x.save_directory: Visualizer3D._save_directory = x.save_directory if clf: Visualizer3D.clf()
def render(n_frames=1, axis=np.array([0., 0., 1.]), clf=True, **kwargs): """Render frames from the viewer. Parameters ---------- n_frames : int Number of frames to render. If more than one, the scene will animate. axis : (3,) float or None If present, the animation will rotate about the given axis in world coordinates. Otherwise, the animation will rotate in azimuth. clf : bool If true, the Visualizer is cleared after rendering the figure. kwargs : dict Other keyword arguments for the SceneViewer instance. Returns ------- list of perception.ColorImage A list of ColorImages rendered from the viewer. """ v = SceneViewer(Visualizer3D._scene, size=Visualizer3D._init_size, animate=(n_frames > 1), animate_axis=axis, max_frames=n_frames, **kwargs) if clf: Visualizer3D.clf() return v.saved_frames
def save(filename, n_frames=1, axis=np.array([0., 0., 1.]), clf=True, **kwargs): """Save frames from the viewer out to a file. Parameters ---------- filename : str The filename in which to save the output image. If more than one frame, should have extension .gif. n_frames : int Number of frames to render. If more than one, the scene will animate. axis : (3,) float or None If present, the animation will rotate about the given axis in world coordinates. Otherwise, the animation will rotate in azimuth. clf : bool If true, the Visualizer is cleared after rendering the figure. kwargs : dict Other keyword arguments for the SceneViewer instance. """ if n_frames > 1 and os.path.splitext(filename)[1] != '.gif': raise ValueError('Expected .gif file for multiple-frame save.') v = SceneViewer(Visualizer3D._scene, size=Visualizer3D._init_size, animate=(n_frames > 1), animate_axis=axis, max_frames=n_frames, **kwargs) data = [m.data for m in v.saved_frames] if len(data) > 1: imageio.mimwrite(filename, data, fps=v._animate_rate, palettesize=128, subrectangles=True) else: imageio.imwrite(filename, data[0]) if clf: Visualizer3D.clf()
'elevation': { 'min': 0.10, 'max': 10.0, }, 'roll': { 'min': -0.2, 'max': 0.2, }, 'x': { 'min': -0.01, 'max': 0.01, }, 'y': { 'min': -0.01, 'max': 0.01, }, 'im_width': 600, 'im_height': 600 } urv = UniformPlanarWorksurfaceImageRandomVariable('pawn', scene, [RenderMode.COLOR], 'camera', cfg) renders = urv.sample(10, front_and_back=True) for i, render in enumerate(renders): color = render.renders[RenderMode.COLOR] color.save('output/random_{}.jpg'.format(i)) v = SceneViewer(scene, raymond_lighting=True)