92
chapter 3
Guinan Primeves
Bresenham’s algonthm is generalized to lines with arbitrary slope by con-
sidering the symmetry between the various octants and quadrants of the xy
plane, For a line with positive slope greater than 1, we interchange the roles of
the x and y ditections. That is, we step along the y direction in unit steps and cal-
culate successive x values nearest the line path, Also, we could revise the pro-
tram to plot pixels starting from either endpoint If the initial postion fora line
with positive slope is the ight eralpoint, both x and ¥ decrease as we sep from
right to let. To ensure thatthe same pixels ae ploted regardiess ofthe starting
enépoint, we always choose the upper (or the lower) ofthe fwo candidate pivels
‘whenever the two vertical separations from the line path are equal (, = dj). For
negative slopes, the procedures are similar, except that now one coordinate de-
creases as the other increases. Finally, special cases can be handled separately
Horizontal lines (Ay ~ 0), vertical lines (Ax = 0), and diagonal lines with [Axl =
Tay each can be ioaded directly int the frame bufler veithout processing them
‘through the line-pltting algorithm
Parallei Line Algorithms
The line-generating algorithms we have discussed so far determine pixel posi-
tions sequensally. With a parallel computer, we can calculate pixel positions
eh EEe eer
“EH tH
t + 4
fi renee
Torr Pixel positions along the line path
» i Ty between endpoints 20, 10) and
oe as Tye 20,18), plotted wath Bresenha’s
line algonthonsong, fine path simultaneously by partinoning the computations among, the
Various processors available One approach to the parutioning problem #8 to
Adapt an existing sequential algorithm to take advantage of multiple processors
“Alternatively, we can look for other ways to set up the processing 50 that pose
positions can be calculated efficiently in parallel An mportant consideration in
evising a parallel algorithm is to balance the processing load among the avail-
able processors.
Given rn, Processors, we can set up a parallel Bresenham line algorithm by
subdividing she line path into n, partinons and simultaneously generating line
segments in each of the subintervals For a line with slope 0 < m <1 and left
endpoint coordinate position (yy), We partition the line along the positive x di-
rection. The distance between beginning x postions of adjacent partitions can be
calculated as
An =
where Ar is the width of the line, and the value ‘or partition width Ax, is com.
puted using intege: division. Numbering the partitions, and the processors, as 0.
1,2, up ton, ~1, we calculate the starting x coordinate for the kth partition as
meme kh, G6
As an example, suppose Ax = 15 and we have n, = 4 processors. Then the width
of the partitions is 4 and the starting x values for the partitions are t,t + 4, % +
8, and x) + 12. With this partitioning scheme, the width of the last (rightmost)
subinterval will be smaller than the others in some cases. In addition, if the line
endpoints are not integers, truncation errors can result in vanable width parti
tuons along the length of the line,
To apply Bresenham’s algorithm over the partitions, we need the initial
value for the y coordinate and the initial value for the decision parameter in each
partition. The change Ay, in the y direction over each partition is calculated from
the line slope m and partition width x,
Ay, = mx, a7)
At the kth partition, the starting y coordinate is then
i =o + moundikay,) os
The initial decision parameter for Bresen| jin’s algorithm at the start of the Ath
subinterval is obtained from Eq. 312
p> (kin )(2Ay) ~ round(kdy, (28x) + 28y ~ Ax B19
Each processor then calculates pixel positions aver its assigned subinterval using
the starting decision parameter value for that subinterval and the starting coordi
nates (x, 4»). We cen also reduce the floating-point calculations to integer arith
metic in the computations for starting values y and p, by substituting m =
Ay/ x and rearranging terms. The extension of the parallel Bresenham algorithr
toa line with slope greater than 1 is achieved by partitioning the line in the y de
Section 3.2
{ine Orang Algor
93Figure 3:10
Bounding box for a line wath
coordinate extents Ax and Ay.
94
rection and calculating beginning x values for the partitions. For negative slopes,
‘we increment coordinate values in one direction and decremen: in the other.
‘Another way to set up parallel algorithms on raster systems is to assign
each processor to a particular group of screen pixels. With a sufficient number of
processors (such as a Connection Machine CM-2 with over 65,000 processors), we
can assign each processor to one pixel within some screen region. This approach
can be adapted to line display by assigning one processor to each of the pixels
within the limits of the line coordinate extents (bounding rectangle) and calculating,
pixel distances from the line path. The number of pheels within the bounding box
ofa line is Ax-Ay (Fig. 3-10), Perpendicular distance ¢ from the line in Fig, 3-10 to
a pixel with coordinates (x, y) is obtained with the calculation
d= Ant ny +c 320)
where
ay
ae Se
iinclength
ax
B
Tinetenggh
adv ~ god
Tinelength
with
linelength = Vax? = By?
(Once the constants A, 8, and C have been evaluated for the line, each processor
needs to perform two multiplications and two additions to compute the pixel
distance d. A pixel is plotted if dis less than a specified line-thickness parameter.
Instead of partitioning the screen into single pixels, we can assign to each.
processor either a scar line or a column of pixels depending on the ne slope.
Each processor then calculates the intersection of the line with the horizontal row
oor vertical column of pixels assigned that processor. For a line with slope Im |<
1, each processor simply solves the line equation for v, given an x column, value.
For a line with slope magnitude greater than 1, the line equation is solved for x
by each processor, given a scan-line y value. Such direct methods, although slow
fon sequential machines, can be performed very efficiently using multiple proces:
33
LOADING THE FRAME BUFFER
When straight line segments and other objects are scan converted for display
with a raster system, [rame-buffer positions must be calculated. We have as
sumed that this is accomplished with the set Pixel procedure, which stores 1n
tensity values for the pixels at corresponding addresses within the frame-bulfer
array Scan-conversion algorithms generate pixel positions at successive unit in-