1 / 56

VTK: Fundamental Algorithms, Scalar – Color Mapping

VTK: Fundamental Algorithms, Scalar – Color Mapping. Shroeder et al. Chapter 6. University of Texas – Pan American CSCI 6361, Spring 2014. After Taku Komura and other lecture sets http://www.inf.ed.ac.uk/teaching/courses/vis/. Overview. Recall …. From last time: Data representation

kathy
Download Presentation

VTK: Fundamental Algorithms, Scalar – Color Mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VTK: Fundamental Algorithms,Scalar – Color Mapping Shroeder et al. Chapter 6 University of Texas – Pan American CSCI 6361, Spring 2014 After Taku Komura and other lecture sets http://www.inf.ed.ac.uk/teaching/courses/vis/

  2. Overview

  3. Recall … • From last time: • Data representation • structure + value • structure = topology & geometry • value = attribute • Attribute Classification • scalar (today) • vector • tensor

  4. Visualization Algorithms • Generally, classified by attribute type • scalar algorithms (e.g. color mapping) • vector algorithms (e.g. glyphs) • tensor algorithms (e.g. tensor ellipses)

  5. Scalar Algorithms • Visualization algorithms generally: • scalar algorithms (e.g. color mapping) • vector algorithms (e.g. glyphs) • tensor algorithms (e.g. tensor ellipses) • Scalar data : single value, e.g., 2.72, at each location • Structure of data set may be 1D, 2D or 3D+ • want to visualize the scalar within this structure • Two fundamental algorithms • color mapping (transformation : value -> color) • contouring (transformation : value transition -> contour)

  6. Color Mapping • Map scalar value to color range for display • e.g. • scalar value = height / max elevation • color range = blue -> red • Color Lookup Tables (LUT) • provide scalar to color conversion • scalar values = indices into LUT

  7. Satellite – Different Color Mappings

  8. CG Color Look­up Table, 1(same idea used for compressed images) • Display hardware may not have sufficient capacity (memory) to store all, e.g, cell phone • So, choose some to store • e.g., lots of shades of blue for water or sky (and not too many green) • Any specific 2n colors • (e.g., below, 2^8 = 256 colors), 8 bit color, but which 256, out of 16.7m is important • Look­up table allows 2n colors be used in one picture, • Color table is a resource managed (usually) by window manager

  9. CG Color Look­Up Table, 2 • Pixel value is indexed to color look up table (CLUT) where color is stored. • CLUT look up done at video rates, overlapped with fetch and DAC • CLUT allows variety of effects • pseudo coloring (LandSat images, stress diagrams, thermograms...) • fast image changes: change table rather than stored image • multiple images: select or composite/blend

  10. Color Look Up Table, or LUT • Maps (scalar) values to colors • scalar values Si in range {min -> max} • n unique colors, {color0... colorn-1} in LUT • Define mapped color C: • Right from previous satellite imagery

  11. Color Transfer Function • More general form of color LUT • scalar value S; color value C • color transfer function: f(S) = C • Any functional expression can map scalar value into intensity values for color components • e.g. define f() to convert densities to realistic skin/bone/tissue colors

  12. Color Components – R, G, B • Recall, electromagnetic spectrum visible to humans • continuous range 400-700nm • 3 type of receptors (cones) in eye for R, G, B • So, often use the RGB model in computer graphics for visualization

  13. RGB Color Space • Colors represented as R,G,B intensities • 3D color space (cube) with axes R, G and B • each axis 0 -> 1 (below scaled to 0-255 for 1 byte per color channel) • Black = (0,0,0) (origin); White = (1,1,1) (opposite corner) • Problem : difficult to map continuous scalar range to 3D space • can use subset (e.g. a diagonal axis) but imperfect

  14. Example: RGB Image • Below is each of R,G and B in picture • RGB Channel Separation

  15. Color Spaces and Grayscale • Can map color to gray scale • Linear combination of R, G, B • Grayscale = (R + G + B) / 3 • Defined as linear range • Easy to map linear scalar range to grayscale intensity • Can enhance structural detail in visualization • The shading effect is emphasized • As distraction of color is removed • Not really using full graphics capability • Loose color associations : • e.g. red=bad/hot, green=safe, blue=cold

  16. Another Color ModelHSV: Hue, Saturation, Value …VTK uses for color map • HSV: hue, saturation, value • encapsulates information about a color in terms that are more familiar to humans: • What color is it? • How vibrant is it? • How light or dark is it? • H (Hue) = dominant wavelength of color • color type {e.g. red, blue, green...} • 0 -> 360o • S (Saturation) = amount of Hue present • Center has no saturation (hue), so “white” • “vibrancy” or purity of color • e.g., for Hue ~blue • 0.5 = sky color, 1.0 = primary blue • V (Value) = brightness of color • brightness of the color • e.g., 0 = black, 1 = bright

  17. Example: HSV Image Components • x

  18. Different Color LUTs • From VTK book • Visualizing gas density in a combustion chamber • Scalar = gas density • Color Map = • A: grayscale • B: hue range blue to red • C: hue range red to blue • D: specifically designed transfer function • Highlights contrast

  19. Color Table Design … Which You’ll Do • “More of an art that a science” • where does visualization end and art begin? • Key focus of color table design • emphasis important features / distinctions • minimize extraneous detail • Often task specific • consider application • e.g. temperature change, use hue red to blue • consider viewer (color associations, color blindness) • Rainbow color maps • rapid change in color hue representing a ‘rainbow’ of colors. • shows small gradients well as colors change quickly.

  20. Examples – 2D Color Images • Infra-red intensity viewed as Hue • received from sensor as 2D array of infrared readings • visualize as color image using color mapping • Temperature: • (left) - Red is “hot” (and white is really hot), blue is cool • (right) - Reddish is “hot” , green is “cool”, and black really cool

  21. Examples – 3D Height Data • Here’s hawaii … • HSV based color transfer function • continuous transition of height represented • 8 color limited lookup table • discrete height transitions • “rainbow type” effect

  22. Examples: Molecular Visualizations • Two variables visualized relating to electric properties • mapped to Hue and Saturation

  23. Example: Color Transfer Function • Are the dimples on this golfball evenly distributed? • (hard to tell with this representation – how about a color map?)

  24. Example: Color Transfer Function • Answer: • No (Improves flight characteristics) • Visualization technique: • color map each point based on distance (scalar) from regular sphere

  25. Assignment • .

  26. Overview • Context for next assignment • “Color mapping” • Application of psuedocolor sequences to univariate scalar data • Using terrain, elevation, height data • What it is, again • Examples and rules for design • Vtk implementation of color mapping • Example code (available at course internet site), as are many • Assignment • Design and implement an “interactive general purpose color mapping program for terrain data”

  27. VTK Color Mapping – In a Nutshell • Will take a close look - see hawaii.tcl example • To create a new LUT object with a name lut: • vtkLookupTable lut • To set the color range in the HSV colorspace: • lut SetHueRange start finish • lut SetSaturationRange start finish • lut SetValueRange start finish • range = [0,1] • Also define specific N color lookup table

  28. Examples of 3D Height (Terrain) Data 1. HSV based color transfer function • continuous transition of height represented 2. Color (8) lookup table • discrete height transitions • segmentation • “rainbow type” effect

  29. Vtk Implementation • Assignment 4 asks that you design and implement an “interactive terrain data display” program (or some subset) • Use hawaii vtk data set and program • Look at: • Vtk file formats • Example program segment • Vtk data, methods, documentation: • vtkElevationFilter • vtkLookupTable • vtkDataSetMapper

  30. Data: honolulu.vtk • Data set (16m) • Many formats supported, *.vtk (below) is just one • Other data sets available • www. …/*.vtk • cube.vtk for test • skin.vtk for halloween # vtk DataFile Version 1.0 Terrain data for Honolulu, Hawaii ASCII DATASET POLYDATA POINTS 202740 float 0.000000 0.000000 0.000000 0.000000 30.000000 0.000000 0.000000 60.000000 0.000000 0.000000 90.000000 0.000000 0.000000 120.000000 0.000000 0.000000 150.000000 0.000000 0.000000 180.000000 0.000000 0.000000 210.000000 0.000000 0.000000 240.000000 0.000000 0.000000 270.000000 0.000000 0.000000 300.000000 0.000000 0.000000 330.000000 0.000000 0.000000 360.000000 0.000000 0.000000 390.000000 0.000000 0.000000 420.000000 0.000000 0.000000 450.000000 0.000000

  31. “Color Mapping” Terrain Data: hawaii.cpp • Hawaii.cpp (and .tcl) • Also, data set (16mb) and .tcl version • Pretty easy …, but usual “nameology” challenges • Will look at each vtkPolyDataReader *polydata = vtkPolyDataReader::New(); polydata->SetFileName("honolulu.vtk"); vtkElevationFilter *colorIt = vtkElevationFilter::New(); colorIt->SetInput((vtkDataSet *)polydata->GetOutput()); colorIt->SetLowPoint(0,0,0); colorIt->SetHighPoint(0,0,1000); colorIt->SetScalarRange(0,1000); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetHueRange(0.7,0); lut->SetSaturationRange(1.0,0); lut->SetValueRange(.5,1.0); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInput(colorIt->GetOutput()); mapper->SetScalarRange(0,1000); mapper->SetLookupTable(lut); mapper->ImmediateModeRenderingOn;

  32. and VTK Documentation Online • http://www.vtk.org/

  33. “Color Mapping” Terrain Data • vtkElevationFilter • “generates scalar values from a dataset” vtkPolyDataReader *polydata = vtkPolyDataReader::New(); polydata->SetFileName("honolulu.vtk"); vtkElevationFilter *colorIt = vtkElevationFilter::New(); colorIt->SetInput((vtkDataSet *)polydata->GetOutput()); colorIt->SetLowPoint(0,0,0); colorIt->SetHighPoint(0,0,1000); colorIt->SetScalarRange(0,1000); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetHueRange(0.7,0); lut->SetSaturationRange(1.0,0); lut->SetValueRange(.5,1.0); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInput(colorIt->GetOutput()); mapper->SetScalarRange(0,1000); mapper->SetLookupTable(lut); mapper->ImmediateModeRenderingOn;

  34. vtkElevationFilterClass Reference • Typical of documentation for large class based (oo) systems • Inheritance diagram, etc. • E.g., vtkElevationFilter is a derived class, etc. • i.e., a “subclass” of vtkDataSetToDataSetFilter • May need to consult other classes to fully understand what a particular subclass does

  35. vtkElevationFilter Detailed Description • Description • “vtkElevationFilter is a filter to generate scalar values from a dataset. The scalar values lie within a user specified range, and are generated by computing a projection of each dataset point onto a line. The line can be oriented arbitrarily. A typical example is to generate scalars based on elevation or height above a plane.” • Wow, really great that’s in there and don’t have to program myself!” • That’s the point! • But, how do you know? • Public methods • What programmer sets

  36. vtkElevationFilterMethod Descriptions • Method/function descriptions // not shown colorIt-> SetInput((vtkDataSet *)polydata->GetOutput()); // below are shown at right colorIt->SetLowPoint(0,0,0); colorIt->SetHighPoint(0,0,1000); colorIt->SetScalarRange(0,1000);

  37. vtkElevationFilter Include File • The details, if you want or need to know … it’s all there • Definitions, etc. in “.h” (include) file Graphics/vtkElevationFilter.h • Also can look at entire c++ code • For the curious • Link in documentation

  38. “Color Mapping” Terrain Data • vtkLookupTable • an object that is used by mapper objects to map scalar values into rgba vtkPolyDataReader *polydata = vtkPolyDataReader::New(); polydata->SetFileName("honolulu.vtk"); vtkElevationFilter *colorIt = vtkElevationFilter::New(); colorIt->SetInput((vtkDataSet *)polydata->GetOutput()); colorIt->SetLowPoint(0,0,0); colorIt->SetHighPoint(0,0,1000); colorIt->SetScalarRange(0,1000); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetHueRange(0.7,0); lut->SetSaturationRange(1.0,0); lut->SetValueRange(.5,1.0); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInput(colorIt->GetOutput()); mapper->SetScalarRange(0,1000); mapper->SetLookupTable(lut); mapper->ImmediateModeRenderingOn;

  39. vtkLookupTableClass Reference • Same song, second verse • Class reference

  40. vtkLookUpTableDetailed Description • As before … • “vtkLookupTable is an object that is used by mapper objects to map scalar values into rgba (red-green-blue-alpha transparency) color specification, or rgba into scalar values. The color table can be created by direct insertion of color values, or by specifying hue, saturation, value, and alpha range and generating a table.”

  41. vtkLookUpTableMethods • lut->SetHueRange(0.7,0); • lut-> SetSaturationRange(1.0,0); • lut->SetValueRange(.5,1.0);

  42. vtkLookUpTableMethod Descriptions • lut->SetHueRange(0.7,0); • lut-> SetSaturationRange(1.0,0); • lut->SetValueRange(.5,1.0);

  43. “Color Mapping” Terrain Data • vtkDataSetMapper • mapper to map data sets (i.e., vtkDataSet and all derived classes) to graphics primitives. vtkPolyDataReader *polydata = vtkPolyDataReader::New(); polydata->SetFileName("honolulu.vtk"); vtkElevationFilter *colorIt = vtkElevationFilter::New(); colorIt->SetInput((vtkDataSet *)polydata->GetOutput()); colorIt->SetLowPoint(0,0,0); colorIt->SetHighPoint(0,0,1000); colorIt->SetScalarRange(0,1000); vtkLookupTable *lut = vtkLookupTable::New(); lut->SetHueRange(0.7,0); lut->SetSaturationRange(1.0,0); lut->SetValueRange(.5,1.0); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInput(colorIt->GetOutput()); mapper->SetScalarRange(0,1000); mapper->SetLookupTable(lut); mapper->ImmediateModeRenderingOn;

  44. vtkDataSetMapper Class Reference • Same song, … • Class reference

  45. vtkDataSetMapper Detailed Description • “vtkDataSetMapper is a mapper to map data sets (i.e., vtkDataSet and all derived classes) to graphics primitives. The mapping procedure is as follows: all 0D, 1D, and 2D cells are converted into points, lines, and polygons/triangle strips and then mapped to the graphics system. The 2D faces of 3D cells are mapped only if they are used by only one cell, i.e., on the boundary of the data set.”

  46. That Should Get You Started

  47. VTK Events and Interaction • .

  48. Recall, Software ArchitectureNow will see how to access window system (for keyboard input) • VTK classes use/call: • OpenGL, which accesses Graphics Hardware • Also, Window System • And input devices, through window system • Also, application can access OpenGL and Window System • E.g., your program, using VTK • Uses VTK classes “Application Library” (VTK, GLUT, … or anything) Your (application) program Graphics Library (OpenGL, DirectX, …) Graphics Hardware (frame buffers, firmware, …) Window System (MS Windows, Apple, Motif) mouse, keyboard, … Display (and input) Hardware (screen, mouse, ….)

  49. User Interface Events • All os, windowing systems, etc. are based on “event-driven architecture” • “Events” distributed to programs by window system • Events can be anything • Or, conversely, everything • E.g., button clicks, key presses, mouse movements, window resize, …

  50. Events to Appropriate Event Queues OS perspective: Program 1 Program 2 Program 3 Event queue 1 Event queue 2 Event queue 3 Windproc 1 Windproc 2 Windproc 3

More Related