Presentation is loading. Please wait.

Presentation is loading. Please wait.

VTK. VTK Online Resources On-line Resources VTK –Manual: –Examples:

Similar presentations


Presentation on theme: "VTK. VTK Online Resources On-line Resources VTK –Manual: –Examples:"— Presentation transcript:

1 VTK

2 VTK Online Resources On-line Resources VTK –Manual: http://www.vtk.org/doc/release/4.2/html/http://www.vtk.org/doc/release/4.2/html/ –Examples: http://public.kitware.com/VTK/example-code.phphttp://public.kitware.com/VTK/example-code.php –More examples: http://www.vtk.org/doc/release/4.2/html/pages.htmlhttp://www.vtk.org/doc/release/4.2/html/pages.html –Everything else: http://www.vtk.org/http://www.vtk.org/ TCL –Manual: http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htmhttp://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm –Online tutorial: http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.htmlhttp://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html –Everything else: http://www.tcl.tk/http://www.tcl.tk/

3 Recall, VTK Architecture “Object-oriented” –Instance, inheritance, subclass, … Instances of vtkRenderWindow Instances of vtkRenderer Instances of vtkActor vtkMapper defines actor geometry vtkProperty defines actor surface properties One or more vtLights illuminate the scence

4 Model.cxx – Overview #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up One vtkRenderer defines view for each renderer Instances of vtkRenderWindow Instances of vtkRenderer Instances of vtkActor vtkMapper defines actor geometry vtkProperty defines actor surface properties One or more vtLights illuminate the scence

5 Model.cxx – Overview – 1/5 #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up One vtkRenderer defines view for each renderer Instances of vtkRenderWindow Instances of vtkRenderer Instances of vtkActor vtkMapper defines actor geometry vtkProperty defines actor surface properties One or more vtLights illuminate the scence

6 Model.cxx – 2a/5 #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkConeSource.h" #include "vtkPolyDataMapper.h" #include "vtkActor.h" #include "vtkCubeSource.h" #include "vtkSphereSource.h" #include "vtkProperty.h" main () { // create rendering windows and three renderers vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderer *ren2 = vtkRenderer::New(); vtkRenderWindow *renWindow1 = vtkRenderWindow::New(); renWindow1->AddRenderer(ren1); renWindow1->AddRenderer(ren2); vtkRenderWindowInteractor *iren1 = vtkRenderWindowInteractor::New(); iren1->SetRenderWindow(renWindow1);. :

7 Model.cxx – 2b/5 #include - vtk stuff main () { // create rendering windows and three renderers (just 1 shown) // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up main () { // create rendering windows and three renderers vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderer *ren2 = vtkRenderer::New(); vtkRenderWindow *renWindow1 = vtkRenderWindow::New(); renWindow1->AddRenderer(ren1); renWindow1->AddRenderer(ren2); vtkRenderWindowInteractor *iren1 = vtkRenderWindowInteractor::New(); iren1->SetRenderWindow(renWindow1);. :

8 Model.cxx – 3/5 #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up // create an actor and give it cone geometry vtkConeSource *cone = vtkConeSource::New(); cone->SetResolution(8); vtkPolyDataMapper *coneMaper = vtkPolyDataMapper::New(); coneMapper->SetInput(cone->GetOutput()); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper(coneMapper); coneActor->GetProperty()- >SetColor(0.2000,0.6300,0.7900); // create an actor and give it cube geometry vtkCubeSource *cube = vtkCubeSource::New(); vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New(); cubeMapper->SetInput(cube->GetOutput()); vtkActor *cubeActor = vtkActor::New(); cubeActor->SetMapper(cubeMapper); cubeActor->GetProperty()- >SetColor(0.9804,0.5020,0.4471); // create an actor and give it sphere geometry vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetThetaResolution(16); sphere->SetPhiResolution(16); vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New(); sphereMapper->SetInput(sphere->GetOutput()); vtkActor *sphereActor = vtkActor::New(); sphereActor->SetMapper(sphereMapper); sphereActor->GetProperty()- >SetColor(0.8900,0.6600,0.4100);

