Presentation is loading. Please wait.

Presentation is loading. Please wait.

(c) 2002 University of Wisconsin, CS559

Similar presentations


Presentation on theme: "(c) 2002 University of Wisconsin, CS559"— Presentation transcript:

1 (c) 2002 University of Wisconsin, CS559
Last Time Drawing lines Inside/Outside tests for polygons 10/22/02 (c) 2002 University of Wisconsin, CS559

2 (c) 2002 University of Wisconsin, CS559
Today Drawing Polygons 10/22/02 (c) 2002 University of Wisconsin, CS559

3 (c) 2002 University of Wisconsin, CS559
What is inside - 1? Easy for simple polygons - no self intersections or holes OpenGL requires these. Undefined for other cases OpenGL also requires convex polygons For general polygons, three rules are possible: Non-exterior rule: A point is inside if every ray to infinity intersects the polygon Non-zero winding number rule: Draw a ray to infinity that does not hit a vertex, if the number of edges crossing in one direction is not equal to the number crossing the other way, the point is inside Parity rule: Draw a ray to infinity and count the number or edges that cross it. If even, the point is outside, if odd, it’s inside 10/22/02 (c) 2002 University of Wisconsin, CS559

4 (c) 2002 University of Wisconsin, CS559
Inside/Outside Rules Polygon Non-exterior Non-zero Winding No. Parity 10/22/02 (c) 2002 University of Wisconsin, CS559

5 (c) 2002 University of Wisconsin, CS559
What is inside - 2? Assume sampling with an array of spikes If spike is inside, pixel is inside 10/22/02 (c) 2002 University of Wisconsin, CS559

6 (c) 2002 University of Wisconsin, CS559
What is inside - 2? Assume sampling with an array of spikes If spike is inside, pixel is inside 10/22/02 (c) 2002 University of Wisconsin, CS559

7 (c) 2002 University of Wisconsin, CS559
Ambiguous Case Ambiguous cases: What if a pixel lies on an edge? Problem because if two polygons share a common edge, we don’t want pixels on the edge to belong to both Ambiguity would lead to different results if the drawing order were different Rule: if (x+, y+) is in, (x,y) is in What if a pixel is on a vertex? Does our rule still work? 10/22/02 (c) 2002 University of Wisconsin, CS559

8 (c) 2002 University of Wisconsin, CS559
Ambiguous Case 1 Rule: On edge? If (x+, y+) is in, pixel is in Which pixels are colored? 10/22/02 (c) 2002 University of Wisconsin, CS559

9 (c) 2002 University of Wisconsin, CS559
Ambiguous Case 1 Rule: Keep left and bottom edges Assuming y increases in the up direction If rectangles meet at an edge, how often is the edge pixel drawn? 10/22/02 (c) 2002 University of Wisconsin, CS559

10 (c) 2002 University of Wisconsin, CS559
Ambiguous Case 2 10/22/02 (c) 2002 University of Wisconsin, CS559

11 (c) 2002 University of Wisconsin, CS559
Ambiguous Case 2 ? ? ? or ? 10/22/02 (c) 2002 University of Wisconsin, CS559

12 (c) 2002 University of Wisconsin, CS559
Really Ambiguous We will accept ambiguity in such cases The center pixel may end up colored by one of two polygons in this case Which two? 1 6 2 5 3 4 10/22/02 (c) 2002 University of Wisconsin, CS559

13 (c) 2002 University of Wisconsin, CS559
Exploiting Coherence When filling a polygon Several contiguous pixels along a row tend to be in the polygon - a span of pixels Scanline coherence Consider whole spans, not individual pixels The pixels required don’t vary much from one span to the next Edge coherence Incrementally update the span endpoints 10/22/02 (c) 2002 University of Wisconsin, CS559

14 (c) 2002 University of Wisconsin, CS559
Sweep Fill Algorithms Algorithmic issues: Reduce to filling many spans Which edges define the span of pixels to fill? How do you update these edges when moving from span to span? What happens when you cross a vertex? 10/22/02 (c) 2002 University of Wisconsin, CS559

15 (c) 2002 University of Wisconsin, CS559
Spans Process - fill the bottom horizontal span of pixels; move up and keep filling Have xmin, xmax for each span Define: floor(x): largest integer < x ceiling(x): smallest integer >=x Fill from ceiling(xmin) up to floor(xmax) Consistent with convention 10/22/02 (c) 2002 University of Wisconsin, CS559

