260 likes | 444 Views
VTK: The Visualization Toolkit. Qaiser Chaudry Georgia Institute of Technology June 28, 2006. Visualization. Box ?. What is VTK?. An open source, freely available software system for 3D graphics, image processing, and visualization.
E N D
VTK: The Visualization Toolkit Qaiser Chaudry Georgia Institute of Technology June 28, 2006
Visualization Box ?
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.
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!
Interpreted Wrapper (Tcl, Java, Python) • Tcl/Tk shell • Java interpreter • Python interpreter • Tcl/Tk source • Java JDK • Python source C++ core All class source code (could take hours to compile) Libraries and includes (dll and .h files) Or (.a and .h files) Binary Installation: if you will use the classes to build your applicatoin Source code Installation: If you want to extend vtk System Architecture
The Graphics Model The purpose is to render the geometry (volume) on the screen vtkCamera vtkActor • vtkProperty • vtkMapper • vtkTransform vtkLight vtkRenderWindow vtkRenderer vtkRenderWindowInteractor
To see is to believe … 1 vtkRenderWindow vtkCamera 2 vtkRenderer vtkLight vtkActor ( property, geometry(mapper), transformation, etc)
camera Light screen Actor The Graphics Model The purpose is to render the geometry (volume) on the screen
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
Example -1 • A polygonal model of a cone • Render to screen. • Rotate the cone 360 degrees • source -> mapper -> actor -> renderer -> renderwindow
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 );
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 );
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; }
Creating Multiple Renderers vtkRenderer *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 );
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); }
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);
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);
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 );
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
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();
TCL Vs C++ #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;} package require vtk vtkConeSource cone cone SetHeight 3.0 cone SetRadius 1.0 cone SetResolution 10 vtkPolyDataMapper coneMapper coneMapper SetInput [cone GetOutput] vtkActor coneActor coneActor SetMapper coneMapper vtkRenderer ren1 ren1 AddActor coneActor ren1 SetBackground 0.1 0.2 0.4 vtkRenderWindow renWin renWin AddRenderer ren1 renWin SetSize 300 300 for {set i 0} {$i < 360} {incr i} { after 10 renWin Render [ren1 GetActiveCamera] Azimuth 1 } vtkCommand DeleteAllObjects exit
Demos • Diffuse Lighting • Modeling • Volume Rendering • 3D Model Motor • Medical imaging
What is ITK? National Library of Medicine Insight Segmentation and Registration Toolkit (ITK) • Image Processing • Segmentation • Registration • No Graphical User Interface (GUI) • No Visualization
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/