9 Model.cxx – 4/5 #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up // assign our actor to both renderers ren1->AddActor(coneActor); ren2->AddActor(sphereActor); ren3->AddActor(cubeActor); // set the size of our window renWindow1->SetSize(800,400); renWindow2->SetSize(400,400); // set the viewports and background of the renderers ren1->SetViewport(0,0,0.5,1); ren1->SetBackground(0.9,0.9,0.9); ren2->SetViewport(0.5,0,1,1); ren2->SetBackground(1,1,1); ren3->SetBackground(1,1,1); // draw the resulting scene renWindow1->Render(); renWindow2->Render(); iren1->Start();

10 Model.cxx – 5/5 #include - vtk stuff main () { // create rendering windows and three renderers // create an actor and give it cone geometry // create an actor and give it cube geometry // create an actor and give it sphere geometry // assign our actor to both renderers // set the size of our window // set the viewports and background of the renderers // draw the resulting scene // Clean up // Clean up ren1->Delete(); ren2->Delete(); renWindow1->Delete(); iren1->Delete(); ren3->Delete(); renWindow2->Delete(); iren2->Delete(); cone->Delete(); coneMapper->Delete(); coneActor->Delete(); cube->Delete(); cubeMapper->Delete(); cubeActor->Delete(); sphere->Delete(); sphereMapper->Delete(); sphereActor->Delete(); return 0; }

11 VTK Applications, 1 http://public.kitware.com/VTK/example-code.php for this and sphere examplehttp://public.kitware.com/VTK/example-code.php 2 steps in creating graphics and visualization applications with VTK: –First, construct a data pipeline (i.e., visualization network) to process data –Second, – create the necessary graphics objects to display the data VTK architecture is based on a demand-driven, pipeline architecture (a visualization network) –Applications must first create a network, and then EXECUTE it –Typically requires: 1. Render() (sent to the rendering window) or an 2. Update() (sent to a filter in the pipeline) Just instantiating the objects and hooking them together won't do anything – YOU HAVE TO REQUEST DATA to get data

12 VTK Visualization Pipeline Pipeline has two phases: –Visualization phase Processes up to and including mapping of data to geometry –Graphics phase Creating the scene Or, visualization (VTK) transforms data into pictures

13 VTK Applications, 2 Constructing a pipeline means: –Connecting sources (ingest or create data), filters (process data), and mappers (map through lookup table and into graphics library) –Many different types available –Type checking (either at compile-time in C++ or run-time in Tcl) controls which filters can be connected together To create the graphics objects, typically –create a rendering window to render into –create a renderer –create an interactor (allows you to interact with the graphics) –create one or more actors (each of which is linked to a mapper) –render May also wish to: –transform objects; –set material properties; and/or –create lights, cameras, texture maps, and lookup tables, and various other graphics objects.

14 Sphere Example Will go through pipeline and render to window void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

15 Sphere Example – Some Terms … geometry void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

16 Sphere Example – Some Terms … map void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

17 Sphere Example – Some Terms … actor void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

18 Sphere Example – Some Terms … renderer, render window void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

19 Sphere Example – Some Terms … interactor void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights and cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

20 Sphere Example – Some Terms … render void main () { // geometry for sphere created vtkSphereSource *sphere = vtkSphereSource::New(); sphere->SetRadius(1.0); sphere->SetThetaResolution(18); sphere->SetPhiResolution(18); // map to graphics library vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(sphere->GetOutput()); // actor coordinates geometry, properties, transformation vtkActor *aSphere = vtkActor::New(); aSphere->SetMapper(map); aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue // renderer and render window vtkRenderer *ren1 = vtkRenderer::New(); // render window vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); // interactor vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); ren1->AddActor(aSphere); // add the actor to the scene ren1->SetBackground(1,1,1); // Background color white renWin->Render(); // render an image (lights, cameras are created automatically) iren->Start(); } // begin mouse interaction (goes away, if not)

21 Cone – VTK Visualization Pipeline 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 ); // Create the Renderer and assign actors to it 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 ); }

