View
218
Download
0
Category
Tags:
Preview:
Citation preview
CDS 130 - 003Fall, 2010
Computing for Scientists
Visualization(Oct . 28, 2010 – Nov. 09, 2010)
Jie Zhang Copyright ©
Content
1. Introduction
2. Computer Visualization Pipeline
3. 2-D Data Visualization– Height-plot method– Color map method
References:
(1) “Data Visualization: Principles and Practice”, by Alexandru C. Telea, A. K. Peters Ltd, ISBN-13: 978-1-56881-306-6, 2008
(2) CDS 301 “Scientific Information and Data Visualization”, Fall 2009 at http://solar.gmu.edu/teaching/2009_CDS301/index.html
1. Introduction
What is visualization? Why visualization?
Picture
A Picture Is Worth a Thousand Words
Cave Painting: the dawn of civilization
Graph: Height-Plot
Height plot of thePredator-Prey Model
Numeric output of thePredator-Prey Model
A graph is worth one thousand numbers
YearP
opu
latio
n
Graph: 3-D Height-Plot
Numeric output: a 2-Dimension data array,
which is the same as ……
Graph: 3-D Height-Plot
Height plot
A graph is worth one million numbers
Visualization is a cognitive process performed by humans in forming a mental image of a domain space
Visualization - Cognition
Human Cognition
•Most effective way human takes in information, digest information, making decision, and being creative.•The most important among the five senses
Scientific visualization is an interdisciplinary branch of science primarily concerned with the visualization of three dimensional phenomena (meteorological, medical, biological etc) where the emphasis is on realistic rendering of volumes, surfaces, illumination sources with a dynamic (time) component.
Friendly (2008), also
http://en.wikipedia.org/wiki/Scientific_visualization
What is Scientific Visualization
At Information Age
Goal of Scientific Visualization
• Provide scientific insights
• Effective communication
Example: Scalar Data
•Height plot of a 2-D data, and the contour lines•In topology, the data are of 2-D: a curved surface •The data are mapped into 3-D geometric space in computer memory•The data are then rendered onto a 2-D visual plane on a screen
Example: Vector Data
Stream tubes: show how water flows through a box with an inlet at the top-right and an outlet at the lower-left of the
box; the data are (1) 3-D volume, (2) vector
Example: Unstructured Data
Scattered Point Cloud and Surface Reconstruction.The data are a set of sampled data points in 3-D space, and the distribution of data is unstructured; need to reconstruct the surface from the scattered points
Sampled data Rendered data
Example: Volume Visualization
3-D data of human head. Instead of showing a subset (e.g, a slice as in CT images), the whole 3-D data are shown at once using the technique of Opacity Transfer Function
Example: Information Visu.
•The file system of FFmpeg, a popular software package for encoding audio and video data into digital format•Information, such as name and address, can not be interpolated; the visualization focuses on the relations.
An attempt at visualizing the Fourth Dimension: Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.
--Albert Einstein--
2. Computer Visualization Pipeline
How to do it by a computer?
We illustrate the process using the well known 2-D Gaussian function:
)( 22
),f( yxeyx
Gaussian Function in 1-D
It is straightforward to visualize the 1-D Gaussian function
)( 2
)f( xex
(1) Choose a data domain, e.g., x in [-3.0, 3.0]
(2) Choose a set of regular points in x, e.g., step size 0.5: x1=-3.0, x2=-2.5, x3=-2.0, x4=-2.5……….X13=3.0
(3) Calculate the corresponding functional value f(xi)
(4) Draw the 13 data points (xi, f(xi)) for i=1:13
(5) Connecting these points to form a curve, which shows the Gaussian function
Gaussian Function in 1-D)( 2
)f( xex x=-3.0:0.1:3.0; %declare the domain space and define the grid % x: one dimensional data arrayy=exp(-power(x,2)); %calculate the discrete functional value % y: also one dimensional data arrayplot(x,y,'*')hold onplot(x,y)
xlabel('x')ylabel('y')title('Gaussian 1D')print -dpng 'Gaussian_1d.png'
X: 1-D data array interval or domain: from -3.0 to 3.0 sub-interval: 0.1 value=[-3.0, -2.9, -2.8,………2.9, 3.0] number of elements: N=61
Gaussian Function in 1-D)( 2
)f( xex
Gaussian Function in 2-D
We know the result. In a height-plot format, It should look like something below. But how to do it through the computer?
)( 22
),f( yxeyx
A 3-D height plot showingthe Gaussian Surface
The Grid on the domain
Created by PARAVIEW, a power visualization package
Pipeline Step 1: Data Acquisition
Step 1: data acquisition. For any input data (experiment, simulation etc) , convert the data into a discrete dataset over a regular grid
Gaussian Example: •Choose a uniform grid in the domain space
•Nx=30 (i=1:30)•Ny=30 (j=1:30)
•Calculate the functional value at these grid points•This creates a set of 30 X 30, or 900 in total discrete 3D data points [x,y,z]
Pipeline Step 2: Data Mapping
Step 2: Mapping the discrete dataset onto a 3-D scene. Neighboring discrete data points are grouped to form graphic primitive shapes that a computer can handle efficiently, e.g., point, line, triangle, quadrilateral, and tetrahedron
Computer graphics only handles a 3-D scene
Gaussian Example:•Form a set of four-vertex polygons or quadrilateral in 3-D space•For each quadrilateral, the position of the four vertices are known, and its normal direction is calculated (in order to determine its luminance)
Pipeline Step 2: Data Mapping
Quadrilateral shape
Pipeline Step 3: Rendering
Step 3: Computer graphics renders the 3-D scene (a set of primitive shapes) onto a 2D projected place, by
1. Choose the view angle
2. Choose the light source
3. Choose the shadingGaussian Example:•Viewed from top-front•From a point light source in the front•Smooth shading
Shading
Flat Shading Gouraud Shading
Shading•Flat shading:
•Given a polygon surface (e.g., quadrilateral), flat shading applies the lighting model once for the complete polygon, e.g., for the center point•The whole polygon surface has the same light intensity•The least expensive•But visual artifact of the “faceted” surface
•Gouraud shading (or smooth shading):•Apply lighting model at every vertex of the polygon•The intensity between the vertices are calculated using interpolation, thus yielding smooth variation
Visualization Pipeline
float data[N_x,N_y]
Quadrilateral in 3D
)( 22
),f( yxeyx Continuous data
Discrete dataset
Geometric object
Displayed image
1. Data Acquisition
2. Data Mapping
3. Rendering
Visualization Pipeline: SummaryStep 1: data acquisition, which is to convert any input data into a discrete dataset within a domain. For Gaussian function, the input is a continuous Gaussian function, the output is a discrete dataset
Step 2: data mapping: which is to map the discrete dataset from step one (input) onto a 3-D scene (output) in computer memory. For Gaussian function, the output is a set of quadrilaterals in 3-D space. Each quadrilateral has four vertexes.
Step 3: rendering, which is to display the 3-D scene created in step 2 (input) onto a projected 2-D image (output).
3. 2-D data Visualization-(Nov. 1, 2010)
Visualization with Matlab
Watch Matlab tutorial video on arrays, including indexing and “find” function:“http://www.mathworks.com/demos/matlab/visualizing-data-overview-matlab-video-demonstration.html”
2-D Data Visualization
•Method 1: Height plot•Create 2-D data array in Matlab•Nested “For” loop in Matlab•“surf” in Matlab
•Method 2: Colormap•RGB color system•“image” in Matlab
Height-Plot Method
Height Plot
0 5 10 15 20 25 30 35 400
20
40
60
80
100
120
Years
Pop
ulat
ion
Population Evolution Over the Period of 40 years
Population plot from Natalia Lattanzio
Gaussian Function
)( 2
)f( xex
(1) Choose a data domain, e.g., x in [-3.0, 3.0]
(2) Choose a set of regular points in x with a subinterval of 0.1: x1=-3.0, x2=-2.9, x3=-2.8, x4=-2.7……….X13=3.0
(3) Calculate the corresponding functional value f(xi)
(4) Draw the 61 data points (xi, f(xi)) for i=1:61
(5) Connecting these points to form a curve, which shows the Gaussian function
Gaussian Function in 1-D)( 2
)f( xex %find number of intervalsx_start=-3.0x_end=3.0x_sub=0.1N=(x_end-x_start)/x_sub %number of iteration N+1
%for loop to find discrete x and y valuesfor i=[1:N+1] x(i)=x_start+(i-1)*x_sub; y(i)=exp(-power(x(i),2));end
plot(x,y,'*')hold onplot(x,y)
X: 1-D data array interval or domain: from -3.0 to 3.0 sub-interval: 0.1 value=[-3.0, -2.9, -2.8,………2.9, 3.0] number of elements: N=61
Gaussian Function in 1-D)( 2
)f( xex
sine Function xx sin)f(
(1) Choose a data domain, x in [-6.28, 6.28] or [-2π,2π]
(2) Choose a set of regular points in x with a subinterval of 0.1: x1=-6.28, x2=-6.18, x3=-6.08.8, x4=-2.7…x..=6.28
(3) Calculate the corresponding functional value f(xi)
(4) Connecting these points to form a curve, which shows the sine function
Class activity
y=sin(x) % sine function in Matlab
Height-Plot of 2-D Gaussian)( 22
),f( yxeyx
2-D Array
Watch Matlab tutorial video on arrays, including indexing and “find” function:“http://www.mathworks.com/demos/matlab/working-with-arrays-matlab-video-tutorial.html”
A large amount of scientific data are in the format of 2-D array, e.g., images
2-D Array • Create 1-D array
>> a=[1,2,3,4,5]>> a=[1 2 3 4 5]>> a=1:5>> a=[1:5]
%indexing and assigning values using for loops%.e.g., assign x^2for i=[1:5]
x(i)=power(i,2)end
%what are x?
• Index is used to access the array
1 2 3 4 5>>x(3)
2-D Array • Create 2-D array
>> a=[1,2,3;4,5,6;7,8,9] %3 x 3 array
a= 1 2 3 4 5 6 7 8 9
2-D Array
• Index of 2-D array
(1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2) (3,3)
>>a(1,1) 1>>a(2,3) 6
>>a(i,j)
• Index of a 2-D array has two subscripts• First subscript, often noted by “i”, indicate the
row number• Second subscript, often noted by “j”, indicate
the column number
(continued)(Nov. 4, 2010)
2-D Array
• Visualize the index and the value of a 2-D array
>> a=[1,2,3;4,5,6;7,8,9] %3 x 3 arraya= 1 2 3 4 5 6 7 8 9>>surf(a)
2-D Array
• Re-assign the value of the elements
>> a=(2,2)ans = 5
>>a(2,2)=10a= 1 2 3 4 10 6 7 8 9
2-D Array
a= 2 2 2 3 4 5 6 6 6
Group exercise: (1) Create the following 2-D array(2) Visualize it using “surf”(3) Change the element at (2,2) to 20(4) Visualize the new 2-D array
Nested FOR loops
• Create a 2-D array using nested FOR loops
for i=[1:3] for j=[1:3] a(i,j)=j+(i-1)*3; endend
a= 1 2 3 4 5 6 7 8 9
• Double FOR loop is a quick way to go through every data elements in the 2-D data array
• Assign the value• Check the value• Change the value
Nested FOR loops
for i=[1:3] for j=[1:3] a(i,j)=i+j endEnd
a= ? ? ? ? ? ? ? ? ?
Find the values of the following double FOR loops:
2-D height plot
Draw a 2-D function in the following domain space:
(1) x between [-3, 3], with step size of 0.1
(2) y between [-3,3] , with step size of 0.1
)( 22
),f( yxeyx
2-D height plotx_start=-3.0x_end=3.0x_sub=0.1Nx=(x_end-x_start)/x_sub %number of points along x
y_start=-3.0y_end=3.0y_sub=0.1Ny=(y_end-y_start)/y_sub %number of points along y
for i=[1:Nx] for j=[1:Ny] x(i)=x_start+i*x_sub;
y(j)=y_start+j*y_sub;f(i,j)=exp(-(power(x(i),2)+power(y(j),2)))
endend
surf(f)
2-D height plot)( 22
),f( yxeyx
2-D height plot
Draw the following 2-D function in the following domain space:
(1) x between [-3, 3], with step size of 0.1
(2) y between [-3,3] , with step size of 0.1
22),f( yxyx
Group exercise:
2-D height plot22),f( yxyx
Image method and
Colormap(Nov. 4, 2010)
ColorQuestion:
Do scientific data have intrinsic color?
For example, temperature reading around the globe.
For example, the values of 2-D Gaussian function
ColorAnswer:
•Most scientific data concern about value, strength, or intensity. They have no color
•Color image of scientific data are called pseudo-color image, which uses color as a cue to indicate the value of the data.
Colormap
Gray-scale Map Rainbow Colormap
Computer Color•A special type of vector with dimension c=3
•The value of a color = (R, G, B)
•RGB system: convenient for computer•R: red•G: green•B: blue
•HSV system: intuitive for human•H: Hue (the color, from red to blue)•S: Saturation (purity of the color, or how much is mixed with white•V: Value (the brightness)
Computer Color•A pixel of a LCD monitor contains three sub-pixels: R, G, B•Each sub-pixel displays the intensity of one primary color•Modern LCD monitor uses 1 Byte or 8 bits to determine the intensity of the primary color
•Each primary color has 255 intensity levels•The number of colors of a LCD monitor= 255 (red) x 255 (green) x 255 (blue)= 16,581,375Or 16 million different colors•The monitor shows true color
•Human eyes discern 10 million color
(continued)(Nov. 9, 2010)
RGB CubeR
G
B
yellow
magenta
Cyan
RGB System•Every color is represented as a mix of “pure” red, green and blue colors in different amount•Equal amounts of the three colors give gray shades•RGB cube
• main diagonal line connecting the points (0,0,0) and (1,1,1) is the locus of all the grayscale value
•Color (0,0,0): dark•Color (1,1,1): white•Color (0.5,0.5,0.5): gray level between dark and white•Color (1,0,0): Red•Color (0,1,0): Green•Color (1,1,0): ?•(1,0,1): ?•(0,1,1): ?
Colormap in Matlab
To select a colormap interactively: Use the “Colormap” menu in the “Figure Properties” pane of the “Plot Tools GUI”
Matlab built-in Colormap
Example: Re-usable functionfunction gauss = Gaussian_2d ()
x_start=-3.0x_end=3.0x_sub=0.1Nx=(x_end-x_start)/x_sub %number of points along xy_start=-3.0y_end=3.0y_sub=0.1Ny=(y_end-y_start)/y_sub %number of points along y
for i=[1:Nx] for j=[1:Ny] x(i)=x_start+i*x_sub;
y(j)=y_start+j*y_sub;f(i,j)=exp(-(power(x(i),2)+power(y(j),2)))
endend
gauss=f;endfunction
)( 22
),f( yxeyx
Return value
Colormap in Matalb
>z=Gaussian_2d>surf(z) %default color map “jet”>colormap(gray)>colormap(jet)
Call the function you created and visualize it
Use “Colormap” to change color
colormap(jet) colormap(gray)
colormap
Create the following 2-D array in Matlab/Octave
>a=(1,2,3;4,5,6;7,8,9)
Visualize it using “surf” function, the surface function or 3-D height-plot provided by Matalb
Change to colormap to “gray”, “jet”, “spring”, ‘hot” et al.
Group exercise:
Colormap in Matalb
>m=gray>size(m)ans = 64 3>m 0.000 0.000 0.000 0.015 0.015 0.015 0.031 0.031 0.031 0.047 0.047 0.047 0.063 0.063 0.063 ………. 0.968 0.968 0.968 0.984 0.984 0.984 1.000 1.000 1.000
How does a colormap work? • map your data value on each pixel (e.g., row i,
column j) into a color based on the colormap• Re-scale is needed
Row 1Row 2Row 3Row 4Row 5-----Row 62Row 63Row 64
• A data value of 5.0 will correspond to color (0.063, 0.063, 0.063), and computer understands this color and will display it correctly
• A data value of 0 will correspond to color (0, 0, 0), or dark pixel
• A data value of 64 will correspond to color (1, 1, 1) or a white pixel
• Your data need to be re-scaled between 0 and 64
• “surf” do re-scale for you
Colormap: re-scale
What happens in computer is that, the data range of the 2-D Gaussian function from 0 to 1, is mapped to the color range from 1 to 64.
• 0 in function value corresponds to color number 1• 1 in function value corresponds to color number 64• Any value in between in function is re-scaled to a
value between 1 and 64• 0.5 in function corresponds to color number 32
you use a colormap of 64 colors to visualize a 2-D data, e.g., 2-D Gaussian
colormap
Create the following 2-D array in Matlab/Octave
>a=(1,2,3;4,5,6;7,8,9)
Visualize it using “surf” function, the surface function or 3-D height-plot provided by Matalb
Change the size of the colormap
>surf(a)
>colormap(gray(64)) % gray colormap with 64 colors
>colormap(gray(9)) % gray colormap with 9 colors
>colormap(gray(2)) % gray colormap with 2 colors
>m=colormap(gray(2))
Group exercise: Do you understand the changes?
“image” method in Matlab•For many applications, you want to show your data as a flat image, when your data are given as a 2-D matrix.•“image” does the trick for you
•“image” does not scale the data for you.
>z=Gaussian_2d %get the 2-D data>colormap(gray) %choose gray colormap>image(z) % show the image % but it does not work % it is dark
>image(z*64)
>image(z*256)
It does not work!
It works! Why?
Why it saturates at the center?
“image” method in Matlab
2-D Gaussian image in gray colormap
2-D Gaussian image in jet colormap
colormapGroup exercise: visualize the following 2-D array using “image” method
>for i=[1:64]>for j=[1:64]>f(i,j)=i>end>end >colormap(gray(64))>image(a)
%repeat the process, but change f(i,j)=j %Do you fully understand what you get?
%what if colormap(gray(32))%what if colormap(gray(128))
>m=colormap(jet(10)) % check out the color array
Question: what visualization techniques are used in this image?
The End
Recommended