21
1/1/20 00 1 Topic >>>> Scan Conversion CSE5280 - Computer Graphics

Topic >>>> Scan Conversion

  • Upload
    enoch

  • View
    76

  • Download
    0

Embed Size (px)

DESCRIPTION

Topic >>>> Scan Conversion. CSE5280 - Computer Graphics. Graphics Display Devices. Frame Buffer – a region of memory sufficiently large to hold all of the pixel values for the display. Graphics Display Devices - cont. - PowerPoint PPT Presentation

Citation preview

Page 1: Topic >>>> Scan Conversion

1/1/2000 1

Topic >>>> Scan Conversion

CSE5280 - Computer Graphics

Page 2: Topic >>>> Scan Conversion

1/1/2000 2

Graphics Display Devices

Frame Buffer – a region of memory sufficiently large to hold all of the pixel values for the display

Page 3: Topic >>>> Scan Conversion

1/1/2000 3

Graphics Display Devices - cont

How each pixel value in the frame buffer is sent to the right place on the display surface

Page 4: Topic >>>> Scan Conversion

1/1/2000 4

Graphics Devices – cont

Each pixel has a 2D address (x,y)For each address (x,y) there is a specific memory location

that holds the value of the pixel (I.e. mem[136][252])The scan controller sends the logical address (136, 252) to

the frame buffer, which emits the value mem[136][252]The value mem[136][252] is converted to a corresponding

intensity or color in the conversion circuit, and that intensity or color is sent to the proper physical position, (136, 252), on the display surface

Page 5: Topic >>>> Scan Conversion

1/1/2000 5

Scan Converting Lines

Line DrawingDraw a line on a raster screen between 2 pointsWhat’s wrong with the statement of the problem?

• It does not say anything about which pts are allowed as end pts

• It does not give a clear meaning to “draw”• It does not say what constitutes a “line” in the raster world• It does not say how to measure the success of the

proposed algorithm

Page 6: Topic >>>> Scan Conversion

1/1/2000 6

Scan Converting Lines - cont

Problem StatementGiven 2 points P and Q in the plane, both with

integer coordinates, determine which pixels on a raster screen should be “on” in order to make a picture of a unit-width line segment starting at point P and ending at point Q

Page 7: Topic >>>> Scan Conversion

1/1/2000 7

Finding the next pixel

Special Case:Horizontal Line:

• Draw pixel P and increment the x coordinate value by one to get the next pixel.

Vertical Line:• Draw the pixel P and increment the y coordinate value by one to get

the next pixelDiagonal Line:

• Draw the pixel P and increment both the x and y coordinate values by one to get the next pixel

What should we use in the general case?

Page 8: Topic >>>> Scan Conversion

1/1/2000 8

Vertical Distance

Why can we use the vertical distance as a measure of which point is closer?Because vertical distance is proportional to the

actual distanceHow do we show this?Congruent Triangles

Page 9: Topic >>>> Scan Conversion

1/1/2000 9

Vertical Distance – cont

By similar triangles we can see that the true distances to the line (in blue) are directly proportional to the vertical distances to the line (in black) for each point.Therefore the point with the smaller vertical distance to the line is the closest to the line

Page 10: Topic >>>> Scan Conversion

1/1/2000 10

Strategy 1 – Incremental Algorithm

The Basic AlgorithmFind the equation of the line that connects the 2

points P and QStarting with the leftmost point P, increment by 1

to calculate where A = slope, and B = y intercept

Intensify the pixel at

This computation selects the closest pixel, the pixel whose distance to the “true” line is smallest

ixBAxy ii

)5.0()(,)(, iiii yFlooryRoundwhereyRoundx

Page 11: Topic >>>> Scan Conversion

1/1/2000 11

Strategy 1 – Incremental Algorithm

The Incremental AlgorithmEach iteration requires a floating-point multiplication

therefore, modify

If , then Thus, a unit change in x changes y by slope A, which

is the slope of the lineAt each step, we make incremental calculations

based on the preceding step to find the next y value

xAyBxxABAxY iiii 11

1x Ayy ii 1

Page 12: Topic >>>> Scan Conversion

1/1/2000 12

Strategy 1 – Incremental Aglo

Page 13: Topic >>>> Scan Conversion

1/1/2000 13

Example Code

Page 14: Topic >>>> Scan Conversion

1/1/2000 14

Problem with the Incremental Algorithm

Rounding integers takes timeReal variables have limited precision, summing an inexact slope (A) repetitively introduces a cumulative error buildupVariables y and A must be a real or fractional binary because the slope is a fractionSpecial case needed for vertical lines

Page 15: Topic >>>> Scan Conversion

1/1/2000 15

Strategy 2 – Midpoint Line Algorithm Assume that the line’s slope is shallow and positive ( 0 < slope < 1); other slopes can be handled by suitable reflections about the principle axesCall the lower left endpoint and the upper right endpoint Assume that we have just selected the pixel P at

Next, we must choose between the pixel to the right (pixel E), or one right and one up (pixel NE)Let Q be the intersection point of the line being scan-converted with the grid line

0,0 yx 11, yx

pp yx ,

1 pxx

Page 16: Topic >>>> Scan Conversion

1/1/2000 16

Strategy 2 – Midpoint Line Algorithm

Page 17: Topic >>>> Scan Conversion

1/1/2000 17

Strategy 2 – Midpoint Line AlgorithmThe line passes between E and NEThe point that is closer to the intersection point Q must be chosenObserve on which side of the line the midpoint M lies:E is closer to the line if the midpoint lies above the line (I.e. the line

crosses the bottom half)NE is closer to the line if the midpoint lies below the line, I.e., the

line crosses the top halfThe error, the vertical distance between the chosen pixel and the actual line is always <= ½The algorithm chooses NE as the next pixel for the line shownNow, find a way to calculate on which side of the line the midpoint lies

Page 18: Topic >>>> Scan Conversion

1/1/2000 18

The LineThe line equation as a function f(x): f(x) = A*x + B = dy/dx * x + B

Line equation as an implicit function:F(x,y) = a * x + b * y + c = 0 for coefficients a, b, c where a, b != 0;

from above, y *dx = dy*x + B*dx, so a = dy, b = -dx, c=B *dx, a>0 for y(0) < y(1)

Properties (proof by the case analysis): when any point M is on the line when any point M is above the line when any point M is below the lineOur decision will be based on the value of the function at the

midpoint M at

0)( , mm yxF0),( mm yxF

0),( mm yxF

21,1 pp yx

Page 19: Topic >>>> Scan Conversion

1/1/2000 19

Decision Variable

Decision Variable d:We only need the sign of to see

where the line lies, and then pick the nearest pixel

• If d > 0 choose pixel NE• If d < 0 choose pixel E• If d = 0 choose either one consistently

How to update d:On the basis of picking E or NE, figure out the location of the

M for that pixel, and the corresponding value of d for the next grid line

)21,1( pp yxF

),1( 21 pp yxFD

Page 20: Topic >>>> Scan Conversion

1/1/2000 20

Example Code

Page 21: Topic >>>> Scan Conversion

1/1/2000 21

Scan Conversion Summary