22.01.2014 Views

Diapositivo 1 - Sweet - Universidade de Aveiro

Diapositivo 1 - Sweet - Universidade de Aveiro

Diapositivo 1 - Sweet - Universidade de Aveiro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What is VTK?<br />

An Introduction to the<br />

Visualization Toolkit<br />

Information Visualization – Paulo Dias<br />

• Open Source library based in Object<br />

Oriented Programming<br />

• multi-platform (Windows/Unix/Mac)<br />

• C++ implementation with several wrappers<br />

for other languages (Tcl/Tk-Python-Java)<br />

• No User Interface but possible to integrate<br />

with several libraries: Tk, Motif, Visual<br />

Studio, Qt, …<br />

Instituto <strong>de</strong><br />

Engenharia Electrónica e<br />

Telemática<br />

<strong>de</strong> <strong>Aveiro</strong><br />

z<br />

Departamento <strong>de</strong><br />

Electrónica, Telecomunicações e Informática<br />

<strong>Universida<strong>de</strong></strong> <strong>de</strong> <strong>Aveiro</strong><br />

<strong>de</strong>ti <strong>de</strong>partamento <strong>de</strong> electrónica telecomunicações e informática<br />

universida<strong>de</strong> <strong>de</strong> aveiro<br />

2<br />

VTK Goals<br />

• Scientific Visualization<br />

• Information Visualization<br />

• Large Data Visualization<br />

• Volume ren<strong>de</strong>ring<br />

• 3D Interaction<br />

What we get<br />

• Several data representation: points,<br />

polygonal meshes, images, volumes,<br />

structured and unstructured grids.<br />

• Importers and exporters for several<br />

formats allowing data exchange between<br />

applications.<br />

• Hundreds of filters for data processing.<br />

3<br />

4<br />

The origin<br />

• VTK Started December 1993<br />

as supporting software for the<br />

book “ The visualization Toolkit:<br />

An Object Oriented Approach<br />

to 3D Graphics” by Will<br />

Schroe<strong>de</strong>r, Ken Martin and Bill<br />

Lorensen (Prentice Hall).<br />

• Supported by Kitware<br />

company:<br />

http://public.kitware.com/VTK/<br />

• Software, Books, FAQ’s,<br />

examples, forums…<br />

Main characteristics<br />

• High level of abstraction when compared<br />

with other libraries such as OpenGL.<br />

• Support all the main visualization<br />

algorithms.<br />

• Hundred of classes and functions.<br />

• Key to success:<br />

– Get used to the objects.<br />

– Use examples.<br />

5<br />

6<br />

1


Architecture<br />

• C++ core: inclu<strong>de</strong> data structures,<br />

algoritms and co<strong>de</strong>.<br />

• Interpretation layers: to allow use with<br />

several languages :<br />

– C++<br />

– Tcl<br />

– JAVA<br />

– Python<br />

VTK subsystems<br />

• Graphics<br />

• Image Processing (2D and 3D ImageData<br />

and Filter)<br />

• 3D Geometry (DataSets and Filters)<br />

• Picking, Interactions<br />

• 2D Chart API<br />

• Information Visualization<br />

7<br />

8<br />

VTK Visualization Pipeline<br />

VTK Graphic<br />

data mappers actors<br />

• Just like hollywood: Lights, Cameras,<br />

Actors, Properties. The graphics mo<strong>de</strong>l<br />

inclu<strong>de</strong>s tools for<br />

– Window managing (Creation and<br />

manipulation of ren<strong>de</strong>ring windows).<br />

– Mappers and their properties.<br />

– 2D, 3D and volume ren<strong>de</strong>ring.<br />

9<br />

10<br />

VTK Graphic<br />

Dataset<br />

A VTK scene consists of:<br />

• vtkRen<strong>de</strong>rWindow - contains the final image<br />

• vtkRen<strong>de</strong>rer - draws into the ren<strong>de</strong>r window<br />

• vtkActor - combines properties / geometry<br />

– vtkProp, vtkProp3D<br />

– vtkProperty<br />

• vtkLights - illuminates actors<br />

• vtkCamera - ren<strong>de</strong>rs the scene<br />

• vtkMapper - represents geometry<br />

– vtkPolyDataMapper, vtkDataSetMapper are subclasses<br />

• vtkTransform - positions actors<br />

• Dataset structure consists of<br />

– points (x-y-z coordinates)<br />

– cells (e.g., polygons, lines, voxels) which are<br />

<strong>de</strong>fined by connectivity list referring to points<br />

