VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

25
VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006

Transcript of VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Page 1: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

VTK: The Visualization Toolkit

Qaiser Chaudry

Georgia Institute of Technology

June 28, 2006

Page 2: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Visualization

Box ?

Page 3: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

What is VTK?

• An open source, freely available software system for 3D graphics, image processing, and visualization.

• Support for hundreds of algorithms in visualization and image processing

• Object-oriented design with different interpreted language wrapers.

Page 4: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

At a Glance • The core of VTK is written entirely in C++

• Contains 600 existing classes with 325K lines of code

• VTK will compile and run on Windows 98/NT, SGI, Linux, Sun, HP, etc.

• Supports OpenGL

• Different interfaces for fast prototyping: Tcl , Java, and Python

• Has users all over the world – The beauty of Open Source!

Page 5: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

System ArchitectureInterpreted Wrapper (Tcl, Java, Python)

C++ core

Binary Installation: if you will usethe classes to build your applicatoin

Source code Installation: If you want to extend vtk

•Tcl/Tk source•Java JDK•Python source

All class source code(could take hours to compile)

Libraries and includes(dll and .h files)Or(.a and .h files)

•Tcl/Tk shell•Java interpreter•Python interpreter

Page 6: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

VTK classes

Page 7: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

The Graphics Model

The purpose is to render the geometry (volume) on the screen

vtkCameravtkLight

vtkActor

•vtkProperty•vtkMapper•vtkTransformvtkRenderWindow

vtkRenderervtkRenderWindowInteractor

Page 8: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

To see is to believe …1 vtkRenderWindow

2 vtkRenderervtkCamera

vtkLight

vtkActor( property, geometry(mapper), transformation, etc)

Page 9: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

The Graphics ModelThe purpose is to render the geometry (volume) on the screen

cameraLightActor

screen

Page 10: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Example Program

Main() { create a window; create a renderer; give the renderer to the window; create procedural geometry; create a mapper; give the geometry to the mapper; create an actor; give the mapper to the actor;

give the actor to the renderer; window->render(); }

Window

Renderer

Actor

Mapper

Geometry

Page 11: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Example -1

• A polygonal model of a cone

• Render to screen.

• Rotate the cone 360 degrees

• source -> mapper -> actor -> renderer -> renderwindow

Page 12: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Example -1// First include the required header files for the VTK classes we are using.

#include "vtkConeSource.h"

#include "vtkPolyDataMapper.h"

#include "vtkRenderWindow.h"

#include "vtkCamera.h"

#include "vtkActor.h"

#include "vtkRenderer.h“

int main( int argc, char *argv[] )

{

// Create an instance of vtkConeSource.

vtkConeSource *cone = vtkConeSource::New();

cone->SetHeight( 3.0 );

cone->SetRadius( 1.0 );

cone->SetResolution( 10 );

Page 13: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Example -1 // We create an instance of vtkPolyDataMapper

vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();

coneMapper->SetInput( cone->GetOutput() );

// Create an actor.

vtkActor *coneActor = vtkActor::New();

coneActor->SetMapper( coneMapper );

// Create the renderer.

vtkRenderer *ren1= vtkRenderer::New();

ren1->AddActor( coneActor );

ren1->SetBackground( 0.1, 0.2, 0.4 );// Finally we create the render window.vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 300, 300 );

Page 14: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Example -1// Now we loop over 360 degrees and render the cone each time.int i; for (i = 0; i < 360; ++i) {// Render the image. renWin->Render();// Rotate the active camera by one degree. ren1->GetActiveCamera()->Azimuth( 1 );// Introduce delay to slow down motion. Sleep(10); }// Free up any objects we created. cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete(); return 0;}

Page 15: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Creating Multiple RenderersvtkRenderer *ren1= vtkRenderer::New();

ren1->AddActor( coneActor );

ren1->SetBackground( 0.1, 0.2, 0.4 );

ren1->SetViewport(0.0, 0.0, 0.5, 1.0);

vtkRenderer *ren2= vtkRenderer::New();

ren2->AddActor( coneActor );

ren2->SetBackground( 0.2, 0.3, 0.5 );

ren2->SetViewport(0.5, 0.0, 1.0, 1.0);

vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->AddRenderer( ren2 ); renWin->SetSize( 600, 300 );

Page 16: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Creating Multiple Renderers

// Make one view 90 degrees from the other.ren1->GetActiveCamera()->Azimuth(90);

// Now we loop over 360 degrees and render the cone each time.int i; for (i = 0; i < 360; ++i) { // render the image renWin->Render(); // rotate the active camera by one degree ren1->GetActiveCamera()->Azimuth( 1 ); ren2->GetActiveCamera()->Azimuth( 1 );

Sleep(10); }

