Polygon Filling Goal intensify the pixels that belong to the - - PowerPoint PPT Presentation

polygon filling
SMART_READER_LITE
LIVE PREVIEW

Polygon Filling Goal intensify the pixels that belong to the - - PowerPoint PPT Presentation

Polygon Filling Goal intensify the pixels that belong to the polygon Issues which pixels belong to the polygon Approach use a (horizontal) scan line that traverses the polygon intensify the pixels along the spans (the segments of


slide-1
SLIDE 1

Polygon Filling

Goal intensify the pixels that belong to the polygon Issues which pixels belong to the polygon Approach use a (horizontal) scan line that traverses the polygon intensify the pixels along the spans (the segments of intersection) exploit spatial coherence – little change along a span (span coherence)

  • r between scan lines (scan-line coherence)
slide-2
SLIDE 2

Rectangle Filling

Special case filling rectangles specified by xmin, xmax, ymin, ymax

def drawRectangle(xmin, xmax, ymin, ymax): for y in [ymin : ymax]: # for each vertical scan line: for x in [xmin : xmax]: # for each horizontal span: setPixel(x, y, color)

slide-3
SLIDE 3

Rectangle Filling

Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) 4 12 8 16 20 16 24 5 10

slide-4
SLIDE 4

Rectangle Filling

Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) 5 10 4 12 8 16 20 16 24

slide-5
SLIDE 5

Rectangle Filling

Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) shared edge at x = 16 – order of drawing gives different visual results 5 10 4 12 8 16 20 16 24

slide-6
SLIDE 6

Rectangle Filling

Issues in rectangle (and polygon) filling adjacent rectangles (shared vertices, edges) Solution do not draw the right-most and top-most edges of the rectangle (arbitrary decision – could have chosen to omit left-most, bottom-most) 5 10 4 12 8 16 20 16 24

slide-7
SLIDE 7

Rectangle Filling

Issues in rectangle (and polygon) filling adjacent rectangles (shared vertices, edges) Solution do not draw the right-most and top-most edges of the rectangle 5 10 4 12 8 16 20 16 24

slide-8
SLIDE 8

Polygon Filling

Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge

slide-9
SLIDE 9

Polygon Filling

Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

slide-10
SLIDE 10

Polygon Filling

Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

slide-11
SLIDE 11

Polygon Filling

Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

slide-12
SLIDE 12

Polygon Filling

Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

slide-13
SLIDE 13

Polygon Filling

Check the x-coordinate of intersections between scan line and edges if entering the polygon (i.e. left edge ), round x up (11.4 12) → if leaving the polygon (i.e. right edge), round x down (16.7 16) → If the intersection occurs at integer x-coordinate left edge – draw pixel at x (11 11) → right edge – draw pixel at x-1 (11 10) → 11.4 12 → 16.7 16 → 11 11 → 16 15 →

slide-14
SLIDE 14

Polygon Filling

Check the x-coordinate of intersections between scan line and edges if entering the polygon (i.e. left edge ), round x up (11.4 12) → if leaving the polygon (i.e. right edge), round x down (16.7 16) → If the intersection occurs at integer x-coordinate: left edge – draw pixel at x, right edge – draw pixel at x-1 4 12 8 16 20 16 24 4

slide-15
SLIDE 15

Polygon Filling

Horizontal edges are ignored: either they don't need to be drawn, since they are top edges

  • r they will be drawn as part of a longer span

4 12 8 16 20 16 24 4 should be ignored will be filled

slide-16
SLIDE 16

Polygon Filling

Scan line at level y = 4 intersects edges at x = 11.4, 16.7, 21.6, 26 Every pair of intersections represents a span that needs to be filled s1 = (11.4, 16.7) s2 = (21.6, 26) 4 12 8 16 20 16 24 4

slide-17
SLIDE 17

Polygon Filling

Scan line at level y = 4 intersects edges at x = 11.4, 16.7, 21.6, 26 Every pair of intersections represents a span that needs to be filled s1 = (11.4, 16.7) s2 = (21.6, 26) For each span round up left coordinate, round down the right coordinate s1 = (12, 16) s2 = (22, 25) Intensify pixels at scan line y = 4 and x = [12..17] and x = [23..25] 4 12 8 16 20 16 24 4

slide-18
SLIDE 18

Polygon Filling

Move the scan line by one unit (to draw the next row of pixels) Scan line now intersects edges at x = 11, 26 ignore horizontal edges and edges whose top vertex is on the scan line Every pair of intersections represents a span that needs to be filled s1 = (11, 26) round up/down s1 = (11, 25) Intensify pixels at scan line y = 5 and x = [11..25] 4 12 8 16 20 16 24 4

slide-19
SLIDE 19

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-20
SLIDE 20

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-21
SLIDE 21

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-22
SLIDE 22

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-23
SLIDE 23

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-24
SLIDE 24

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-25
SLIDE 25

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-26
SLIDE 26

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-27
SLIDE 27

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon filled as desired

slide-28
SLIDE 28

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-29
SLIDE 29

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-30
SLIDE 30

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-31
SLIDE 31

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-32
SLIDE 32

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-33
SLIDE 33

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-34
SLIDE 34

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-35
SLIDE 35

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon ignored as desired

slide-36
SLIDE 36

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-37
SLIDE 37

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-38
SLIDE 38

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-39
SLIDE 39

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-40
SLIDE 40

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

slide-41
SLIDE 41

Polygon Filling

Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges (active edges) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon ignored as desired

slide-42
SLIDE 42

Polygon Filling

