Computer Graphics Chapter 4
Computer Graphics Chapter 4
In the earlier chapter, we have described the process of scan converting line segments
or standard geometric curves. However, these curves can constitute only the outline
or boundary of an object. Generally, each object in a scene have a certain colour or
intensity of its surfaces. So, to produce visual realism, we must fill up any closed area
in a scene with appropriate colour or intensity. The process of scan converting closed
object surfaces is called solid area scan conversion or simply flling.
63
(64
Scan Conversion of Solide
(a) (b)
Although the algorithm, as it is presented here, looks very simple, it may produce
incorreet results in certain situations. Let us consider a situation when the straight
line passes through a polygon vertex. Two different situations may arise:
1. The polygon boundaries that meet at the vertex Come from the same side of the
straigit line. In this case, the vertex may be considered to be a local minima or
maxima point.
2. The polygon boundaries that meet at the vertex come from two different sides
of the straight line.
In the former situation, we need to consider the occurrence of two intersections at
the vertex (even-count). In the latter, we have to consider the presence of a single
intersection at the vertex (odd-count). To determine whether a vertex is a local minima
or maxima, we can examine the other end points of the two boundary lines meeting
at the vertex. If the y-values of these two end points are both greater than that of the
vertex, it is considered a local minima. On the other hand, if the y-values of these two
end points are both lesser than that of the vertex, it is considered a local marima. In
Figure 4.3, vertices VË and V2, for example, are odd-count and even-count vertices
respectively.
Even count
V.
V.
Odd count
+1
V v
+1
V,
Figure 4.4: Counting winding number.
The process of setting pixel colour along a particular direction stops as soon as a
boundary pxel in that direction is encountered.
The boundary ill algorithm accepts, as inputs, the seed pixel coordinate (z, y), the
boundary colour and the fll colour. Starting at (z, v), the procedure tests neighbour
positions to determine whether they are parts of the boundary or not. If not, they
are painted with the fill colour or pattern and their neighbours are tested, in turd,
in a similar manner. There are two different approaches to determine the neighbour
pixels: () 4+neighbour and (iü) &-neighbour approach as shown in Figure 4.5. The
pseudo-code for the boundary fill algorithm, in case of a 4-neighbour situation is given
below.
begin
current-pizel = (, y)
current-pizel.colour = colour of current-pizel
if (current pizel colour boundary.colour) then
begin
set-pixel (,y)
boundaryfill(z + 1, y, boundary.colour)
boundaryfillz - 1,y, boundary.colour')
boundaryfill(,y + 1, boundary.colour)
boundaryfill(z,y - 1, boundary_colour)
end
end
implementation of the
The above is a recursive algorithm. However, an iterative
pixels information are
sarne is possible using an explicit stack where the neighbour
procedure can be used for the
pushed in and popped out thereof later. A similar
in
&-neighbour situation. Seed pixels with 4-neighbour and &-neighbour are shown the
Figure 4.5. While using &-neighbour seed pixels, we may face a problemn of flling is
outside region also. This situation is shown in Figure 4.6. Here, the seed pixel of
located at a point nearest to the oblique boundary. One of the eight neighbours
the concerned seed clearly lies outside the boundary and will be responsible for filling
the external region also. A similar problem will arise in the case of 4-neighbour pixels.
The situation is described in Figure 4.7. Here, the area to be filled has two parts, and
the link between the two regions is via a diagonal pixel. If we use 4-neighbour seed
pixels, it is seen that the one of the regions becomes unreachable and cannot be filled.
Besides these special cases, both the algorithms suffer from unknown stack size and
redundant checking of already flled neighbour pixels.
Scan Conversion of Solid
Seed pixel
(b)
Neighbour pixel
(a)
Boundary
Fill colour
Seed pixel
Boundary
Fill colour
Seed pixel
begin
current-pirel = (, y)
Purrent pirel.colour= colour of current-pirel
if (eurrent pirel.colour boundary.colour) and (current-pizel.colour fill.colour)
then
begin
set-pixel (z,y)
floodfll(z + 1,y, boundary.colour, fill.colour)
floodfllz -1,y, boundary.colour, fill.colour)
floodfill(z, y+ 1, boundary.colour, fill.colour)
floodfill(z,y - 1, boundary.colour, fill.colour)
end
end
In the case of any of the above seed fll algorithms, if instead of a colour or grey
shade, we fillthe interior of a polygon with acertain predefined pattern, the algorithm
is termed a pattern fill algorithm.
1
IË+| = I;+
m
Thus, the r-values at the intersection with the next scan ine can be
deternine3
from the previous one.
Scan line algorithm
begin
for each scan line y do
begin
determine intersections with the polygon boundaries
store r-intercept values in a list for scan line y
end
Sort the T-intercept values for the y-list in ascending order
for each y-list do
begin
for all pairs (I1,I2) of T-intercepts in the list do
begin
extract the pair (I1,T2) of z-intercepts
fill the pixels on scan line y in the range (T1,T2
end
end
end
begin
select a seed pixel (Is y,) and push it onto a stack
43 Solid
Aroa Filling Algorithms 71
The above algorithm has some advantages over the other scan line algorithms.
Some of these are as follows:
1. Avery small stack size, compared the huge one needed in case of the scan line
algorithm, is required here.
2. This algorithm can effectively skip any holes present within the polygon to be
filled.
EXAMPLE 4.1: Aring-shaped polygonal area is shown in Figure 4.8(a). Trace the
scan conversion process to ill the polygonal area using the scan line seed fill algorithm.
Solution. The seed pixel is chosen at the location narked with S. A tracing of scan
line seed ill procedure is depicted in Figure 4.8. The numbers 1, 2, 3, ., ete. indicates
successive seed locations pushed on the stack in that order.
(a (b (c)
d f)
g
i
(1
2 2
(m) n (o)
(q (r
(p)
FILLED
SUCCESSFULLY
Boundary
1Fill colour
S hitial seed
(t)
(Example 4.!)
Figure 4.8: Steps of scan line seedfill algorithm
y-bucket corresponding to a certaiu
Corner of a rectangular cell.) Each list is called a
arravs or linked lists. For arravs.
y-value. Each list or bucket may be uaintained as
linkel lists, the processing
the maximum size requirennent is iot k1uown initially. For
time requirements are higher.
active edge list may help. Bv
For real-time scan conversion, the concepts of an
scan line intersections can
this, the amount of data storage is further reduced and the
be calculated incrementally.
EXAMPLE 4.2: Consider a polygon with vertices at A(4,5), B(5, 3), Cís 5
DI8. 1), E(1.1), and F(1, 2). Trace the scan conversion
process to fill this polyeon
using the ordered edge list algorithm.
Solution. Here, the highest half-interval scan lines corresponds to the y-values of
y= 4+ and y =1++. Hence, we shall start with a 4-bucket and a 1-bucket as
shown in the Figure 4.9. The 4-bucket contains information regarding
AF, AB. BC and CD, while the 4-bucket contains information regardingpolygon
edges
polygon edge
FE only. Initially the lists corresponding to the 4-bucket and 1-bucket were empty.
Now, since the highest scan line intersects polygon edges AF, AB, BC and CD, we
insert entries corresponding to these edges. The polygon edge FE passes through the
highest half-interval scan line at y = 1+5. Hence, we insert the corresponding entries
to this bucket.
Since the highest half-interval scan line is at y=4+, we start with the
4-bucket.
This is the initial active edge list. Information contents of the initial active edge iS?
are as follows:
Ay Ptr Ay Ptr
A
Ay Ptr Ay Ptr
Ay Ptr
Figure 4.9: y-buckets for ordered edge list ill algorithm (Example 4.2).
Non. r-intercepts of the active edges are sorted. Hence. we get a sorted list of
bves 3.5.4.25,7.5 and 8.0. These c-intercept values are picked up pairwise as
(z).72) from the left and for all intermediate z srt} 2% pixels on the
half-interval scan line at y = 4+; are filled.
Now, r-intercepts are incremented by Ar and Ay is decremented by one. Thus.
we get anew active edge list for scan line at y= 3+4. This list is described as follows:
TAB = 4.75 ArAB = 0.5 AyaB =1
TAF = 2.5 ArAF = -1.0 AyJAF =2
LCB = 6.5 ArCB =-1.0 AyCB =1
LCD = 8.0 Arcp = 0.0 Aycp =3
Now, the c-intercepts are sorted again, paired and scan converted as before. Fol
lowing an increment-decrement step for Ar and Ay respectively (as before), we get
an edge list for scan line at y = 2+5. Note that the bucket entries corresponding to
edges AB and CB no longer exist, because their Ay values reach 0.
IAF = 1.5 AcAr =-1.0 AyAF = 1
zCD = 8.0 Arcp = 0.0 Aycp = 2
Following a similar approach, we get the bucket corresponding to scan line at
y=1+}.
TCD = 8.0 Arcp = 0.0 AyCD = 1
Now, there is already an entry for the y-bucket at y = 1+}. Therefore, the
complete bucket information is as follows:
TFE = 1.0 AtAF =0.0 AyAF = 1
TCD = 8.0 Arcp = 0.0 Aycp =1
Sean
Here, we fill all the pixels having r-coordinates
between 1
Conversion of Solid
8
And the process is complete by now. The initial
y-buckets for this problernfor y - l+}
tracing of the concerned are shoW
in Figure 4.9 and Figure 4.10 shows a pictorial
problem
M (b)
B
A C
B
B
(d
(c)
(e) (f
Figure 4.10: Steps of ordered edge list fill algorithm (Example 4.2).
44 Questions 77
4.4 QUESTIONS
for doing
.What is solid aren scan conversion? Name some conmon algorithms
this.
8-connected pixels
,o What are advantages and disadvantages of 4-connected and
in the case of the floodfill algorithm?
. ls the floodfill algorithm suitable for large polygons? If not, then can you suggest
aremedy?
the odd
AWrite a procedure to determine aseed pixel for flling a polygon using
even method.
winding
As Write a procedure to determine a seed pixel for filling a polygon using the
number method.
2 x 2.
A6 Write an algorithm tor pattern illing where patterns are of size
8-connected area.
A7 Write a floodfill algorithmn to fill an
5), D(8, 1),
A8 A polygon ABCDEF has vertices at A(4, 5), B(5, 3), C(8,pixel, trace the
E(1, 1) and F(1, 2). Considering a suitable wall inside seed
floodfill algorithm and show the first ive snapshots of the stack used.
C(8, 5), D(8, 1),
4.9 A polygon ABCDEF has vertices at A(4, 5), B(5, 3),
E(1, 1) and F(1, 2). Apply the ordered edge list algorithm using active edge
line at
list to show the changes in the y-bucket values for each half-interval scan
fractional
yt. Assume intersections of scan lines and polygon edges at suitable
or integral values for r and y.
4), C(9, 7),
4.10 The coordinates of a polygon ABCDEFGH are A(2, 4), B(9,edges that will
D(8, 7), E(8, 9), F(4, 9), G(4, 7) and H(2, 7). Find out the
for1m active list on scan lines y = 6, 7, 8, 9 and 10.