SlideShare a Scribd company logo
1 of 38
•
•
•
•
•

Different types of Polygons
Simple Convex
Simple Concave
Non-simple : self-intersecting
With holes

Convex

Concave

Self-intersecting
Polygon Scan Conversion
• Scan Conversion = Fill
• How to tell inside from outside
– Convex easy
– Nonsimple difficult
– Odd even test
• Count edge crossings
odd-even fill
Winding Number
• Count clockwise crossings as positive and
counterclockwise crossings as negative
winding number = 1

winding number = 2
• Alternate definition of inside: inside if winding number ≠ 0
Filling in the Frame Buffer
• Fill at end of pipeline
– Convex Polygons only
– Nonconvex polygons assumed to have been
tessellated
– Shades (colors) have been computed for vertices
(Gouraud shading)

– March across scan lines interpolating shades
• Incremental work small
Using Interpolation
C1 C2 C3 specified by glColor or by vertex shading
C4 determined by interpolating between C1 and C2
C5 determined by interpolating between C2 and C3
interpolate between C4 and C5 along span
C1
C4

scan line

C2
C5
span

C3
Scan Line Polygon Fill
•

Determine overlap Intervals for scan lines that cross that area.
– Requires determining intersection positions of the edges of the
polygon with the scan lines
– Fill colors are applied to each section of the scanline that lies
within the interior of the region.
– Interior regions determined as in odd-even test

10 13 16 19
Interior pixels along a scan line passing through a
polygon area
10

13 16

19

• In the given example, four pixel intersections are at
x=10, x=13, x=16 and x=19
• These intersection points are then sorted from left to
right , and the corresponding frame buffer positions
between each intersection pair are set to specified color
– 10 to 13, and 16 to 19
Scan Line Polygon Fill
• Some scan line intersections at polygon
vertices require special handling:
– A scan line passing through a vertex
intersects two polygon edges at that position
Scan Line y’
1

2

1

Scan Line y

1

2

1

1

Intersection points along the scan lines that intersect polygon
vertices.
Scan line y’ generates an even number of intersections that
can be paired to identify correctly the interior pixel spans.
To identify the interior pixels for scan line y, we must count
the vertex intersection as only one point.
Scan Line Polygon Fill
• The topological difference between scan Line y and scan
Line y’
• For scan line y, the two edges sharing an intersection
vertex are on opposite sides of the scan line.
– Count this vertex as one intersection point

• For scan line y’, the two intersecting edges are both
above the scan line
Scan Line Polygon Fill
• We can distinguish these cases by tracing around the
polygon boundary either in clockwise or
counterclockwise order and observing the relative
changes in vertex y coordinates as we move from one
edge to the next.
• Let (y1, y2) and (y2, y3) be the endpoint y values of two
consecutive edges. If y1, y2, y3 monotonically increase
or decrease, we need to count the middle vertex as a
single intersection point for any scan line passing
through that vertex.
Scan Line Polygon Fill
•

One method for implementing the adjustment
to the vertex intersection count is to shorten
some polygon edges to split those vertices that
should be counted as one intersection
– When the end point y coordinates of the two edges
are increasing , the y value of the upper endpoint for
the current edge is decreased by 1
– When the endpoint y values are monotonically
decreasing, we decrease the y coordinate of the
upper endpoint of the edge following the current
edge
Scan Line Polygon Fill Algorithm

(a)

(b)

Adjusting endpoint values for a polygon, as we process edges in order
around the polygon perimeter. The edge currently being processed is
indicated as a solid like. In (a), the y coordinate of the upper endpoint of
the current edge id decreased by 1. In (b), the y coordinate of the upper
end point of the next edge is decreased by 1
The scan conversion algorithm works as follows
i. Intersect each scanline with all edges
ii. Sort intersections in x
iii. Calculate parity of intersections to determine in/out
iv. Fill the “in” pixels
Special cases to be handled:
i. Horizontal edges should be excluded
ii. Vertices lying on scanlines handled by shortening of edges,
• Coherence between scanlines tells us that
Edges that intersect scanline y are likely to intersect y + 1
X changes predictably from scanline y to y + 1 (Incremental Calculation
Possible)
(Xk + 1, Yk + 1)

(Xk , Yk )

Scan Line yk + 1

Scan Line yk
•

The slope of the edge is constant from one scan line to the next:
– let m denote the slope of the edge.

yk +1 − yk = 1
1
xk +1 = xk +
m
•

Each successive x is computed by adding the inverse of the slope and
rounding to the nearest integer
Integer operations
•

Recall that slope is the ratio of two integers:

∆y
m=
∆x
•

So, incremental calculation of x can be expressed as

∆y
xk +1 = xk +
∆x
Integer operations
• How to compute x intercepts incrementally using
integer operations:
– Initialize a counter to 0
– Increment counter by ∆x each time we move up to a
new scan line.
– If counter becomes greater or equal to ∆y, increment
the current x intersection value by 1 and decrease the
counter by ∆y
• Example: m=7/3
• Initial scanline counter = 0
• Next scanlines
– Counter =3
– Counter =6
– Counter =9
• increment x intercept by
• Reset counter to 9-7 = 2
Line with slope 7/3

yk
xk
decrement

decrement

0
4
1
5

2
6
3
0 y0
counter

decrement

x0
• Above scheme truncates integers.
• How do we round to nearest integer?
– We need to compare the counter to ∆y/2.
– Can be done by integer arithmetic by incrementing counter by
2∆x at each step and comparing with ∆y
– When the counetr is greater than or equal to ∆y, increase x
value by 1 and decrement the counter by 2∆y
• Example: m=7/3
• Initial scanline counter = 0
• Next scanlines
– Counter =6
– Counter =12
• increment x intercept by
• Reset counter to 12-(2*7) = -2
decrement
decrement

0
-6
2
-4

4
decrement -2
6
0 y0
counter
x0
Sorted Edge Table (SET)
In SET, there is an entry for each scanline.
Traverse edges of the polygon to construct a Sorted Edge Table (SET)

1. Eliminate horizontal edges
2. Add edge to linked-list for the scan line corresponding to the y_lower
vertex. Shorten edges if necessary to resolve the vertex-intersection
problem.

3. For each edge entry, store the following:

-

y_upper: the largest y value on that edge (last scanline to
consider)

-

x_lower: the x intercept at that scanline (initial x value)

-

1/m: for incrementing x

4. For each scan line the edges are sorted from left to right (based on x)
B
yC

yA

C
E

C’

yB xC 1 / mBC

yE x A 1 / mAE

D
A

1
0

y B x A 1 / mAB
Active Edge List (AEL)
• Construct Active Edge List during scan conversion. AEL
is a linked list of active edges on the current scanline, y.
The active edges are kept sorted by x
– The active edge list contains all the edges crossed by that scan
line.
– As we move up, update the active edge list using the sorted
edge table if necessary.
Algorithm
1.
2.
3.

Set y to the smallest y coordinate that has an entry in the SET; i.e, y for the
first nonempty bucket.
Initialize the AEL to be empty.
For each scanline y repeat:
3.1 Copy from SET bucket y to the AEL those edges whose y_min = y
(entering edges).
3.2 The sort the AEL on x is easier because SET is presorted.
3.3 Fill in desired pixel values on scanline y by using pairs of x
coordinates from AEL.
3.5 Remove from the AEL those entries for which y = y_max (edges not
involved in the next scanline.)
3.4 Increment y by 1 (to the coordinate of the next scanline).
3.5 For each nonvertical edge remaining in the AEL, update x for the new
y.
Flood Fill Algorithm
• These algorithms assume that at least one pixel interior
to a polygon or region is known
-assume that the boundary is defined by Bresenham’s
Flood Fill
• Fill can be done recursively if we know a seed
point (x,y) located inside (WHITE)
• Scan convert edges into buffer in edge/inside
color (BLACK)
flood_fill(int x, int y) {
if(read_pixel(x,y)= = WHITE) {
write_pixel(x,y,BLACK);
flood_fill(x-1, y);
flood_fill(x+1, y);
flood_fill(x, y+1);
flood_fill(x, y-1);
}
}
Depth or Z-Buffer
• For each pixel, we store COLOR (color buffer)
and DEPTH (depth buffer).
• Algorithm:
Initialize all elements of buffer COLOR(row, col) to
background color, and DEPTH(row, col) to
maximum-depth;
FOR EACH polygon:
Rasterize polygon to frame;
FOR EACH pixel center (x, y) that is covered:
IF polygon depth at (x, y) < DEPTH(x, y)
THEN COLOR(x, y) = polygon color at (x, y)
AND DEPTH(x, y) = polygon depth at (x, y)
Depth Buffer Operation
Frame

Depth
∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

∞

Initialize (“New Frame”)
Depth Buffer Operation – First
Polygon
Frame

Depth
∞

∞

∞

∞

∞

∞

24

∞

∞

∞

∞

26

27

∞

∞

∞

28

29

30

∞

Pink Triangle -- depths computed at pixel centers
Depth Buffer Operation -- First
Polygon
Frame

Depth
∞

∞

∞

∞

∞

∞

24

∞

∞

∞

∞

26

27

∞

∞

∞

28

29

30

∞

Pink Triangle -- pixel values assigned
Depth Buffer Operation – Second
Polygon
Frame

Depth
∞

∞

10

9

∞

∞

24

9

8

∞

∞

26

8

7

∞

∞

28

7

6

∞

Green Rectangle -- depths computed at pixel centers
Depth Buffer Operation – Second
Polygon
Frame

Depth
∞

∞

10

9

∞

∞

24

9

8

∞

∞

26

8

7

∞

∞

28

7

6

∞

Green Rectangle -- pixel values assigned: NOTE REPLACEMENTS!
Depth Buffer Operation – Third
Polygon
Frame

68 not stored

Depth
∞

∞

10

9

72

∞

24

9

8

75

∞

26

8

7

∞

∞

28

7

6

∞

Blue Pentagon -- depths computed at pixel centers

71 not
stored
Depth Buffer Operation – Third
Polygon
Frame

Depth
∞

∞

10

9

72

∞

24

9

8

75

∞

26

8

7

∞

∞

28

7

6

∞

Blue Pentagon -- pixel values assigned: NOTE ‘GOES BEHIND’!
screen
scan-line

More Related Content

What's hot

Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewingRabin BK
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.Mohd Arif
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithmMani Kanth
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphicsSafayet Hossain
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsJoseph Charles
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
 
Hidden surfaces
Hidden surfacesHidden surfaces
Hidden surfacesMohd Arif
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Video display devices
Video display devicesVideo display devices
Video display devicesMohd Arif
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmMani Kanth
 

What's hot (20)

Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Clipping
ClippingClipping
Clipping
 
Line clipping
Line clippingLine clipping
Line clipping
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphics
 
Clipping
ClippingClipping
Clipping
 
Anti aliasing Computer Graphics
Anti aliasing Computer GraphicsAnti aliasing Computer Graphics
Anti aliasing Computer Graphics
 
Hidden surfaces
Hidden surfacesHidden surfaces
Hidden surfaces
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
Curves and surfaces
Curves and surfacesCurves and surfaces
Curves and surfaces
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 

Viewers also liked

Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithmsavelraj
 
Area filling algo
Area filling algoArea filling algo
Area filling algoPrince Soni
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of adaSahil Kumar
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics Barani Tharan
 
Lecture applications of cg
Lecture   applications of cgLecture   applications of cg
Lecture applications of cgavelraj
 
CAD - Unit-1 (Fundamentals of Computer Graphics)
CAD - Unit-1 (Fundamentals of Computer Graphics)CAD - Unit-1 (Fundamentals of Computer Graphics)
CAD - Unit-1 (Fundamentals of Computer Graphics)Priscilla CPG
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmMaruf Abdullah (Rion)
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics ProgramesAbhishek Sharma
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmShilpa Hait
 
Lecture+ +raster+&+random+scan+systems
Lecture+ +raster+&+random+scan+systemsLecture+ +raster+&+random+scan+systems
Lecture+ +raster+&+random+scan+systemsavelraj
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 

Viewers also liked (19)

Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Euler and hamilton paths
Euler and hamilton pathsEuler and hamilton paths
Euler and hamilton paths
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics
 
Lecture applications of cg
Lecture   applications of cgLecture   applications of cg
Lecture applications of cg
 
CAD - Unit-1 (Fundamentals of Computer Graphics)
CAD - Unit-1 (Fundamentals of Computer Graphics)CAD - Unit-1 (Fundamentals of Computer Graphics)
CAD - Unit-1 (Fundamentals of Computer Graphics)
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Clipping
ClippingClipping
Clipping
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
 
Lecture+ +raster+&+random+scan+systems
Lecture+ +raster+&+random+scan+systemsLecture+ +raster+&+random+scan+systems
Lecture+ +raster+&+random+scan+systems
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 

Similar to Types of Polygons & Polygon Scan Conversion

Unit-5 BSR-1-02-2024 advanced algorithms .pptx
Unit-5 BSR-1-02-2024 advanced algorithms .pptxUnit-5 BSR-1-02-2024 advanced algorithms .pptx
Unit-5 BSR-1-02-2024 advanced algorithms .pptxIronMan665214
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphicsShaishavShah8
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & RasterizationAhmed Daoud
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...Kasun Ranga Wijeweera
 
CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxlara333479
 
rural marketing ppt
rural marketing pptrural marketing ppt
rural marketing pptelaya1984
 
Visual surface detection i
Visual surface detection   iVisual surface detection   i
Visual surface detection ielaya1984
 

Similar to Types of Polygons & Polygon Scan Conversion (20)

UNIT2.pptx
UNIT2.pptxUNIT2.pptx
UNIT2.pptx
 
Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
Unit-5 BSR-1-02-2024 advanced algorithms .pptx
Unit-5 BSR-1-02-2024 advanced algorithms .pptxUnit-5 BSR-1-02-2024 advanced algorithms .pptx
Unit-5 BSR-1-02-2024 advanced algorithms .pptx
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
 
Lecture24
Lecture24Lecture24
Lecture24
 
14485616.ppt
14485616.ppt14485616.ppt
14485616.ppt
 
curve one
curve onecurve one
curve one
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & Rasterization
 
1516 contouring
1516 contouring1516 contouring
1516 contouring
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
cg mod2.pdf
cg mod2.pdfcg mod2.pdf
cg mod2.pdf
 
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...
Convex Partitioning of a Polygon into Smaller Number of Pieces with Lowest Me...
 
Unit 4 notes
Unit 4 notesUnit 4 notes
Unit 4 notes
 
CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptx
 
Lec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdfLec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdf
 
rural marketing ppt
rural marketing pptrural marketing ppt
rural marketing ppt
 
Visual surface detection i
Visual surface detection   iVisual surface detection   i
Visual surface detection i
 

More from wahab13

Texture mapping
Texture mapping Texture mapping
Texture mapping wahab13
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2wahab13
 
Hw1 SE sol
Hw1 SE solHw1 SE sol
Hw1 SE solwahab13
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlockwahab13
 
Paging examples
Paging examplesPaging examples
Paging exampleswahab13
 

More from wahab13 (6)

Texture mapping
Texture mapping Texture mapping
Texture mapping
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2
 
Hw1 SE sol
Hw1 SE solHw1 SE sol
Hw1 SE sol
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Paging examples
Paging examplesPaging examples
Paging examples
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

Types of Polygons & Polygon Scan Conversion

  • 1. • • • • • Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes Convex Concave Self-intersecting
  • 2. Polygon Scan Conversion • Scan Conversion = Fill • How to tell inside from outside – Convex easy – Nonsimple difficult – Odd even test • Count edge crossings odd-even fill
  • 3. Winding Number • Count clockwise crossings as positive and counterclockwise crossings as negative winding number = 1 winding number = 2 • Alternate definition of inside: inside if winding number ≠ 0
  • 4. Filling in the Frame Buffer • Fill at end of pipeline – Convex Polygons only – Nonconvex polygons assumed to have been tessellated – Shades (colors) have been computed for vertices (Gouraud shading) – March across scan lines interpolating shades • Incremental work small
  • 5. Using Interpolation C1 C2 C3 specified by glColor or by vertex shading C4 determined by interpolating between C1 and C2 C5 determined by interpolating between C2 and C3 interpolate between C4 and C5 along span C1 C4 scan line C2 C5 span C3
  • 6. Scan Line Polygon Fill • Determine overlap Intervals for scan lines that cross that area. – Requires determining intersection positions of the edges of the polygon with the scan lines – Fill colors are applied to each section of the scanline that lies within the interior of the region. – Interior regions determined as in odd-even test 10 13 16 19 Interior pixels along a scan line passing through a polygon area
  • 7. 10 13 16 19 • In the given example, four pixel intersections are at x=10, x=13, x=16 and x=19 • These intersection points are then sorted from left to right , and the corresponding frame buffer positions between each intersection pair are set to specified color – 10 to 13, and 16 to 19
  • 8. Scan Line Polygon Fill • Some scan line intersections at polygon vertices require special handling: – A scan line passing through a vertex intersects two polygon edges at that position
  • 9. Scan Line y’ 1 2 1 Scan Line y 1 2 1 1 Intersection points along the scan lines that intersect polygon vertices. Scan line y’ generates an even number of intersections that can be paired to identify correctly the interior pixel spans. To identify the interior pixels for scan line y, we must count the vertex intersection as only one point.
  • 10. Scan Line Polygon Fill • The topological difference between scan Line y and scan Line y’ • For scan line y, the two edges sharing an intersection vertex are on opposite sides of the scan line. – Count this vertex as one intersection point • For scan line y’, the two intersecting edges are both above the scan line
  • 11. Scan Line Polygon Fill • We can distinguish these cases by tracing around the polygon boundary either in clockwise or counterclockwise order and observing the relative changes in vertex y coordinates as we move from one edge to the next. • Let (y1, y2) and (y2, y3) be the endpoint y values of two consecutive edges. If y1, y2, y3 monotonically increase or decrease, we need to count the middle vertex as a single intersection point for any scan line passing through that vertex.
  • 12. Scan Line Polygon Fill • One method for implementing the adjustment to the vertex intersection count is to shorten some polygon edges to split those vertices that should be counted as one intersection – When the end point y coordinates of the two edges are increasing , the y value of the upper endpoint for the current edge is decreased by 1 – When the endpoint y values are monotonically decreasing, we decrease the y coordinate of the upper endpoint of the edge following the current edge
  • 13. Scan Line Polygon Fill Algorithm (a) (b) Adjusting endpoint values for a polygon, as we process edges in order around the polygon perimeter. The edge currently being processed is indicated as a solid like. In (a), the y coordinate of the upper endpoint of the current edge id decreased by 1. In (b), the y coordinate of the upper end point of the next edge is decreased by 1
  • 14. The scan conversion algorithm works as follows i. Intersect each scanline with all edges ii. Sort intersections in x iii. Calculate parity of intersections to determine in/out iv. Fill the “in” pixels Special cases to be handled: i. Horizontal edges should be excluded ii. Vertices lying on scanlines handled by shortening of edges, • Coherence between scanlines tells us that Edges that intersect scanline y are likely to intersect y + 1 X changes predictably from scanline y to y + 1 (Incremental Calculation Possible) (Xk + 1, Yk + 1) (Xk , Yk ) Scan Line yk + 1 Scan Line yk
  • 15. • The slope of the edge is constant from one scan line to the next: – let m denote the slope of the edge. yk +1 − yk = 1 1 xk +1 = xk + m • Each successive x is computed by adding the inverse of the slope and rounding to the nearest integer
  • 16. Integer operations • Recall that slope is the ratio of two integers: ∆y m= ∆x • So, incremental calculation of x can be expressed as ∆y xk +1 = xk + ∆x
  • 17. Integer operations • How to compute x intercepts incrementally using integer operations: – Initialize a counter to 0 – Increment counter by ∆x each time we move up to a new scan line. – If counter becomes greater or equal to ∆y, increment the current x intersection value by 1 and decrease the counter by ∆y
  • 18. • Example: m=7/3 • Initial scanline counter = 0 • Next scanlines – Counter =3 – Counter =6 – Counter =9 • increment x intercept by • Reset counter to 9-7 = 2
  • 19. Line with slope 7/3 yk xk
  • 21. • Above scheme truncates integers. • How do we round to nearest integer? – We need to compare the counter to ∆y/2. – Can be done by integer arithmetic by incrementing counter by 2∆x at each step and comparing with ∆y – When the counetr is greater than or equal to ∆y, increase x value by 1 and decrement the counter by 2∆y
  • 22. • Example: m=7/3 • Initial scanline counter = 0 • Next scanlines – Counter =6 – Counter =12 • increment x intercept by • Reset counter to 12-(2*7) = -2
  • 24. Sorted Edge Table (SET) In SET, there is an entry for each scanline. Traverse edges of the polygon to construct a Sorted Edge Table (SET) 1. Eliminate horizontal edges 2. Add edge to linked-list for the scan line corresponding to the y_lower vertex. Shorten edges if necessary to resolve the vertex-intersection problem. 3. For each edge entry, store the following: - y_upper: the largest y value on that edge (last scanline to consider) - x_lower: the x intercept at that scanline (initial x value) - 1/m: for incrementing x 4. For each scan line the edges are sorted from left to right (based on x)
  • 25. B yC yA C E C’ yB xC 1 / mBC yE x A 1 / mAE D A 1 0 y B x A 1 / mAB
  • 26. Active Edge List (AEL) • Construct Active Edge List during scan conversion. AEL is a linked list of active edges on the current scanline, y. The active edges are kept sorted by x – The active edge list contains all the edges crossed by that scan line. – As we move up, update the active edge list using the sorted edge table if necessary.
  • 27. Algorithm 1. 2. 3. Set y to the smallest y coordinate that has an entry in the SET; i.e, y for the first nonempty bucket. Initialize the AEL to be empty. For each scanline y repeat: 3.1 Copy from SET bucket y to the AEL those edges whose y_min = y (entering edges). 3.2 The sort the AEL on x is easier because SET is presorted. 3.3 Fill in desired pixel values on scanline y by using pairs of x coordinates from AEL. 3.5 Remove from the AEL those entries for which y = y_max (edges not involved in the next scanline.) 3.4 Increment y by 1 (to the coordinate of the next scanline). 3.5 For each nonvertical edge remaining in the AEL, update x for the new y.
  • 28. Flood Fill Algorithm • These algorithms assume that at least one pixel interior to a polygon or region is known -assume that the boundary is defined by Bresenham’s
  • 29. Flood Fill • Fill can be done recursively if we know a seed point (x,y) located inside (WHITE) • Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }
  • 30. Depth or Z-Buffer • For each pixel, we store COLOR (color buffer) and DEPTH (depth buffer). • Algorithm: Initialize all elements of buffer COLOR(row, col) to background color, and DEPTH(row, col) to maximum-depth; FOR EACH polygon: Rasterize polygon to frame; FOR EACH pixel center (x, y) that is covered: IF polygon depth at (x, y) < DEPTH(x, y) THEN COLOR(x, y) = polygon color at (x, y) AND DEPTH(x, y) = polygon depth at (x, y)
  • 32. Depth Buffer Operation – First Polygon Frame Depth ∞ ∞ ∞ ∞ ∞ ∞ 24 ∞ ∞ ∞ ∞ 26 27 ∞ ∞ ∞ 28 29 30 ∞ Pink Triangle -- depths computed at pixel centers
  • 33. Depth Buffer Operation -- First Polygon Frame Depth ∞ ∞ ∞ ∞ ∞ ∞ 24 ∞ ∞ ∞ ∞ 26 27 ∞ ∞ ∞ 28 29 30 ∞ Pink Triangle -- pixel values assigned
  • 34. Depth Buffer Operation – Second Polygon Frame Depth ∞ ∞ 10 9 ∞ ∞ 24 9 8 ∞ ∞ 26 8 7 ∞ ∞ 28 7 6 ∞ Green Rectangle -- depths computed at pixel centers
  • 35. Depth Buffer Operation – Second Polygon Frame Depth ∞ ∞ 10 9 ∞ ∞ 24 9 8 ∞ ∞ 26 8 7 ∞ ∞ 28 7 6 ∞ Green Rectangle -- pixel values assigned: NOTE REPLACEMENTS!
  • 36. Depth Buffer Operation – Third Polygon Frame 68 not stored Depth ∞ ∞ 10 9 72 ∞ 24 9 8 75 ∞ 26 8 7 ∞ ∞ 28 7 6 ∞ Blue Pentagon -- depths computed at pixel centers 71 not stored
  • 37. Depth Buffer Operation – Third Polygon Frame Depth ∞ ∞ 10 9 72 ∞ 24 9 8 75 ∞ 26 8 7 ∞ ∞ 28 7 6 ∞ Blue Pentagon -- pixel values assigned: NOTE ‘GOES BEHIND’!