Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scientific Visualization Using VTK – Fall 2011

Similar presentations


Presentation on theme: "Scientific Visualization Using VTK – Fall 2011"— Presentation transcript:

1 Scientific Visualization Using VTK – Fall 2011
Robert Putnam Scientific Visualization Using VTK – Fall 2011 1

2 Scientific Visualization Using VTK – Fall 2011
Outline Introduction VTK overview VTK data geometry/topology Case study Interactive session Scientific Visualization Using VTK – Fall 2011 2

3 Scientific Visualization Using VTK – Fall 2011
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 2D or 3D space (e.g., from simulation mesh or scanner). *Adapted from The ParaView Tutorial, Moreland Scientific Visualization Using VTK – Fall 2011 3

4 Scientific Visualization Using VTK – Fall 2011
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 2011 4

5 Scientific Visualization Using VTK – Fall 2011
Generic visualization pipeline Source(s) Filters(s) Output data/geometry/topology graphics Scientific Visualization Using VTK – Fall 2011 5

6 Scientific Visualization Using VTK – Fall 2011
VTK terminology/model Source Filter Mapper Renderer data/geometry/topology graphics Scientific Visualization Using VTK – Fall 2011 6

7 Scientific Visualization Using VTK – Fall 2011
VTK terminology/model “Scene" Lights, Camera Actor Source/ Reader Filter Mapper Renderer DataObject ProcessObject RenderWindow graphics data/geometry/topology Scientific Visualization Using VTK – Fall 2011 7

8 Scientific Visualization Using VTK – Fall 2011
Pipeline -> Sample Code vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkContourFilter *iso = vtkContourFilter::New(); iso->SetInputConnection(reader->GetOutputPort()); iso->SetValue(0,0.26); vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New(); isoMapper->SetInputConnection(iso->GetOutputPort()); vtkActor *isoActor = vtkActor::New(); isoActor->SetMapper(isoMapper); vtkRenderer *ren1 = vtkRenderer::New(); ren1->AddActor(isoActor); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->SetSize(500,500); renWin->AddRenderer(ren1); Reader Filter Mapper Actor Renderer RenderWindow Scientific Visualization Using VTK – Fall 2011 8

9 Scientific Visualization Using VTK – Fall 2011
C++ v. Tcl C++ Tcl vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkContourFilter *iso = vtkCountourFilter::New(); iso->SetInputConnection(reader->GetOutputPort()); iso->SetValue(0, .26); vtkStructuredGridReader reader reader SetFileName "density.vtk" reader Update vtkContourFilter iso iso SetInputConnection [reader GetOutputPort] iso SetValue 0 .26 Scientific Visualization Using VTK – Fall 2011 9

10 Scientific Visualization Using VTK – Fall 2011
Coding tip of the day! Google “VTK class list”, or Go to: Scientific Visualization Using VTK – Fall 2011 10

11 Scientific Visualization Using VTK – Fall 2011
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 2011

12 Scientific Visualization Using VTK – Fall 2011
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 2011

13 Scientific Visualization Using VTK – Fall 2011
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 2011

14 Scientific Visualization Using VTK – Fall 2011
VTK – Geometry v. Topology or 0,1 1,1 2,1 3,1 0,1 1,1 2,1 3,1 0,0 1,0 2,0 3,0 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 2011

15 Scientific Visualization Using VTK – Fall 2011
VTK – Geometry v. Topology or 0,1 1,1 2,1 3,1 0,1 1,1 2,1 3,1 0,0 1,0 2,0 3,0 0,0 1,0 2,0 3,0 or or 0,1 1,1 2,1 3,1 0,1 1,1 2,1 3,1 0,0 1,0 2,0 3,0 0,0 1,0 2,0 3,0 Scientific Visualization Using VTK – Fall 2011

16 Scientific Visualization Using VTK – Fall 2011
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 2011

17 Scientific Visualization Using VTK – Fall 2011
Characteristics of Data 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 2011

18 Scientific Visualization Using VTK – Fall 2011
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 2011 18

19 Scientific Visualization Using VTK – Fall 2011
Examples of Dataset Types (cont) Polygonal Data irregular in both topology and geometry examples: vertices, polyvertices, lines, polylines, polygons, triangle strips Unstructured Grid examples: any combination of cells applications: finite element analysis, structural design, vibration Scientific Visualization Using VTK – Fall 2011

20 Scientific Visualization Using VTK – Fall 2011
Examples of Cell Types Scientific Visualization Using VTK – Fall 2011

21 Scientific Visualization Using VTK – Fall 2011
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 3D texture space used for texture mapping Tensors 3x3 only examples: stress, strain Scientific Visualization Using VTK – Fall 2011 21

22 Scientific Visualization Using VTK – Fall 2011
File Format – Structured Points Editor structured-points.vtk: # vtk DataFile 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 Scientific Visualization Using VTK – Fall 2011 22

23 Scientific Visualization Using VTK – Fall 2011
File Format – Structured Points Editor structured-points.vtk: # vtk DataFile 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 Scientific Visualization Using VTK – Fall 2011 23

24 Scientific Visualization Using VTK – Fall 2011
File Format – Structured Points Editor structured-points2.vtk: # vtk DataFile 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 Scientific Visualization Using VTK – Fall 2011 24

25 Scientific Visualization Using VTK – Fall 2011
File Format – Structured Points Editor structured-points2.vtk: # vtk DataFile 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 Scientific Visualization Using VTK – Fall 2011 25

26 Scientific Visualization Using VTK – Fall 2011
Structured Points – C++ code Editor structured-points.cxx: vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New(); reader->SetFileName("structured-points.vtk"); reader->Update(); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetNumberOfColors(2); lut->SetTableValue(0, 0.0, 0.0, 1.0, 1); lut->SetTableValue(1, 1.0, 0.0, 0.0, 1); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInputConnection(reader->GetOutputPort()); mapper->SetLookupTable(lut); vtkActor *actor = vtkActor::New(); actor->SetMapper(mapper); actor->GetProperty()->EdgeVisibilityOn(); actor->GetProperty()->SetLineWidth(2); Scientific Visualization Using VTK – Fall 2011 26

27 Scientific Visualization Using VTK – Fall 2011
Structured Points – C++ code (cont.) Editor structured-points.cxx: vtkRenderer *ren1 = vtkRenderer::New(); ren1->AddActor(actor); ren1->SetBackground(0.5,0.5,0.5); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); renWin->SetSize(500,500); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); iren->Initialize(); iren->Start(); Scientific Visualization Using VTK – Fall 2011 27

28 Scientific Visualization Using VTK – Fall 2011
Work flow – Case Study BU Space Physics simulation Meteor trails in the ionosphere Data wrangling: Consolidate datafiles (from parallel code), create single binary datafile Add VTK header: # vtk DataFile Version 3.0 output of reassemble.c BINARY DATASET STRUCTURED_POINTS ORIGIN SPACING DIMENSIONS POINT_DATA SCALARS plasma float LOOKUP_TABLE default Scientific Visualization Using VTK – Fall 2011

29 Scientific Visualization Using VTK – Fall 2011
Work flow – Case Study Use Tcl for fast development/testing: vtkStructuredPointsReader reader reader SetFileName "opp.vtk" reader Update vtkContourFilter iso iso SetInputConnection [reader GetOutputPort] iso SetValue 0 0.1 . . . Scientific Visualization Using VTK – Fall 2011

30 Scientific Visualization Using VTK – Fall 2011
Work flow – Case Study Add gaussian filter : vtkImageGaussianSmooth gaussian gaussian SetInputConnection [reader GetOutputPort] gaussian SetDimensionality 3 gaussian SetRadiusFactor 1 vtkContourFilter iso iso SetInputConnection [gaussian GetOutputPort] iso SetValue 0 0.1 . . . Scientific Visualization Using VTK – Fall 2011

31 Scientific Visualization Using VTK – Fall 2011
Work flow – Case Study Add more isosurfaces : vtkContourFilter iso iso SetInputConnection [gaussian GetOutputPort] iso SetValue 0 1.0 iso SetValue 1 0.5 iso SetValue 2 0.1 Scientific Visualization Using VTK – Fall 2011

32 Scientific Visualization Using VTK – Fall 2011
Work flow – Case Study Port to C++, add cutplane, transparency : vtkPlane *plane = vtkPlane::New(); plane->SetOrigin(256,2,63.5); plane->SetNormal(0,1,0); vtkCutter *planeCut = vtkCutter::New(); planeCut->SetInputConnection(reader>GetOutputPort()); planeCut->SetCutFunction(plane); vtkActor *isoActor = vtkActor::New(); isoActor->SetMapper(isoMapper); isoActor->GetProperty()->SetOpacity(iv_opacity); Scientific Visualization Using VTK – Fall 2011

33 Scientific Visualization Using VTK – Fall 2011
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 2011

34 Scientific Visualization Using VTK – Fall 2011
VTK – Getting Started - UI Unix Shell: katana:% cone2 Scientific Visualization Using VTK – Fall 2011 34

35 Scientific Visualization Using VTK – Fall 2011
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 2011 35

36 Scientific Visualization Using VTK – Fall 2011
Code – simple.cxx Editor: simple.cxx #include <stdio.h> #include <stdlib.h> #include "vtk-include.h" int main(int argc, char *argv[]) { vtkRenderer *ren1 = vtkRenderer::New(); ren1->SetBackground(0.0,0.0,0.0); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->SetSize(500,500); renWin->AddRenderer(ren1); renWin->Render(); sleep(2); } Scientific Visualization Using VTK – Fall 2011 36

37 Scientific Visualization Using VTK – Fall 2011
Exercise Editor: simple2.cxx Change background color to gray (or fuchsia, etc.) Scientific Visualization Using VTK – Fall 2011 37

38 Scientific Visualization Using VTK – Fall 2011
Code – Exercise Editor: simple2.cxx int main(int argc, char *argv[]) { vtkRenderer *ren1 = vtkRenderer::New(); ren1->SetBackground(0.5,0.5,0.5); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->SetSize(500,500); renWin->AddRenderer(ren1); renWin->Render(); sleep(2); } Scientific Visualization Using VTK – Fall 2011 38

39 Scientific Visualization Using VTK – Fall 2011
Code – cone.cxx Editor cone.cxx: vtkConeSource *cone = vtkConeSource::New(); cone->SetResolution(100); vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection(cone->GetOutputPort()); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper(coneMapper); coneActor->GetProperty()->SetColor(1.0, 0.0, 0.0); vtkRenderer *ren1 = vtkRenderer::New(); ren1->SetBackground(0.0,0.0,0.0); ren1->AddActor(coneActor); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->SetSize(500,500); renWin->AddRenderer(ren1); renWin->Render(); sleep(3); Scientific Visualization Using VTK – Fall 2011 39

40 Scientific Visualization Using VTK – Fall 2011
Code – cone2.cxx Editor cone2.cxx: vtkConeSource *cone = vtkConeSource::New(); cone->SetResolution(100); vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection(cone->GetOutputPort()); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper(coneMapper); coneActor->GetProperty()->SetColor(1.0, 0.0, 0.0); vtkRenderer *ren1 = vtkRenderer::New(); ren1->SetBackground(0.0,0.0,0.0); ren1->AddActor(coneActor); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->SetSize(500,500); renWin->AddRenderer(ren1); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); iren->Initialize(); iren->Start(); Scientific Visualization Using VTK – Fall 2011 40