16 (c) 2002 University of Wisconsin, CS559
Algorithm For each row in the polygon: Throw away irrelevant edges Obtain newly relevant edges Fill span Update current edges Issues: How do we update existing edges? When is an edge relevant/irrelevant? All can be resolved by referring to our convention about what polygon pixel belongs to 10/22/02 (c) 2002 University of Wisconsin, CS559

17 (c) 2002 University of Wisconsin, CS559
Updating Edges Each edge is a line of the form: Next row is: So, each current edge can have it’s x position updated by adding a constant stored with the edge Other values may also be updated, such as depth or color information 10/22/02 (c) 2002 University of Wisconsin, CS559

18 When are Edges Relevant (1)
Use figures and convention to determine when edge is irrelevant For y<ymin and y>=ymax of edge Similarly, edge is relevant when y>=ymin and y<ymax of edge What about horizontal edges? m’ is infinite 10/22/02 (c) 2002 University of Wisconsin, CS559

19 When are Edges Relevant (2)
Convex polygon: Always only two edges active 2 1,2 1 1,3 3 3,4 4 10/22/02 (c) 2002 University of Wisconsin, CS559

20 When are Edges Relevant (3)
Horizontal edges? 2 2? 1 3 1,3 4? 4 10/22/02 (c) 2002 University of Wisconsin, CS559

21 (c) 2002 University of Wisconsin, CS559
Sweep Fill Details Maintain a list of active edges in case there are multiple spans of pixels - known as Active Edge List. For each edge on the list, must know: x-value, maximum y value of edge, m’ Maybe also depth, color… Keep all edges in a table, indexed by minimum y value - Edge Table For row = min to row=max AEL=append(AEL, ET(row)); remove edges whose ymax=row sort AEL by x-value fill spans update each edge in AEL 10/22/02 (c) 2002 University of Wisconsin, CS559

22 (c) 2002 University of Wisconsin, CS559
Edge Table Row: 6 6 5 5 4 4 6 4 3 3 2 2 1 2 4 6 6 1 6 6 1 2 3 4 5 6 ymax xmin 1/m 10/22/02 (c) 2002 University of Wisconsin, CS559

23 Active Edge List (shown just before filling each row)
6 6 5 4 6 6 6 5 4 4 6 6 6 4 3 2 4 6 6 3 2 2 4 6 6 2 1 2 4 6 6 1 6 6 1 2 3 4 5 6 ymax x 1/m 10/22/02 (c) 2002 University of Wisconsin, CS559

24 (c) 2002 University of Wisconsin, CS559
Edge Table Row: 6 6 5 5 4 4 3 3 2 2 1 2 1 5 6 -1 5 1 6 6 1 2 3 4 5 6 ymax xmin 1/m 10/22/02 (c) 2002 University of Wisconsin, CS559

25 (c) 2002 University of Wisconsin, CS559
Active Edge List Row: 6 6 5 5 4 3 -1 5 5 1 5 4 3 4 1 5 4 -1 5 3 2 3 1 5 5 -1 5 2 1 2 1 5 6 -1 5 1 6 6 1 2 3 4 5 6 ymax x 1/m 10/22/02 (c) 2002 University of Wisconsin, CS559

26 (c) 2002 University of Wisconsin, CS559
Comments Sort is quite fast, because AEL is usually almost in order OpenGL limits to convex polygons, meaning two and only two elements in AEL at any time, and no sorting Can generate memory addresses (for pixel writes) efficiently Does not require floating point - next slide 10/22/02 (c) 2002 University of Wisconsin, CS559

27 Avoiding Floating Point
For edge, m=x/y, which is a rational number View x as xi+xn/y, with xn<y. Store xi and xn Then x->x+m’ is given by: xn=xn+x if (xn>=y) { xi=xi+1; xn=xn- y } Advantages: no floating point can tell if x is an integer or not, and get floor(x) and ceiling(x) easily, for the span endpoints 10/22/02 (c) 2002 University of Wisconsin, CS559


Download ppt "(c) 2002 University of Wisconsin, CS559"

Similar presentations


Ads by Google