340 likes | 614 Views
VTK. VTK Online Resources. On-line Resources VTK Manual: http://www.vtk.org/doc/release/4.2/html/ Examples: http://public.kitware.com/VTK/example-code.php More examples: http://www.vtk.org/doc/release/4.2/html/pages.html Everything else: http://www.vtk.org/ TCL
E N D
VTK Online Resources • On-line Resources • VTK • Manual: http://www.vtk.org/doc/release/4.2/html/ • Examples: http://public.kitware.com/VTK/example-code.php • More examples: http://www.vtk.org/doc/release/4.2/html/pages.html • Everything else: http://www.vtk.org/ • TCL • Manual: http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm • Online tutorial: http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html • Everything else: http://www.tcl.tk/
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 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 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 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
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); • . • :
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); • . • :
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);
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();
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; • }
VTK Applications, 1 • http://public.kitware.com/VTK/example-code.php for this and sphere example • 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
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
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.
Sphere ExampleWill 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)
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)
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)
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)
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)
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)
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)
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 ); }
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
Cone examples • Book examples • (where vtk installed)…vtksrc/examples/tutorial
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() );
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 );
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; }
(Several) Coordinate Systems • Model/object … • local coordinate system • World … • Where the models are placed • In cg and VTK several coordinate systems come into play: • View … • Logical Image Plane • Display (image plane) • X,Y Pixel locations
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
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.
Real End • .