CSCE 441: Computer Graphics Scan Conversion of Polygons - PowerPoint PPT Presentation

1 / 98
About This Presentation
Title:

CSCE 441: Computer Graphics Scan Conversion of Polygons

Description:

Title: Interpolatory, Non-Stationary Subdivision for Surfaces of Revolution Author: symonds2 Last modified by: jchai Created Date: 7/3/2001 5:50:38 PM – PowerPoint PPT presentation

Number of Views:203
Avg rating:3.0/5.0
Slides: 99
Provided by: symo7
Category:

less

Transcript and Presenter's Notes

Title: CSCE 441: Computer Graphics Scan Conversion of Polygons


1
CSCE 441 Computer GraphicsScan Conversion of
Polygons
Jinxiang Chai
2
OpenGL Geometric Primitives
  • All geometric primitives are specified by vertices

3
OpenGL Geometric Primitives
  • All geometric primitives are specified by vertices

4
OpenGL Geometric Primitives
  • All geometric primitives are specified by vertices

5
Drawing General Polygons
  • How to draw every interior pixels?

?
6
Drawing Curved Objects
  • How to draw every interior pixels?

?
7
Outline
  • Methods for drawing polygons or curved objects
  • - Scanline conversion of polygons
  • - Boundary-fill
  • - Flood-fill
  • Required readings
  • - HB 4-9 to 4-14

8
Drawing Rectangles
  • Which pixels should be filled?

9
Drawing Rectangles
  • Is this correct?

10
Drawing Rectangles
  • What if two rectangles overlap?

11
Drawing Rectangles
  • Is this correct?

12
Drawing Rectangles
Overlap!!!
  • Is this correct?

13
Drawing Rectangles
  • Solution Exclude pixels on top and right

14
Drawing Rectangles
  • Artifacts are possible

15
General Polygons Basic Idea
  • How to draw every interior pixels?

16
General Polygons Basic Idea
  • How to draw every interior pixels for a scan line?

17
General Polygons Basic Idea
  • Intersect scan lines with edges
  • Find ranges along x
  • Fill interior of those
  • ranges
  • Dont fill top/right
  • Edges may NOT match
  • with line drawing algo

18
General Polygons Basic Idea
Use coherence to speed up
  • Intersect scan lines with edges
  • Find ranges along x
  • Fill interior of those
  • ranges
  • Dont fill top/right
  • Edges may NOT match
  • with line drawing algo

19
General Polygons Basic Idea
Use coherence to speed up
  • Intersect scan lines with edges
  • Find ranges along x
  • Fill interior of those
  • ranges

Edges intersecting one scan line are mostly same
as those intersecting previous scan line
20
General Polygons Basic Idea
Use coherence to speed up
  • Intersect scan lines with edges
  • Find ranges along x
  • Fill interior of those
  • ranges

The x-value of an intersection with one scan line
is close to the intersection with the previous one
21
How to store polygon edges?
22
General Polygons Data Structures
  • Sorted Edge Table

Store a linked-list per scan-line. Insert edges
into table at scan-line associated with lowest
end-point.
Scan Lines
Edges
23
General Polygons Example
C
Sorted Edge Table
B
D
G
E
F
A
24
General Polygons Example
C
Sorted Edge Table
B
D
G
E
F
A
25
General Polygons Example
C
Sorted Edge Table
B
D
G
AB
AG
E
F
A
26
General Polygons Example
C
Sorted Edge Table
B
D
G
AB
AG
E
F
Exclude horizontal edges!
A
27
General Polygons Example
C
Sorted Edge Table
B
D
G
FG
ED
AB
AG
E
F
A
28
General Polygons Example
C
Sorted Edge Table
B
D
CD
G
FG
ED
AB
AG
E
F
A
29
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
E
F
A
30
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
E
F
Which edges are intersecting with the current
scan line?
A
31
General Polygons Data Structures
  • Active Edge List

List of all edges intersecting current scan-line
sorted by their x-values
Edges
32
General Polygons Data Structures
  • Active Edge List

List of all edges intersecting current scan-line
sorted by their x-values
Edges
Implement active edge list with linked list
33
General Polygons Data Structures
  • Active Edge List

List of all edges intersecting current scan-line
sorted by their x-values
Edges
Implement active edge list with linked list
So what kind of information should be stored in
the linked list for our polygon drawing algorithm?
34
General Polygons Data Structures
  • Edge

