Vtkjs

Download this notebook from GitHub (right-click to download).


In [1]:
import panel as pn
pn.extension('vtk')

The VTK pane renders vtk.js files inside a panel, making it possible to load and interact with complex geometries in 3D.

Parameters:

For layout and styling related parameters see the customization user guide.

  • axes (dict): A dictionary with the parameters of the axes to construct in the 3D view. Must contain at least xticker, yticker and zticker.

    • [x|y|z]ticker is a dictionary which contains:

      • ticks (array of numbers) - required. Positions in the scene coordinates of the corresponding axis ticks
      • labels (array of strings) - optional. Label displayed respectively to the ticks positions.

        If labels are not defined they are inferred from the ticks array.

    • digits: number of decimal digits when ticks are converted to labels.
    • fontsize: size in pts of the ticks labels.
    • show_grid: boolean. If true (default) the axes grid is visible.
    • grid_opacity: float between 0-1. Defines the grid opacity.
    • axes_opacity: float between 0-1. Defines the axes lines opacity.
  • camera (dict): A dictionary reflecting the current state of the VTK camera
  • enable_keybindings (bool): A boolean to activate/deactivate keybindings. Bound keys are:

    • s: set representation of all actors to surface
    • w: set representation of all actors to wireframe
    • v: set representation of all actors to vertex
    • r: center the actors and move the camera so that all actors are visible

    The mouse must be over the pane to work.
    Warning: These keybindings may not work as expected in a notebook context, if they interact with already bound keys.

  • orientation_widget (bool): A boolean to activate/deactivate the orientation widget in the 3D pane.
  • ìnteractive_orientation_widget (bool): If True the orientation widget is clickable and allows to rotate the scene in one of the orthographic projections.
  • object (str or object): Can be a string pointing to a local or remote file with a .vtkjs extension.

The simplest way to construct a VTK pane is to give it a vtk.js file which it will serialize and embed in the plot. The VTK pane also supports the regular sizing options provided by Bokeh, including responsive sizing modes:

In [2]:
vtk_pane = pn.pane.VTK('https://raw.githubusercontent.com/Kitware/vtk-js/master/Data/StanfordDragon.vtkjs',
                     sizing_mode='stretch_width', height=400, enable_keybindings=True, orientation_widget=True)
vtk_pane
Out[2]: