0% found this document useful (0 votes)
13 views52 pages

University Institute of Engineering Department of Computer Science & Engineering

The document outlines the subject of Computer Graphics, focusing on scan converting polygons and various algorithms such as the Scan Line Algorithm and Boundary Fill Algorithm. It discusses methods for filling primitives, including rectangles and polygons, and introduces concepts like 4-connected and 8-connected filling. Additionally, it covers the inside-outside test for determining point locations relative to polygons using the Odd-Even Rule and Nonzero Winding Number Rule.

Uploaded by

bossjojo915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views52 pages

University Institute of Engineering Department of Computer Science & Engineering

The document outlines the subject of Computer Graphics, focusing on scan converting polygons and various algorithms such as the Scan Line Algorithm and Boundary Fill Algorithm. It discusses methods for filling primitives, including rectangles and polygons, and introduces concepts like 4-connected and 8-connected filling. Additionally, it covers the inside-outside test for determining point locations relative to polygons using the Odd-Even Rule and Nonzero Winding Number Rule.

Uploaded by

bossjojo915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 52

Department of Computer Science and Engineering (CSE)

University Institute of Engineering


DEPARTMENT OF COMPUTER SCIENCE
& ENGINEERING
Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Computer Graphics with lab
Subject Code: 22CSH-352/22ITH-352
Prepared by:
Er. Puneet Kaur(E6913)

DISCOVER . LEARN . EMPOWER


Scan converting polygons

1
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)

Contents
• Scan Converting polygons
• Scan line algorithm
• Boundary Fill Algorithm
• 4-connected
• 8-Connected
• Flood fill

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Filling Primitives: Rectangles,


Polygons & Circles
• Two part process
– Which pixels to fill?
– What values to fill them with?

University Institute of Engineering (UIE) 4


Department of Computer Science and Engineering (CSE)

Scan Line Algorithm


• Use a horizontal scan line that traverses the scene top-down.
• Find out the Ymin and Ymax from the given polygon.
– For each scan line:
1. Find the intersections of the scan line with all edges of the polygon.
2. Sort the intersections by increasing x coordinate.
3. Fill in all pixels between pairs of intersections.
For example:
For scan line number 8 the sorted list
of x-coordinates is (2,4,9,13)
(b and c are initially no integers)
Therefore fill pixels with x coordinates
2-4 and 9-13.

University Institute of Engineering (UIE) 5


Department of Computer Science and Engineering (CSE)

Scan Line Algorithm


Edge Coherence

University Institute of Engineering (UIE) 6


Department of Computer Science and Engineering (CSE)

• When scan line intersects polygon vertex a special handling is required


to find the exact intersection points To handle such cases, we must look
at the other endpoints of the two line segments of the polygon which
meet at this vertex. If these points lie on the same (up or down) side of
the scan line, then the point in question counts as an even number of
intersections. If they lie on opposite sides of the scan line, then the
point is counted as single intersection.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 8


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 9


Department of Computer Science and Engineering (CSE)

Scan Filling Primitives:


Rectangles
• Easy algorithm
– Fill from xmin to xmax
Fill from ymin to ymax
• Issues
– What if two adjacent
rectangles share an edge?
– Color the boundary pixels twice?
– Rules:
• Color only interior pixels
• Color left and bottom edges

University Institute of Engineering (UIE) 10


Department of Computer Science and Engineering (CSE)

Boundary-Fill Algorithm

• Start with some


internal point (x,y)
• Color it
• Check neighbors for
filled or border color
• Color neighbors if OK
• Continue recursively

University Institute of Engineering (UIE) 11


Department of Computer Science and Engineering (CSE)

• There are 2 methods to implement boundary fill


algorithm.
• 4-Connected
• 8-Connected

University Institute of Engineering (UIE) 12


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 13


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 14


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 15


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 16


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 17


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 18


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 19


Department of Computer Science and Engineering (CSE)

4 Connected Boundary-Fill
Algo

Void BoundaryFill4( int x, int y, int fill, int bnd)


{
If Color(x,y) != fill and Color(x,y) != bnd
{
SetColor(x,y) = fill;
BoundaryFill4(x+1, y, fill, bnd);
BoundaryFill4(x, y +1, fill, bnd);
BoundaryFill4(x-1, y, fill, bnd);
BoundaryFill4(x, y -1, fill, bnd);
}
}

University Institute of Engineering (UIE) 20


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 21


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 22


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 23


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 24


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 25


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 26


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 27


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 28


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 29


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 30


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 31


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 32


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 33


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 34


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 35


Department of Computer Science and Engineering (CSE)

Boundary-Fill Algorithm
• Issues with recursive boundary-fill algorithm:
– May make mistakes if parts of the space already filled with
the Fill color
– Requires very big stack size

University Institute of Engineering (UIE) 1994 Foley/VanDam/Finer/Huges/Phillips ICG 36


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 37


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 38


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 39


Department of Computer Science and Engineering (CSE)

Inside-outside Test

• This method is also known as counting number method. While


filling an object, we often need to identify whether particular
point is inside the object or outside it. There are two methods by
which we can identify whether particular point is inside an
object or outside.
• Odd-Even Rule
• Nonzero winding number rule

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

Odd-Even Rule

University Institute of Engineering (UIE) 41


Department of Computer Science and Engineering (CSE)

Nonzero Winding Number


Rule
• Initialize ‘w.no=0’
• If line crosses an edge
directed bottom to top then
add 1 to w.no variable.
• If top to bottom add
-1 to w.no variable.

If w.no=0 (point outside)


Else inside (w.no is not equal
to zero)

University Institute of Engineering (UIE) 42


Department of Computer Science and Engineering (CSE)

Nonzero Winding Number Rule


• Draw a scan line from the point to be test towards the left most
of X direction.
• Give the value 1 to all the edges which are going to upward
direction and all other -1 as direction values.
• Check the edge direction values from which the scan line is
passing and sum up them.
• If the total sum of this direction value is non-zero, then this point
to be tested is an interior point, otherwise it is an exterior
point.
• In the above figure, we sum up the direction values from which
the scan line is passing then the total is 1 – 1 + 1 = 1; which is
non-zero. So the point is said to be an interior point.

University Institute of Engineering (UIE)


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 44


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 45


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 46


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 47


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 48


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 49


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 50


Department of Computer Science and Engineering (CSE)

University Institute of Engineering (UIE) 51


Department of Computer Science and Engineering (CSE)

References
• Computer Graphics C Version, Donald Hearn and M.Pauline Baker
Pearson Education.
• Computer Graphics Principles and Practice C.foley, VanDam, Feiner and
Hughes, Pearson Education

University Institute of Engineering (UIE)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy