Visualization Homework
From BillsNotes
Assigned: Week 8, Tuesday, 8/22
Due: Week 9, Thursday, 8/31
In this assignment, you will be using the python interface to the Visualization Toolkit, a popular open source visualization library useful for scientific visualization. The documentation (http://www.vtk.org/doc/release/4.2/html/) is pretty good; you should refer to it if you have trouble.
You will primarily be tweaking existing scripts, so you do not necessarily need to know python to complete the assignment. However, there are several tutorials (http://wiki.python.org/moin/BeginnersGuide/Programmers) available from the python website (http://www.python.org/)
What to turn in:
Turn in answers to each numbered question in Step 2 below, either typed or written. Also turn in the script you will write in Step 3, and a screenshot of the visualization the script produces.
| Table of contents [ |
Step 1: Verify Environment
To complete homework 3, you'll need to have an x-server running on the machine from which you connect to cormorant.
Running an X-server
If you're running linux (or any *nix) with a graphical interface, you're all set.On windows, you'll need to install and run an X-server. Cygwin is one choice, but may be overkill. Some students report that Xming is a good free X-server for windows. Combined with PuTTY or another ssh program, this is all you need. I have not used this program before, however, so I cannot vouch for its efficacy.
If you do decide to use Cygwin, you'll need to install the X11 packages and ssh by following the instructions here. After following the installation instructions, run the following command:
$ /path/to/cygwin/usr/X11R6/bin/startxwin.batreplacing "/path/to/cygwin/" with the location of your cygwin root directory. This command should open an X-terminal. Use this terminal in the instructions below.
Logging on to cormorant.cs.pdx.edu
From a workstation running an X-server, use ssh to login to cormorant.cs.pdx.edu, using the username portion of your email address registered with the class mailing list and the password provided over email. Use the '-Y' flag to enable X11 forwarding. (The '-X' flag is techincally more secure, but most applications can't run with the reduced permissions, including the render windows of vtk.)$ ssh -Y username@cormorant.cs.pdx.edu
Verify that the environment variable VTK_DATA_ROOT is set properly.
$ echo $VTK_DATA_ROOT /usr/local/vtk/VTKData
Testing python and VTK
Test your ability to view vtk render windows py running an example script with python. Note that the rendering may take some time if you are connected from a remote machine.
$ python /usr/local/vtk/VTK-4.4/Examples/VisualizationAlgorithms/Python/CutCombustor.py
Step 2: Review examples
Some fundamental techniques for visualizing 3D datasets are isosurfaces, cutting planes, and volume rendering. In this step, we will look at some example scripts for these visualizations in VTK and answer some questions about them.
Copy some example files into a local directory
$ cp /usr/local/vtk/VTK-4.4/Examples/VisualizationAlgorithms/Python/CutCombustor.py . $ cp /usr/local/vtk/VTK-4.4/Examples/VisualizationAlgorithms/Python/streamSurface.py . $ cp /usr/local/vtk/VTK-4.4/Examples/VisualizationAlgorithms/Python/ColorIsosurface.py .
Isosurfaces
Run the ColorIsosurface.py script, and consider the visualization produced.
$ python ColorIsosurface.py
- Question 1: Based on class notes, prior knowledge, intuition from this visualization, or web research, describe what an isosurface is.
Open the file ColorIsosurface.py using an editor of your choice.
- Question 2: The isosurface itself is defined over the scalar data associated with the mesh; density in this case. What physical quantity does the color of the isosurface represent?
PLOT3D uses function numbers to indicate specific physical quantities; 100 is Density, and 153 is VelocityMagnitude for example. You can change the scalar quantity used to define the isosurface by using a different number. The complete list appears in the documentation for vtkPLOT3D.
- Question 3: Which method is used to change the value of the isosurface? Raise the value used to define the isosurface. At about which value do the isosurfaces disappear?
- Question 4: Insert the line "pl3d.AddFunction(184)" just beneath line 20. This line adds the function "Swirl" to the dataset. What object must you modify to color the isosurface by this new physical quantity?
- Question 5: Color the isosurface using "Swirl." Run the script again. What color is the isosurface? Why? What do you need to change to make a more interesting visualization?
Cutting Surfaces
Run CutCombustor.py
$ python CutCombustor.py
Note that there are two embedded surfaces in this visualization, one showing the mesh structure, and one colored by the scalar values.
- Question 6: What's the difference between vtkCutter and vtkStructuredGridGeometryFilter?
- Question 7: What would you need to do to change the orientation of the wireframe surface? Make the appropriate change to whatever orientation you prefer.
- Question 8: In line 14, change the function number from 100 (density) to 120 (temperature). Rerun the script. Consider your answer to Question 5. Why do we not encounter a similar problem here?
Stream Surfaces
Streamlines/streamsurfaces are used to visualize a vector field. Run the script streamSurface.py
$ python streamSurface.py
- Question 9: The vtkStreamLine object does the heavy lifting for this visualization. Change its behavior by passing a different value to the SetMaximumPropagationTime method. What visual feature does this method appear to control?
- Question 10: A velocity field can represented by associating velocity components (u, v) with each point in a mesh. Describe (in English, or pseudo code if you prefer) a possible algorithm to generate a streamline given a velocity field and a starting point.
Step 3: Build your own
Write a script to draw an isosurface and a cutting plane for the file /home/workspace/ccalmr/salt.vtk
This file is in a different file format than the samples above. For this file, you will use the class vtkDataSetReader like this:
reader = vtk.vtkDataSetReader()
reader.SetFileName("/home/workspace/ccalmr/salt.vtk")
reader.Update()
This dataset is defined with a scalar attribute "salt" and several other field attributes (all scalars). To determine appropriate values for isosurfaces and locations for cutting planes, you may wish to inspect the dataset directly. In python, put the line
print reader.GetOutput()
to print some useful information to standard out, including the bounding box of the dataset. To choose an appropriate isosurface value, note that ocean salinity ranges from 0 parts per million (fresh water) to around 32 parts per million (ocean).
Note that this dataset is an UNSTRUCTURED grid, so any class with "StructuredGrid" in the name will throw an error. Find a suitable replacement using the VTK documentation, or check with the instructor.
Turn in a color screenshot of your visualization via email in addition to your final script.