ids<br />

• Access is via integer ID<br />

Points<br />

Cell<br />

11<br />

12<br />

2


Data Representation - Cells and points<br />

Data Types<br />

• 5 different type of data:<br />

• Vertex<br />

• Polyvertex<br />

• Line<br />

• Polyline<br />

• Triangle<br />

• Triangle Strip<br />

• Quadrilateral<br />

• Polygon<br />

• Tetrahedron<br />

• Hexahedron<br />

• Voxel<br />

– vtkImageData - Structured Points<br />

– vtkRectilinear Grid - Rectilinear Grid<br />

– vtkStructuredGrid - Structured Grid<br />

– vtkUnstructuredGrid - Unstructured Grid<br />

– vtkPolyData - Polygonal Data<br />

• Format choice is important for efficiency and for use<br />

of a<strong>de</strong>quate filters<br />

13<br />

14<br />

DataSet Attributes<br />

• vtkDataSet also has point and cell<br />

attribute data:<br />

– Scalars<br />

– Vectors - 3-vector<br />

– Tensors - 3x3 symmetric matrix<br />

– Normals - unit vector<br />

– Texture Coordinates 1-3D<br />

– Array of arrays (i.e. FieldData)<br />

VTK –Example<br />

#inclu<strong>de</strong> "vtkConeSource.h"<br />

#inclu<strong>de</strong> "vtkPolyDataMapper.h"<br />

#inclu<strong>de</strong> "vtkActor.h"<br />

#inclu<strong>de</strong> "vtkRen<strong>de</strong>rWindow.h"<br />

#inclu<strong>de</strong> "vtkRen<strong>de</strong>rWindowInteractor.h"<br />

#inclu<strong>de</strong> "vtkRen<strong>de</strong>rer.h"<br />

#inclu<strong>de</strong> "vtkProperty.h"<br />

void main ()<br />

{<br />

// create cone geometry<br />

vtkConeSource *cone =<br />

vtkConeSource::New();<br />

// create cone mapper for mapping the cone<br />

to the graphics library.<br />

vtkPolyDataMapper *coneMapper =<br />

vtkPolyDataMapper::New();<br />

coneMapper ->SetInput(cone->GetOutput());<br />

// actor coordinates geometry, properties,<br />

transformation<br />

vtkActor *aCone = vtkActor::New();<br />

aCone->SetMapper(coneMapper);<br />

aCone->GetProperty()->SetColor(0,0,1); //<br />

cone color blue<br />

// an interactor<br />

vtkRen<strong>de</strong>rWindowInteractor *iren =<br />

vtkRen<strong>de</strong>rWindowInteractor::New();<br />

iren->SetRen<strong>de</strong>rWindow(renWin);<br />

// add the actor to the scene<br />

ren1->AddActor(aCone);<br />

ren1->SetBackground(1,1,1); //<br />

Background color white<br />

// ren<strong>de</strong>r an image<br />

renWin->Ren<strong>de</strong>r();<br />

// begin mouse interaction<br />

iren->Start();<br />

cone->Delete();<br />

coneMapper->Delete();<br />

aCone->Delete();<br />

ren1->Delete();<br />

renWin->Delete();<br />

iren->Delete();<br />

}<br />

15<br />

// a ren<strong>de</strong>rer and ren<strong>de</strong>r window<br />

vtkRen<strong>de</strong>rer *ren1 = vtkRen<strong>de</strong>rer::New();<br />

vtkRen<strong>de</strong>rWindow *renWin =<br />

vtkRen<strong>de</strong>rWindow::New();<br />

renWin->AddRen<strong>de</strong>rer(ren1);<br />

16<br />

vtkRen<strong>de</strong>rWindowInteractor<br />

• SetRen<strong>de</strong>rWindow – ren<strong>de</strong>r window<br />

• Key and mouse bindings (Interactor Style)<br />

• Light Follow Camera (a headlight)<br />

• Picking interaction<br />

Interactor Styles<br />

• Button 1 – rotate<br />

• Button 2 – translate ( Button 1 for 2-button<br />

• mouse)<br />

• Button 3 – zoom<br />

• Keypress e or q – exit<br />

• Keypress f – “fly-to” point un<strong>de</strong>r mouse<br />

• Keypress s/w – surface/wireframe<br />

• Keypress p – pick<br />

• Keypress r – reset camera<br />

• Keypress 3 – toggle stereo<br />

Switch styles: Keypress j – joystick; t - trackball<br />

style<br />

17<br />

18<br />

3


