timor.utilities.visualization ============================= .. py:module:: timor.utilities.visualization Attributes ---------- .. autoapisummary:: timor.utilities.visualization.DEFAULT_APPEARANCE timor.utilities.visualization.DEFAULT_COLOR timor.utilities.visualization.DEFAULT_COLOR_MAP Classes ------- .. autoapisummary:: timor.utilities.visualization.MeshcatVisualizerWithAnimation Functions --------- .. autoapisummary:: timor.utilities.visualization.adapt_appearance timor.utilities.visualization.animation timor.utilities.visualization.center_camera timor.utilities.visualization.clear_visualizer timor.utilities.visualization.color_visualization timor.utilities.visualization.drawable_coordinate_system timor.utilities.visualization.place_arrow timor.utilities.visualization.place_billboard timor.utilities.visualization.place_sphere timor.utilities.visualization.plot_time_series timor.utilities.visualization.save_visualizer_scene timor.utilities.visualization.save_visualizer_screenshot Module Contents --------------- .. py:data:: DEFAULT_APPEARANCE :value: (('/Background', 'visible', False), ('/Lights/SpotLight', 'visible', True),... .. py:data:: DEFAULT_COLOR .. py:data:: DEFAULT_COLOR_MAP .. py:class:: MeshcatVisualizerWithAnimation .. autoapi-inheritance-diagram:: timor.utilities.visualization.MeshcatVisualizerWithAnimation :parts: 1 :private-bases: Extends Pinocchio's MeshcatVisualizer by create_animation_frame. This creates an animation from the current state of all pinocchio robots within the scene; .. py:method:: create_animation_frame(geometry_type, frame) Can be used to capture the current visualizer state as an animation frame .. py:method:: from_MeshcatVisualizer(vis) :classmethod: Turn a normal MeshcatVisualizer into a MeshcatVisualizerWithAnimation .. py:function:: adapt_appearance(viz, settings = DEFAULT_APPEARANCE) Applies the given appearance to the visualizer window. .. py:function:: animation(robot, q, dt, visualizer = None, appearance = DEFAULT_APPEARANCE) Creates an animation of a robot movement. :param robot: The robot to animate :param q: The joint angles to animate :param dt: The time step between frames :param visualizer: If given, the movie will be generated in the existing visualizer :param appearance: Looks of the visualizer window. .. py:function:: center_camera(viz, around) Centers the camera of the viewer window s.t. it targets the origin (if it is not already centered otherwise). It is placed behind the "around" placement, s.t. any object placed there is shown prominently. The camera will, as common in robotics, be placed above the object. :param viz: The viewer to center (e.g. from `MeshcatVisualizer`) :param around: The point to look at .. py:function:: clear_visualizer(visualizer) Clears the viewer window, i.e. leaving it open but removing all objects that are typically set. Usually, visualizer.clean() alone should be enough, but at some occasions this does not work. This method has been tested to work in all cases so far. :param visualizer: The visualizer to clear .. py:function:: color_visualization(viz, assembly, color_map = None, appearance = DEFAULT_APPEARANCE) Adds colors to a visualized robot in viz, depending on module types. This method only works for visualizers that already contain a (colorless) visualization of the robot based on the provided assembly. It will then color the robot according to the provided color_map. :param viz: The visualizer to color :param assembly: The assembly (that can already be visualized in viz) to color :param color_map: A dictionary mapping module integer enumerated module types OR module IDs OR geometry names to colors. If color_map maps module IDs to colors, this method first tries to interpret them as custom module IDs matching the internal representation in the assembly. If this fails, it will interpret them as original IDs. :param appearance: Looks of the visualizer window; an example is given by DEFAULT_APPEARANCE .. py:function:: drawable_coordinate_system(placement, scale = 1.0) A visual representation of the origin of a coordinate system. The coordinate axis are drawn as three lines in red, green, and blue along the x, y, and z axes. The `scale` parameter controls the length of the three lines. Returns an `Object` which can be passed to `set_object()` Other than meshcat.geometry.triad, this allows drawing the triad in any coordinate system, which is defined by . :param placement: 4x4 homogeneous transformation :param scale: Length of the drawn vectors for the coordinate system main axes :return: A meshcat object that can be visualized via viewer[your_name].set_object(this) .. py:function:: place_arrow(viz, name, material = meshcat.geometry.MeshBasicMaterial(), scale = 1.0, placement = transformation.Transformation.neutral(), axis = 'z') Creates a composed meshcat geometry object that looks like an arrow. :param viz: Visualizer instance to draw into :param name: Unique object name for the visualizer :param material: If provided, this defines the appearance (e.g. color) :param scale: Arrow length in meters will be 0.1 * scale :param placement: Defines orientation and placement of the arrow. :param axis: Axis alignment of the arrow. The default is alignment to the z-axis in the "placement" coordinate frame .. py:function:: place_billboard(viz, text, name, placement, text_color = 'black', background_color = 'transparent', scale = 1.0, base_width = 100, font_size = 32, super_sample = 4.0) Add a billboard (2D text) to the visualization. Note needs to install additional dependency with `pip install timor-python.[viz]`. :param viz: MeshcatVisualizer instance to draw into (viz.viewer if you have a MeshcatVisualizer). :param text: Text to be displayed (does not support newline but many of the unicode characters, s.a. emoticons). :param name: Unique object name within the visualizer (overwrites existing object with same name). :param placement: Defines placement of the billboard. :param text_color: Color of the text (CSS4 color name or hex code, e.g. #abcdef). :param background_color: Color of the background (CSS4 color name or hex code, e.g. #abcdef). :param scale: Scaling factor for the text and billboard size. :param base_width: (Max) width of the billboard in pixels; will be smaller if text is shorter. :param font_size: Font size in pixels. :param super_sample: How much to increase font_size and base_width and reduce scale to get crisper text. .. py:function:: place_sphere(viz, name, radius, placement, material = meshcat.geometry.MeshBasicMaterial()) Place a sphere with name, radius and color at a specific placement. :param viz: MeshcatVisualizer instance to draw into (viz.viewer if you have a MeshcatVisualizer) :param name: Unique object name within the visualizer :param radius: Sphere radius in meters :param placement: Defines placement of the sphere. :param material: material used to render this sphere .. py:function:: plot_time_series(times, data, marker = None, additional_subplots = 0, show_figure = False, subplot_kwargs = None) Helper to plot time series data :param times: Time (x-value) for the sampled data at N steps :param data: Timeseries, each containing a NxM array of N samples of M-dimensional data at each time in times and an axis label for this data; creates one subplot per timeseries :param marker: A dictionary where keys are times to draw a marking line with label and color at :param additional_subplots: leave space for more subplots :param show_figure: Call show on returned figure :param subplot_kwargs: Kwargs handed to subplots, including pyplot.figure kwargs (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html) :return: figure containing all these .. py:function:: save_visualizer_scene(viz, filename, overwrite = False, camera_transform = None) Saves the current visualizer scene as static html file. Other than save_visualizer_screenshot(), this method does not require the viewer to be open. :param viz: MeshcatVisualizer instance :param filename: Filename to save the screenshot to. If it does not end with .html, it will be appended. :param overwrite: If True, the file will be overwritten if it already exists. :param camera_transform: If provided, the camera will be placed at this transformation before saving the scene. .. py:function:: save_visualizer_screenshot(viz, filename, overwrite = False, timeout_seconds = 1, camera_transform = None, open_at_timeout = False, crop_to_content = False) Takes a screenshot of the current visualizer viewer and saves it to a png file. The get_image() method for a MeshcatVisualizer only works when the viewer is open. If not, it stalls forever, which is why a timeout is used here. :param viz: MeshcatVisualizer instance :param filename: Filename to save the screenshot to. If it does not end with .png, it will be appended. :param overwrite: If True, the file will be overwritten if it already exists. :param timeout_seconds: Timeout (integers only). If getting the screenshot is not successfull during this time, nothing will be saved. This is commonly the case when the viewer is not open. :param camera_transform: If provided, this will be the '/Cameras/default' setting used to take the screenshot. :param open_at_timeout: If True, the viewer will be opened if the timeout is reached. If so, this method will be called again, trying to take the screenshot a second time :param crop_to_content: If true, crops the image to the bounding box of the content. This only affects the image if the background is transparent (a filled background counts as content).