Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.

Similar presentations


Presentation on theme: "Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in."— Presentation transcript:

1 Rasterization Overview Raster Display Device

2 Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in raster graphics to represent primitives in vector graphics).

3 Scan Converting Lines The Basic Incremental Algorithm A line scan-converting algorithm computes the coordinates of the pixels that lie on or near an ideal, infinitely thin straight line imposed on a 2D grid. (Selects pixels on the line to light up.) P a (x a,y a ) P b (x b,y b )

4 We need to compute x a, x a+1, x a+2, …, x b y a, y a+1, y a+2, …, y b dy=y b -y a ; dx=x b -x a ; m = dy /dx; for i = a, a+1, …, b. X i,

5 To increase efficiency, we consider y i = y a + m*(x i – x a ) and x i+1 = x i + 1 y i+1 = y a + m*(x i+1 - x a ) = y a + m*(x i +1- x a ) = y a + m*(x i – x a ) + m = y i + m …. Since pixels are at integer locations, we need round up if m is not an integer:

6 p i (x i, round(y i )), i=a, a+1, a+2, …,b. desired line (x i +1,Round(y i +m)) (x i +1, y i +m) (x i, y i ) (x i, Round(y i ))

7 DDA (digital differential analyzer): void Line(int x a, int y a, int x b, int y b, int color) { int x; float dy, dx, y, m; dy=y b -y a ; dx=x b -x a ; m=dy/dx; y=y a ; for(x=x a ; x<=x b ; x++) { // light the pixel near (x,y) with the color setPixelColor(x, (int)(y+0.5), color); y += m; }

8 This code is only good for |m|<=1. Swap x and y when calling the function with |m|>1, and a flag is needed for displaying the swapped case. Drawbacks: accumulating error, FP operation.

9 Fill Rectangles -> Area Fill  Choosing pixels inside the area  setPixelColor(x, y, color) We may need to compute color based on x, y if the filling is not a single color. A simple rectangle single color filling algorithm: int x, y for (y=y min ; y<=y max ; y++)/* for each scan line */ for (x=x min ; x<=x max ; x++) /* for each pixel */ setPixelColor(x, y, color);

10 Rules for shared edges =>A shared vertical edge belongs to the rightmost of the two sharing shapes =>A shared non-vertical edge belongs to the upper shape. =>Therefore only draw the pixels on the left and bottom edges. Revised code for rectangle single color filling: int x, y for (y=y min ; y<y max ; y++) for (x=x min ; x<x max ; x++) SetPixelColor(x, y, color);

11 Fill Polygons (Polygon Scan-Conversion) Parity: number of times a scan line has intersected the polygon. Initially it is 0 (even). Extrema: the intersection points of the scan line with the polygon. Span: a segment of a scan line between two consecutive extrema that is also within the polygon.

12 The Odd-Parity Rule =>For each intersection encountered, inverts the parity. =>Draw when the parity is odd. =>Don’t draw when it is even. The span-filling algorithm for filling a polygon on a scan-line: ->Find the intersections of the scan line with all edges of the polygon (extrema for the spans) ->Sort the intersections by increasing x coordinate ->Fill in all pixels between pairs of intersections that lie interior to the polygon (span), using the odd-parity rule to determine a point is inside the polygon or not. Polygon Filling Rule: draw only pixels that lie interior or on a left or bottom edge.

13 Four elaboration on handling intersection points: =>Fraction intersection x values: Round down x coordinate if the parity is even (when this intersection is counted); round up x coordinates if the parity is odd (when this intersection is counted). Count the pixel that are exactly inside. =>Integer intersection x values: Left (odd) in. Right (even) out. =>Shared vertices: Count y min, don’t count y max. =>Horizontal edges: Draw the bottom ones. Ignore horizontal edges when computing intersection points. Fraction extrema Odd upEven down Integer Extrema Left (odd) in Right (even) out Shared vertices y min iny max out Horizontal edges Bottom (y min ) in Top (y max ) out

14 PSC (Polygon Scan Conversion): determine the pixels and set them to the specified color. =>Algorithm:  Find the first and the last scan line that intersect with the polygon. first: y=y min : (min y value of the polygon) last: y=y max : (max y value of the polygon)  For each scan line between [y min, y max ], fill the spans (span-filling) : Three stages of span filling: -> Find (the extrema by intersecting the scan line with the polygon). -> Sort (the extrema by x) -> Fill (the pixels using the odd-parity rule).

15 Slivers: relax the filling rule, count nearby pixels Texture Filling

16 Pattern Filling setPixelColor(x,y,pattern[x%M,y%N]);

17 Clipping in a Raster World Clipping cuts the outside parts out before displaying Clipping a point. Point P(x, y) if ((x>=x min && x =y min && y<=y max )) setPixelColor(x, y, color);

18 Clipping filled polygons =>Clip while scan-convert. =>Clip extrema in pairs:. Keep the pair if both extrema are inside.. Remove the pair if both extrema are outside and on the same side.. Move the outside extreme point to the edge if one extreme point is out and the other is in.


Download ppt "Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in."

Similar presentations


Ads by Google