Page 17: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Properties and Transformation// Create an actor to represent the first cone. The actor's properties are

modified to give it different surface properties. By default, an actor is created with a property so the GetProperty() method can be used.

vtkActor *coneActor = vtkActor::New();

coneActor->SetMapper( coneMapper );

coneActor->GetProperty()->SetColor(0.2, 0.63, 0.79);

coneActor->GetProperty()->SetDiffuse(0.7);

coneActor->GetProperty()->SetSpecular(0.4);

coneActor->GetProperty()->SetSpecularPower(20);

Page 18: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Properties and Transformation// Create a property and directly manipulate it. Assign it to the second actor.

vtkProperty *property = vtkProperty::New();

property->SetColor(1.0, 0.3882, 0.2784);

property->SetDiffuse(0.7);

property->SetSpecular(0.4);

property->SetSpecularPower(20);

vtkActor *coneActor2 = vtkActor::New();

coneActor2->SetMapper(coneMapper);

coneActor2->GetProperty()->SetColor(0.2, 0.63, 0.79);

coneActor2->SetProperty(property);

coneActor2->SetPosition(0, 3, 0);

Page 19: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Properties and Transformation

// Create the renderer and assign actors to it.

vtkRenderer *ren1= vtkRenderer::New();

ren1->AddActor( coneActor );

ren1->AddActor( coneActor2 );

ren1->SetBackground( 0.1, 0.2, 0.4 );

Page 20: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

User interaction • vtkRenderWindowInteractor – allow the user to interact

with the graphics objects

• w: wireframe mode

• s: surface mode

• r: reset the transformation

• e: exit

• Left Button: rotate

• Right Button: zoom

Page 21: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

User interaction// The vtkRenderWindowInteractor class watches for events (e.g., keypress,

mouse) in the vtkRenderWindow.

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);

// Here we specify a particular interactor style.

vtkInteractorStyleTrackballCamera *style =

vtkInteractorStyleTrackballCamera::New();

iren->SetInteractorStyle(style);

// Leave an event loop running. Exit when the user presses the "e" key.

iren->Initialize();

iren->Start();

Page 22: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

TCL Vs C++

package require vtk

vtkConeSource conecone SetHeight 3.0cone SetRadius 1.0cone SetResolution 10

vtkPolyDataMapper coneMapperconeMapper SetInput [cone GetOutput]

vtkActor coneActorconeActor SetMapper coneMapper

vtkRenderer ren1 ren1 AddActor coneActorren1 SetBackground 0.1 0.2 0.4

vtkRenderWindow renWinrenWin AddRenderer ren1renWin SetSize 300 300

for {set i 0} {$i < 360} {incr i} { after 10 renWin Render [ren1 GetActiveCamera] Azimuth 1}

vtkCommand DeleteAllObjects

exit

#include "vtkConeSource.h"#include "vtkPolyDataMapper.h"#include "vtkRenderWindow.h"#include "vtkCamera.h"#include "vtkActor.h"#include "vtkRenderer.h"int main( int argc, char *argv[] ){ 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 *ren1= vtkRenderer::New(); ren1->AddActor( coneActor ); ren1->SetBackground( 0.1, 0.2, 0.4 );

vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 300, 300 );

int i; for (i = 0; i < 360; ++i) { Sleep(10); renWin->Render(); ren1->GetActiveCamera()->Azimuth( 1 ); }

cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete(); return 0;}

Page 23: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

Demos

• Diffuse Lighting

• Modeling

• Volume Rendering

• 3D Model Motor

• Medical imaging

Page 24: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

What is ITK?

• Image Processing

• Segmentation

• Registration

• No Graphical User Interface (GUI)

• No Visualization

National Library of Medicine Insight Segmentation and Registration Toolkit (ITK)

Page 25: VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006.

References• www.cse.ohio-state.edu/~hwshen/788/sp01/

• http://www.kitware.com/

• http://www.vtk.org/

• The VTK Users's Guide

• The Visualization Toolkit An Object-Oriented Approach To 3D Graphics 3rd Edition

• http://www.itk.org/