E26/CS40 Computer Graphics: Lab #3
Scanline Fill
nick guerette . adem kader . heather jones
09.20.2004

labs home    |    lab1    |    lab3    |    lab4    |    lab5    |    lab6    |    lab7    |    lab8    |    lab9    |    final project


description.

In this lab, we implemented the "scanline fill algorithm" for polygons and applied it to ellipses and circles. Given any number of points (the points might be outside the image area) our program can fill the polygon connecting the last point to the first one, thus making the region a closed area. For convenience, the border and the fill always have the same color (and the border of the polygon is drawn as it's filled in).

We also implemented a Polyline algorithm which takes as input an array of points and the number of points in the array, and then connects these points in order (first point gets connected to the second, the second to the third and so on). Unless the last point and the first point are the same, the algorithm does not close the polygon.

 

questions.

  1. Is your polygon algorithm consistent with respect to screen coordinate issues, and does it produce rectangles that are the correct area? What changes to the algorithm did you have to make in order to make it consistent? You might want to make a simple image to demonstrate the mathematical consistency on your web page.
    Our algorithm is consistent with screen coordinate issues and produces polygons that are the correct area. To make our program work properly, we modified the code so that when we pass the points, the algorithm starts from the right pixels and ends at the leftmost pixels, coloring in between the pixels, but not the pixels corresponding to the given points.
    fig2 shows how the algorithm will work if p1, p2, p3 and p4 are the arguments of our algorithm. For every scan, the algorithm will start filling to the left of the rightmost pixel. Then as soon as an edge is reached, it will stop filling. The same idea is also used for the vertical part, therefore for points p1, p2, p3, p4 (fig2) we will have a rectangle (or a square) with size (p4 - p1)*(p2 - p1), which is the correct area.
    Fig1 shows how the algorithm will work for adjacent pixels. For points (0,1),(0,0),(1,0) and (1,1), scanfill fills only one pixel.


    fig1. example of a polyfill result

    fig2. filling a polygon


    If we

  2. How many filled polygons of a reasonable (400 pixels < area < 1000 pixels) size and complexity (5-7 edges) can your algorithm draw in 1 second?
    On average, our algorithm filled around 3800 polygons per second.


    polyfill - 3815 polygons / second

    circlefill - 35390 circles / second

  3. How many filled circles of a reasonable size (10 pixels < r < 20 pixels) can your algorithm draw in 1 second?
    Our algorithm filled about 35000 circles per second.


  4. If you extended this assignment in any way, describe what you did and how you did it. Include pictures, or links to pictures that show what you did?
    We added a pattern attribute to our global graphics state, which stores an array of bytes representing a pattern, and values for rows and columns specifying the dimensions of the pattern.  The pattern may be an arbitrary size, and each byte represents a transparency, allowing this attribute to be used for either filling patterns or gradients.  The pattern template is positioned relative to the boundaries of a polygon being drawn rather than the screen coordinate system, in order to make the pattern fill consistent between polygons drawn in different locations.  Functions were written for initializing a blank (entirely opaque) pattern, reading a pattern from and writing a pattern to a PGM image file, and clearing a pattern and freeing the memory it occupied. In addition, an attribute of an enumerated type specifying a gradient mode was added to the global graphics state.  When this attribute specifies a type of gradient and a filled polygon is drawn, a function specific to the type of gradient specified is called to calculate a pattern string based on the size of the polygon being drawn.  The only gradient method actually implemented was a vertical gradient, with transparency increasing in the positive y-direction (toward the bottom of the screen).  Since the pattern attribute is used for gradient filling, patterns cannot be drawn with gradients.



  5. REQUIRED IMAGES


    required image 1


    heather's


    nick's


    adem's


no copyright; all of the above work was done for the sake of science and engineering