CSCE 441: Computer Graphics

Fall 2017


Assignment 2: Polygon Scan Conversion and Clipping [150 points]

Due 9/27/2017

Purpose:
This assignment is designed to help you become familiar with polygon scan conversion and clipping algorithms. The scan conversion section of this assignment will later be used in Assignment 4 as well.

Description:
In this assignment you will write a program that allows the user to input a set of polygons, scan converts those polygons onto the screen, allows the user to specify a clipping rectangle and displays the clipped polygons. You will NOT be using OpenGL's polygon or clipping commands. Instead, you will use the skeleton code provided. This code provides a 2D array for you to set color values and displays that 2D array. However, you may use OpenGL to draw anything else (lines, points, etc...) as part of the user interface for the assignment.

You should write a program that:
  • allows the user to specify the polygons using the mouse. The user will press the left mouse button to specify a vertex. Each button press will be the next vertex (in order) for the polygon. The final point of the polygon will be specified by pressing the right mouse button. So the user can specify a triangle with two left clicks and one right click. The user may define up to 10 polygons, each with at most 10 vertices (before clipping).
  • scan converts those polygons. Each polygon should be drawn using a different color. You should use an active edge table for this portion of the project.
  • lets the user enter clipping mode by pressing 'C'. Once this key has been pressed, no more polygons can be entered.
  • allows the user to specify the clipping rectangle by clicking and dragging the mouse. The point the user clicks with the left mouse button will be one corner of the rectangle and the point the mouse is released will be the other. The clipping region should be highlighted as the user drags the mouse (draw the four edges of the rectangle) with the polygons the user entered still being shown.
  • allows the user to change the clip region as many times as desired. In each case, the original polygons should be used for clipping and not the already clipped polygons. You may use a polygon clipping algorithm that leaves extraneous edges for concave polygons being clipped.
Do not be surprised if your program runs somewhat slowly.

Grading:
[15] Capturing user polygon input correctly
[55] Scan converting input polygons
[5] Different color for each scanned polygon
[5] Mode transition to clipping mode
[15] Capturing clip rectangle correctly and drawing of clip rectangle
[55] Clipping of polygons and scan conversion of clipped polygons


FAQ

The assignment says that we should use an active edge table to scan convert the polygons. Does that mean we cannot use glBegin(GL_POLYGON)?

As stated in the assignment page, “You will NOT be using OpenGL's polygon or clipping commands.” The entire point of this assignment is to test your knowledge of the polygon drawing and clipping algorithms… not to see if they’re implemented correctly in OpenGL.

What about drawing the edges of the window for the clipping region? Can we use glBegin(GL_LINES)?

Yes. This assignment is not about line drawing. If you would like to use OpenGL to draw horizontal and vertical lines, you may.

When the user drags the mouse during clipping, we need to draw the four edges of the clipping rectangle. Do we also need to change the background color inside the clipping rectangle to highlight it?

You do not need to change the background color inside the clipped rectangle. You should only draw the outline of the rectangle.

Should the polygons the users originally inputs always remain displayed in the screen?

When the user is in clipping mode, only the portions of the polygons inside the clip rectangle should be visible. When the user is not in clipping mode, all of the polygons should be visible.

Each time the user drags and lets go of the mouse, a clipping region is highlighted so nothing outside the clipping rectangle is displayed?

Yes. While the user is dragging the clipping rectangle, you can show all of the polygons until they let go of the mouse button. Then you should clip the polygons and only draw what is inside the clipping rectangle. Alternatively, if your polygon drawing and clipping is fast enough, you can do it in real-time as the user drags the window.


Honors

For those taking the honors section of this course, you will be implementing a tile-based rasterizer. Divide the screen into roughly square regions (tiles) and place each polygon in the work queue of the tiles it intersects (you may use a bounding box to approximate this). Then rasterize each tile into a local buffer using the inside/outside test specified in lecture. You will implement clipping by not testing those pixels outside the clip region. Furthermore, you will implement the assignment using OpenMP (Note that you need to enable openmp in the Visual Studio project settings). OpenMP allows you to trivially parallelize portions of code using the

#pragma omp parallel for

construct. You should parallelize the individual pixel rasterization in each tile.

Once your rasterizer is working, you will analyze its performance under different numbers of processors using

omp_set_num_threads

Make sure you do not set the number of threads to be higher than the number of cores on your machine. You should also analyze how the size of the tiles affects performance as well.

You should use an accurate timer and perform all of your tests on the same machine with the same conditions if possible. Here is some code you can use to capture timing data in Windows. You might also consider how you implement your algorithm. For example, you might only build an active edge table using the ymin/ymax extents of the polygons and restrict drawing to that area. In addition, if you want your code to perform well, you should keep memory allocations to a minimum (which may mean avoiding the STL depending on how you use it). If you need to allocate memory, you also might consider implementing a very simple fixed size memory pool allocator. Here's a simple fixed-size pool that I wrote if you want to use it.

Write up your results in a short report to be included with your submission detailing any conclusions you arrived at as well as graphs showing your experiments to back up your conclusions. Your report will be graded based on the experiments you perform and conclusions you draw rather than achieving an expected result.

Honors Section Grading:
[15] Capturing user polygon input correctly
[55] Scan converting input polygons
[5] Different color for each scanned polygon
[5] Mode transition to clipping mode
[15] Capturing clip rectangle correctly and drawing of clip rectangle
[30] Clipping of polygons and scan conversion of clipped polygons
[25] Performance analysis