Who Am I? - PowerPoint PPT Presentation

About This Presentation
Title:

Who Am I?

Description:

... of the form y=m x c, where m= y/ x, 0 m 1, integer coordinates ... Incrementally update the span endpoints. 10/15/02 (c) 2002 University of Wisconsin, CS559 ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 31
Provided by: Stephen787
Category:
Tags:

less

Transcript and Presenter's Notes

Title: Who Am I?


1
Who Am I?
  • Prof Stephen Chenney
  • These notes will be online after the lecture in
    fact theyre online already
  • http//www.cs.wisc.edu/schenney/courses/guest/cs5
    59-sept1603.ppt

2
Sampling and Drawing
  • Today well talk about rasterization
  • A regular, rectangular grid is referred to as a
    raster
  • A piece of history there are also vector
    displays
  • The raster name comes from the ways the pixels
    are drawn to the screen left to right, top to
    bottom
  • Rasterization is the problem of determining which
    pixels to color which samples to use to draw
    an object

3
Drawing Points
  • You can draw points at any continuous position,
    not just at a pixel center (a sample point)
  • How do we know which pixel to turn on?

4
Drawing Points
  • You can draw points at any continuous position,
    not just at a pixel center (a sample point)
  • How do we know which pixel to turn on?
  • Solution is the simple one
  • Find the closest sample and turn it on fill the
    pixel
  • Can also specify a radius fill a square of that
    size, or fill a circle
  • Square is faster
  • The best solution is anti-aliased points, where
    you partially color multiple pixels

5
Drawing Lines
  • Lines have a similar problem to points they are
    not likely to hit any pixel centers exactly
  • What might we do instead?
  • What are the aesthetic/perceptual issues in
    drawing lines?

6
Drawing Lines
  • Task Decide which pixels to fill (samples to
    use) to represent a line
  • Issues
  • If slope between -1 and 1, one pixel per column.
    Otherwise, one pixel per row
  • Constant brightness? Lines of the same length
    should light the same number of pixels (we
    normally ignore this)
  • Anti-aliasing? (Getting rid of the jaggies)

7
Line Drawing Algorithms
  • Consider lines of the form ym x c, where
    m?y/?x, 0ltmlt1, 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

8
Bresenhams Algorithm Overview
  • Aim For each x, plot the pixel whose y-value is
    closest to the line
  • Given (xi,yi), must choose from either
    (xi1,yi1) or (xi1,yi)
  • Idea compute a decision variable
  • Value that will determine which pixel to draw
  • Easy to update from one pixel to the next
  • Bresenhams algorithm is the midpoint algorithm
    for lines
  • Other midpoint algorithms for conic sections
    (circles, ellipses)

9
Midpoint Methods
  • Consider the midpoint between (xi1,yi1) and
    (xi1,yi)
  • If its above the line, we choose (xi1,yi),
    otherwise we choose (xi1,yi1)
  • Amazing thing You can do this with only integer
    add/subtract and if/then

yi1
yi1
yi
yi
xi1
xi
xi1
xi
Choose (xi1,yi)
Choose (xi1,yi1)
10
Midpoint Decision Variable
  • Write the line in implicit form
  • The value of F(x,y) tells us where points are
    with respect to the line
  • F(x,y)0 the point is on the line
  • F(x,y)lt0 The point is above the line
  • F(x,y)gt0 The point is below the line
  • The decision variable is the value of di
    2F(xi1,yi0.5)
  • The factor of two makes the math easier

11
What Can We Decide?
  • di negative gt next point at (xi1,yi)
  • di positive gt next point at (xi1,yi1)
  • At each point, we compute di and decide which
    pixel to draw
  • How do we update it? What is di1?

12
Updating The Decision Variable
  • dk1 is the old value, dk, plus an increment
  • If we chose yi1yi1
  • If we chose yi1yi
  • What is d1 (assuming integer endpoints)?
  • Notice that we dont need c any more

13
Bresenhams Algorithm
  • For integers, slope between 0 and 1
  • xx1, yy1, d2dy - dx, draw (x, y)
  • until xx2
  • xx1
  • If dgt0 then yy1, draw (x, y), dd2?y - 2?x
  • If dlt0 then yy, draw (x, y), dd2?y
  • Compute the constants (2?y-2?x and 2?y ) once at
    the start
  • Inner loop does only adds and comparisons
  • Floating point has slightly more difficult
    initialization, but is otherwise the same
  • Care must be taken to ensure that it doesnt
    matter which order the endpoints are specified in
    (make a uniform decision if d0)

14
Example (2,2) to (7,6)
?x5, ?y4 x y d
7
6
5
4
3
2
1
2
3
4
5
6
7
8
1
15
Example (2,2) to (7,6)
?x5, ?y4 x y d 2 2 3 3 3 1 4 4 -1 5 4 7 6 5 5 7
6 3
7
6
5
4
3
2
1
2
3
4
5
6
7
8
1
16
Filling Triangles
  • Sampling triangles
  • When is a pixel inside a triangle?
  • Given a pixel, which triangle does it lie in?
    Point location
  • Triangle representation
  • Triangle defined by three vertices, in known
    order (clockwise, ccw)
  • We care most about triangles for 3D graphics
  • We care most about rectangles for 2D graphics
  • Filling more general shapes is difficult

17
What is inside?
  • Assume sampling with an array of spikes
  • If spike is inside, pixel is inside

18
What is inside?
  • Assume sampling with an array of spikes
  • If spike is inside, pixel is inside

19
Ambiguous Case
  • Ambiguous cases What if a pixel lies on an edge?
  • Problem because if two polygons share a common
    edge, we dont 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 (? is a
    small number)
  • What if a pixel is on a vertex? Does our rule
    still work?

?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
20
Ambiguous Case 1
  • Rule
  • On edge? If (x?, y?) is in, pixel is in
  • Which pixels are colored?

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

?
22
Ambiguous Case 2
23
Ambiguous Case 2
?
?
or
?
?
24
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
25
Exploiting Coherence
  • When filling a triangle (or polygon)
  • Several contiguous pixels along a row tend to be
    in the triangle - a span of pixels
  • Scanline coherence
  • Consider whole spans, not individual pixels
  • The pixels required dont vary much from one span
    to the next
  • Edge coherence
  • Incrementally update the span endpoints

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

27
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 lt x (not standard
    floor)
  • ceiling(x) smallest integer gtx
  • Fill from ceiling(xmin) up to floor(xmax)
  • Consistent with convention

28
Updating Edges
  • Each edge is a line of the form
  • Next row is
  • So, each current edge can have its x position
    updated by adding a constant stored with the edge
  • Other values may also be updated, such as depth
    or color information
  • For max efficiency, use a version of the midpoint
    algorithm

29
When are Edges Relevant?
  • Edge is relevant when ygtymin and yltymax of edge
  • What about horizontal edges?
  • m is infinite

30
Avoiding Floating Point
  • For edge, m?x/?y, which is a rational number
  • View x as xixn/?y, with xnlt?y. Store xi and xn
  • Then x-gtxm is given by
  • xnxn?x
  • if (xngt?y) xixi1 xnxn- ?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
Write a Comment
User Comments (0)
About PowerShow.com