CS 4204, Project 2 - Due May 1, 2007

3D Data Visualization

One of the important applications of computer graphics is data visualization. In this case, the goal is to create a tool that will help people explore the structure of a 2-dimensional spatial function such as a digital image, digital elevation map, or other function of two variables. Depending on the application, one might want to view the data as a digital image, an array of numbers, or as a topographic surface. Your job is to write a program that reads in a raw monochromatic image as an array of 8-bit unsigned bytes in row order and then provides the user with these three viewing options. Your grade will be based, in part, on the quality of your user interface and the ease of use of your program.

Input:

The program should ask for the name of the data file and the row-column dimensions, and you should provide for images as large as 1024 x 1024 picture elements. The program should remember the file name and dimensions it used last and propose this as the current input. Assume that the image dimensions are smaller than the screen dimensions.

To help you create a good program interface, we are providing you with a program called prj4204.exe that will get program parameters and launch your program for you. When you run this program, two dialogue boxes will be shown. The first is an Open File Dialogue box. You can select an image file; if you have selected an image file before, the name of that image file will be the default name and you can just press the OPEN button to select it. The second dialogue box is for you to input two parameters, the width and height (in pixels) of the image. The initial values are 128; if you have specified values before, they will be the default values. The third parameter is the file name of your graphics program; again a default name is provided if you have specified one before.

If you press OK in the second dialogue box, the graphics program will be launched with three command line parameters as follows:

<program name> <image file name> <width> <height>

If you select CANCEL in one of the two dialogue boxes, no further action is performed. The information about the last selection is kept in the file OGL.INI, which is located in the current working directory. With this program, you need not bother to code to get the input parameters for Project 2; this program can launch your program with the necessary parameters. You can get the parameters through command line parameters in your GL program.

There are two test images that you can use to test out your programs. These are binary greyscale images stored row by row, 1 byte per pixel. Click on the images to download them. Remember that the images you see in your browser are in .gif format, but the ones you download are in binary (raw) format.

window.img, 128 × 128
thomas.img, 258 × 79

Image Viewing:

By default, when the program executes, the function should be displayed as a greyscale image. Using the mouse, it should be possible to point at a pixel and determine that pixel's location and functional value. Normally people with interest in digital images like to think of coordinate (0,0) as being in the upper left corner, so you should adhere to that convention.

Zoom:

It should be possible to point at a pixel with the mouse and do a 32× zoom on the 15 × 15 pixel subimage centered where the mouse is pointing into a new 480 × 480 pixel window. This is done by replicating the image pixels into 32 × 32 pixel blocks. There should be a quick way to return to the original image view. Note that glut has the ability to create both subwindows and multiple main windows. The glutSetWindow and glutGetWindow functions permit you to manage multiple top level windows. You will need glutDestroyWindow to remove a window without terminating your program. Assume also that the image is small enough so that no scrolling is necessary in any window.

Numeric:

This is the same as the zoom function, except in addition, each pixel should be labeled with its numerical value. The numerical values can be written in color, and it might be a nice touch to use a unique color for the center pixel.

Topographic:

It should be possible to point at a pixel with the mouse, extract a 33 × 33 pixel subimage centered at the mouse, and view the subimage as a 3-dimensional surface in a 256 × 256 pixel window. Figure out how to shade the surface so that its 3-dimensional structure will be easy to visualize. Each square facet should be drawn with its edge, and the surface should be drawn in perspective using viewing parameters of your choice. The image at the top of the assignment page is an example of what such a 2D surface might look like.

Notice in this example that one can't tell how high this surface is above the 0-plane. Thus, it is a nice touch to add a "skirt" around the surface so that it looks as though it was cut out of the function with a cookie cutter. Each facet can be drawn as a polygon, though most are likely to be nonplanar polygons. Since in OpenGL there is no way to draw polygons with boundaries directly, the general idea is to draw all the polygon boundaries first and then to draw the polygons again with interior fill and hidden surface removal. The interiors will overwrite invisible edges. The problem is that the interior of a polygon will overwrite its own edges. One way around this is to write the edge of a polygon into a stencil buffer and then to write the interior only at pixels where no edges were written into the stencil buffer.

As for the shading of each facet, there are a number of possibilities. The facets could be shaded according to their numerical value. To achieve greater realism one could establish a hypothetical illumination source and then shade the surface with an intensity that depends on the relationships among facet normal, light source position, and camera position. Note that these capabilities are built into OpenGL. Use your own ingenuity here; we have found that illumination sources can be invaluable for adding to the impact of the surface visualization.

Should your topographic view appear too dense (256 × 256 is quite a small window), you may decide to reduce the size of the subimage you display. Don't make it smaller than 17 × 17, however.

Digital Images:

These digital images are just black and white and are stored one byte per pixel in row order, starting at the top of the image. There are no file headers. To create a greyscale, just assign the same values to R, G, and B colors. When you open an image file for reading, make sure you open it for binary input or the 0 data values in the file will be mistaken for endlines. Check out C++ Binary File I/O if you have forgotten how to do this. The functions necessary to read and write images into and from the frame buffer are glDrawPixels and glReadPixels. OpenGL should be initialized with a call to the function, glPixelStorei (GL_UNPACK_ALIGNMENT, 1).

The User Interface:

Use what you learned about human-computer interfaces from your experiences with Project 1. Keep in mind that the goal of this project is to facilitate getting image information out of a file and to make it easy to visualize the surface structure of a digital image.

Documentation:

As with every program you will write this semester, your code will need to conform to the departmental standards, which include prettyprinting such as whitespace and indentation, a documentation header for each function you write including main, and readable inline documentation that describes the function of each chunk of code. Remember, too, to use the OpenGL datatypes for the OpenGL function arguments. The CS documentation standards may be found at http://ei.cs.vt.edu/~cs2604/Standards/Standards.html".

Partners:

Project 2 may be done jointly with one other class member. In that case, both names must appear in the program headers. To request to work together, submit a collaboration request form (no Email) by class time Tuesday, April 17. This form is found on the class web page.

Submission:

Email your final working program source code files as a .zip archive to Rongrong at by midnight the day it is due. Late projects lose 25% per day. The explanations of how it all works should be included in your code documentation; provide any linking instructions for John as a readme.txt. Partners should submit only a single copy of the project.

Here are the grading criterea. Note, however, that while ease of use counts only 4 points out of 20, a poor interface may make it impossible for us to evaluate the functionality thoroughly.