1 / 29

Where We Stand

This text discusses various algorithms for line drawing and polygon filling, including Bresenham's algorithm and sweep-fill methods. It addresses issues such as anti-aliasing and coherence in scanline and edge-based approaches.

cwelborn
Download Presentation

Where We Stand

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Where We Stand • At this point we know how to: • Convert points from local to window coordinates • Clip polygons and lines to the view volume • Next thing: • Determine which pixels are covered by any given line or polygon • Anti-Aliasing

  2. Drawing Lines • Task: Decide which pixels to fill (samples to use) to represent a line • We know that all of the line lies inside the visible region (clipping gave us this!) • Issues: • If slope between -1 and 1, one pixel per column. Otherwise, one pixel per row • Constant brightness? • Anti-aliasing? (Getting rid of the “jaggies”)

  3. Line Drawing Algorithms • Consider lines of the form y=m x + c, where m=y/x, 0<m<1, integer coordinates • All others follow by symmetry • Variety of slow algorithms (Why slow?): • step x, compute new y at each step by equation, rounding: • step x, compute new y at each step by adding m to old y, rounding:

  4. Bresenham’s Algorithm Overview • Plot the pixel whose y-value is closest to the line • Given (xi,yi), must choose from either (xi+1,yi+1) or (xi+1,yi) • Idea: compute a decision variable • Value that will determine which pixel to draw • Easy to update from one pixel to the next

  5. Decision Variable • Decision variable is: yi+1 d2 d1 yi xi xi+1

  6. What Can We Decide? • d1<d2 => pi negative => next point at (xi+1,yi) • d1>d2 => pi positive => next point at (xi+1,yi+1) • So, we know what to draw based on the decision variable • How do we update it? What is pk+1?

  7. Updating The Decision Variable • If yi+1=yi+1: • If yi+1=yi: • What is p1 (assuming integer endpoints)?

  8. Bresenham’s Algorithm • For integers, slope between 0 and 1: • x=x1, y=y1, p=2 dy - dx, draw (x, y) • until x=x2 • x=x+1 • p>0 ? y=y+1, draw (x, y), p=p+2 y - 2 x • p<0? y=y, draw (x, y), p=p+2 y • Compute the constants once at the start • Only does add and comparisons • Floating point has slightly more difficult initialization

  9. Example: (2,2) to (7,6) x=5, y=4 i x y p 1 2 2 3 2 3 3 1 3 4 4 -1 4 5 4 7 5 6 5 5 6 7 6 3 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8

  10. Filling polygons • Sampling polygons: • When is a pixel inside a polygon? • Given a pixel, which polygon does it lie in? • Polygon issues: • Polygon defined by a list of edges - each is a pair of vertices • All vertices are inside the view volume and map to valid pixels. (Clipping gave us this.) Also, assume integers in window coordinates

  11. What is inside - 1? • Easy for simple polygons - no self intersections • OpenGL requires these. Undefined for other cases • OpenGL also requires convex polygons • For general polygons, three rules are possible: • non-exterior rule • non-zero winding number rule • parity rule

  12. Parity Non-zero Winding No. Polygon Non-exterior

  13. What is inside - 2? • Assume sampling with an array of spikes • If spike is inside, pixel is inside

  14. What is inside - 2? • Assume sampling with an array of spikes • If spike is inside, pixel is inside

  15. Rules • Ambiguous cases: • On edge? if (x+d, y+e) is in, pixel is in • Keeps left and bottom edges • What if it’s on a vertex? Which do we want to keep?

  16. Ambiguous Case 1 • Rule: • On edge? If (x+d, y+e) is in, pixel is in • Which pixels are colored?

  17. 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?

  18. Ambiguous Case 2

  19. Ambiguous Case 2 ? ? or ? ? ? ?

  20. Really Ambiguous

  21. 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

  22. Sweep Fill Algorithms Watt Sect 6.4.2 • 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?

  23. 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

  24. 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

  25. 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

  26. 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

  27. When are Edges Relevant (2) 2 Convex polygon: Always only two edges active 1,2 1 1,3 3 4 3,4

  28. When are Edges Relevant (3) 2 2? Horizontal edges Ignore them! 1 3 1,3 4? 4

  29. 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 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 Sweep Fill Details

More Related