maxY highest y-value currentX x-value of
end-point with lowest y-value xIncr 1 / slope
Edge
mazY
currentX
xIncr
35
Scan line intersection
Scan line yk1
Scan line yk
36
Scan line intersection
Scan line yk1
Scan line yk
37
General Polygons Data Structures
  • Edge

maxY highest y-value currentX x-value of
end-point with lowest y-value xIncr 1 / slope
Edge
mazY
currentX
xIncr
Horizontal edges will not be used!!!
38
General Polygons Algorithm
  • line 0
  • While (line lt height )
  • Add edges to Active Edge List from Sorted Edge
    Table starting at line
  • Remove edges that end at line
  • Fill pixels
  • Increment x-values on edges in Active Edge List
  • Increment line

39
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
A
40
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
A
maxY
currentX
xIncr
41
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List?
E
F
A
42
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
ED
FG
A
maxY
currentX
xIncr
43
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
ED
FG
A
maxY
Is it correct?
currentX
xIncr
44
General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
45
General Polygons Algorithm
  • line 0
  • While (line lt height )
  • Add edges to Active Edge List from Sorted Edge
    Table starting at line
  • Remove edges that end at line
  • Fill pixels
  • Increment x-values on edges in Active Edge List
  • Increment line

46
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
47
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
?
?
?
currentX
?
xIncr
48
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
49
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
50
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
51
General Polygons Algorithm
  • line 0
  • While (line lt height )
  • Add edges to Active Edge List from Active Edge
    Table starting at line
  • Remove edges that end at line
  • Fill pixels
  • Increment x-values on edges in Active Edge List
  • Increment scan line

52
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
53
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
54
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
55
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
56
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
57
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
CD
A
maxY
currentX
xIncr
58
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
CD
A
maxY
currentX
xIncr
59
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
CD
A
maxY
currentX
xIncr
60
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
CD
A
maxY
currentX
xIncr
61
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
AB
A
maxY
currentX
xIncr
62
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
AB
A
maxY
currentX
xIncr
63
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
A
maxY
currentX
xIncr
64
General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
A
maxY
currentX
xIncr
65
General Polygons Algorithm
  • line 0
  • While (line lt height )
  • Add edges to Active Edge List from Sorted Edge
    Table starting at line
  • Remove edges that end at line
  • Fill pixels
  • Increment x-values on edges in Active Edge List
  • Increment scan line

66
Pixel Fill-in
  • Which intervals should we draw?

67
Pixel Fill-in
  • Which intervals should we draw?
  • - Odd intervals. But need to pay attention
    to scan lines passing through vertices.

68
General Polygons Problems
  • Sliver polygons may not be drawn correctly
  • No simple solution
  • Long, thin triangles
  • cause problems
  • Want triangles with
  • good aspect ratio
  • (close to equilateral)

69
Curved Boundaries
  • How to deal with curved boundaries?

70
Boundary Fill
  • Start with drawn boundaries and an interior point
  • Recursively recolor outward from that point
  • If neighbor different, then recolor and recur
  • Everything within the boundary is changed to that
    color

71
Boundary Fill
  • Start with drawn boundaries and an interior point
  • Recursively recolor outward from that point
  • If neighbor different, then recolor and recur
  • Everything within the boundary is changed to that
    color

72
Boundary Fill
  • Work for inner and outer boundaries

73
Boundary Fill
  • Start with drawn outline of a polygon and an
    interior point
  • Recursively recolor outward from that point
  • If neighbor different, then recolor and recur
  • Everything within the boundary is changed to that
    color

74
Boundary Fill
  • How to define a neigbhbor?

8-connected
4-connected
75
Boundary Fill Example
Black pixels indicate boundary pixels
76
Boundary Fill Example
77
Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
78
Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
79
Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
80
Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
81
Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
82
Boundary Fill
83
How to deal with this?
  • Multiple color boundaries?

How to paint this region to yellow?
84
How to deal with this?
  • Multiple color boundaries?
  • Three keys
  • a start pixel
  • a target color
  • a paint color

How to paint this region to yellow?
85
Flood Fill
  • Start with a point
  • Define color under that point as the interior
    color
  • Recursively recolor outward from that point
  • If neighbor is interior color, then recolor and
    recur
  • Contiguous regions are recolored

86
Flood Fill Example
87
Flood Fill Example
88
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
89
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
90
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
91
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
92
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
93
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
94
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
95
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
96
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
97
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
98
Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
Write a Comment
User Comments (0)
About PowerShow.com