show

m3sh.vis.show(width=1200, height=600, title=None, info=False, shadows=False, *, lmbdown=None, lmbup=None, rmbdown=None, rmbup=None, keydown=None, keyup=None, mousemove=None)[source]

Start the VTK event loop.

Open window for rendering and start the VTK event loop.

Parameters:
  • width (int, optional) – Window width in pixels.

  • height (int, optional) – Window height in pixels.

  • title (str, optional) – Window title.

  • info (bool, optional) – Show rendering backend information.

  • shadows (bool, optional) – Render shadows, experimental.

This is a blocking function, a script will not advance beyond it until the event loop stops. Interaction with displayed objects has to be triggered by mouse and keyboard events and corresponding event handlers, see below.

Keyword Arguments:
  • lmbdown (list[callable]) – Left button press callbacks.

  • lmbup (list[callable]) – Left button release callbacks.

  • rmbdown (list[callable]) – Right button press callbacks.

  • rmbup (list[callable]) – Right button release callbacks.

  • keydown (list[callable]) – Key press callbacks.

  • keyup (list[callable]) – Key release callbacks.

  • mousemove (list[callable]) – Mouse move callbacks.

Mouse and keyboard events

Button and keyboard press and release events as well as mouse move events are recognized. Assign a list of callbacks to the corresponding keyword argument to register callback functions.

Note

If more than one callback is registered to an event, callbacks are executed in the given order.

Callback functions

A callback function’s signature has to be defined in the following way:

m3sh.vis.callback(iren, x, y, **kwargs)
Parameters:
  • iren (vtkRenderWindowInteractor) – Render window interactor.

  • x (int) – Display coordinates of the mouse cursor.

  • y (int) – Display coordinates of the mouse cursor.

When activated the callback receives a handle to the affected render window via the corresponding render window interactor iren as well as the mouse cursor position inside this windows in pixels.

The iren argument can also be used to query the status of modifier keys via its GetShiftKey(), GetAltKey(), and GetControlKey() methods.

Note

An object itself can be used as callback when it implements the __call__() method.

Example

Display a cube. Pressing the space bar will make a screenshot of the current window. Since we do not care about the cursor position when the space bar was pressed the positional arguments x and y are collected in the *args argument and ignored.

1import m3sh.vis as vis
2
3def key_press_callback(iren, *args, **kwargs):
4    if iren.GetKeySym().lower() == 'space':
5        vis.screenshot('box.png')
6
7vis.box([-1, -1, -1], [1, 1, 1], edges=True)
8vis.show(title='box', keydown=[key_press_callback])