Picking<br />

• vtkPropPicker - hardware-assisted picking of<br />

vtkProps (returns vtkProp picked and x,y,z<br />

coordinate)<br />

• vtkWorldPointPicker - get x-y-z coordinate; does not<br />

pick prop (hardware assisted, returns x,y,z<br />

coordinate)<br />

• vtkPicker - pick based on prop3D’s bounding box<br />

(software ray cast – returns vtkProp)<br />

• vtkPointPicker - pick points (closest point to camera<br />

within tolerance - software ray cast – returns point id<br />

& x,y,z coordinate)<br />

• vtkCellPicker - pick cells (software ray cast –<br />

returns cell id & x,y,z)<br />

3D Widgets<br />

• Ad<strong>de</strong>d since VTK 4.0 release<br />

• Requires version 4.2 or later<br />

• Subclass of vtkInteractorObserver<br />

• Interactor observers watch events<br />

invoked on vtkRen<strong>de</strong>rWindowInteractor<br />

• Events are caught and acted upon<br />

• Events can be prioritized and or<strong>de</strong>red<br />

19<br />

20<br />

3D Widgets<br />

• vtkPointWidget<br />

• vtkLineWidget<br />

• vtkPlaneWidget<br />

• vtkImplicitPlaneWidget<br />

• vtkImagePlaneWidget<br />

• vtkBoxWidget<br />

• vtkSphereWidget<br />

• …..<br />

Algorithms / Filters<br />

• Algorithms operate on data objects<br />

source<br />

data<br />

filter<br />

data<br />

mapper<br />

s<br />

actors<br />

21<br />

22<br />

Algorithms / Filters<br />

• vtkAppendFilter<br />

• vtkAppendPolyData<br />

• vtkBooleanTexture<br />

• vtkBrownianPoints<br />

• vtkCastToConcrete<br />

• vtkCellCenters<br />

• vtkCellDataToPointData<br />

• vtkCullVisiblePoints<br />

• vtkCleanPolyData<br />

• vtkClipPolyData<br />

• vtkEdgePoints<br />

• vtkElevationFilter<br />

• vtkExtractEdges<br />

• vtkExtractGeometry<br />

• vtkExtractGrid<br />

• vtkExtractTensorComponent<br />

s<br />

• vtkExtractUnstructuredGrid<br />

• vtkExtractVOI<br />

• vtkExtractVectorComponents<br />

• vtkFeatureEdges…<br />

Vtk Chart API<br />

• Multiple chart types<br />

– Line plots<br />

– Bar graphs<br />

– Scatter plots<br />

– Area charts<br />

– Pie charts<br />

– Flood plots<br />

23<br />

24<br />

4


VTK chart API<br />

Information Visualization in VTK<br />

• Titan project 2008 - collaborative effort<br />

between Sandia National Laboratories and<br />

Kitware Inc.<br />

• One of the first software <strong>de</strong>velopment<br />

efforts to address the merging of scientific<br />

visualization and information visualization<br />

25<br />

26<br />

VTK infoVis<br />

VTK infoVis<br />

vtkTable<br />

vtkDataObject<br />

vtkArray<br />

vtkGraph<br />

vtkTable<br />

vtkGraph (network)<br />

vtkDirectedGraph<br />

vtkTree (hierarchy)<br />

vtkDirectedAcyclicGraph<br />

vtkUndirectedGraph<br />

vtkArray<br />

vtkTree<br />

From:<br />

http://titan.sandia.gov/media/Information_Visualization_in_VTK.pdf<br />

27<br />

vtkMutableDirectedGraph<br />

vtkMutableUndirectedGraph<br />

28<br />

From: http://titan.sandia.gov/media/Information_Visualization_in_VTK.pdf<br />

VTK infoVis<br />

VTK infoVis<br />

AND MORE:<br />

– Data conversion<br />

– Database access<br />

– Graph algorithms<br />

– Statistics<br />

vtkGraphLayout<br />

vtkTreeMapView<br />

From: http://titan.sandia.gov/media/Information_Visualization_in_VTK.pdf<br />

29<br />

From: http://titan.sandia.gov/media/Information_Visualization_in_VTK.pdf<br />

30<br />

5


Main advantages<br />

Main problems<br />

– Free<br />

– Easy creation of graphical applications<br />

– C++ source co<strong>de</strong> available<br />

– Make learning of computer Graphics,<br />

Visualization and Image Processing easier.<br />

– Platform in<strong>de</strong>pen<strong>de</strong>nt.<br />

