Snapshot

Snapshot#

Snapshots are photos taken from a rendering view of a VTK polydata.

It can be generated from any .vtp files having scalar arrays in it.

Rendering Polydata#

VTK polydata is a common format for combining a geometric mesh and a array of scalars (data inside cell centers).

To render it, we use PyVista library, which provides methods and objects for rendering and taking a snapshot of the render view. After taking the snapshot, the output image is treated using Pillow, for cropping and adding watermarks, if necessary.

Usage#

Snapshot module does not support running it as a script. Instead it should be used in a jupyter notebook environment, providing a configuration file.

This limitation is due to the fact that PyVista renders the polydata in another window, and it only supports jupyter backend for static rendering.

Here is an example of a configuration file:

polydata:
- file_path: "" # Path of the polydata file
  images:
  - image_label: "" # Label for the output image
    scalar_label: "" # Scalar name for the output image
projection:
  offset: 15 # Distance between projections
  axis: [x_plus, x_minus, y_plus, y_minus] # Select which axis will be projected
  rotation: [0, 0, 0] # Rotation of the original mesh
colormap:
  n_divs: 10 # Scalar bar division
  # target_step: 0.1 # Optional parameter, if specified the number of divisions will be calculated automatically
camera:
  zoom: 1
  offset_position: [0, 0, 0] # Offset from the original mesh center
  view_up: [0, 0, 0] # Direction of view which will be pointing upwards in the image
  window_size: [0, 0] # Rendering window size
  crop:
    width_ratio: 0.8
    height_ratio: 0.8
    watermark_path: "./fixtures/snapshot/axis.png"

In the documentation, there is a notebook with an example for consuming it as an API.