Advanced and Spring 2008

Filip Malmberg [email protected]

IT Uppsala universitet UU/IT VTK – The Visualization ToolKit

. What is VTK? . What can VTK be used for? . How to actually use VTK?

@ UU/IT 08-01-29 | #2 UU/IT VTK – The Visualization ToolKit . Open source, freely available software for • • image processing • visualization . Managed by , Inc. . Object-oriented design (++) . High-level of abstraction . Use C++, Tcl/, Python, Java

@ UU/IT 08-01-29 | #3 UU/IT True visualization system . Techniques for visualizing • scalar fields • vector fields • tensor fields . Polygon reduction . Mesh smoothing . Image processing . Your own algorithms

@ UU/IT 08-01-29 | #4 UU/IT Additional features . Parallel support • message passing • multi-threading . Stereo support . Integrates with Motif, , Tcl/Tk, Python/Tk, X11, Windows, ... . Event handling . 3D widgets

@ UU/IT 08-01-29 | #5 UU/IT 3D graphics . Surface rendering . • Ray casting • Texture mapping (2D, 3D) . Lights and cameras . Textures . Save render window to .png, .jpg, ... (useful for movie creation)

@ UU/IT 08-01-29 | #6 UU/IT Data Representation

. Collection of cells & points . Cells specify topology • Shape such as triangle, tetrahedron . Points specify geometry • Point coordinates assigned to a topology . Data attributes • Data associated with topology or geometry

@ UU/IT 08-01-29 | #7 UU/IT Data attributes assigned to points or cells . Scalar . Vector • magnitude and direction . Normal • a vector of magnitude 1 • used for lighting . Texture coordinate • mapping data points into a texture space . Tensor

@ UU/IT 08-01-29 | #8 UU/IT Visualization of attributes . Scalar fields • Color Mapping . vtkLookupTable . vtkScalarsToColors . vtkColorTransferFunction

• Contouring . vtkContourFilter . vtkMarchingCubes

@ UU/IT 08-01-29 | #9 UU/IT Visualization of attributes . Vector fields • Glyphs . vtkGlyph3D • Streamlines/points/tubes . vtkStreamer . vtkStreamLine . vtkStreamPoints

@ UU/IT 08-01-29 | #10 UU/IT Visualization of attributes . Tensor fields • vtkTensor • vtkTensorGlyph

@ UU/IT 08-01-29 | #11 UU/IT The Visualization Pipeline

DATA Visualization algorithms

FILTER MAPPING

Interactive feedback DISPLAY

@ UU/IT 08-01-29 | #12 UU/IT Objects . Data objects • e.g. vtkPolyData, vtkImageData . Process objects • Source objects (vtkReader, vtkSphereSource) • Filter objects (vtkContourFilter) • Mapper objects (vtkPolyDataMapper)

@ UU/IT 08-01-29 | #13 UU/IT 7 basic VTK objects to render a scene

1. vtkRenderWindow: manages a window on the display device 2. vtkRenderer: coordinates the rendering process involving lights, cameras, and actors 3. vtkLight: a source of light to illuminate the scene 4. vtkCamera: defines the view position, focal point, etc. 5. vtkActor: represents an object rendered in the scene, both its properties and position in the world coordinate system 6. vtkProperty: defines the appearance properties of an actor including colour, transparency, and lighting properties such as specular and diffuse. Also representational properties like wireframe and solid surface 7. vtkMapper: the geometric representation for an actor. More than one actor may refer to the same mapper

@ UU/IT 08-01-29 | #14 UU/IT Cube example

http://www.it.uu.se/edu/course/avgrafik/vt07/

@ UU/IT 08-01-29 | #15 UU/IT User interaction . vtkRenderWindowInteractor • allows the user to interact with the objects . Try the following key presses w wireframe mode s surface mode j joystick mode t trackball mode button1 rotate button2 translate button3 scale r reset camera view e, q exit

@ UU/IT 08-01-29 | #16 UU/IT Sphere example

http://www.it.uu.se/edu/course/avgrafik/vt07/

@ UU/IT 08-01-29 | #17 UU/IT VTK and C++

. Build with CMake and your favorite compiler . CMake generates makefiles or project files for your environment . Use the resulting file(s) to build your executable . Under Windows you can use Microsoft Visual C++ 8 Express Edition . You have to install Tcl and/or Python to run vtk scripts

@ UU/IT 08-01-29 | #18 UU/IT VTK and Python . Interpreted scripting language, allows rapid development. . Easy to learn if you know e.g. C++ or Java. . More information available on www.python.org

@ UU/IT 08-01-29 | #19 UU/IT VTK resources . www.vtk.org • Download • Documentation • Mailing lists • Links • FAQ, Search . www.kitware.com • VTK Textbook • VTK User’s guide • Mastering CMake

@ UU/IT 08-01-29 | #20 UU/IT VTK Examples . Really useful for getting started . Available on the VTK webpage or in the VTK folder.

@ UU/IT 08-01-29 | #21 UU/IT VTK documentation

@ UU/IT 08-01-29 | #22 UU/IT Summary + . Free and open source . Create graphics/visualization applications fairly fast . Object oriented - easy to derive new classes . Build applications using “interpretive” languages Tcl, Python, and Java . Many (state-of-the-art) algorithms . Heavily tested in real-world applications . Large user base provides decent support . Commercial support and consulting available

@ UU/IT 08-01-29 | #23 UU/IT Summary -

. Not a super-fast graphics engine due to portability and C++ dynamic binding – you need a decent workstation . Very large class hierarchy  learning threshold might be steep

@ UU/IT 08-01-29 | #24 UU/IT Questions?

@ UU/IT 08-01-29 | #25 UU/IT Computer exercises 2008 . 2 assignments on VTK

@ UU/IT 08-01-29 | #26 UU/IT Computer exercises 2008 . 2 assignments on shader programming with the OpenGL shading language

@ UU/IT 08-01-29 | #27 UU/IT Computer exercises 2008 . Bonus deadline is next lab session • Give a demonstration of your program • Show source code • Be able to answer questions . A1, A3 = 1p A2, A4 = 2p

@ UU/IT 08-01-29 | #28 UU/IT Computer exercises 2008 . Lab 1 Wednesday January 30 8:15-12:00 P1312D Basics of VTK . UpUnet account, UU-LOCAL, password C . VTK 5.0.0 is installed in • G:\Program\ACGV\VTK-5.0.0 . You need to set the proper paths, run the script in a command prompt • G:\Program\ACGV\set_paths.bat

@ UU/IT 08-01-29 | #29