Output Primitives (Rasterization)
Output Primitives (Rasterization)
Output Primitives (Rasterization)
Basic raster graphics algorithms for drawing 2D primitives (from a graphic package implementors point of view)
(Foley-van Dam: Computer Graphics, Chapter 3)
Primitives
Describe the component parts of the scene (trees, walls, atoms, cars etc.) to be displayed. (Graphics output)Primitives: Functions in a graphics package that we use to describe the picture components Geometric primitives: Output primitives describing the geometry of objects. The simplest one: points, straight-line segments Output primitives are projected to a 2D plane, corresponding to the display area of an output device, and scan-converted into integer pixel positions.
2
Clipping
Clipping before scan conversion
Advantage: the scan converter must deal with only the clipped version of the primitive, not with the original (possibly much larger) one. Scissoring: scan convert the entire primitive but to write only the visible pixels in the clip-rectangle region of the canvas (checking each pixel s coordinates against the (x, y) bounds of the rectangle). E.g. Lines, rectangles, and polygons
Clipping after scan converting the entire collection of primitives into a temporary canvas
Wasteful, but easy to implement E.g. Text
window
3
[Criteria] uniform, user-selected density straight lines should appear straight line end-points should be constrained line drawing algorithms should be fast
4
3.
Go to starting point Increment x and y values by constants proportional to x and y such that one of them is 1. Round to the closest raster position
Drawbacks
Rounding to an integer takes time Floating-point operations (the slope is a fraction)
7
yi+1 = mxi+1 + B = m (xi + x) + B = yi + m x If x = 1 then yi+1 = yi + m A unit change in x changes the value of y by m.
8
PutPixel
If |m| > 1, a step in x creates a step in y that is greater than 1. Thus, we must reverse the roles of x and y by assigning a unit step to y and incrementing x by x = y / m = 1 /m. The checking for special cases (horizontal, vertical or diagonal lines) is omitted.
9
10
Bresenham:
If distance (NE, Q) > distance (E, Q) then select E = (xp+1, yp) else select NE = (xp+1, yp+1) P (xp, yp)
NE Q M E
Midpoint Line: We observe on which side of the line the midpoint M lies.
11
12
To apply the midpoint criterion, we need only to compute F(M) = F(xp+1, yp+) and to test its sign.
13
Q M E
14
NE Q M E
15
Advantages
need to add integers and multiply by 2 (which can be done by shift operations) incremental algorithm
16
17
13 12 11 10 9 8 7 6 4 5 6 7 8 9 10 11
18
SW
19
21
To draw a quarter circle using the explicit form: increment x from 0 to R in unit steps solving for +y at each step. Inefficient! square-root operations Large gaps for values of x close to R.
22
24
else
select E = (xp+1, yp);
25
We have to calculate new d based on the point of evaluation P=(xp, yp), but this is not expensive computationally.
26
By substituting d - 1/4 by h, we can get the integer midpoint circle scan-conversion algorithm.
27
// E
//SE
28
29
30