Assignment #2 -- Scan Conversion


Due Date

This assignment is due at 11:59pm on Friday, February 20th. Projects turned in late will lose point as described in the policies handout. This assignment should be done alone or in pairs. You may share ideas with other groups, but you may not share code.

SUBMISSION DETAILS

You may submit on either Unix or Windows. The platform you submit on will be the one used to grade assignments. 

Do not touch any file after the submission date. Readers will check the file time stamps. Regardless of which platform you used for the assignment, you should have an as2 directory in both of your Unix and Windows accounts. You should put a README file into both of these directories that at the minimum contains the following data:

You should also e-mail your README file to cs184@imail.eecs.berkeley.edu. On the subject line you should specify your account names and the assignment number (e.g: cs184-aa, cs184-ab: as2).

All files needed to compile your code should appear in the Windows or Unix directory of the user indicated in your README file. It is your responsibility to make sure that they will compile and run properly. You will also need to set the permissions properly.

Windows: The grader should be able to recompile your program by simply opening the project and rebuilding it from scratch.

Unix: Remember that the grader should be able to recompile your program simply by typing make.

The TAs have provided sample code for you to start with. If you chose to use that code, you are responsible for figuring out how to use properly. If you have questions, post them to the news group or ask the TAs during their office hours.

Do not wait until the last minute to start this assignment.



Overview

The assignment is to scan convert polygons. The input will be a file of the form described. The output will be a display of the scan converted polygons. The polygons may be concave and self intersecting, so be sure to test as many cases as possible. You will be using the algorithm presented in class.

You will use a slightly different mapping for the display window to make it easier to view the results of this assignment. Your window should contain 50 rows of 50 "display-pixels" each. Each "display-pixel" may be very large. For instance, if your window were 500 by 500 pixels, each "display-pixel" would be 10 by 10 pixels in size.

The lower left corner of the lower left pixel is (0.0, 0.0), while the lower left corner of the upper right pixel is (0.98, 0.98).

Each polygon should be drawn in a distinct (easily distinguishable) color. You should also draw the grid.

Your program should accept a single command line argument which is the name of a file containing the description for the polygons.

Your program should first generate a filled rendering of the input polygons with the outline of each polygon shown using one-real-pixel thick line (this thin outline may be generated with the openGL line command).

The program should then wait for a left mouse-click. Once the user has clicked, the program should use your favorite line algorithm (DDE, Bresenham etc.) to draw the boundary of each polygon using its vertices, also in large display-pixels. The lines should be drawn over the already displayed filled polygons. Note that when you do this no pixel that was filled in during the fill process can leak out of this outline. Also note that there cannot be any unfilled pixels inside the outline. Further left mouse-clicks should turn this option on/off (i.e toggle the thick lines).


File Format

The first line should contain an integer, designating the number of polygons  your scene contains. The subsequent lines should have an integer, which is the number of vertices a polygon contains followed by x,y pairs on each line for all the vertices in order, repeated for each polygon. For example, we can represent a scene containing 2 polygons by:
2
3
0.1 0.1
0.2 0.2
0.3 0.1
4
0.5 0.1
0.6 0.9
0.2 0.5
0.1 0.7

Vertex positions are in the normalized device coordinate system. So 0,0 is the lower-left corner of the lower-left-most pixel and 1,1 is the upper-right corner of the upper-right-most pixel.

Bonus

You can implement the following for additional marks:

Questions should be posted to the news group or to cs184@imail.eecs.berkeley.edu.