Scientific Visualization using VTK Robert Putnam putnambu edu
Scientific Visualization using VTK Robert Putnam putnam@bu. edu Scientific Visualization with VTK – Fall 2010
Outline • • • Introduction VTK overview VTK data geometry/topology Case study Interactive session Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
VTK Visualization Toolkit – 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 with VTK – Fall 2010
Generic visualization pipeline Filters(s) data/geometry/topology Scientific Visualization with VTK – Fall 2010 ----------- Source(s) Output graphics
VTK terminology/model Filter data/geometry/topology Scientific Visualization with VTK – Fall 2010 ----------- Source Mapper Renderer graphics
VTK terminology/model “Scene" Filter Data. Object Process. Object data/geometry/topology Scientific Visualization with VTK – Fall 2010 ----------- Source/ Reader Lights, Camera Actor Mapper Render. Window graphics
Pipeline -> Sample Code vtk. Structured. Grid. Reader reader Set. File. Name "density. vtk" reader Update Reader vtk. Contour. Filter iso Set. Input. Connection [reader Get. Output. Port] iso Set. Value 0. 26 Filter vtk. Poly. Data. Mapper iso. Mapper Set. Input. Connection [iso Get. Output. Port] Mapper vtk. Actor iso. Actor Set. Mapper iso. Mapper Actor vtk. Renderer ren 1 Add. Actor iso. Actor Renderer vtk. Render. Window ren. Win Add. Renderer ren 1 ren. Win Set. Size 500 ren. Win Render Scientific Visualization with VTK – Fall 2010 Render. Window
TCL v. C++ • 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 • 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); Scientific Visualization with VTK – Fall 2010
Coding tip of the day! • • Google “VTK class list”, or Go to: http: //www. vtk. org/doc/nightly/html/annotated. html Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
VTK – Geometry v. Topology 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
VTK – Geometry v. Topology or 0, 1 1, 1 2, 1 3, 1 0, 0 1, 0 2, 0 3, 0 Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Geometry/Topology Structure 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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 – examples: quadrilaterals, hexahedron – applications: fluid flow, heat transfer Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Examples of Cell Types Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
Structured Points – Tcl code Editor structured-points. tcl: vtk. Structured. Points. Reader reader Set. File. Name "structured-points. vtk" reader Update vtk. Lookup. Table 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 Set. Input. Connection [reader Get. Output. Port] mapper Set. Lookup. Table lut vtk. Actor actor Set. Mapper mapper [actor Get. Property] Edge. Visibility. On [actor Get. Property] Set. Line. Width 2 Scientific Visualization with VTK – Fall 2010
Structured Points – Tcl code (cont. ) Editor structured-points. tcl: vtk. Renderer ren 1 Add. Actor actor ren 1 Set. Background 0. 5 vtk. Render. Window ren. Win Add. Renderer ren 1 ren. Win Set. Size 500 vtk. Render. Window. Interactor iren Set. Render. Window ren. Win iren Initialize wm withdraw. Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
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. Cutter *plane. Cut = vtk. Cutter: : New(); plane. Cut->Set. Input. Connection(reader->Get. Output. Port()); plane. Cut->Set. Cut. Function(plane); Scientific Visualization with VTK – Fall 2010
Work flow – Case Study Change color map, use script to loop over *. vtk, generate multiple jpegs, read into Adobe Premiere, produce animation: Scientific Visualization with VTK – Fall 2010
VTK – Getting Started - UI Unix Shell: katana: % cd ~/materials katana: % vtk cone 2. tcl Scientific Visualization with VTK – Fall 2010
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 u –command window e –exit Scientific Visualization with VTK – Fall 2010
Code – cone 2. tcl Editor cone 2. tcl: vtk. Cone. Source cone Set. Resolution 100 vtk. Poly. Data. Mapper cone. Mapper Set. Input [cone Get. Output] vtk. Actor cone. Actor Set. Mapper cone. Mapper [cone. Actor Get. Property] Set. Color 1. 0 0. 0 vtk. Renderer ren 1 Set. Background 0. 0 ren 1 Add. Actor cone. Actor vtk. Render. Window ren. Win Set. Size 500 ren. Win Add. Renderer ren 1 vtk. Render. Window. Interactor iren Set. Render. Window ren. Win iren Initialize Scientific Visualization with VTK – Fall 2010
Exercise Editor: cone 3. tcl 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 cone. Actor 2 Set. Position -1. 0 0. 0 Scientific Visualization with VTK – Fall 2010
Code – Exercise Editor: cone 3. tcl. . . vtk. Actor 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 cone. Actor 2 Set. Position -1. 0 0. 0. . . ren 1 Add. Actor cone. Actor 2. . . Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
File Format – Structured Grid Editor density. vtk: # vtk Data. File Version 3. 0 vtk output 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 LOOKUP_TABLE default 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 with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Clipping Editor: clipping. tcl vtk. Structured. Grid. Reader reader Set. File. Name “density. vtk” reader Update vtk. Plane plane eval plane Set. Origin [[reader Get. Output] Get. Center] plane Set. Normal -0. 287 0 0. 9579 vtk. Clip. Data. Set clip Set. Input. Connection [reader Get. Output. Port] clip Set. Clip. Function plane clip Inside. Out. On vtk. Data. Set. Mapper clip. Mapper Set. Input. Connection [clip Get. Output. Port] eval clip. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor clip. Actor Set. Mapper clip. Mapper Scientific Visualization with VTK – Fall 2010
Code – Cutplane/Slicing Editor: cutplane. tcl vtk. Structured. Grid. Reader reader Set. File. Name “density. vtk” reader Update vtk. Plane plane eval plane Set. Origin [[reader Get. Output] Get. Center] plane Set. Normal -0. 287 0 0. 9579 vtk. Cutter plane. Cut Set. Input. Connection [reader Get. Output. Port] plane. Cut Set. Cut. Function plane vtk. Poly. Data. Mapper cut. Mapper Set. Input. Connection [plane. Cut Get. Output. Port] eval cut. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor cut. Actor Set. Mapper cut. Mapper Scientific Visualization with VTK – Fall 2010
Code – Extract. Grid Editor: extract. tcl vtk. Structured. Grid. Reader reader Set. File. Name “density. vtk” reader Update vtk. Extract. Grid extract Set. Input. Connection [reader Get. Output. Port] extract Set. VOI -1000 7 10 extract Set. Sample. Rate 1 1 1 extract Include. Boundary. On vtk. Data. Set. Mapper mapper Set. Input. Connection [extract Get. Output. Port] eval mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor extract. Actor mapper Scientific Visualization with VTK – Fall 2010
Color Mapping Scalar Algorithms – Color Mapping • maps scalar data to colors • implemented by using scalar values as an index into a color lookup table • specify a HSVA (Hue-Saturation-Value-Alpha) ramp and then generate the colors in the table by using linear interpolation into the HSVA space. – VTK • vtk. Lookup. Table • vtk. Data. Set. Mapper Scientific Visualization with VTK – Fall 2010
Code – Color Mapping Editor: colormap. numcolors. tcl. . . vtk. Lookup. Table lut Set. Numberof. Colors 16 lut Set. Hue. Range 0. 0 0. 667 lut Build vtk. Structured. Grid. Reader reader Set. File. Name “subset. vtk” reader Update vtk. Data. Set. Mapper mapper Set. Input. Connection [reader Get. Output. Port] mapper Set. Lookup. Table lut eval mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor actor Set. Mapper mapper . . . Scientific Visualization with VTK – Fall 2010
Exercise * Change the number of colors in colormap * Reverse the Hue Range * Change the Scalar Range mapper Set. Scalar. Range 0. 0 0. 7 Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Contour (isoline) Editor: contour. single. tcl. . . vtk. Structured. Grid. Reader reader Set. File. Name “subset. vtk” reader Update vtk. Contour. Filter contour Set. Input. Connection [reader Get. Output. Port] contour Set. Value 0 0. 26 vtk. Poly. Data. Mapper contour. Mapper Set. Input. Connection [contour Get. Output. Port] eval contour. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor contour. Actor Set. Mapper contour. Mapper . . . Scientific Visualization with VTK – Fall 2010
Code – Contour (isosurface) Editor: isosurface. 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 0. 26 vtk. Poly. Data. Mapper iso. Mapper Set. Input. Connection [iso Get. Output. Port] eval iso. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor iso. Actor Set. Mapper iso. Mapper . . . Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Scalar Generation Editor: hawaii. color. tcl vtk. Poly. Data. Reader hawaii Set. File. Name "honolulu. vtk" hawaii Update vtk. Elevation. Filter elevation Set. Input [hawaii Get. Output] elevation Set. Low. Point 0 0 0 elevation Set. High. Point 0 0 1000 elevation Set. Scalar. Range 0 1000 vtk. Lookup. Table lut Set. Hue. Range 0. 7 0 vtk. Data. Set. Mapper hawaii. Mapper Set. Input [elevation Get. Output] hawaii. Mapper Set. Scalar. Range 0 1000 hawaii. Mapper Set. Lookup. Table lut vtk. Actor hawaii. Actor Set. Mapper hawaii. Mapper Scientific Visualization with VTK – Fall 2010
Scalar generation – Color Map Editor: hawaii. color 2. tcl vtk. Lookup. Table lut Set. Number. Of. Colors 9 lut Set. Table. Value 0 0 0. 4 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 Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Hedge. Hogs Editor: hedgehog. tcl vtk. Structured. Grid. Reader reader Set. File. Name “density. vtk” reader Update vtk. Hedge. Hog hhog Set. Input [reader Get. Output] hhog Set. Scale. Factor 0. 001 vtk. Poly. Data. Mapper hhog. Mapper Set. Input [hhog Get. Output] hhog. Mapper Set. Lookup. Table lut eval hhog. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor hhog. Actor Set. Mapper hhog. Mapper Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Oriented Glyphs Editor: glyph. tcl vtk. Arrow. Source 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 Set. Input [reader Get. Output. Port] glyph Set. Source [arrow Get. Output. Port] 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. 2 vtk. Poly. Data. Mapper glyph. Mapper Set. Input [glyph Get. Output] glyph. Mapper Set. Lookup. Table lut glyph. Mapper Scalar. Visibility. On eval glyph. Mapper Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
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 with VTK – Fall 2010
Code – Streamlines Editor: stream. Lines. tcl vtk. Point. Source seeds Set. Radius 3. 0 eval seeds Set. Center [[reader Get. Output] Get. Center] seeds Set. Number. Of. Points 100 vtk. Runge. Kutta 4 integ vtk. Stream. Tracer streamer Set. Input. Connection [reader Get. Output. Port] streamer Set. Source. Connection [seeds Get. Output. Port] streamer Set. Maximum. Propagation 100 streamer Set. Maximum. Propagation. Unit. To. Time. Unit streamer Set. Initial. Integration. Step. Unit. To. Cell. Length. Unit streamer Set. Initial. Integration. Step 0. 1 streamer Set. Integration. Direction. To. Both streamer Set. Integrator integ vtk. Poly. Data. Mapper map. Stream. Lines Set. Input. Connection [streamer Get. Output. Port] eval map. Stream. Lines Set. Scalar. Range [[reader Get. Output] Get. Scalar. Range] vtk. Actor stream. Line. Actor Set. Mapper map. Stream. Lines Scientific Visualization with VTK – Fall 2010
Code – Streamtubes Editor: stream. Tubes. vary. Radius. tcl vtk. Point. Source seeds Set. Radius 1. 0 seeds Set. Number. Of. Points 50 vtk. Runge. Kutta 4 integ vtk. Stream. Tracer streamer Set. Input. Connection [reader Get. Output. Port] streamer Set. Source. Connection [seeds Get. Output. Port]. . . vtk. Tube. Filter 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. Off stream. Tube Set. Vary. Radius. To. Vary. Radius. By. Scalar vtk. Poly. Data. Mapper map. Stream. Tube Set. Input. Connection [stream. Tube Get. Output. Port] map. Stream. Tube Set. Lookup. Table lut eval map. Stream. Tube Set. Scalar. Range [[[[reader Get. Output] Get. Point. Data] Get. Scalars] Get. Range] vtk. Actor stream. Tube. Actor Set. Mapper map. Stream. Tube [stream. Tube. Actor Get. Property] Backface. Culling. On Scientific Visualization with VTK – Fall 2010
Annotation – used for annotating visualization – VTK • vtk. Scalar. Bar. Actor • vtk. Text. Mapper • vtk. Scaled. Text. Actor Scientific Visualization with VTK – Fall 2010
Code – color. Bar Editor: color. Bar. tcl vtk. Structured. Grid. Reader reader Set. File. Name “density. vtk” reader Update vtk. Scalar. Bar. Actor 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. Render. Window ren. Win Add. Renderer ren 1 vtk. Render. Window. Interactor iren Set. Render. Window ren. Win ren 1 Add. Actor stream. Tube. Actor ren 1 Add. Actor outline. Actor ren 1 Add. Actor scalar. Bar ren 1 Set. Background 0. 5 Scientific Visualization with VTK – Fall 2010
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 with VTK – Fall 2010
Saving Images – common formats: • jpeg (lossy) • png (lossless) • postscript • tiff (lossless) – VTK • vtk. Window. To. Image. Filter • vtk. Render. Large. Image Scientific Visualization with VTK – Fall 2010
Code – Saving Images Editor: output. tcl ren. Win Render vtk. Window. To. Image. Filter w 2 if Set. Input ren. Win w 2 if Update vtk. Render. Large. Image render. Large Set. Input ren 1 render. Large Set. Magnification 4 #vtk. JPEGWriter writer # writer Set. Input. Connection [w 2 if Get. Output. Port] # writer Set. File. Name "image. jpg" # writer Set. Quality 100 # writer Write #vtk. PNGWriter writer # writer Set. Input. Connection [w 2 if Get. Output. Port] # writer Set. File. Name "image. png" # writer Write #vtk. Post. Script. Writer writer # writer Set. Input. Connection [w 2 if Get. Output. Port] # writer Set. File. Name "image. ps" # writer Write #vtk. TIFFWriter writer # writer Set. Input. Connection [w 2 if Get. Output. Port] # writer Set. File. Name "image. tif" # writer Write vtk. TIFFWriter lwriter Set. Input. Connection [render. Large Get. Output. Port] lwriter Set. File. Name "largeimage. tif" lwriter Write Scientific Visualization with VTK – Fall 2010
VTK - Resources IS&T tutorials – Scientific Visualization with 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 with VTK – Fall 2010
Questions? Tutorial survey: - http: //scv. bu. edu/survey/fall 10 tut_survey. html Scientific Visualization with VTK – Fall 2010
- Slides: 69