Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

Similar presentations


Presentation on theme: "1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai."— Presentation transcript:

1 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai

2 2/108 OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_QUADS

3 3/108 OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_QUADS

4 4/108 OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_QUADS

5 5/108 Drawing General Polygons How to draw every interior pixel? ?

6 6/108 Drawing General Polygons How to draw every interior pixel?

7 7/108 Drawing Curved Objects How to draw every interior pixels?

8 8/108 Outline Methods for drawing polygons or curved objects - Scanline conversion of polygons - Boundary-fill - Flood-fill Required readings: - HB 6-10 to 6-14

9 9/108 Drawing Rectangles Which pixels should be filled?

10 10/108 Drawing Rectangles Is this correct?

11 11/108 Drawing Rectangles What if two rectangles overlap?

12 12/108 Drawing Rectangles Is this correct?

13 13/108 Drawing Rectangles Is this correct? Overlap!!!

14 14/108 Drawing Rectangles Solution: Exclude pixels on top and right

15 15/108 Drawing Rectangles Artifacts are possible

16 16/108 General Polygons – Basic Idea How to draw every interior pixel? - process the screen scan line from the bottom of the boundaries to the top - draw every interior pixel for each scan line.

17 17/108 General Polygons – Basic Idea How to draw every interior pixel for a scan line?

18 18/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges

19 19/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges

20 20/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges What about this line?

21 21/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Draw odd intervals only

22 22/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Draw odd intervals only Don’t fill top/right Edges may NOT match with line drawing algorithm

23 23/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Draw odd intervals only Use coherence to speed up

24 24/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Draw odd intervals only Use coherence to speed up Edges intersecting one scan line are mostly same as those intersecting previous scan line

25 25/108 General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Draw odd intervals only Use coherence to speed up The x-value of an intersection with one scan line is close to the intersection with the previous one

26 26/108 How to store polygon edges?

27 27/108 How to store polygon edges? Scan Lines Associate polygon edges with scan lines

28 28/108 How to store polygon edges? Scan Lines Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line

29 29/108 How to store polygon edges? Scan Lines Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line

30 30/108 How to store polygon edges? Scan Lines Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line

31 31/108 General Polygons – Data Structures Sorted Edge Table: Scan Lines Edges Store a linked-list per scan- line. Insert edges into table at scan-line associated with lowest end-point.

32 32/108 General Polygons – Example A B C D EF G Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

33 33/108 General Polygons – Example A B C D EF G Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

34 34/108 General Polygons – Example A B C D EF G ABAG Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

35 35/108 General Polygons – Example A B C D EF G ABAG Sorted Edge Table Exclude horizontal edges! Insert edges into table at scan-line associated with lowest end-point!

36 36/108 General Polygons – Example A B C D EF G ABAG FGED Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

37 37/108 General Polygons – Example A B C D EF G ABAG FGED CD Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

38 38/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Insert edges into table at scan-line associated with lowest end-point!

39 39/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Which edges are intersecting with the current scan line? Insert edges into table at scan-line associated with lowest end-point!

40 40/108 General Polygons – Data Structures Active Edge List: Edges List of all edges intersecting current scan-line sorted by their x-values

41 41/108 Linked List A data structure consisting of a group of nodes which together form a sequence Each node includes - a datum - a reference (link) to the next node

42 42/108 General Polygons – Data Structures Active Edge List: Edges List of all edges intersecting current scan-line sorted by their x-values Implement active edge list with linked list

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

44 44/108 General Polygons – Data Structures Edge: maxY: highest y-value currentX: x-value of end- point with lowest y-value xIncr: 1 / slope mazY currentX xIncr Edge

45 45/108 Scan line intersection Scan line y k +1 Scan line y k mazY currentX xIncr Edge

46 46/108 Scan line intersection Scan line y k +1 Scan line y k mazY currentX xIncr Edge with x k and 1/m, we can efficiently compute the next endpoint! - increment y k by 1 - increment x k by 1/m with y end, we know when to end the edge.

47 47/108 General Polygons – Data Structures Edge: maxY: highest y-value currentX: x-value of end- point with lowest y-value xIncr: 1 / slope mazY currentX xIncr Edge Horizontal edges will not be used!!!

48 48/108 General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill interior pixels on the current scan line Increment x-values on edges in Active Edge List Increment line

49 49/108 General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill interior pixels on the current scan line Increment x-values on edges in Active Edge List Increment line Incrementally update the coordinates of intersection points!

50 50/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List

