Simple VTK Visualization¶
This module contains utilities for working with VTK visualizations.
Simple VTK Viewer¶
The simple vtk viewer is a limited viewer class that wraps most of the vtk boilerplate code. It is meant to do simple tests or to use interactively from the python console.
-
class
SimpleVtkViewer
[source]¶ A very simple windows with vtk renderers and interactors.
This class is intended for interactive work and fast prototyping. As such it is very simple and limited. For full interactive applications consider using
subject_viewer
-
addImg
(img)[source]¶ Use this method to show an image inside an image plane widget.
Parameters: img (vtkImageData) – Image Returns: The created imagePlaneWidget
-
addPolyData
(polyData, LUT=None)[source]¶ Adds a poly data to the viewer, a LUT can be set.
Parameters: - polyData (vtkPolyData) – Polydata object to add to the scene
- LUT (vtkScalarsToColors) – A lookup table to apply to the polydata
Returns: The vtkActor instance created, it may be used to change the visual properties
-
VTK Widgets¶
Warning
Sphinx bug, methods are not static
-
class
persistentImagePlane
(orientation=0)[source]¶ A vtkImagePlaneWidget which can keep its state between calls to SetInputData.
It adds a second text message showing the mm coordinates of the cursors This message can be further enhanced by using a label image and a label dictionary Additionally the values displayed in the first message can be replaced by values taken from another image, this is useful when the displayed image contains colors or other contexts that are not the main value (ex, fmri) Finally, this class generates custom events when moving the cursor and when changing the slice.
-
SetInputData
(img)[source]¶ Changes the input data por the plane widget
Parameters: img (vtkImageData) – New image data
-
SetInteractor
(iact)[source]¶ Links the widget to an interactor
Parameters: iact (vtkRenderWindowInteractor) – Render window interactor
-
addLabels
(label_img)[source]¶ A second image can be used to get labels for image coordinates (ex. aparc)
Parameters: label_img (vtkImageData) – Image to use as reference for labels
-
get_label
(x, y, z)[source]¶ Auxiliary function to get the label in a given coordinate (in mm)
Parameters: Returns: If a lookuptable is set returns the text label, otherwise the numeric label
-
setLabelsLut
(lut)[source]¶ A lookup table can be used to translate numeric labels into text labels
Parameters: lut (vtkLookupTable) – Lookup table
-
set_orientation
(orientation)[source]¶ Sets image plane orientation
Parameters: orientation (int) – x:0 , y:1, z:2
-
text1_to_std
()[source]¶ Turn text1 behaviour back to standard, reverts the effects of text1_value_from_img
-
text1_value_from_img
(img2)[source]¶ Text 1 value can be read from a different image than the one been shown, useful for composed images
Parameters: img2 (vtkImageData) – Image to get values for lower left corner text
-
-
class
OutlineActor
[source]¶ A simple shortcut for displaying the outline of an object
Encapsulates an outline filter, a mapper and an actor
-
SetInputData
(input_data)[source]¶ For better compatibility with vtk methods style
Parameters: input_data (vtkDataObject) – Object whose outline we want
-
set_input_data
(input_data)[source]¶ Sets the input data for the outline
Parameters: input_data (vtkDataObject) – Object whose outline we want
-
-
class
OrientationAxes
[source]¶ An orientation cube with faces labeled for Right, Left, Anterior, Posterior, Superior and Inferior
-
class
cursors
(axis=0)[source]¶ Emulates the cursors in vtkImagePlaneWidget
There will be two copies of the cursors polydata, one in front and one at the back of the image plane, the separation between them is controlled by the
set_delta()
method-
change_axis
(axis)[source]¶ Change the axis perpendicular to the image plane
Parameters: axis (int) – x:0 , y:1, z:2
-
set_delta
(delta)[source]¶ Sets separation between front and back cursors.
Parameters: delta (float) – Separation
-
Other Utilities¶
-
save_ren_win_picture
(ren_win, file_name, magnification=1)[source]¶ Saves an screenshot of a render window
Parameters: - ren_win (vtkRenderWindow) – Render Window
- file_name (str) – Path to save screenshot
-
build_grid
(orig_img, img_slice, sampling_rate=5)[source]¶ Creates an homogenous grid, useful for showing the effects of transformations
The grid dimensions are based on the orig_img, img_slice is used to position the grid along the x axis, For the moment only grids perpendicular to the x axis are available
Parameters: - orig_img (vtkImageData) – Image to base grid on
- img_slice (int) – Slice of the image where the grid will be located (along the x asis)
- sampling_rate (int) – Density of the grid, there will be a line each sampling_rate voxels
-
remove_nan_from_grid
(grid)[source]¶ Remove missing values from a grid, it is necessary in some version of vtk to avoid crash
Parameters: grid (vtkPolyData) – Should only contain lines
-
get_window_level
(img)[source]¶ Automatically gets appropriate window and level values for displaying an image
Parameters: img (vtkImageData) – Image - Returns
- (window,level), proposed values