Dr. Qaiser Chaudry. System Architecture. Interpreted Wrapper (Tcl, Java, Python). C++ core. Binary Installation: if you
Medical Image Processing and Analysis Lecture -12
1 Dr. Qaiser Chaudry
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.
Dr. Qaiser Chaudry
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, SGI, Linux, Sun, HP, etc. • Support OpenGL • Different interfaces for fast prototyping: Tcl , Java, and Python • Have users all over the world – The beauty of Open Source!
The Graphics Model The purpose is to render the geometry (volume) on the screen camera
screen
Dr. Qaiser Chaudry
Actor
Light
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;
}
Dr. Qaiser Chaudry
give the actor to the renderer; window->render();
Window Renderer Actor Mapper Geometry
Example -1 • • • •
Dr. Qaiser Chaudry
A polygonal model of a cone Render to screen. Rotate the cone 360 degrees source -> mapper -> actor -> renderer -> renderwindow
Example -1 # # This example creates a polygonal model of a cone, and then rendered it to # the screen. It willrotate the cone 360 degrees and then exit. The basic # setup of source -> mapper -> actor -> renderer -> renderwindow is # typical of most VTK programs. # # # First we include the VTK Tcl packages which will make available # all of the vtk commands to Tcl # package require vtk # # Next we create an instance of vtkConeSource and set some of its # properties # vtkConeSource cone cone SetHeight 3.0 cone SetRadius 1.0 cone SetResolution 10
Dr. Qaiser Chaudry
Example -1 # # We create an instance of vtkPolyDataMapper to map the polygonal data # into graphics primitives. We connect the output of the cone souece # to the input of this mapper # vtkPolyDataMapper coneMapper coneMapper SetInput [cone GetOutput] # # create an actor to represent the cone. The actor coordinates rendering of # the graphics primitives for a mapper. We set this actor's mapper to be # coneMapper which we created above. # vtkActor coneActor coneActor SetMapper coneMapper # # Create the Renderer and assign actors to it. A renderer is like a # viewport. It is part or all of a window on the screen and it is responsible # for drawing the actors it has. We also set the background color here # vtkRenderer ren1 ren1 AddActor coneActor ren1 SetBackground 0.5 0.2 0.4
Dr. Qaiser Chaudry
Example -1 # # Finally we create the render window which will show up on the screen # We put our renderer into the render window using AddRenderer. We also # set the size to be 300 pixels by 300 # vtkRenderWindow renWin renWin AddRenderer ren1 renWin SetSize 300 300 # # now we loop over 360 degreeees and render the cone each time # for {set i 0} {$i < 360} {incr i} { after 20 # render the image renWin Render # rotate the active camera by one degree [ren1 GetActiveCamera] Azimuth 1 } # # Free up any objects we created # vtkCommand DeleteAllObjects
# add both renderers to window and change size vtkRenderWindow renWin renWin AddRenderer ren1 renWin AddRenderer ren2 renWin SetSize 600 300
• • • • • •
for {set i 0} {$i < 360} {incr i} { after 20 renWin Render [ren1 GetActiveCamera] Azimuth 1 [ren2 GetActiveCamera] Azimuth 1 }
Dr. Qaiser Chaudry
User interaction • vtkRenderWindowInteractor – allow the user to interact with the graphics objects
Dr. Qaiser Chaudry
•
w: wireframe mode
•
Left Button: rotate
•
s: surface mode
•
Right Button: zoom
•
r: reset the transformation
•
e: exit
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();
Dr. Qaiser Chaudry
User interaction vtkRenderWindow renWin renWin AddRenderer ren1 renWin SetSize 300 300 renWin Render # create rendrer window interactor vtkRenderWindowInteractor iren iren SetRenderWindow renWin # Add observer and initialize interactor iren AddObserver UserEvent {wm deiconify .vtkInteract} iren Initialize # prevent the tk window from showing up then start the event loop wm withdraw .
Dr. Qaiser Chaudry
Demos • Bottle • Spring • 3D Model Motor • Medical imaging • Stomach model
Dr. Qaiser Chaudry
What is ITK?
National Library of Medicine Insight Segmentation and Registration Toolkit (ITK)
• Image Processing • Segmentation • Registration • No Graphical User Interface (GUI) • No Visualization
Dr. Qaiser Chaudry
References • • • • • •
Dr. Qaiser Chaudry
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/