timor.utilities.visualization
Attributes
Classes
Extends Pinocchio's MeshcatVisualizer by create_animation_frame. |
Functions
|
Applies the given appearance to the visualizer window. |
|
Creates an animation of a robot movement. |
|
Centers the camera of the viewer window s.t. it targets the origin (if it is not already centered otherwise). |
|
Clears the viewer window, i.e. leaving it open but removing all objects that are typically set. |
|
Adds colors to a visualized robot in viz, depending on module types. |
|
A visual representation of the origin of a coordinate system. |
|
Creates a composed meshcat geometry object that looks like an arrow. |
|
Add a billboard (2D text) to the visualization. |
|
Place a sphere with name, radius and color at a specific placement. |
|
Helper to plot time series data |
|
Saves the current visualizer scene as static html file. |
|
Takes a screenshot of the current visualizer viewer and saves it to a png file. |
Module Contents
- timor.utilities.visualization.DEFAULT_APPEARANCE = (('/Background', 'visible', False), ('/Lights/SpotLight', 'visible', True),...
- timor.utilities.visualization.DEFAULT_COLOR
- timor.utilities.visualization.DEFAULT_COLOR_MAP
- class timor.utilities.visualization.MeshcatVisualizerWithAnimation

Extends Pinocchio’s MeshcatVisualizer by create_animation_frame.
This creates an animation from the current state of all pinocchio robots within the scene;
- create_animation_frame(geometry_type, frame)
Can be used to capture the current visualizer state as an animation frame
- classmethod from_MeshcatVisualizer(vis)
Turn a normal MeshcatVisualizer into a MeshcatVisualizerWithAnimation
- Parameters:
vis (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer)
- Return type:
- timor.utilities.visualization.adapt_appearance(viz, settings=DEFAULT_APPEARANCE)
Applies the given appearance to the visualizer window.
- timor.utilities.visualization.animation(robot, q, dt, visualizer=None, appearance=DEFAULT_APPEARANCE)
Creates an animation of a robot movement.
- Parameters:
robot (Robot.PinRobot) – The robot to animate
q (numpy.ndarray) – The joint angles to animate
dt (float) – The time step between frames
visualizer (Union[pinocchio.visualize.MeshcatVisualizer, MeshcatVisualizerWithAnimation]) – If given, the movie will be generated in the existing visualizer
appearance (Tuple[str, str, float]) – Looks of the visualizer window.
- Return type:
- timor.utilities.visualization.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.
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – The viewer to center (e.g. from MeshcatVisualizer)
around (Union[numpy.ndarray, List[float], Tuple[float, float, float]]) – The point to look at
- timor.utilities.visualization.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.
- Parameters:
visualizer (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – The visualizer to clear
- timor.utilities.visualization.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.
- Parameters:
appearance (Tuple[str, str, float]) – Looks of the visualizer window; an example is given by DEFAULT_APPEARANCE
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer)
assembly (timor.ModuleAssembly)
color_map (Dict[Union[str, int, timor.utilities.module_classification.ModuleType], numpy.ndarray])
- timor.utilities.visualization.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 <original coordinate system @ transformation>.
- Parameters:
placement (timor.utilities.transformation.TransformationLike) – 4x4 homogeneous transformation
scale (float) – Length of the drawn vectors for the coordinate system main axes
- Returns:
A meshcat object that can be visualized via viewer[your_name].set_object(this)
- Return type:
meshcat.geometry
- timor.utilities.visualization.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.
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – Visualizer instance to draw into
name (str) – Unique object name for the visualizer
material (meshcat.geometry.Material) – If provided, this defines the appearance (e.g. color)
scale (float) – Arrow length in meters will be 0.1 * scale
placement (timor.utilities.transformation.TransformationLike) – Defines orientation and placement of the arrow.
axis (str) – Axis alignment of the arrow. The default is alignment to the z-axis in the “placement” coordinate frame
- Return type:
None
- timor.utilities.visualization.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].
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – MeshcatVisualizer instance to draw into (viz.viewer if you have a MeshcatVisualizer).
text (str) – Text to be displayed (does not support newline but many of the unicode characters, s.a. emoticons).
name (str) – Unique object name within the visualizer (overwrites existing object with same name).
placement (timor.utilities.transformation.TransformationConvertable) – Defines placement of the billboard.
text_color (str) – Color of the text (CSS4 color name or hex code, e.g. #abcdef).
background_color (str) – Color of the background (CSS4 color name or hex code, e.g. #abcdef).
scale (float) – Scaling factor for the text and billboard size.
base_width (int) – (Max) width of the billboard in pixels; will be smaller if text is shorter.
font_size (int) – Font size in pixels.
super_sample (float) – How much to increase font_size and base_width and reduce scale to get crisper text.
- timor.utilities.visualization.place_sphere(viz, name, radius, placement, material=meshcat.geometry.MeshBasicMaterial())
Place a sphere with name, radius and color at a specific placement.
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – MeshcatVisualizer instance to draw into (viz.viewer if you have a MeshcatVisualizer)
name (str) – Unique object name within the visualizer
radius (float) – Sphere radius in meters
placement (timor.utilities.transformation.Transformation) – Defines placement of the sphere.
material (meshcat.geometry.Material) – material used to render this sphere
- timor.utilities.visualization.plot_time_series(times, data, marker=None, additional_subplots=0, show_figure=False, subplot_kwargs=None)
Helper to plot time series data
- Parameters:
times (Sequence[float]) – Time (x-value) for the sampled data at N steps
data (Sequence[Tuple[numpy.ndarray, str]]) – 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
marker (Dict[float, Tuple[str, str]]) – A dictionary where keys are times to draw a marking line with label and color at
additional_subplots (int) – leave space for more subplots
show_figure (bool) – Call show on returned figure
subplot_kwargs (Optional[Dict]) – Kwargs handed to subplots, including pyplot.figure kwargs (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html)
- Returns:
figure containing all these
- Return type:
matplotlib.pyplot.Figure
- timor.utilities.visualization.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.
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – MeshcatVisualizer instance
filename (Union[pathlib.Path, str]) – Filename to save the screenshot to. If it does not end with .html, it will be appended.
overwrite (bool) – If True, the file will be overwritten if it already exists.
camera_transform (Optional[timor.utilities.transformation.Transformation]) – If provided, the camera will be placed at this transformation before saving the scene.
- timor.utilities.visualization.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.
- Parameters:
viz (pinocchio.visualize.meshcat_visualizer.MeshcatVisualizer) – MeshcatVisualizer instance
filename (Union[pathlib.Path, str]) – Filename to save the screenshot to. If it does not end with .png, it will be appended.
overwrite (bool) – If True, the file will be overwritten if it already exists.
timeout_seconds (int) – 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.
camera_transform (Optional[timor.utilities.transformation.Transformation]) – If provided, this will be the ‘/Cameras/default’ setting used to take the screenshot.
open_at_timeout (bool) – 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
crop_to_content (bool) – 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).