Download presentation

Presentation is loading. Please wait.

Published byLily Lyons Modified over 2 years ago

1
6.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 6 – Filling An Area

2
6.2 Si23_03 Area Filling n As with line drawing, we need a highly efficient way of determining which pixels to illuminate to fill the interior of an area n This will usually be implemented in the hardware of a workstation n But what is the interior of an area?

3
6.3 Si23_03 Definining Interiors n Even-odd rule n Non-zero winding rule

4
6.4 Si23_03 An Example This polygon has vertices: (0,1) (2,8) (4,6) (7,8) (9,4) (6,1) and 6 edges e 1,.. e e1e1 e2e2 e3e3 e4e4 e5e5 e6e6

5
6.5 Si23_03 Scan line approach To fill the area, we can work in scan lines. Take a y-value; find intersections with edges. Join successive pairs filling in a span of pixels e1e1 e2e2 e3e3 e4e4 e5e5 e6e6

6
6.6 Si23_03 Different Cases - the normal case Scan line 5: intersection e 1 = 1.14 intersection e 4 = 8.5 Pixels 2-8 on scan line are filled in e1e1 e2e2 e3e3 e4e4 e5e5 e6e6

7
6.7 Si23_03 Different Cases - Passing through a vertex e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 Scan line 6 intersects e 1,e 2,e 3,e 4 at 1.4, 4, 4, 8 respectively - two spans drawn Scan line 4 intersects e 1,e 4,e 5 at 0.9, 9, 9 respectively - when edges are either side of scan line, just count upper ie e 4

8
6.8 Si23_03 Different cases - horizontal edges e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 A horizontal edge such as e 6 can be ignored; it will get drawn automatically

9
6.9 Si23_03 Pre-Processing the Polygon e1e1 e2e2 e3e3 e4e4 e5e5 We have removed e 6, and shortened e 5 by one scan line

10
6.10 Si23_03 Optimization e1e1 e2e2 e3e3 e4e4 e5e5 To speed up the intersection calculations it helps to know where the edges lie: eg e 1 goes from scan line 1 to scan line 8; e 2 from line 8 to line 6 Thus we know which edges to test for each scan line

11
6.11 Si23_03 Bucket Sort the Edges e1e1 e2e2 e3e3 e4e4 e5e5 In fact it is useful to sort the edges by their lowest point; we do this by bucket sort - one bucket per scan line 0: 1: e 1,e 5 2: 3: 4: e 4 5: 6: e 2,e 3 7: 8: 9:

12
6.12 Si23_03 Next Optimization - Using Coherence e1e1 e2e2 e3e3 e4e4 e5e5 The next optimization is to use scan line coherence Eg look at e 1 - assume intersection with line 1 known (x=0) - then intersection with scan line 2 is: x* = x + 1/m (m=slope) ie: x* = x + Dx / Dy ie: x* = / 7 = 2/7 Dy Dx

13
6.13 Si23_03 Creating An Edge Table e1e1 e2e2 e3e3 e4e4 e5e5 It is useful to store information about edges in a table: e 1 1st x max y Dx Dy

14
6.14 Si23_03 An Efficient Polygon Fill Algorithm e1e1 e2e2 e3e3 e4e4 e5e5 (1) Set y = 0 (2) Check y-bucket (3) Add any edges in bucket to active edge table (aet) (4) If aet empty, then set y = y + 1, and go to (2)

15
6.15 Si23_03 Active Edge Table (5) Put x-values in order and fill in between successive pairs e 1 5 x 0 6 max y DxDy y = e1e1 e2e2 e3e3 e4e4 e5e5

16
6.16 Si23_03 Active Edge Table e1e1 e2e2 e3e3 e4e4 e5e5 (6) Set y = y+1; remove any edge from active table with ymax < y (7) Increment x by Dx / Dy e 1 5 x 2/7 7 max y DxDy y = 2 (8) Return to (2)

17
6.17 Si23_03 Next Scan Line e1e1 e2e2 e3e3 e4e4 e5e5 At each stage of the algorithm, a span (or spans) of pixels are drawn

18
6.18 Si23_03 Working in Integers n The final efficiency step is to work in integer arithmetic only - this needs an extra column in the aet as we accumulate separately the whole part of x and its fractional part

19
6.19 Si23_03 Working in Integers First intersection is at x=0, and the slope of the edge is 7/2 - ie DY=7, DX=2 The successive intersection points are: 02/74/76/78/7 etc The corresponding starting pixels for scan line filling are: We can deduce this just by adding DX at each stage, until DY reached at which point DX is reduced by DY: (8-7)etc

20
6.20 Si23_03 Integer Active Edge Table e 1 5 x 0 6 max y DxDy y = e1e1 e2e2 e3e3 e4e4 e5e5 becomes 008 e x int x frac max y DxDy

21
6.21 Si23_03 Integer Active Edge Table e1e1 e2e2 e3e3 e4e4 e5e5 At step (7), rather than increment x by Dx/Dy, we increment x-frac by Dx; whenever x-frac exceeds Dy, we add 1 to x- int & reduce x-frac by Dy 028 e x int x frac max y DxDy y = 2

22
6.22 Si23_03 Getting Started with SVG

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google