22 VTK Interaction Create a new vtkRenderWindowInteractor –controls user interaction with VTK visualisation –vtkRenderWindowInteractor iren Set the RenderWindow object that it will control –iren SetRenderWindow renWin Make the interactor active and start processing events –iren Initialize Functions available (vtkRenderWindowInteractor): –Rotate ( left mouse button ) –Zoom ( Right mouse button ) –Pan ( left mouse + shift key ) –‘w’ Draw as a wireframe mesh –‘s’ Draw as a surface mesh –‘r’ Reset camera view –‘u’ user defined command. Here, bring up window command box –iren SetUserMethod {wm deiconify.vtkInteract} –‘e’ exit –‘p’ pick actor underneath mouse pointer

23 Cone examples Book examples –(where vtk installed)…vtksrc/examples/tutorial

24 Cone – Visualization Pipeline // This example creates a polygonal model of a cone, and then renders it to // the screen. It will rotate the cone 360 degrees and then exit. The basic // setup of source -> mapper -> actor -> renderer -> renderwindow is // typical of most VTK programs. // First include the required header files for the VTK classes int main( int argc, char *argv[] ) { // Next we create an instance of vtkConeSource and set some of its // properties. The instance of vtkConeSource "cone" is part of a // visualization pipeline (it is a source process object); // it produces data (output type is vtkPolyData) //which other filters may process. // vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 ); // In this example we terminate the pipeline with a mapper process object. // (Intermediate filters such as vtkShrinkPolyData could be inserted in // between the source and the mapper.) We create an instance of // vtkPolyDataMapper to map the polygonal data into graphics primitives. We // connect the output of the cone source to the input of this mapper. // vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInput( cone->GetOutput() );

25 Cone – Visualization Pipeline // Create an actor to represent the cone. //The actor orchestrates rendering // of the mapper's graphics primitives. // We set this actor's mapper to be // coneMapper which we created/ above. vtkActor *coneActor = vtkActor::New(); 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= vtkRenderer::New(); ren1->AddActor( coneActor ); ren1->SetBackground( 0.1, 0.2, 0.4 );

26 Cone – Visualization Pipeline // Finally create render window which will show up on screen. // We put our renderer into render window using AddRenderer. // set the size to be 300 pixels by 300. // vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 300, 300 ); // Now 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 ); // orange arrow } // Free up any objects we created using the Delete() method. // cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete(); return 0; }

27 (Several) Coordinate Systems Model/object … –local coordinate system World … –Where the models are placed View … –Logical Image Plane Display (image plane) –X,Y Pixel locations In cg and VTK several coordinate systems come into play:

28 VTK Camera Camera movements around focal point –camera.tcl –Pointing toward focal point, white –Elevation, green –Azimuth, orange –Roll, yellow –Direction of projection, purple arrow Camera movements centered at camera position –Pointing toward focal point, white –View up, blue –Pitch (vs. elevation), green –Yaw (vs. azimuth), orange –Roll, yellow –View plane normal (vs. direction of projection), purple arrow

29 Homework 2 Create a simple scene using the built-in VTK source objects, cf. Figure 3-26. Use at least three different objects with different object types, placed in different positions, each with different color and surface properties. It would be great to get into it and do something interesting, e.g., a clock. Use the built-in window interactor to play around with viewing the scene. Turn in next week a screen capture and the code. Starting with a VTK supplied example is fine. As possible try to get TCL or Python to work, and consider using that for your work.

30 Real End.


Download ppt "VTK. VTK Online Resources On-line Resources VTK –Manual: –Examples:"

Similar presentations


Ads by Google