51 51/108 General Polygons – Algorithm line = 0 While (line < 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

52 52/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr AGAB

53 53/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr AGAB

54 54/108 General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill interior pixels on the current line Increment x-values on edges in Active Edge List Increment line

55 55/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr AGAB

56 56/108 General Polygons – Algorithm line = 0 While (line < 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

57 57/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr AGAB

58 58/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List AGAB maxY currentX xIncr

59 59/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List?

60 60/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr EDFG

61 61/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List maxY currentX xIncr EDFG Is it correct?

62 62/108 General Polygons – Algorithm line = 0 While (line < 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

63 63/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Sorted Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

64 64/108 General Polygons – Algorithm line = 0 While (line < 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

65 65/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

66 66/108 General Polygons – Algorithm line = 0 While (line < 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

67 67/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG ??? ?

68 68/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

69 69/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

70 70/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

71 71/108 General Polygons – Algorithm line = 0 While (line < 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

72 72/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AGAB maxY currentX xIncr EDFG

73 73/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr ED

74 74/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr ED

75 75/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr ED

76 76/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr ED

77 77/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr EDCD

78 78/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr EDCD

79 79/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr CD

80 80/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List AB maxY currentX xIncr CD

81 81/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List BC maxY currentX xIncr CDAB

82 82/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List BC maxY currentX xIncr CDAB

83 83/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List BC maxY currentX xIncr CD

84 84/108 General Polygons – Example A B C D EF G ABAG FGED CD BC Active Edge Table Active Edge List BC maxY currentX xIncr CD

85 85/108 General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels //draw pixels on the scanline Increment x-values on edges in Active Edge List Increment scan line // move to the next scanline

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

87 87/108 General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels //draw pixels on the scanline Increment x-values on edges in Active Edge List Increment scan line // move to the next scanline

88 88/108 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)

89 89/108 Drawing Curved Objects How to draw every interior pixels? - process the scan line from the bottom to top - find the intersection positions between the current scan line and the boundaries of fill region - use coherence properties to reduce the process - fill interior pixel in the odd intervals. ?

90 90/108 Drawing Curved Objects Scan-line fill for regions with curved boundaries Extend Scan-line fill for polygons to drawing curved objects - need to calculate intersection points based on curved equation - cannot use the straightforward incremental calculations - For simple curves such as circles or ellipses, use midpoint method for incremental calculations of intersection points. ?

91 91/108 A More General Fill Approach How to deal with curved or irregular boundaries?

92 92/108 A More General Fill Approach Basic idea of Boundary fill algorithm - pick an interior pixel - continue re-coloring pixels until it reaches boundary pixels or previously visited pixels. Particularly useful for interactive painting packages - interior points are easily selected or annotated - the figure interior is then painted in the fill color Paint demo

93 93/108 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

94 94/108 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

95 95/108 Boundary Fill Work for inner and outer boundaries

96 96/108 Boundary Fill Start with drawn outline of a polygon and an interior point Recursively recolor outward from that point  If neighbor pixels are not boundary pixels or previously visited pixels, then recolor and recur Everything within the boundary is changed to that color

97 97/108 Boundary Fill How to define a neighbor? 4-connected 8-connected

98 98/108 Boundary Fill – Example Black pixels indicate boundary pixels.

99 99/108 Boundary Fill – Example Black pixels indicate boundary pixels. Red pixels indicate the filled color (previously visited pixels).

100 100/108 Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels (boundary color) or previously visited pixels (fill color)!

101 101/108 Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

102 102/108 Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

103 103/108 Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

104 104/108 Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

105 105/108 Boundary Fill

106 106/108 Boundary Fill -Might not fill regions correctly if some interior pixels are already displayed in the fill color. - Need to change the color of those pixels before boundary fill

107 107/108 Boundary Fill – Example Black pixels indicate boundary pixels.

108 108/108 Boundary Fill – Example Black pixels indicate boundary pixels.

109 109/108 How to Deal with This? Multiple color boundaries? How to paint this region to yellow?

110 110/108 How to Deal with This? Multiple color boundaries? How to paint this region to yellow? Three keys: - a start pixel - annotated interior pixels - a paint color

111 111/108 Flood Fill/ Seed 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 re-colored

112 112/108 Flood Fill – Example

113 113/108 Flood Fill – Example

114 114/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

115 115/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

116 116/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

117 117/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

118 118/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

119 119/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

120 120/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

121 121/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

122 122/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

123 123/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

124 124/108 Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

125 125/108 Boundary-Fill vs. Flood-Fill Both need to start with an interior pixel. Boundary-Fill requires annotating boundary pixels while flood-fill requires annotating interior pixels. Both are appealing to fill in the irregular boundaries.


Download ppt "1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai."

Similar presentations


Ads by Google