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.bat
replacing "/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

Open the file ColorIsosurface.py using an editor of your choice.

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.


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.

Stream Surfaces

Streamlines/streamsurfaces are used to visualize a vector field. Run the script streamSurface.py

$ python streamSurface.py

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.