VTK VisualizationToolkit Introduction
VTK VisualizationToolkit Introduction
Carlos A. Vinhais
cvinhais@gmail.com Department of Physics ISEP School of Engineering Polytechnic Institute of Porto Porto, PORTUGAL
Outline
VTK Introduction
Resources Installation
Computer Hands-On
Build VTK with Cmake Test VTK Helloworld Cone1.cxx Cone2.cxx Cone3.cxx SingleScreenShot
VTK Architecture
Low level object model VTK file format Rendering Engine Visualization pipeline Minimal Example VTK Programming VTK Interactors
Learn by Examples
3D Graphics Visualization Techniques Imaging
Carlos Vinhais
Documentation
Online help, HTML based http://www.vtk.org/doc/release/5.8/html/
2.
3. 4. 5. 6.
Run Cmake to configure and generate the VTK project Compile VTK libraries Test VTK with the exrecises
VTK - Visualization Toolkit 5
Cmake used to generate projects, makefiles or workspaces For different compilers and OS. Cmake is Cross platform.
Carlos Vinhais
Data objects have geometric and topological structure (points and cells) Cells are topological arrangements of points
Carlos Vinhais VTK - Visualization Toolkit 6
Smart Pointers
Class template vtkSmartPointer<>
vtkSmartPointer<vtkObjectBase> obj = vtkSmartPointer<vtkExampleClass> ::New(); otheObject -> SetExample(obj);
Carlos Vinhais
Carlos Vinhais
Carlos Vinhais
vtkRenderWindow
contains the final image
vtkRenderer
draws into the render window
vtkActor
combines properties/geometry
vtkMapper
represents geometry
vtkLights
illuminate actors
vtkProp, vtkProp3D
Superclasses
vtkCamera
renders the scene
vtkProperty
vtkTransform
position actors
VTK - Visualization Toolkit 10
Carlos Vinhais
Pipeline execution
Visualization pipelines use lazy evaluation Only executes when data is required for computation
Carlos Vinhais VTK - Visualization Toolkit 11
Pipeline execution
Carlos Vinhais
12
Carlos Vinhais
13
vtkActors
Combine object properties, geometries and orientation in virtual coordinates
Data source
Procedural data, cone, sphere, cylinder, etc. Or data read from a file
vtkRenderer
Coordinates lights, cameras and actors to create an image
vtkRenderWindow
Manages the rendering process on the render window(s) on display device
vtkRenderWindowInteractor
Connection between the operating system and the VTK rendering engine
Carlos Vinhais
14
Carlos Vinhais
15
VTK Programming
Conversions between languages relatively straightforward
Class names and method names remain the same Implementation details change (syntax) GUI details change
Example
C++ Python Tcl Java
ren1->GetActiveCamera()->Azimuth( 1 ); ren1.GetActiveCamera().Azimuth( 1 ) [ren1 GetActiveCamera] Azimuth 1 ren1.GetActiveCamera().Azimuth( 1 );
Carlos Vinhais
16
VTK Programming
// // // // C++ The basic setup of: source->mapper->actor->renderer->renderwindow is typical of most VTK programs. # # # # Python The basic setup of: source->mapper->actor->renderer->renderwindow is typical of most VTK programs. vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 ); vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper -> SetInput(cone->GetOutput()); vtkActor *coneActor = vtkActor::New(); coneActor -> SetMapper( coneMapper ); vtkRenderer *renderer = vtkRenderer::New(); renderer -> AddActor( coneActor ); renderer -> SetBackground(0.1, 0.2, 0.4); vtkRenderWindow *renderWindow = vtkRenderWindow::New(); renderWindow -> AddRenderer( renderer ); renderWindow -> SetSize( 300, 300 ); vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New(); renderWindowInteractor -> SetRenderWindow( renderWindow ); renderWindow -> Render(); renderWindowInteractor -> Start(); cone = vtk.vtkConeSource() cone.SetHeight( 3.0 ) cone.SetRadius( 1.0 ) cone.SetResolution( 10 ) coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInput( cone.GetOutput() )
coneActor= vtk.vtkActor() coneActor.SetMapper( coneMapper) ren1= vtk.vtkRenderer() ren1.AddActor( coneActor) ren1.SetBackground( 0.1, 0.2, 0.4 ) renWin= vtk.vtkRenderWindow() renWin.AddRenderer( ren1 ) renWin.SetSize( 300, 300 )
...
Carlos Vinhais
17
VTK Interactors
vtkRenderWindowInteractor
Keypress: j|t
Toggle between joystick or trackball mode In joystick style the motion occurs continuously as long as the mouse button is pressed In trackball style the motion occurs when the mouse button is pressed and the mouse cursor moves Toggle between camera and actor modes In camera mode, the mouse events affect the camera position and focal point In actor mode, the mouse events affect the object under the mouse pointer Exit/quit application Toggle in and out of stereo model Default is red-blue stereo pairs
Keypress: c|a
Keypress: e|q
Keypress: 3
Carlos Vinhais
18
VTK Interactors
Keypress u
Invokes user-defined mode brings up an command interactor window Rerender using irenRender Fly-to the point under the cursor Sets the focal point allowing rotations about that point Pick operation Render window has an internal instance of vtkPropPickerfor picking Reset the camera along the viewing direction Centers the actors All actors visible
Keypress f
Keypress p
solid
Keypress r
Keypress s
All actors represented as surfaces All actors represented in wire frame
wired
Keypress w
stereo
Carlos Vinhais VTK - Visualization Toolkit 19
Test VTK
Get the source code!
Helloworld.zip (CMakeLists.txt + Helloworld.cxx) Requires ITK installed!
Carlos Vinhais VTK - Visualization Toolkit 20
SingleScreenShot
Full screen, stereo
Carlos Vinhais VTK - Visualization Toolkit 21
Carlos Vinhais
22
Carlos Vinhais
23
3D Graphics
Surface rendering Volume rendering
Ray casting
Texture mapping (2D) Lights and cameras Textures Save render window to .png, .jpg, ... (useful for movie creation) ...
VTK - Visualization Toolkit 24
Carlos Vinhais
Visualization Techniques
Scalar algorithms
Contouring Color mapping
Vector algorithms
Streamlines streamtubes
Tensor algorithms
Tensor ellipsoids
Carlos Vinhais VTK - Visualization Toolkit 25
Imaging
vtkImageToImageFilter
Diffusion High-pass / Low-pass (Fourier) Convolution Gradient (magnitude) Distance map Morphology Skeletons
Carlos Vinhais VTK - Visualization Toolkit 26
Carlos Vinhais
27
Carlos Vinhais
28
3D Widgets
Watch for events invoked by vtkRenderWindowInteractor Subclasses of vtkInteractorObserver List of most important widgets
vtkScalarBarWidget vtkPointWidget vtkLineWidget vtkPlaneWidget vtkImplicitPlane vtkBoxWidget vtkImagePlaneWidget vtkSphereWidget vtkSplineWidget
Carlos Vinhais
29
Cutting surface interpolates the data Result is always type vtkPolyData vtkCutter needs an implicit function to cut May use more cut values
SetValue() method GenerateValues() method
Carlos Vinhais
30
Probing
vtkAppendFilter builds new dataset by appending datasets
Specialized filter vtkAppendPolyData
Carlos Vinhais
31
Complex
Symbolic representation of the human face Expression controlled by the data values
vtkGlyph3D class
Scaled, colored Orientated along a direction Glyphs copied to each point of the dataset
Carlos Vinhais
33
Carlos Vinhais
34
Carlos Vinhais
35
http://www-itg.lbl.gov/Frog
Carlos Vinhais VTK - Visualization Toolkit 36