41 Scientific Visualization Using VTK – Fall 2011
Exercise Editor: cone3.cxx Add coneActor2, and color it green. (Copy coneActor, 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: coneActor2->RotateZ(90); coneActor2->SetScale(0.5,0.5,0.5); coneActor2->SetPosition(-1.0,0.0,0.0); Otherwise, use ‘a’ to use mouse to separate the green and red cones. Scientific Visualization Using VTK – Fall 2011 41

42 Scientific Visualization Using VTK – Fall 2011
Code – Exercise Editor: cone3.cxx . . . vtkActor *coneActor2 = vtkActor::New(); coneActor2->SetMapper(coneMapper); coneActor2->GetProperty()->SetColor(0.0, 1.0, 0.0); coneActor2->RotateZ(90); coneActor2->SetScale(0.5,0.5,0.5); coneActor2->SetPosition(-1.0,0.0,0.0); ren1->AddActor(coneActor); ren1->AddActor(coneActor2); Scientific Visualization Using VTK – Fall 2011 42

43 Scientific Visualization Using VTK – Fall 2011
VTK - Readers Image and Volume Readers vtkStructuredPointsReader - read VTK structured points data files vtkSLCReader - read SLC structured points files vtkTIFFReader - read files in TIFF format vtkVolumeReader - read image (volume) files vtkVolume16Reader - read 16-bit image (volume) files Structured Grid Readers vtkStructuredGridReader - read VTK structured grid data files vtkPLOT3DReader - read structured grid PLOT3D files Rectilinear Grid Readers vtkRectilinearGridReader - read VTK rectilinear grid data files Unstructured Grid Readers vtkUnstructuredGridReader - read VTK unstructured grid data files Scientific Visualization Using VTK – Fall 2011 43

44 Scientific Visualization Using VTK – Fall 2011
VTK - Readers Polygonal Data Readers vtkPolyDataReader - read VTK polygonal data files vtkBYUReader - read MOVIE.BYU files vtkMCubesReader - read binary marching cubes files vtkOBJReader - read Wavefront (Maya) .obj files vtkPLYReader - read Stanford University PLY polygonal data files vtkSTLReader - read stereo-lithography files vtkUGFacetReader - read EDS Unigraphic facet files Image and Volume Readers (add’l) vtkBMPReader - read PC bitmap files vtkDEMReader - read digital elevation model files vtkJPEGReader - read JPEG files vtkImageReader - read various image files vtkPNMReader - read PNM (ppm, pgm, pbm) files vtkPNGRReader - read Portable Network Graphic files Scientific Visualization Using VTK – Fall 2011 44

45 Scientific Visualization Using VTK – Fall 2011
File Format – Structured Grid Editor density.vtk: # vtk DataFile Version 3.0 vtk sample data ASCII DATASET STRUCTURED_GRID DIMENSIONS POINTS float . . . POINT_DATA 47025 SCALARS Density float VECTORS Momentum float Scientific Visualization Using VTK – Fall 2011 45

46 Scientific Visualization Using VTK – Fall 2011
Clipping, Cutting, Subsampling Selection Algorithms - Clipping can reveal internal details of surface VTK - vtkClipDataSet - Cutting/Slicing cutting through a dataset with a surface VTK - vtkCutter - Subsampling reduces data size by selecting a subset of the original data VTK - vtkExtractGrid Scientific Visualization Using VTK – Fall 2011 46

47 Scientific Visualization Using VTK – Fall 2011
Code – Clipping Editor: clipping.cxx vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkPlane *plane = vtkPlane::New(); plane->SetOrigin(reader->GetOutput()->GetCenter()); plane->SetNormal(-0.287, 0, ); vtkClipDataSet *clip = vtkClipDataSet::New(); clip->SetInputConnection(reader->GetOutputPort()); clip->SetClipFunction(plane); clip->InsideOutOn(); vtkDataSetMapper *clipMapper = vtkDataSetMapper::New(); clipMapper->SetInputConnection(clip->GetOutputPort()); clipMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *clipActor = vtkActor::New(); clipActor->SetMapper(clipMapper); Scientific Visualization Using VTK – Fall 2011 47

48 Scientific Visualization Using VTK – Fall 2011
Code – Cutplane/Slicing Editor: cutplane.cxx vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkPlane *plane = vtkPlane::New(); plane->SetOrigin(reader->GetOutput()->GetCenter()); plane->SetNormal(-0.287, 0, ); vtkCutter *planeCut = vtkCutter::New(); planeCut->SetInputConnection(reader->GetOutputPort()); planeCut->SetCutFunction(plane); vtkPolyDataMapper *cutMapper = vtkPolyDataMapper::New(); cutMapper->SetInputConnection(planeCut->GetOutputPort()); cutMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *cutActor = vtkActor::New(); cutActor->SetMapper(cutMapper); *To see the cutplane with a colorbar guide, try ‘cutplane-with-colorbar’. Scientific Visualization Using VTK – Fall 2011 48

49 Scientific Visualization Using VTK – Fall 2011
Code – ExtractGrid Editor: extract.cxx vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkExtractGrid *extract = vtkExtractGrid::New(); extract->SetInputConnection(reader->GetOutputPort()); extract->SetVOI(-1000,1000,-1000,1000,7,10); vtkDataSetMapper *extractMapper = vtkDataSetMapper::New(); extractMapper->SetInputConnection(extract->GetOutputPort()); extractMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *extractActor = vtkActor::New(); extractActor->SetMapper(extractMapper); *Optional: enable EdgeVisibility in ExtractActor. Scientific Visualization Using VTK – Fall 2011 49

50 Scientific Visualization Using VTK – Fall 2011
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 vtkLookupTable vtkDataSetMapper Scientific Visualization Using VTK – Fall 2011

51 Scientific Visualization Using VTK – Fall 2011
Code – Color Mapping Editor: colormap.numcolors.cxx . . . vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("subset.vtk"); reader->Update(); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetNumberOfColors(16); lut->SetHueRange(0.0, 0.667); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInputConnection(reader->GetOutputPort()); mapper->SetLookupTable(lut); mapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *actor = vtkActor::New(); actor->SetMapper(mapper); Scientific Visualization Using VTK – Fall 2011 51

52 Scientific Visualization Using VTK – Fall 2011
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] mapper SetScalarRange Scientific Visualization Using VTK – Fall 2011 52

