User Interfaces#

The opynsim.ui module provides utilities for creating and displaying interactive user interfaces, including:

  • High-Level Visualization Functions: Functions prefixed with show_ are typically high-level functions that internally handle initialization, maintaining the GUI main loop, and cleanup for the caller. They are similar to other Python APIs, like matplotlib.pyplot.show and pyvista.Plotter.show.

  • Mid-Level Visualization Builders: TODO.

In effect, opynsim.ui combines the rendering capabilities of the opynsim.graphics module with an application framework that manages interaction. The implementation was ported from the OpenSim Creator, which is compatible with OPynSim’s data files, but doesn’t support scripting.

Example#

import opynsim
import opynsim.ui

# Create/import a `Model` + `ModelState`.
model_specification = opynsim.example_specification_double_pendulum()
model = opynsim.compile_specification(model_specification)
model_state = model.initial_state()
model.realize(model_state, opynsim.ModelStateStage.REPORT)  # usually required for rendering

# Show them in an interactive window.
opynsim.ui.show_model_in_state(model, model_state)

API Reference#

opynsim.ui.show_hello_ui() None#

Displays OPynSim’s ‘hello world’ user interface in a window.

Blocks and runs the GUI main loop until the window is closed.

opynsim.ui.show_model_in_state(model: opynsim._core.Model, model_state: opynsim._core.ModelState, *, dimensions: tuple[int, int] = (640, 480), background_color: collections.abc.Sequence[float] = [1.0, 1.0, 1.0, 1.0], zoom_to_fit: bool = True, draw_floor: bool = False) None#

Displays an interactive visualizer for the given opynsim.Model + opynsim.ModelState in a window.

Blocks and runs the GUI main loop until the window is closed.

Parameters:
  • model (opynsim.Model) – The model to show.

  • model_state (opynsim.ModelState) – The state of the model to show. Should be realized to at least opynsim.ModelStateStage.REPORT.

  • dimensions (tuple[int, int]) – The desired output resolution (width, height) of the window in device-independent pixels.

  • background_color – The desired background color of the rendered scene, specified as normalized floats representing RGBA.

  • zoom_to_fit (bool) – Tells the ui to automatically set up the camera to focus on the center of the bounds of the scene at a distance that can see the entire scene.

  • draw_floor (bool) – Draws a floor, matching the default behavior of Simbody and OpenSim GUI.