1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics
1/1/20002 Graphics Display Devices Frame Buffer – a region of memory sufficiently large to hold all of the pixel values for the display
1/1/20003 Graphics Display Devices - cont How each pixel value in the frame buffer is sent to the right place on the display surface
1/1/20004 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
1/1/20005 Scan Converting Lines Line Drawing Draw a line on a raster screen between 2 points What’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
1/1/20006 Scan Converting Lines - cont Problem Statement Given 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
1/1/20007 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 pixel Diagonal 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?
1/1/20008 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 distance How do we show this? Congruent Triangles
1/1/20009 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
1/1/ Strategy 1 – Incremental Algorithm The Basic Algorithm Find the equation of the line that connects the 2 points P and Q Starting 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
1/1/ Strategy 1 – Incremental Algorithm The Incremental Algorithm Each 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 line At each step, we make incremental calculations based on the preceding step to find the next y value
1/1/ Strategy 1 – Incremental Aglo
1/1/ Example Code
1/1/ Problem with the Incremental Algorithm Rounding integers takes time Real variables have limited precision, summing an inexact slope (A) repetitively introduces a cumulative error buildup Variables y and A must be a real or fractional binary because the slope is a fraction Special case needed for vertical lines
1/1/ 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 axes Call 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
1/1/ Strategy 2 – Midpoint Line Algorithm
1/1/ Strategy 2 – Midpoint Line Algorithm The line passes between E and NE The point that is closer to the intersection point Q must be chosen Observe 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 half The 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 shown Now, find a way to calculate on which side of the line the midpoint lies
1/1/ The Line The 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 line Our decision will be based on the value of the function at the midpoint M at
1/1/ 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
1/1/ Example Code
1/1/ Scan Conversion Summary