Title: Computational Methods in Physics PHYS 3437
1Computational Methods in Physics PHYS 3437
- Dr Rob Thacker
- Dept of Astronomy Physics (MM-301C)
- thacker_at_ap.smu.ca
2Todays Lecture
- Visualization
- More on Opendx
- 3d visualization methods
- Isosurfaces
- Volume rendering
- Making movies
- makempeg script the Berkeley mpeg encoder
- References
- Some overheads borrowed from a presentations by
Tamara Munzner, Gordon Kindlmann
3Getting started with Opendx
- Using Import Data is perhaps the simplest way to
get started with Opendx - Selecting it will take you to the Data Prompter
4Data Prompter
- The data prompter will create a .general file
which the import module can read - Well look at importing gridded data
- Will take many different types
- Lets look at the simplest a regular grid
5Datafile description
Using an engineering example in this case
Once the data is described, use save as in
the File menu to save the general description
used by dx
6Simplest tool
- Default viz option will allow you to see the data
immediately - Ensure everything loaded in OK
7Note on Windows version
- The windows version has problems with spaces in
file names - Dont save files with names such as
- C\Programs and something\myfiles\and so on\
- Helpful to set up an Opendx directory right at
the top of the directory tree - e.g. C\Opendx
- Also, the default viewer in the data prompter did
not work for me - But could just be my laptop running out of memory
- One of the drawbacks of Opendx is that it rapidly
consumes memory - A workstation dedicated to visualization usually
needs 2 GB or more of memory - Will exploit multiple processors though good
news! - Everything else seems fine though, the VPE works
without a problem
8Checking data
- You can test that your loaded data is correct in
a couple of ways - Try the test import button
- Will give information about range and so forth
- Examine the data directly with the browse data
button - Lastly, go directly to the visualization system
described on the previous page - Unfortunately, if something is wrong it wont
tell you much quantitative information about the
problem
9Creating a program
- The default visualization system is useful, but
most of the time well want to create our own
programs - When we used the data prompter we saved a
description of the file called fan.64_ascii in
fan.general - We can load this into our own program
- The next few overheads walk through a simple 3d
visualization
10Creating the visualization program
Open the program editor and expand the ALL
listing of modules, place fileselector, import,
isosurface, image
Link by left clicking on tab and then drawing a
line to the other box
Now double click on fileselector
11Fileselector
- This will bring up a control panel into which you
can type the name of the .general file saved when
using the data prompter
12Executing the program
Select Execute Once from the execute menu
13Image output
- Running the program will produce an isosurface
output
14Interacting with the image
- Under options select the view control
Select rotate under mode
15Rotate the image
- Click and drag on the image with the mouse to
rotate - It isnt that fast though
- Note the globe is turned on by selecting it in
the options menu
16Algorithms for 3d visualization
- A bit of background to the algorithms used in 3d
visualization will explain why it is such a
computationally expensive process - Look briefly at
- Isosurface rendering
- Playing with it in Opendx using the isosurface
module - Volume rendering methods
- Volume rendering is part of the Image module
17Voxel data
- The analogy of a pixel in 2d is the voxel in 3d
- Field values are described at the vertices rather
than in the center - Field values along the edges and internally can
be derived by a number of interpolation functions
18Isosurface Extraction
0
1
1
3
2
- Which choose a fixed iso-value
- Then need to extract out the contour (surface in
3d) corresponding to this value - The marching cubes algorithm is the most common
method - Patent has recently expired on this algorithm
1
3
6
6
3
3
7
9
7
3
2
7
8
6
2
1
2
3
4
3
Iso-value 5
19First step of Marching cubes
- Classify the voxel by the values at the vertices
- Each vertex is either- outside the surface (gt
isovalue) - inside the surface (lt isovalue)
10
10
Iso9
5
5
10
8
Iso7
8
8
inside
outside
20Marching Cubes Triangle Example
21Example Triangle configurations
- These 15 base examples can be used to derive the
28256 total configurations
22Surface vs volume rendering compared
- Surface Rendering
- 2d surfaces are rendered within a 3d space
object appears solid - Data must be converted into geometrical
primitives such as triangles for rendering - This process may lead to information being lost
or disguised - Makes sense for objects with a solid surface
- Volume Rendering
- Entire volume can be rendered providing interior
information - data is not explicitly hidden
- Spatial data is mapped to a volume of RGBA values
using a transfer function - This volume is rendered directly using a variety
of techniques - Makes sense for objects with complex interior
structure and no solid boundaries
23Improving on the earlier visual program
Add these new modules Set the opacity of the 1st
color module to 0.3, for the second 0.7
24New image is a combination of a surface and a
volume rendering
- Surface has a reduced opacity so we can see
through it - Interior volume is shown using different colours
for different field values
25Volume render alone
26Volume Rendering Pipeline
- Data volumes are used as input to the transfer
function, which produces a sample volume of
colors and opacities as output - Sample volume is rendered to produce a final image
FRGBA(data)
data volume(s)
sample volume
transfer function
final image
rendering
27Transfer Functions (TFs)
RGB
a
- Map data value to color and opacity
f
Gordon Kindlmann
28Choosing transfer functions
- This is one of the black arts of visualization
- Need to know fundamental scales of variation in
your problem (linear? Logarithmic?) - Opacity cant be too high otherwise we cant see
through - If its too low we dont perceive enough
information - Colours should be chosen in sympathy with the
data - Volume rendering generally doesnt cope well with
too much high frequency data
29Examples
Cutting out high values has no effect
Linear increase places too much weight on mid
range
a
a
f
f
Sharply peaked to high opacity effectively gives
a surface render
Moving to a lower value of f doesnt help
a
a
f
f
Gordon Kindlmann
30Ray casting one rendering technique
- The sample volume must now be rendered
- Vast body of literature on different techniques
- Simplest idea is ray casting
- (1) Send ensemble of rays through the system
corresponding to image pixels - (2) Interpolate values along each ray from grid
- (3) Local gradient is calculated to estimate
amount of light reflected back to image - (4) Values are composited together from back to
front
Image source Wikipedia
31Trilinear Interpolation
- What is the effect of interpolation on the volume
rendered image? Could choose nearest neighbour
value, or linear interpolation - Below is a comparison of nearest neighbour to
trilinear - The additional expense of the interpolation
removes a significant amount of noise in the
final image
Michael Knapp
Nearest Neighbor
Trilinear Interpolation
32Multiple layers in volume rendering
- Example using a tool called vfleet
- Rendering of gas density in one of my simulations
- Transfer function has been chosen to pick out
three surfaces - See through isosurfaces
- Exactly the same as having multiple opaque
isosurfaces
33Making movies
- Some toolkits (e.g. AVS) will make movies from a
bunch of frames (images) for you - Opendx unfortunately doesnt
- First step in making a movie manually is to
create a series of frames with a fixed naming
convention - e.g. frame.00001.gif, frame.00002.gif,
frame.00003.gif - From this series of frames a number of freely
available tools will compile them into a movie
for you - Most tools rely on some kind of UNIX script to do
this - Ill give explicit details for the makempeg
script - This makes MPEG-1 standard movies which are
lossless - Fairly low compression ratio, but no bad
rectangular artifacts - Ideal for scientific viz.
34Makempeg
- I will put this Unix driver script on the class
website (if you are interested) - Rather dated now, but it works effectively
- You need two other packages
- Berkeley MPEG encoder (will also put on website)
- This is the program that creates (encodes) the
movie from your images - Compile this code, will create the mpeg
executable - netpbm image manipulation tools (can be installed
in Linux) - Need by the makempeg script to convert images
into the format used by the MPEG encoder - Place the makempeg script and mpeg executable in
the same directory as your frames of name
xxxx.yyyyy.ext
35Running makempeg
- Example command
- makempeg fs 1 fe 10 fi 1 base test ext gif
- Will make a movie
- Starting at frame 1 (-fs)
- Ending at frame 10 (-fe)
- Increments between frames is 1 (-fi)
- Name of files is test.????.gif
- -base base name
- -ext filename extension (could be jpg, tiff)
- Script expects 4 digit number for each frame
- i.e. test.0001.gif test.0002.gif test.0003.gif
- Script will convert to the YUV format and then
launch the encoder - Quite quick may be up to 2 minutes for a larger
movie, much faster for smaller
36Example movie made with makempeg
37Summary
- Use the data prompter to create the description
file for Opendx data - Construct visual programs quickly and easily by
linking modules together in the visual program
editor - Isosurface and volume rendering techniques are
both supported by Opendx - Selecting suitable transfer functions is
non-trivial and takes time - Lastly, movies can be made quickly and easily
from a series of frames using a large number of
freely available tools - Ive provided codes for one method on the website
38Student presentations
- No lectures March 24th, 26th, 31st
April 2nd Mike Hiland Ashley Campbell Glen Hodge Masaki Uchida April 7th Michael Palmer Nick Presse Cristina Collicott