Unit 2
Unit 2
Unit 2
• Filling Process:
The algorithm begins filling the region by changing the color of the
seed point to the desired fill color. It then examines its neighboring
pixels (often the four neighboring pixels: up, down, left, and right) to
determine if they should also be filled.
implementing seed fill
Recursive or Stack-Based Approach: There are two common methods
for implementing seed fill:
• Recursive: In the recursive approach, if a neighboring pixel has the
same color as the seed point's original color, the algorithm recursively
calls itself on that neighboring pixel.
• Stack-Based: In the stack-based approach, the algorithm uses a stack
data structure to keep track of the pixels to be processed. It pushes
neighboring pixels onto the stack for processing, allowing it to handle
large regions without overflowing the call stack.
implementing seed fill
• Repeat: Steps 2 and 3 are repeated until all connected pixels within
the region have been filled, and there are no more pixels left to
process.
• Instead of relying on the boundary of the object, it relies on the fill color. In
other words, it replaces the interior color of the object with the fill color.
When no more pixels of the original interior color exist, the algorithm is
completed.
The central part is the viewing region or window, all the lines which lie
within this region are completely visible. A region code is always
assigned to the endpoints of the given line.
3) if OR = 0000,
else
Perform AND operation on both
these endpoints.
i) if AND ≠ 0000,
then the line is invisible and not inside
the window. Also, it can’t be considered
for clipping.
ii) else AND = 0000,
then line is partially inside the window
and considered for clipping.
Cohen Sutherland Line Clipping
Line AB is the visible case
Line OP is an invisible case
Line PQ is an invisible line
Line IJ are clipping candidates
Line MN are clipping candidate
Line CD are clipping candidate
Example of Cohen-Sutherland Line Clipping
Algorithm
• Let R be the
rectangular window
whose lower left-hand
corner is at L (-3, 1)
and upper right-hand
corner is at R (2, 6).
Find the region codes
for the endpoints in
fig:
Example of Cohen-Sutherland Line Clipping
Algorithm
A (-4, 2)→ 0001 F (1, 2)→ 0000
B (-1, 7) → 1000 G (1, -2) →0100
C (-1, 5)→ 0000 H (3, 3) → 0100
D (3, 8) → 1010 I (-4, 7) → 1001
E (-2, 3) → 0000 J (-2, 10) → 1000
Example of Cohen-Sutherland Line Clipping
Algorithm
• We place the line segments in their appropriate categories by testing
the region codes found in the problem.
• Category1 (visible): EF since the region code for both endpoints is
0000.
• Category2 (not visible): IJ since (1001) AND (1000) =1000 (which is
not 0000).
• Category 3 (candidate for clipping): AB since (0001) AND (1000) =
0000, CD since (0000) AND (1010) =0000, and GH. since (0100) AND
(0010) =0000.
• The candidates for clipping are AB, CD, and GH.
Weiler-Atherton Polygon Clipping:
• When the clipped polygons have two or more separate sections, then
it is the concave polygon handled by this algorithm.
• The vertex-processing procedures for window boundaries are
modified so that concave polygon is displayed.
• Let the clipping window be initially called clip polygon and the
polygon to be clipped the subject polygon.
• We start with an arbitrary vertex of the subject polygon and trace
around its border in the clockwise direction until an intersection with
the clip polygon is encountered
Weiler-Atherton Polygon Clipping:
1. Finding all the intersection points and grouping them Here, let
there be a polygon ABCD and another polygon VWXYZ. Let ABCD
be the clipping polygon and let VWXYZ be the clipped polygon.
Weiler-Atherton Polygon Clipping:
2. Making and
filling of two
lists Now, we
make two lists.
One for the
clipping polygon
and one for the
clipped polygon.
Now this is how
we fill it:
Weiler-Atherton Polygon Clipping:
3. Running of the
algorithm We start at
the clipped polygon’s
list, i.e. VWXYZ. Now,
we find the first
intersecting point that
is entering. Hence we
choose i1. From here
we begin the making
of the list of vertices
(or vector) to make a
clipped sub-polygon.
Weiler-Atherton Polygon Clipping:
Weiler-Atherton Polygon Clipping: