CHAPTER 7 - Implementation 3

Objectives<next>


Rasterization


Scan Conversion of Line Segments


DDA Algorithm (Digital Differential Analyzer)


Problem


Using Symmetry


Bresenham's Algorithm


Candidate Pixels


Decision Variable


Incremental Form


Midpoint Line Algorithm (alternate discussion from Foley)

Bresenham [BRES65] developed this classic algorithm which uses integer arithmetic and thus removes the need for the round operation. It can also be applied to the integer computation of circles. The algorithm can be extended to handle lines with fp endpoints.

The algorithm assumes slopes are in [0,1] and the lower left endpoint is at (x0,y0) and the upper right endpoint is at (x1,y1).

Using the grid below for discussion.

Assume pixel (xp,yp) has been selected to be displayed. Let point Q represent the intersection of the line we wish to draw with the line representing the vertical raster grid one pixel to the right of (xp,yp). We now have a choice, either select the pixel one increment to the right (pixel E) or select the pixel one increment to the right and one increment up (pixel NE).

Bresenham's algorithm computes the vertical distances from E to Q and from NE to Q. The sign of the difference is used to select the point whose distance from Q is smaller. This distance is always <= 1/2.

Algorithm :

EXAMPLE

Consider the line defined by endpoints (1, 2) and (5, 3). Then dy = 3 - 2 = 1, dx = 5 - 1 = 4 and B is determined as y = (dy/dx)x + B or

2 = (1/4) 1 + B, where B = 7/4.

The point (2,1) is below the line and F(2,1) = (1) 2 - (4) 1 + (4)(7/4) = 5.

The point (2,4) is above the line and F(2,4) = (1) 2 - (4) 4 + (4) (7/4) = -7.

END EXAMPLE

To summarize: at each step choose between two pixels based on sign of decision variable d calculated in previous step. Update decision variable by /\E or /\NE depending on which point is chosen in current step.

To calculate the initial value of d to start the algorithm use the first endpoint (x0,y0) then


Polygon Scan Conversion


Winding Number


Filling in the Frame Buffer


Using Interpolation


Flood Fill


Scan Line Fill

  • Can also fill by maintaining a data structure of all intersections of polygons with scan lines
    • Sort by scan line
    • Fill each span


Data Structure


Aliasing

  • Ideal rasterized line should be 1 pixel wide

  • Choosing best y for each x (or visa versa) produces aliased raster lines

Antialiasing by Area Averaging

  • Color multiple pixels for each x depending on coverage by ideal line


Polygon Aliasing

  • Aliasing problems can be serious for polygons
    • Jaggedness of edges
    • Small polygons neglected
    • Need compositing so color of one polygon does not totally determine color of pixel


<next>