On-Line Computer Graphics Notes

Scan Conversion


A fundamental operation that is used extensively in computer graphics and visualization is the process of scan conversion or rasterization. Given a polygon in image space, this process determines the pixels that intersect the polygon. This process is utilized in visible-surface algorithms, incremental-shading techniques, polygon-fill algorithms, ray-tracing-acceleration algorithms, and a number of other tasks that are critical to the understanding of the computer graphics field.

For a postscript version of these notes look here.


Scan Conversion of Trapezoids in Device Space

Scan Conversion is the process of finding the screen pixels that intersect a polygon. To do this, we find it convienent to move to a copy of image space that is scaled to closely correspond to the pixels in our display window. This space, commonly called device space is parameterized so that the lower-left-hand corner is at (0,0), and so that the pixels can all be indexed by integers.

tex2html_wrap312

To scan convert a polygon in this space, we will split the polygon into a set of trapezoids as is shown below, and then scan convert each trapezoid. Each trapezoid will be of a special form where the top and bottom edges of the trapezoid are parallel to the scanlines (i.e., of a constant y value). We will also consider ``degenerate'' trapezoids - triangles - which have either the top of bottom edge of zero length. In the following illustration, the polygon is split into five trapezoids. The top and bottom trapezoids are actually triangles.

tex2html_wrap314

The union of all pixels that intersect the set of trapezoids will be the set of pixels that intersect the polygon.

tex2html_wrap316


The idea here is easy. We will establish an ``edge tracker'' which follows the endpoints of the lines formed by intersecting each scanline with the trapezoid.

tex2html_wrap318

This edge tracker can be easily defined as an simple data structure which is initialized for the scanline at the top of each trapezoid and updated for each subsequent scanline.


Initializing an Edge Tracker

Suppose we are given an edge defined by two points tex2html_wrap_inline174 and tex2html_wrap_inline176, defined in device space. If we define tex2html_wrap_inline178, tex2html_wrap_inline180 and tex2html_wrap_inline182, then the following illustration shows how to calculate the initial point (only the x and y values are shown for simplicity).

tex2html_wrap320

We see that the initial point is
displaymath188
To calculate tex2html_wrap_inline190, we notice that there are two similar triangles in the illustration, and therefore we can write
displaymath192
or
displaymath194
Similarly, we could calculate
displaymath196


Updating an Edge Tracker for Subsequent Scanlines

Suppose we are given an edge defined by two points tex2html_wrap_inline198 and tex2html_wrap_inline200, defined in device space. If we define tex2html_wrap_inline202, tex2html_wrap_inline204 and tex2html_wrap_inline206, then the following illustration shows how to update the edge tracker (only the x and y values are shown for simplicity).

tex2html_wrap322

Here we have again similar triangles, and it can be seen that to move the tracker from one scanline to another, we only need update the endpoint
displaymath212
to
displaymath214
and this same calculation works for each endpoint.

We can calculate tex2html_wrap_inline216 directly from the similar triangles:
displaymath218
and similarly
displaymath220
Thus, updating the endpoint tracker is very easy, all we do is add simple increments onto the x, y and z coordinates, and we move to the endpoint on the next line.


The Endpoint Data Structure

The easiest way to implement an trapezoid edge tracker is to create a simple data structure that holds both the (x,y,z) information for the endpoints and the increments that are necessary to move the endpoint from scanline to scanline. The node typically contains (at least) the following information.
singlespace75

where (x,y,z) is the endpoint, tex2html_wrap_inline244 is the increment added to the x coordinate to move from scanline to scanline, tex2html_wrap_inline248 is the increment added to the z coordinate to move from scanline to scanline, and tex2html_wrap_inline252 is the lower bound on the trapezoid that enables us to tell our algorithm when to stop tracking.


Identifying the Intersecting Pixels on Each Scanline

To find the pixels that intersect a trapezoid, we create two edge trackers and iteratively work down (scanline by scanline) through the trapezoid. For each scanline, this enables us to determine the endpoints of a line that forms the intersection of the scanline and the polygon.

To find the pixels that intersect the trapezoid on a scanline, we only need find the lower-left-hand corner of each pixel. If we have calculated endpoints tex2html_wrap_inline254 and tex2html_wrap_inline256 on the scanline with integer value y, then the pixels intersecting the trapezoid are indexed by
align94

tex2html_wrap324


Incrementing the Z Value for Consecutive Pixels

Establishing an increment for the z value as we move from scanline to scanline is quite straightforward. The same is true for as we move from pixel to pixel - however the two increments are different. Both increments can be calculated directly from the normal vector to the trapezoid (trapezoids are assumed to be planar, as are polygons).

To see this, let tex2html_wrap_inline262 be the normal vector to the trapezoid that is defined in device space. If we have two points tex2html_wrap_inline264 and tex2html_wrap_inline266 in the plane of the trapezoid, then we know that
displaymath268
since tex2html_wrap_inline270 is a vector in the plane. Now, suppose we let
displaymath272
and
displaymath274
which represent the coordinates of two consecutive pixels in device space and tex2html_wrap_inline276 is unknown. If we let tex2html_wrap_inline278, we can calculate the dot product as
align107
which can be solved to give
displaymath280
the horizontal increment for z from pixel to pixel. We note that this is not the same as the vertical increment for z in general.


Establishing a Depth Value at Each Pixel

Since a pixel is identified by its device-space coordinate at the lower-left-hand corner of the pixel, it is useful in our rendering algorithms to be able to assign a z value for a trapezoid at this point. We have already shown how to calculate the z values at the endpoints, we only need modify this value so that it is appropriate for the coordinate of the lower-left-hand corner of the pixel. So given an endpoint (x,y,z), consider the figure below.

tex2html_wrap326

From the figure, we can see that we should subtract from z, a portion of the horizontal z increment that corresponds to the distance of x from the left side of the pixel. That is,
displaymath298
with this z value, and the horizontal z increment tex2html_wrap_inline304 we can specify a depth value for the trapezoid for each pixel along the scanline.


Using the above calculations, we can use the endpoint data structure to set up edge-tracking mechanisms, and can both enumerate the pixels within a trapezoid and assign a z value to each pixel.


Summary

Scan Conversion is a procedure that is use repeatedly in computer graphics algorithms. It is a simple procedure, designed around an edge-tracking paradigm, which can be implemented by adding simply-calculated increments onto base values. One of the primary uses of the algorithm is to establish depth (z) values at each pixel for polygons in the scene, this enables us to retain only the visible polygons in our final renderings. However, we can also utilize quantities relating to color, texture, and parameterization as information in our endpoint nodes and increment them as well. These quantities are included in the algorithm in a manner similar to the z coordinate above.


This document maintained by Ken Joy

Comments to the Author

All contents copyright (c) 1996, 1997
Computer Science Department,
University of California, Davis
All rights reserved.



Ken Joy
Thu May 15 08:38:19 PDT 1997