Data structures Edge – representation of a polygon edge ET (edge table) – all edges sorted by ymin, of their lower vertex AEL (active edge list) – the edges intersected by current scan line Algorithm

store all edges in ET buckets based on ymin of their lower vertex yscan = lowest y coordinate of the polygon AEL = empty list do move from ET to AEL all edges whose ymin = yscan sort edges in AEL based on their x-intersection with yscan fill pixels between successive pairs in AEL yscan = yscan + 1 remove from AEL all edges whose ymax = yscan for each edge in AEL update x-intersection with yscan while AEL not empty

slide-43
SLIDE 43

Polygon Filling

Data structures Edge – representation of a polygon edge ymin, ymax – y coordinate of lower and higher vertex x – intersection with current scan line m – slope of the edge (to update the x intersection) ET (edge table) –all edges sorted by ymin, of their lowest vertex a Hash Map with integer key (ymin) and list values (edges) AEL (active edge list) – a Linked List of edges edges with ymin = 10 edges with ymin = 5 edges with ymin = 4 edges with ymin = 1 ymin | ymax | x | m

slide-44
SLIDE 44

Polygon Filling

Data structures Edge updateX – adds 1/m to current x value (m is slope of the edge) leftX – rounds up the x value (if left side of a span) rightX – rounds down the x value (if right side of a span) ET (edge table) STL map sorted on the key (ymin) AEL (active edge list) – from STL list sort remove merge

slide-45
SLIDE 45

Polygon Filling

Incremental computation of x-coordinate of the scan line and edge intersection Use scan line coherence – relatively small change between scan lines scan line equation y = mx + k → x = y/m + n , n = -k/m to find x” x” = y”/m + n = (y’ + 1)/m + n since y” = y'+1 = y’/m + 1/m + n = y’m + n + 1/m = x’ + 1/m To get the next x intersection just add 1/m to the previous one

x’ x” y’ y”

slide-46
SLIDE 46

Integer Arithmetic

Integer arithmetic for computing x-coordinate of the scan line and edge intersection x” = x’ + 1/m m = dy/dx 1/m = dx/dy From earlier slide we keep adding 1/m = dx/dy , so the sequence of intersections is x, x + dx , x + 2dx , x + 3dx , x + 4dx , etc. dy dy dy dy Example: edge = (x0, y0, x1, y1) = (3, 2, 5, 7) dx = 5-3 = 2, dy = 7-5 = 5 3, 3 + 2 , 3 + 4 , 3 + 6 = 4 + 1 , 4 + 3 , 4 + 5 = 5 + 0 5 5 5 5 5 5 5

slide-47
SLIDE 47

Integer Arithmetic

Integer arithmetic for computing x-coordinate of the scan line and edge intersection x” = x’ + 1/m m = dy/dx 1/m = dx/dy From earlier slide we keep adding 1/m = dx/dy , so the sequence of intersections is x, x + dx , x + 2dx , x + 3dx , x + 4dx , etc. dy dy dy dy To handle overflow in numerator, keep track of its value (i.e. k*dx) and current x

if numer >= dy:

numer = numer - dy x = x + 1 Example: edge = (x0, y0, x1, y1) = (3, 2, 5, 7) dx = 5-3 = 2, dy = 7-5 = 5 3, 3 + 2 , 3 + 4 , 3 + 6 = 4 + 1 , 4 + 3 , 4 + 5 = 5 + 0 5 5 5 5 5 5 5

  • nly for slope m > 1
slide-48
SLIDE 48

Integer Arithmetic

Calculating the x intersection given the previous sequence 3, 3 + 2 , 3 + 4 , 3 + 6 = 4 + 1 , 4 + 3 , 4 + 5 = 5 + 0 5 5 5 5 5 5 5 if a left edge (i.e. entering the polygon) – round up when numer > 0 3, 4, 4, 5, 5, 5 if a right edge (i.e. leaving the polygon) – round down, including integer values 2, 3, 3, 4, 4, 4 left edge right edge

slide-49
SLIDE 49

Integer Artihmetic

Integer arithmetic for slope 0 < m < 1 x” = x’ + 1/m m = dy/dx 1/m = dx/dy Same idea, but dx/dy has a whole part, w, and fractional part, f Example: edge = (x0, y0, x1, y1) = (3, 2, 8, 5) dx = 8-3 = 5, dy = 5-2 = 3 w = dx/dy = 5/3 = 1 f = dx%dy = 5%3 = 2 3 3 + 5/3 =

slide-50
SLIDE 50

Integer Artihmetic

Integer arithmetic for slope 0 < m < 1 x” = x’ + 1/m m = dy/dx 1/m = dx/dy Same idea, but dx/dy has a whole part, w, and fractional part, f Example: edge = (x0, y0, x1, y1) = (3, 2, 8, 5) dx = 8-3 = 5, dy = 5-2 = 3 w = dx/dy = 5/3 = 1 f = dx%dy = 5%3 = 2 3 3 + 5/3 = 3 + 3/3 + 2/3 = 3 + w + f/3 = 4 + f/3 = 4 + 2/3 4 + 2/3 + 5/3 = 4 + 2/3 + w + f/3 = 5 + (2+f)/3 = 5 + 4/3 = 5 + 1 + 1/3 = 6 + 1/3 6 + 1/3 + 5/3 = 6 + 1/3 + w + f/3 = 7 + (1+f)/3 = 7 + 3/3 = 7 + 1 + 0/3 = 8 + 0/3 Procedure always add to x the whole part, w (for slopes m > 1, w = 0) always add to numer the fract. part, f, and adjust if numer >= dy