53 Scientific Visualization Using VTK – Fall 2011
Contouring Scalar Algorithms (cont) Contouring construct a boundary between distinct regions, two steps: explore space to find points near contour connect points into contour (2D) or surface (3D) 2D contour map (isoline): applications: elevation contours from topography, pressure contours (weather maps) from meteorology3D isosurface: 3D isosurface: applications: tissue surfaces from tomography, constant pressure or temperature in fluid flow, implicit surfaces from math and CAD VTK vtkContourFilter Scientific Visualization Using VTK – Fall 2011

54 Scientific Visualization Using VTK – Fall 2011
Code – Contour (isoline) Editor: contour.single.cxx . . . vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("subset.vtk"); reader->Update(); vtkContourFilter *iso = vtkContourFilter::New(); iso->SetInputConnection(reader->GetOutputPort()); iso->SetValue(0,0.26); vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New(); isoMapper->SetInputConnection(iso->GetOutputPort()); isoMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *isoActor = vtkActor::New(); isoActor->SetMapper(isoMapper); Scientific Visualization Using VTK – Fall 2011 54

55 Scientific Visualization Using VTK – Fall 2011
Code – Contour (isosurface) Editor: isosurface.cxx . . . vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName(“density.vtk"); reader->Update(); vtkContourFilter *iso = vtkContourFilter::New(); iso->SetInputConnection(reader->GetOutputPort()); iso->SetValue(0,0.26); vtkPolyDataMapper *isoMapper = vtkPolyDataMapper::New(); isoMapper->SetInputConnection(iso->GetOutputPort()); isoMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *isoActor = vtkActor::New(); isoActor->SetMapper(isoMapper); Scientific Visualization Using VTK – Fall 2011 55

56 Scientific Visualization Using VTK – Fall 2011
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 vtkElevationFilter Scientific Visualization Using VTK – Fall 2011

57 Scientific Visualization Using VTK – Fall 2011
Code – Scalar Generation Editor: hawaii.color.cxx vtkPolyDataReader *hawaii = vtkPolyDataReader::New(); hawaii->SetFileName("honolulu.vtk"); hawaii->Update(); hawaii->GetOutput()->GetBounds(bounds); vtkElevationFilter *elevation = vtkElevationFilter::New(); elevation->SetInputConnection(hawaii->GetOutputPort()); elevation->SetLowPoint(0,0,bounds[4]); elevation->SetHighPoint(0,0,bounds[5]); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetHueRange(0.7,0); vtkDataSetMapper *hawaiiMapper = vtkDataSetMapper::New(); hawaiiMapper->SetInputConnection(elevation->GetOutputPort()); hawaiiMapper->SetLookupTable(lut); vtkActor *hawaiiActor = vtkActor::New(); hawaiiActor->SetMapper(hawaiiMapper); Scientific Visualization Using VTK – Fall 2011 57

58 Scientific Visualization Using VTK – Fall 2011
Scalar generation – Color Map Editor: hawaii.color2.cxx vtkLookupTable *lut = vtkLookupTable::New(); lut->SetNumberOfColors(9); lut->SetTableValue(0, 0.0, 0.40, 0.8, 1); lut->SetTableValue(1, 0.0, 0.75, 0.2, 1); lut->SetTableValue(2, 0.25, 0.625, 0.5, 1); lut->SetTableValue(3, 0.0, 0.5, , 1); lut->SetTableValue(4, 0.5, , 0.0, 1); lut->SetTableValue(5, 0.75, 0.625, 0.25, 1); lut->SetTableValue(6, 1.0, 0.75, , 1); lut->SetTableValue(7, 1.0, 0.75, 0.5, 1); lut->SetTableValue(8, 1.0, 1, 1, 1); Scientific Visualization Using VTK – Fall 2011 58

59 Scientific Visualization Using VTK – Fall 2011
Hedgehogs Vector Algorithms Hedgehogs oriented scaled line for each vector scale indicates magnitude color indicates magnitude, pressure, temperature, or any variable VTK vtkHedgeHog Scientific Visualization Using VTK – Fall 2011

60 Scientific Visualization Using VTK – Fall 2011
Code – HedgeHogs Editor: hedgehog.cxx vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkHedgeHog *hhog = vtkHedgeHog::New(); hhog->SetInputConnection(reader->GetOutputPort()); hhog->SetScaleFactor(0.001); vtkPolyDataMapper *hhogMapper = vtkPolyDataMapper::New(); hhogMapper->SetInputConnection(hhog->GetOutputPort()); hhogMapper->SetLookupTable(lut); hhogMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *hhogActor = vtkActor::New(); hhogActor->SetMapper(hhogMapper); Scientific Visualization Using VTK – Fall 2011 60

61 Scientific Visualization Using VTK – Fall 2011
Oriented Glyphs Vector Algorithms (cont) Oriented Glyphs orientation indicates direction scale indicates magnitude color indicates magnitude, pressure, temperature, or any variable VTK vtkGlyph3D Scientific Visualization Using VTK – Fall 2011

62 Scientific Visualization Using VTK – Fall 2011
Code – Oriented Glyphs Editor: glyph.cxx vtkArrowSource *arrow = vtkArrowSource::New(); arrow->SetTipResolution(6); arrow->SetTipRadius(0.1); arrow->SetTipLength(0.35); arrow->SetShaftResolution(6); arrow->SetShaftRadius(0.03); vtkGlyph3D *glyph = vtkGlyph3D::New(); glyph->SetInputConnection(extract->GetOutputPort()); glyph->SetSource(arrow->GetOutput()); glyph->SetVectorModeToUseVector(); glyph->SetColorModeToColorByScalar(); glyph->SetScaleModeToDataScalingOff(); glyph->OrientOn(); glyph->SetScaleFactor(0.25); vtkPolyDataMapper *glyphMapper = vtkPolyDataMapper::New(); glyphMapper->SetInputConnection(glyph->GetOutputPort()); glyphMapper->SetLookupTable(lut); glyphMapper->SetScalarRange(reader->GetOutput()->GetScalarRange()); Scientific Visualization Using VTK – Fall 2011 62

63 Scientific Visualization Using VTK – Fall 2011
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 2011 63

64 Scientific Visualization Using VTK – Fall 2011
Field Lines Streamlines Lines show particle flow VTK – vtkStreamTracer Streamlets half way between streamlines and glyphs VTK - vtkStreamTracer, vtkGlyph3D Streamribbon rake of two particles to create a ribbon VTK - vtkStreamTracer, vtkRuledSurfaceFilter Streamtube circular rake of particles to create a tube VTK - vtkStreamTracer, vtkTubeFilter Scientific Visualization Using VTK – Fall 2011 64

65 Scientific Visualization Using VTK – Fall 2011
Code – Streamlines Editor: streamLines.cxx vtkPointSource *seeds = vtkPointSource::New(); seeds->SetRadius(3.0); seeds->SetCenter(reader->GetOutput()->GetCenter()); seeds->SetNumberOfPoints(100); vtkRungeKutta4 *integ = vtkRungeKutta4::New(); vtkStreamTracer *streamer = vtkStreamTracer::New(); streamer->SetInputConnection(reader->GetOutputPort()); streamer->SetSourceConnection(seeds->GetOutputPort()); streamer->SetMaximumPropagation(100); streamer->SetIntegrationDirectionToBoth(); streamer->SetIntegrator(integ); vtkPolyDataMapper *mapStreamLines = vtkPolyDataMapper::New(); mapStreamLines->SetInputConnection(streamer->GetOutputPort()); mapStreamLines->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *streamLineActor = vtkActor::New(); streamLineActor->SetMapper(mapStreamLines); Scientific Visualization Using VTK – Fall 2011 65

66 Scientific Visualization Using VTK – Fall 2011
Code – Streamtubes Editor: streamTubes.varyRadius.cxx vtkPointSource *seeds = vtkPointSource::New(); seeds->SetRadius(1.0); seeds->SetCenter(1.5, 0.01, 27); seeds->SetNumberOfPoints(50); vtkRungeKutta4 *integ = vtkRungeKutta4::New(); vtkStreamTracer *streamer = vtkStreamTracer::New(); streamer->SetInputConnection(reader->GetOutputPort()); streamer->SetSourceConnection(seeds->GetOutputPort()); vtkTubeFilter *streamTube = vtkTubeFilter::New(); streamTube->SetInputConnection(streamer->GetOutputPort()); streamTube->SetRadius(0.01); streamTube->SetNumberOfSides(6); streamTube->SetVaryRadiusToVaryRadiusByScalar(); vtkPolyDataMapper *mapStreamTube = vtkPolyDataMapper::New(); mapStreamTube->SetInputConnection(streamTube->GetOutputPort()); mapStreamTube->SetScalarRange(reader->GetOutput()->GetScalarRange()); vtkActor *streamTubeActor = vtkActor::New(); streamTubeActor->SetMapper(mapStreamTube); Scientific Visualization Using VTK – Fall 2011 66

67 Scientific Visualization Using VTK – Fall 2011
Annotation Annotation used for annotating visualization VTK vtkScalarBarActor vtkTextMapper vtkScaledTextActor Scientific Visualization Using VTK – Fall 2011 67

68 Scientific Visualization Using VTK – Fall 2011
Code – colorBar Editor: colorBar.cxx vtkStructuredGridReader *reader = vtkStructuredGridReader::New(); reader->SetFileName("density.vtk"); reader->Update(); vtkScalarBarActor *scalarBar = vtkScalarBarActor::New(); scalarBar->SetLookupTable(lut); scalarBar->SetTitle("Combustor Density Magnitude"); scalarBar->SetNumberOfLabels(2); scalarBar->GetPositionCoordinate()->SetValue(0.1, 0.01); scalarBar->SetOrientationToHorizontal(); scalarBar->SetWidth(0.8); scalarBar->SetHeight(0.09); vtkRenderer *ren1 = vtkRenderer::New(); ren1->SetBackground(0.5,0.5,0.5); ren1->AddActor(streamTubeActor); ren1->AddActor(outlineActor); ren1->AddActor(scalarBar); Scientific Visualization Using VTK – Fall 2011 68

69 Scientific Visualization Using VTK – Fall 2011
VTK - Writers Polygonal Data Writers vtkBYUWriter - write MOVIE.BYU files vtkCGMWriter - write 2D polygonal data as a CGM file vtkIVWriter - write Inventor files vtkMCubesWriter - write triangles in marching cubes format vtkPolyDataWriter - write VTK polygonal data files vtkPLYWriter - write Standford University PLY polygonal data files vtkSTLWriter - write stereo-lithography files Image and Volume writers vtkBMPwriter - write PC bitmap files vtkJPEGwriter - write images in JPEG format vtkPostscriptWriter – write image files in Postscript format vtkPNMwriter - write PNM (ppm, pgm, pbm) image files vtkPNGwriter - write image file in Portable Network Graphic format vtkTIFFWriter – write image files in TIFF format vtkStructuredPointsWriter – write a vtkStructuredPoints file Scientific Visualization Using VTK – Fall 2011 69

70 Scientific Visualization Using VTK – Fall 2011
Saving Images Saving Images common formats: jpeg (lossy) png (lossless) postscript tiff (lossless) VTK vtkWindowToImageFilter vtkRenderLargeImage Scientific Visualization Using VTK – Fall 2011 70

71 Scientific Visualization Using VTK – Fall 2011
Code – Saving Images Editor: output.cxx vtkRenderer *ren1 = vtkRenderer::New(); ren1->AddActor(streamTubeActor); ren1->ResetCamera(); ren1->GetActiveCamera()->Dolly(1.25); ren1->ResetCameraClippingRange(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->PointSmoothingOn(); renWin->LineSmoothingOn(); renWin->PolygonSmoothingOn(); renWin->AddRenderer(ren1); renWin->SetSize(500,500); renWin->Render(); vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New(); w2if->SetInput(renWin); vtkTIFFWriter *writer = vtkTIFFWriter::New(); writer->SetInputConnection(w2if->GetOutputPort()); writer->SetFileName("image.tif"); writer->Write(); vtkRenderLargeImage *renderLarge = vtkRenderLargeImage::New(); renderLarge->SetInput(ren1); renderLarge->SetMagnification(4); vtkTIFFWriter *lwriter = vtkTIFFWriter::New(); lwriter->SetInputConnection(renderLarge->GetOutputPort()); lwriter->SetFileName("./largeimage.tif"); lwriter->Write(); Scientific Visualization Using VTK – Fall 2011 71

72 Scientific Visualization Using VTK – Fall 2011
VTK - Resources IS&T tutorials Scientific Visualization Using VTK VTK Examples Texts The Visualization Toolkit, 4th Edition, Kitware, Inc, 2006. The VTK User’s Guide, 5th Edition, Kitware, Inc, 2006. Websites Wiki Mailing Lists Scientific Visualization Using VTK – Fall 2011 72

73 Scientific Visualization Using VTK – Fall 2011
Questions? Tutorial survey: - Scientific Visualization Using VTK – Fall 2011 73


Download ppt "Scientific Visualization Using VTK – Fall 2011"

Similar presentations


Ads by Google