Scientific Visualization Using VTK Robert Putnam putnambu edu
Scientific Visualization Using VTK Robert Putnam putnam@bu. edu Scientific Visualization Using VTK – Fall 2012
Outline • • • Introduction VTK overview VTK data geometry/topology Case study Interactive session Scientific Visualization Using VTK – Fall 2012
Introduction • Visualization: converting raw data to a form that is viewable and understandable to humans. • Scientific visualization: specifically concerned with data that has a well-defined representation in 2 D or 3 D space (e. g. , from simulation mesh or scanner). *Adapted from The Para. View Tutorial, Moreland Scientific Visualization Using VTK – Fall 2012
VTK Visualization Toolkit – Inception at GE in 1993; since 1998 spun off to “Kitware”, supported by Sandia Labs. – Open source – Set of object-oriented class libraries for visualization and data analysis – Several language interfaces • • – – C++ Tcl Java Python Portable (MS Windows, Linux, OSX) Active developer community Good documentation available, free and otherwise Professional support services available from Kitware Scientific Visualization Using VTK – Fall 2012
Generic visualization pipeline Filters(s) data/geometry/topology Scientific Visualization Using VTK – Fall 2012 ----------- Source(s) Output graphics
VTK terminology/model Filter data/geometry/topology Scientific Visualization Using VTK – Fall 2012 ----------- Source Mapper Renderer graphics
VTK terminology/model “Scene" Filter Data. Object Process. Object data/geometry/topology Scientific Visualization Using VTK – Fall 2012 ----------- Source/ Reader Lights, Camera Actor Mapper Render. Window graphics
Pipeline -> Sample Code vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); Reader vtk. Contour. Filter *iso = vtk. Contour. Filter: : New(); iso->Set. Input. Connection(reader->Get. Output. Port()); iso->Set. Value(0, 0. 26); Filter vtk. Poly. Data. Mapper *iso. Mapper = vtk. Poly. Data. Mapper: : New(); iso. Mapper->Set. Input. Connection(iso->Get. Output. Port()); Mapper vtk. Actor *iso. Actor = vtk. Actor: : New(); iso. Actor->Set. Mapper(iso. Mapper); Actor vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Add. Actor(iso. Actor); Renderer vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Set. Size(500, 500); ren. Win->Add. Renderer(ren 1); Render. Window Scientific Visualization Using VTK – Fall 2012
C++ v. Tcl • C++ vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Contour. Filter *iso = vtk. Countour. Filter: : New(); iso->Set. Input. Connection(reader->Get. Output. Port()); iso->Set. Value(0, . 26); • Tcl vtk. Structured. Grid. Reader reader Set. File. Name "density. vtk" reader Update vtk. Contour. Filter iso Set. Input. Connection [reader Get. Output. Port] iso Set. Value 0. 26 Scientific Visualization Using VTK – Fall 2012
Coding tip of the day! • • Google “VTK class list”, or Go to: http: //www. vtk. org/doc/nightly/html/annotated. html Scientific Visualization Using VTK – Fall 2012
VTK – Geometry v. Topology Geometry of a dataset ~= points 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Topology ~= connections among points, which define cells So, what’s the topology here? Scientific Visualization Using VTK – Fall 2012
VTK – Geometry v. Topology 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization Using VTK – Fall 2012
VTK – Geometry v. Topology 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 or 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization Using VTK – Fall 2012
VTK – Geometry v. Topology or 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization Using VTK – Fall 2012
VTK – Geometry v. Topology or 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 or or 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization Using VTK – Fall 2012
Geometry/Topology Structure Geometry/topology may be regular or irregular – Regular (structured) • need to store only beginning position, spacing, number of points • smaller memory footprint per cell (topology can be generated on the fly) • examples: image data, rectilinear grid, structured grid – Irregular (unstructured) • information can be represented more densely where it changes quickly • higher memory footprint (topology must be explicitly written) but more freedom • examples: polygonal data, unstructured grid Scientific Visualization Using VTK – Fall 2012
Characteristics of Data is organized into datasets for visualization – Datasets consist of two pieces • organizing structure – points (geometry) – cells (topology) • data attributes associated with the structure – File format derived from organizing structure Data is discrete – Interpolation functions generate data values in between known points Scientific Visualization Using VTK – Fall 2012
Examples of Dataset Types Structured Points (Image Data) – regular in both topology and geometry – examples: lines, pixels, voxels – applications: imaging CT, MRI Rectilinear Grid – regular topology but geometry only partially regular – examples: pixels, voxels Structured Grid (Curvilinear) – regular topology and irregular geometry – applications: fluid flow, heat transfer Scientific Visualization Using VTK – Fall 2012
Examples of Dataset Types (cont) Polygonal Data – irregular in both topology and geometry – examples: vertices, polyvertices, lines, polygons, triangle strips Unstructured Grid – irregular in both topology and geometry – examples: any combination of cells – applications: finite element analysis, structural design, vibration Scientific Visualization Using VTK – Fall 2012
Examples of Cell Types Scientific Visualization Using VTK – Fall 2012
Data Attributes Data attributes associated with the organizing structure – Scalars • single valued • examples: temperature, pressure, density, elevation – Vectors • magnitude and direction • examples: velocity, momentum – Normals • direction vectors (magnitude of 1) used for shading – Texture Coordinates • used to map a point in Cartesian space into 1, 2, or 3 D texture space • used for texture mapping – Tensors • 3 x 3 only • examples: stress, strain Scientific Visualization Using VTK – Fall 2012
File Format – Structured Points Editor structured-points. vtk: # vtk Data. File Version 3. 0 first dataset ASCII DATASET STRUCTURED_POINTS DIMENSIONS 3 4 5 ORIGIN 0 0 0 SPACING 1 1 2 POINT_DATA 60 SCALARS temp-point float LOOKUP_TABLE default 000111111000 000111111000 Scientific Visualization Using VTK – Fall 2012
File Format – Structured Points Editor structured-points. vtk: # vtk Data. File Version 3. 0 first dataset ASCII DATASET STRUCTURED_POINTS DIMENSIONS 3 4 5 ORIGIN 0 0 0 SPACING 1 1 2 POINT_DATA 60 SCALARS temp-point float LOOKUP_TABLE default 000111111000 000111111000 Scientific Visualization Using VTK – Fall 2012
File Format – Structured Points Editor structured-points 2. vtk: # vtk Data. File Version 3. 0 first dataset ASCII DATASET STRUCTURED_POINTS DIMENSIONS 3 4 5 ORIGIN 0 0 0 SPACING 1 1 2 CELL_DATA 24 SCALARS temp-cell float LOOKUP_TABLE default 001100 Scientific Visualization Using VTK – Fall 2012
File Format – Structured Points Editor structured-points 2. vtk: # vtk Data. File Version 3. 0 first dataset ASCII DATASET STRUCTURED_POINTS DIMENSIONS 3 4 5 ORIGIN 0 0 0 SPACING 1 1 2 CELL_DATA 24 SCALARS temp-cell float LOOKUP_TABLE default 001100 Scientific Visualization Using VTK – Fall 2012
Structured Points – C++ code Editor structured-points. cxx: vtk. Structured. Points. Reader *reader = vtk. Structured. Points. Reader: : New(); reader->Set. File. Name("structured-points. vtk"); reader->Update(); vtk. Lookup. Table *lut = vtk. Lookup. Table: : New(); lut->Set. Number. Of. Colors(2); lut->Set. Table. Value(0, 0. 0, 1); lut->Set. Table. Value(1, 1. 0, 0. 0, 1); vtk. Data. Set. Mapper *mapper = vtk. Data. Set. Mapper: : New(); mapper->Set. Input. Connection(reader->Get. Output. Port()); mapper->Set. Lookup. Table(lut); vtk. Actor *actor = vtk. Actor: : New(); actor->Set. Mapper(mapper); actor->Get. Property()->Edge. Visibility. On(); actor->Get. Property()->Set. Line. Width(2); Scientific Visualization Using VTK – Fall 2012
Structured Points – C++ code (cont. ) Editor structured-points. cxx: vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Add. Actor(actor); ren 1 ->Set. Background(0. 5, 0. 5); vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Add. Renderer(ren 1); ren. Win->Set. Size(500, 500); vtk. Render. Window. Interactor *iren = vtk. Render. Window. Interactor: : New(); iren->Set. Render. Window(ren. Win); iren->Initialize(); iren->Start(); Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study BU Space Physics simulation Meteor trails in the ionosphere Data wrangling: Consolidate datafiles (from parallel code), create single binary datafile # vtk Data. File Version 3. 0 Add VTK header: output of reassemble. c BINARY DATASET STRUCTURED_POINTS ORIGIN 0. 0 SPACING 1. 0 DIMENSIONS 512 64 128 POINT_DATA 4194304 SCALARS plasma float LOOKUP_TABLE default Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study Use Tcl for fast development/testing: vtk. Structured. Points. Reader reader Set. File. Name "opp. vtk" reader Update vtk. Contour. Filter iso Set. Input. Connection [reader Get. Output. Port] iso Set. Value 0 0. 1. . . Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study Add gaussian filter : vtk. Image. Gaussian. Smooth gaussian Set. Input. Connection [reader Get. Output. Port] gaussian Set. Dimensionality 3 gaussian Set. Radius. Factor 1 vtk. Contour. Filter iso Set. Input. Connection [gaussian Get. Output. Port] iso Set. Value 0 0. 1 . . . Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study Add more isosurfaces : vtk. Contour. Filter iso Set. Input. Connection [gaussian Get. Output. Port] iso Set. Value 0 1. 0 iso Set. Value 1 0. 5 iso Set. Value 2 0. 1 Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study Port to C++, add cutplane, transparency : vtk. Plane *plane = vtk. Plane: : New(); plane->Set. Origin(256, 2, 63. 5); plane->Set. Normal(0, 1, 0); vtk. Actor *iso. Actor = vtk. Actor: : New(); iso. Actor->Get. Property()->Set. Opacity(iv_opacity); vtk. Cutter *plane. Cut = vtk. Cutter: : New(); plane. Cut->Set. Input. Connection(reader->Get. Output. Port()); plane. Cut->Set. Cut. Function(plane); Scientific Visualization Using VTK – Fall 2012
Work flow – Case Study Change color map, use script to loop over *. vtk, generate multiple jpegs, read into Adobe Premiere, produce animation: Scientific Visualization Using VTK – Fall 2012
VTK – Getting Started - UI Unix Shell: katana: % cone 2 Scientific Visualization Using VTK – Fall 2012
Keyboard shortcuts j – joystick (continuous) mode t – trackball mode c –camera move mode a –actor move mode left mouse – rotate x, y ctrl - left mouse – rotate z middle mouse –pan right mouse –zoom r –reset camera s/w –surface/wireframe e (or q) –exit Scientific Visualization Using VTK – Fall 2012
Code – simple. cxx Editor: simple. cxx #include <stdio. h> #include <stdlib. h> #include "vtk-include. h" int main(int argc, char *argv[]) { vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Set. Background(0. 0, 0. 0); vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Set. Size(500, 500); ren. Win->Add. Renderer(ren 1); ren. Win->Render(); sleep(2); } Scientific Visualization Using VTK – Fall 2012
Exercise Editor: simple 2. cxx Change background color to gray (or fuchsia, etc. ) Scientific Visualization Using VTK – Fall 2012
Code – Exercise Editor: simple 2. cxx int main(int argc, char *argv[]) { vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Set. Background(0. 5, 0. 5); vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Set. Size(500, 500); ren. Win->Add. Renderer(ren 1); ren. Win->Render(); sleep(2); } Scientific Visualization Using VTK – Fall 2012
Code – cone 2. cxx Editor cone 2. cxx: vtk. Cone. Source *cone = vtk. Cone. Source: : New(); cone->Set. Resolution(100); vtk. Poly. Data. Mapper *cone. Mapper = vtk. Poly. Data. Mapper: : New(); cone. Mapper->Set. Input. Connection(cone->Get. Output. Port()); vtk. Actor *cone. Actor = vtk. Actor: : New(); cone. Actor->Set. Mapper(cone. Mapper); cone. Actor->Get. Property()->Set. Color(1. 0, 0. 0); vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Set. Background(0. 0, 0. 0); ren 1 ->Add. Actor(cone. Actor); vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Set. Size(500, 500); ren. Win->Add. Renderer(ren 1); vtk. Render. Window. Interactor *iren = vtk. Render. Window. Interactor: : New(); iren->Set. Render. Window(ren. Win); iren->Initialize(); iren->Start(); Scientific Visualization Using VTK – Fall 2012
Exercise Editor: cone 3. cxx Add cone. Actor 2, and color it green. (Copy cone. Actor, and make appropriate changes. Remember to add the new actor to the render window [near the end of the “pipeline”]. ) Optional: to rotate, scale and set the position away from the origin, use the following: cone. Actor 2 ->Rotate. Z(90); cone. Actor 2 ->Set. Scale(0. 5, 0. 5); cone. Actor 2 ->Set. Position(1. 0, 0. 0); Otherwise, use ‘a’ (actor) to use mouse to separate the green and red cones. Scientific Visualization Using VTK – Fall 2012
Code – Exercise Editor: cone 3. cxx. . . vtk. Actor *cone. Actor 2 = vtk. Actor: : New(); cone. Actor 2 ->Set. Mapper(cone. Mapper); cone. Actor 2 ->Get. Property()->Set. Color(0. 0, 1. 0, 0. 0); cone. Actor 2 ->Rotate. Z(90); cone. Actor 2 ->Set. Scale(0. 5, 0. 5); cone. Actor 2 ->Set. Position(1. 0, 0. 0); . . . ren 1 ->Add. Actor(cone. Actor); ren 1 ->Add. Actor(cone. Actor 2); . . . Scientific Visualization Using VTK – Fall 2012
VTK - Readers Image and Volume Readers – – – vtk. Structured. Points. Reader - read VTK structured points data files vtk. SLCReader - read SLC structured points files vtk. TIFFReader - read files in TIFF format vtk. Volume. Reader - read image (volume) files vtk. Volume 16 Reader - read 16 -bit image (volume) files Structured Grid Readers – vtk. Structured. Grid. Reader - read VTK structured grid data files – vtk. PLOT 3 DReader - read structured grid PLOT 3 D files Rectilinear Grid Readers – vtk. Rectilinear. Grid. Reader - read VTK rectilinear grid data files Unstructured Grid Readers – vtk. Unstructured. Grid. Reader - read VTK unstructured grid data files Scientific Visualization Using VTK – Fall 2012
VTK - Readers Polygonal Data Readers – – – – vtk. Poly. Data. Reader - read VTK polygonal data files vtk. BYUReader - read MOVIE. BYU files vtk. MCubes. Reader - read binary marching cubes files vtk. OBJReader - read Wavefront (Maya). obj files vtk. PLYReader - read Stanford University PLY polygonal data files vtk. STLReader - read stereo-lithography files vtk. UGFacet. Reader - read EDS Unigraphic facet files Image and Volume Readers (add’l) – – – vtk. BMPReader - read PC bitmap files vtk. DEMReader - read digital elevation model files vtk. JPEGReader - read JPEG files vtk. Image. Reader - read various image files vtk. PNMReader - read PNM (ppm, pgm, pbm) files vtk. PNGRReader - read Portable Network Graphic files Scientific Visualization Using VTK – Fall 2012
File Format – Structured Grid Editor density. vtk: # vtk Data. File Version 3. 0 vtk sample data ASCII DATASET STRUCTURED_GRID DIMENSIONS 57 33 25 POINTS 47025 float 2. 667 -3. 77476 23. 8329 2. 94346 -3. 74825 23. 6656 3. 21986 -3. 72175 23. 4982 3. 50007 -3. 70204 23. 3738 3. 9116 -3. 72708 23. 5319 4. 1656 -3. 69529 23. 3312. . . POINT_DATA 47025 SCALARS Density float 0. 639897 0. 239841 0. 252319 0. 255393 0. 252118 0. 246661 0. 240134 0. 234116 0. 229199 0. 225886 0. 224268 0. 224647 0. 231496 0. 246895 0. 26417 0. 27585 0. 278987 0. 274621. . . VECTORS Momentum float 0 0 0 13. 753 -5. 32483 -19. 964 42. 3106 -15. 57 -43. 0034 64. 2447 -13. 3958 -46. 2281 73. 7861 -4. 83205 -36. 3829 88. 3374 6. 23797 -22. 8846. . . Scientific Visualization Using VTK – Fall 2012
Clipping, Cutting, Subsampling Selection Algorithms - Clipping • can reveal internal details of surface • VTK - vtk. Clip. Data. Set - Cutting/Slicing • cutting through a dataset with a surface • VTK - vtk. Cutter - Subsampling • reduces data size by selecting a subset of the original data • VTK - vtk. Extract. Grid Scientific Visualization Using VTK – Fall 2012
Code – Clipping Editor: clipping. cxx vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Plane *plane = vtk. Plane: : New(); plane->Set. Origin(reader->Get. Output()->Get. Center()); plane->Set. Normal(-0. 287, 0, 0. 9579); vtk. Clip. Data. Set *clip = vtk. Clip. Data. Set: : New(); clip->Set. Input. Connection(reader->Get. Output. Port()); clip->Set. Clip. Function(plane); clip->Inside. Out. On(); vtk. Data. Set. Mapper *clip. Mapper = vtk. Data. Set. Mapper: : New(); clip. Mapper->Set. Input. Connection(clip->Get. Output. Port()); clip. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *clip. Actor = vtk. Actor: : New(); clip. Actor->Set. Mapper(clip. Mapper); Scientific Visualization Using VTK – Fall 2012 Exercise: What’s the effect of clip->Inside. Out. Off(); ?
Code – Cutplane/Slicing Editor: cutplane. cxx vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Plane *plane = vtk. Plane: : New(); plane->Set. Origin(reader->Get. Output()->Get. Center()); plane->Set. Normal(-0. 287, 0, 0. 9579); vtk. Cutter *plane. Cut = vtk. Cutter: : New(); plane. Cut->Set. Input. Connection(reader->Get. Output. Port()); plane. Cut->Set. Cut. Function(plane); vtk. Poly. Data. Mapper *cut. Mapper = vtk. Poly. Data. Mapper: : New(); cut. Mapper->Set. Input. Connection(plane. Cut->Get. Output. Port()); cut. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *cut. Actor = vtk. Actor: : New(); cut. Actor->Set. Mapper(cut. Mapper); Scientific Visualization Using VTK – Fall 2012 *To see the cutplane with a colorbar guide, try ‘cutplane-with-colorbar’.
Code – Extract. Grid Editor: extract. cxx vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Extract. Grid *extract = vtk. Extract. Grid: : New(); extract->Set. Input. Connection(reader->Get. Output. Port()); extract->Set. VOI(-1000, 7, 10); vtk. Data. Set. Mapper *extract. Mapper = vtk. Data. Set. Mapper: : New(); extract. Mapper->Set. Input. Connection(extract->Get. Output. Port()); extract. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *extract. Actor = vtk. Actor: : New(); extract. Actor->Set. Mapper(extract. Mapper); *Exercise: enable Edge. Visibility in Extract. Actor. Scientific Visualization Using VTK – Fall 2012
Color Mapping Scalar Algorithms – Color Mapping • maps scalar data to colors • implemented by using scalar values as an index into a color lookup table – VTK • vtk. Lookup. Table • vtk. Data. Set. Mapper Scientific Visualization Using VTK – Fall 2012
Code – Color Mapping Editor: colormap. numcolors. cxx. . . vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("subset. vtk"); reader->Update(); vtk. Lookup. Table *lut = vtk. Lookup. Table: : New(); lut->Set. Number. Of. Colors(16); lut->Set. Hue. Range(0. 0, 0. 667); vtk. Data. Set. Mapper *mapper = vtk. Data. Set. Mapper: : New(); mapper->Set. Input. Connection(reader->Get. Output. Port()); mapper->Set. Lookup. Table(lut); mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *actor = vtk. Actor: : New(); actor->Set. Mapper(mapper); Scientific Visualization Using VTK – Fall 2012
Exercise * Change the number of colors in colormap * Reverse the Hue Range * Change the Scalar Range (or see what happens if you don’t set it). E. g. , mapper->Set. Scalar. Range(0. 0, 1. 0); Scientific Visualization Using VTK – Fall 2012
Contouring Scalar Algorithms (cont) – Contouring • construct a boundary between distinct regions, two steps: – explore space to find points near contour – connect points into contour (2 D) or surface (3 D) • 2 D contour map (isoline): – applications: elevation contours from topography, pressure contours (weather maps) from meteorology 3 D isosurface: • 3 D isosurface: – applications: tissue surfaces from tomography, constant pressure or temperature in fluid flow, implicit surfaces from math and CAD – VTK • vtk. Contour. Filter Scientific Visualization Using VTK – Fall 2012
Code – Contour (isoline) Editor: contour. single. cxx. . . vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("subset. vtk"); reader->Update(); vtk. Contour. Filter *iso = vtk. Contour. Filter: : New(); iso->Set. Input. Connection(reader->Get. Output. Port()); iso->Set. Value(0, 0. 26); vtk. Poly. Data. Mapper *iso. Mapper = vtk. Poly. Data. Mapper: : New(); iso. Mapper->Set. Input. Connection(iso->Get. Output. Port()); iso. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *iso. Actor = vtk. Actor: : New(); iso. Actor->Set. Mapper(iso. Mapper); . . . Scientific Visualization Using VTK – Fall 2012
Code – Contour (isosurface) Editor: isosurface. cxx. . . vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name(“density. vtk"); reader->Update(); vtk. Contour. Filter *iso = vtk. Contour. Filter: : New(); iso->Set. Input. Connection(reader->Get. Output. Port()); iso->Set. Value(0, 0. 26); vtk. Poly. Data. Mapper *iso. Mapper = vtk. Poly. Data. Mapper: : New(); iso. Mapper->Set. Input. Connection(iso->Get. Output. Port()); iso. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *iso. Actor = vtk. Actor: : New(); iso. Actor->Set. Mapper(iso. Mapper); . . . Scientific Visualization Using VTK – Fall 2012
Scalar Generation Scalar Algorithms (cont) – Scalar Generation • extract scalars from part of data • example: extracting z coordinate (elevation) from terrain data to create scalar values – VTK • vtk. Elevation. Filter Scientific Visualization Using VTK – Fall 2012
Code – Scalar Generation Editor: hawaii. color. cxx vtk. Poly. Data. Reader *hawaii = vtk. Poly. Data. Reader: : New(); hawaii->Set. File. Name("honolulu. vtk"); hawaii->Update(); hawaii->Get. Output()->Get. Bounds(bounds); vtk. Elevation. Filter *elevation = vtk. Elevation. Filter: : New(); elevation->Set. Input. Connection(hawaii->Get. Output. Port()); elevation->Set. Low. Point(0, 0, bounds[4]); elevation->Set. High. Point(0, 0, bounds[5]); vtk. Lookup. Table *lut = vtk. Lookup. Table: : New(); lut->Set. Hue. Range(0. 7, 0); vtk. Data. Set. Mapper *hawaii. Mapper = vtk. Data. Set. Mapper: : New(); hawaii. Mapper->Set. Input. Connection(elevation->Get. Output. Port()); hawaii. Mapper->Set. Lookup. Table(lut); vtk. Actor *hawaii. Actor = vtk. Actor: : New(); hawaii. Actor->Set. Mapper(hawaii. Mapper); Scientific Visualization Using VTK – Fall 2012
Scalar generation – Color Map Editor: hawaii. color 2. cxx vtk. Lookup. Table *lut = vtk. Lookup. Table: : New(); lut->Set. Number. Of. Colors(9); lut->Set. Table. Value(0, 0. 40, 0. 8, 1); lut->Set. Table. Value(1, 0. 0, 0. 75, 0. 2, 1); lut->Set. Table. Value(2, 0. 25, 0. 625, 0. 5, 1); lut->Set. Table. Value(3, 0. 0, 0. 5, 0. 25, 1); lut->Set. Table. Value(4, 0. 5, 0. 365, 0. 0, 1); lut->Set. Table. Value(5, 0. 75, 0. 625, 0. 25, 1); lut->Set. Table. Value(6, 1. 0, 0. 75, 0. 625, 1); lut->Set. Table. Value(7, 1. 0, 0. 75, 0. 5, 1); lut->Set. Table. Value(8, 1. 0, 1, 1, 1); If time permits, try producing a “global cooling” movie: % make hawaii. color 2. save % hawaii. color 2. save. sh 10 % hawaii. color 2. playback Scientific Visualization Using VTK – Fall 2012
Hedgehogs Vector Algorithms – Hedgehogs • oriented scaled line for each vector • scale indicates magnitude • color indicates magnitude, pressure, temperature, or any variable – VTK • vtk. Hedge. Hog Scientific Visualization Using VTK – Fall 2012
Code – Hedge. Hogs Editor: hedgehog. cxx vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Hedge. Hog *hhog = vtk. Hedge. Hog: : New(); hhog->Set. Input. Connection(reader->Get. Output. Port()); hhog->Set. Scale. Factor(0. 001); vtk. Poly. Data. Mapper *hhog. Mapper = vtk. Poly. Data. Mapper: : New(); hhog. Mapper->Set. Input. Connection(hhog->Get. Output. Port()); hhog. Mapper->Set. Lookup. Table(lut); hhog. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *hhog. Actor = vtk. Actor: : New(); hhog. Actor->Set. Mapper(hhog. Mapper); *line length ~= vector (‘momentum’) magnitude; line color ~= scalar (‘density’) Scientific Visualization Using VTK – Fall 2012
Oriented Glyphs Vector Algorithms (cont) – Oriented Glyphs • orientation indicates direction • scale indicates magnitude • color indicates magnitude, pressure, temperature, or any variable – VTK • vtk. Glyph 3 D Scientific Visualization Using VTK – Fall 2012
Code – Oriented Glyphs Editor: glyph. cxx vtk. Arrow. Source *arrow = vtk. Arrow. Source: : New(); arrow->Set. Tip. Resolution(6); arrow->Set. Tip. Radius(0. 1); arrow->Set. Tip. Length(0. 35); arrow->Set. Shaft. Resolution(6); arrow->Set. Shaft. Radius(0. 03); vtk. Glyph 3 D *glyph = vtk. Glyph 3 D: : New(); glyph->Set. Input. Connection(extract->Get. Output. Port()); glyph->Set. Source(arrow->Get. Output()); glyph->Set. Vector. Mode. To. Use. Vector(); glyph->Set. Color. Mode. To. Color. By. Scalar(); glyph->Set. Scale. Mode. To. Data. Scaling. Off(); glyph->Orient. On(); glyph->Set. Scale. Factor(0. 25); vtk. Poly. Data. Mapper *glyph. Mapper = vtk. Poly. Data. Mapper: : New(); glyph. Mapper->Set. Input. Connection(glyph->Get. Output. Port()); glyph. Mapper->Set. Lookup. Table(lut); glyph. Mapper->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); Scientific Visualization Using VTK – Fall 2012
Field Lines Vector Algorithms (cont) – Field Lines • Fluid flow is described by a vector field in three dimensions for steady (fixed time) flows or four dimensions for unsteady (time varying) flows • Three techniques for determining flow – Pathline (Trace) • tracks particle through unsteady (time-varying) flow • shows particle trajectories over time • rake releases particles from multiple positions at the same time instant • reveals compression, vorticity – Streamline • tracks particle through steady (fixed-time) flow • holds flow steady at a fixed time • snapshot of flow at a given time instant – Streakline • particles released from the same position over a time interval (time-varying) • snapshot of the variation of flow over time • example: dye steadily injected into fluid at a fixed point Scientific Visualization Using VTK – Fall 2012
Field Lines Streamlines • Lines show particle flow • VTK – vtk. Stream. Tracer Streamlets • half way between streamlines and glyphs • VTK - vtk. Stream. Tracer, vtk. Glyph 3 D Streamribbon • rake of two particles to create a ribbon • VTK - vtk. Stream. Tracer, vtk. Ruled. Surface. Filter Streamtube • circular rake of particles to create a tube • VTK - vtk. Stream. Tracer, vtk. Tube. Filter Scientific Visualization Using VTK – Fall 2012
Code – Streamlines Editor: stream. Lines. cxx vtk. Point. Source *seeds = vtk. Point. Source: : New(); seeds->Set. Radius(3. 0); seeds->Set. Center(reader->Get. Output()->Get. Center()); seeds->Set. Number. Of. Points(100); vtk. Runge. Kutta 4 *integ = vtk. Runge. Kutta 4: : New(); vtk. Stream. Tracer *streamer = vtk. Stream. Tracer: : New(); streamer->Set. Input. Connection(reader->Get. Output. Port()); streamer->Set. Source. Connection(seeds->Get. Output. Port()); streamer->Set. Maximum. Propagation(100); streamer->Set. Integration. Direction. To. Both(); streamer->Set. Integrator(integ); vtk. Poly. Data. Mapper *map. Stream. Lines = vtk. Poly. Data. Mapper: : New(); map. Stream. Lines->Set. Input. Connection(streamer->Get. Output. Port()); map. Stream. Lines->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *stream. Line. Actor = vtk. Actor: : New(); stream. Line. Actor->Set. Mapper(map. Stream. Lines); *see also streamline-glyph. cxx Scientific Visualization Using VTK – Fall 2012
Code – Streamtubes Editor: stream. Tubes. vary. Radius. cxx vtk. Point. Source *seeds = vtk. Point. Source: : New(); seeds->Set. Radius(1. 0); seeds->Set. Center(1. 5, 0. 01, 27); seeds->Set. Number. Of. Points(50); vtk. Runge. Kutta 4 *integ = vtk. Runge. Kutta 4: : New(); vtk. Stream. Tracer *streamer = vtk. Stream. Tracer: : New(); streamer->Set. Input. Connection(reader->Get. Output. Port()); streamer->Set. Source. Connection(seeds->Get. Output. Port()); … vtk. Tube. Filter *stream. Tube = vtk. Tube. Filter: : New(); stream. Tube->Set. Input. Connection(streamer->Get. Output. Port()); stream. Tube->Set. Radius(0. 01); stream. Tube->Set. Number. Of. Sides(6); stream. Tube->Set. Vary. Radius. To. Vary. Radius. By. Scalar(); vtk. Poly. Data. Mapper *map. Stream. Tube = vtk. Poly. Data. Mapper: : New(); map. Stream. Tube->Set. Input. Connection(stream. Tube->Get. Output. Port()); map. Stream. Tube->Set. Scalar. Range(reader->Get. Output()->Get. Scalar. Range()); vtk. Actor *stream. Tube. Actor = vtk. Actor: : New(); stream. Tube. Actor->Set. Mapper(map. Stream. Tube); Scientific Visualization Using VTK – Fall 2012
Annotation – used for annotating visualization – VTK • vtk. Scalar. Bar. Actor • vtk. Text. Mapper • vtk. Scaled. Text. Actor Scientific Visualization Using VTK – Fall 2012
Code – color. Bar Editor: color. Bar. cxx vtk. Structured. Grid. Reader *reader = vtk. Structured. Grid. Reader: : New(); reader->Set. File. Name("density. vtk"); reader->Update(); vtk. Scalar. Bar. Actor *scalar. Bar = vtk. Scalar. Bar. Actor: : New(); scalar. Bar->Set. Lookup. Table(lut); scalar. Bar->Set. Title("Combustor Density Magnitude"); scalar. Bar->Set. Number. Of. Labels(2); scalar. Bar->Get. Position. Coordinate()->Set. Value(0. 1, 0. 01); scalar. Bar->Set. Orientation. To. Horizontal(); scalar. Bar->Set. Width(0. 8); scalar. Bar->Set. Height(0. 09); vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Set. Background(0. 5, 0. 5); ren 1 ->Add. Actor(stream. Tube. Actor); ren 1 ->Add. Actor(outline. Actor); ren 1 ->Add. Actor(scalar. Bar); Scientific Visualization Using VTK – Fall 2012
VTK - Writers Polygonal Data Writers – – – – vtk. BYUWriter - write MOVIE. BYU files vtk. CGMWriter - write 2 D polygonal data as a CGM file vtk. IVWriter - write Inventor files vtk. MCubes. Writer - write triangles in marching cubes format vtk. Poly. Data. Writer - write VTK polygonal data files vtk. PLYWriter - write Standford University PLY polygonal data files vtk. STLWriter - write stereo-lithography files Image and Volume writers – – – – vtk. BMPwriter - write PC bitmap files vtk. JPEGwriter - write images in JPEG format vtk. Postscript. Writer – write image files in Postscript format vtk. PNMwriter - write PNM (ppm, pgm, pbm) image files vtk. PNGwriter - write image file in Portable Network Graphic format vtk. TIFFWriter – write image files in TIFF format vtk. Structured. Points. Writer – write a vtk. Structured. Points file Scientific Visualization Using VTK – Fall 2012
Saving Images – common formats: • jpeg (lossy) • png (lossless) • postscript • tiff (lossless) – VTK • vtk. Window. To. Image. Filter • vtk. Render. Large. Image Scientific Visualization Using VTK – Fall 2012
Code – Saving Images Editor: output. cxx vtk. Renderer *ren 1 = vtk. Renderer: : New(); ren 1 ->Add. Actor(stream. Tube. Actor); ren 1 ->Reset. Camera(); ren 1 ->Get. Active. Camera()->Dolly(1. 25); ren 1 ->Reset. Camera. Clipping. Range(); vtk. Render. Window *ren. Win = vtk. Render. Window: : New(); ren. Win->Point. Smoothing. On(); ren. Win->Line. Smoothing. On(); ren. Win->Polygon. Smoothing. On(); ren. Win->Add. Renderer(ren 1); ren. Win->Set. Size(500, 500); ren. Win->Render(); vtk. Window. To. Image. Filter *w 2 if = vtk. Window. To. Image. Filter: : New(); w 2 if->Set. Input(ren. Win); vtk. Render. Large. Image *render. Large = vtk. Render. Large. Image: : New(); render. Large->Set. Input(ren 1); render. Large->Set. Magnification(4); vtk. TIFFWriter *writer = vtk. TIFFWriter: : New(); writer->Set. Input. Connection(w 2 if->Get. Output. Port()); writer->Set. File. Name("image. tif"); writer->Write(); vtk. TIFFWriter *lwriter = vtk. TIFFWriter: : New(); lwriter->Set. Input. Connection(render. Large->Get. Output. Port()); lwriter->Set. File. Name(". /largeimage. tif"); lwriter->Write(); Scientific Visualization Using VTK – Fall 2012
VTK - Resources IS&T tutorials – Scientific Visualization Using VTK www. bu. edu/tech/research/training/tutorials/vtk/ – VTK Examples www. bu. edu/tech/research/training/scv-software-packages/vtk_examples/ Texts – – www. vtk. org www. kitware. com www. vtk. org/doc/release/5. 4/html/classes. html Wiki – The VTK User’s Guide, 5 th Edition, Kitware, Inc, 2006. Websites – – – The Visualization Toolkit, 4 th Edition, Kitware, Inc, 2006. www. vtk. org/Wiki/VTK Mailing Lists – www. vtk. org/VTK/help/mailing. html Scientific Visualization Using VTK – Fall 2012
Questions? Tutorial survey: - http: //scv. bu. edu/survey/tutorial_evaluation. html Scientific Visualization Using VTK – Fall 2012
- Slides: 72