– Large quantity of widgets for object<br />

manipulation<br />

– Integrate software (not a series of pieces of<br />

co<strong>de</strong>).<br />

– Easy visualization of data<br />

– Object Oriented<br />

– Largely used in many commercial<br />

applications, almost standard<br />

31<br />

– Not very fast<br />

– Relatively heavy, need a reasonable machine<br />

– Documentation<br />

32<br />

Help<br />

3D Mo<strong>de</strong>lling and Visualization Course<br />

• VTK User’s Gui<strong>de</strong><br />

• The Visualization Toolkit TextBook<br />

• Doxygen Documentation<br />

• Kitware pages on VTK (examples, testing,<br />

etc…)<br />

FootVR<br />

3D Audio<br />

Brain Imaging<br />

Vectorial Data<br />

2D Audio<br />

Polygonal Meshes<br />

Cutting<br />

33<br />

34<br />

3D Mo<strong>de</strong>lling and Visualization Course<br />

3D Mo<strong>de</strong>lling and Visualization Course<br />

Geoscience data<br />

RIR Acquisition<br />

Medical data<br />

Robotic simulators<br />

35<br />

36<br />

6


VTK Installation<br />

• Download Cmake<br />

http://www.cmake.org/cmake/resources/softwar<br />

e.html<br />

• Download VTK<br />

http://www.vtk.org/VTK/resources/software.html<br />

VTK Installation - Cmake<br />

• Run Cmake -indicate source directory (VTK files)<br />

and where to build binaries.<br />

• Choose compiler (for example Visual Studio 9 –<br />

VS2008)<br />

37<br />

38<br />

VTK Installation - Cmake<br />

• Configure compilation options, namely:<br />

– BUILS_SHARED_LIBS<br />

– VTK_WRAP_JAVA<br />

– CMAKE_INSTALL_PREFIX (directory for<br />

installation)<br />

– VTK_USE_CHARTS<br />

– VTK_USE_INFOVIS<br />

• Click on configure<br />

VTK Installation - Compilation<br />

• Open Project in Visual Studio (solution is in<br />

binary directory with name: vtk.sln)<br />

• Build all (take some time)<br />

• run install project to copy files to install directory<br />

• Add Install directory in path<br />

39<br />

40<br />

VTK Installation – Visual Studio<br />

1. Indicate location of hea<strong>de</strong>r files [configuration properties-<br />

>C/C++->General]. In [Additional Inclu<strong>de</strong> Directories] inclu<strong>de</strong><br />

hea<strong>de</strong>r file directory: [ex:”C:\Program Files\VTK\inclu<strong>de</strong>\vtk“]<br />

VTK Installation – Visual Studio<br />

2. Indicate location of library files [configuration properties->Linker-<br />

>Genera]. In [Additional Library Directories] inclu<strong>de</strong> lib file<br />

directory: [ex:” C:\Program Files\VTK\lib“]<br />

41 42<br />

7


VTK Installation – Visual Studio<br />

3. In Linker->Input->Additional Depen<strong>de</strong>ncies, inclu<strong>de</strong> lib files:<br />

vtkCommon.lib vtkFiltering.lib vtkGraphics.lib vtkHybrid.lib<br />

vtkImaging.lib vtkIO.lib vtkjpeg.lib vtkpng.lib vtkRen<strong>de</strong>ring.lib vtkzlib.lib<br />

vtkWidgets.lib<br />

4. Add vtk DLL directory to the path. In windows can be done thorugh<br />

Control Panel->System->Advanced->Environment variables<br />

and rebooting computer<br />

VTK Installation - netbeans<br />

• Add vtk.jar to the project (right click, libraries).<br />

• Ensure that vtk DLL files are in the path.<br />

• Add the import to the JAVA file:<br />

System.loadLibrary("vtkCommonJava");<br />

System.loadLibrary("vtkFilteringJava");<br />

System.loadLibrary("vtkViewsJava");<br />

System.loadLibrary("vtkImagingJava");<br />

System.loadLibrary("vtkInfovisJava");<br />

System.loadLibrary("vtkGraphicsJava");<br />

System.loadLibrary("vtkRen<strong>de</strong>ringJava");<br />

In VTK (5.8.1), Java wrapping is missing for<br />

vtkChart API. To create the wrapper, copy vtk.jar<br />

to vtk.zip, unzip the file, and run javac *.java insi<strong>de</strong><br />

the unzipped file to wrap all the classes for JAVA,<br />

the zip the files into vtk.jar again.<br />

43<br />

44<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!