Visualization techniques for scalar fields in VTK + Python

Recap: The VTK pipeline

<img src="imgs/vtk_pipeline.png", align=left> $~$

VTK look-up tables and transfer functions


In [90]:
%gui qt
import vtk
from vtkviewer import SimpleVtkViewer
#help(vtk.vtkRectilinearGridReader())

1. Data input (source)


In [91]:
# do not forget to call "Update()" at the end of the reader
rectGridReader = vtk.vtkRectilinearGridReader()
rectGridReader.SetFileName("data/jet4_0.500.vtk")
rectGridReader.Update()

2. Filters


In [93]:
%qtconsole

In [92]:
rectGridOutline = vtk.vtkRectilinearGridOutlineFilter()
rectGridOutline.SetInputData(rectGridReader.GetOutput())

3. Mappers


In [97]:
rectGridOutlineMapper = vtk.vtkPolyDataMapper()
rectGridOutlineMapper.SetInputConnection(rectGridOutline.GetOutputPort())

4. Actors


In [98]:
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(rectGridOutlineMapper)
outlineActor.GetProperty().SetColor(0, 0, 0)

5. Renderers and Windows


In [99]:
#Option 1: Default vtk render window
renderer = vtk.vtkRenderer()
renderer.SetBackground(0.5, 0.5, 0.5)
renderer.AddActor(outlineActor)
renderer.ResetCamera()

renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindow.SetSize(500, 500)
renderWindow.Render()

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renderWindow)
iren.Start()

In [83]:
#Option 2: Using the vtk-viewer for Jupyter to interactively modify the pipeline
vtkSimpleWin = SimpleVtkViewer()
vtkSimpleWin.resize(1000,800)
vtkSimpleWin.hide_axes()

vtkSimpleWin.add_actor(outlineActor)
vtkSimpleWin.add_actor(gridGeomActor)

vtkSimpleWin.ren.SetBackground(0.5, 0.5, 0.5)
vtkSimpleWin.ren.ResetCamera()

__Trick:__ The autocomplete functionality in Jupyter is available by pressing the Tab button.