March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty
March Display Window World –coordinate limits Screen –coordinates (4,2) pixel coordinate
March We’d like to display straight line on the screen. On raster systems, lines are plotted with pixels which have vertical and horizontal finite resolution. The outcome is a jaggy line. In analog displays, such as vector-scan, a smooth line can be displayed, as line equation is translated into deflection voltages. Line Drawing Algorithms
March In raster systems lines are plotted with pixels and step sizes in the horizontal and vertical directions must be sampled at nearest pixel positions.
March 20105
6
7
8
9
10 Circle Drawing Algorithms We could use above equation to step along the x axis from x c - r to x c + r and calculate y positions of pixels.
March This requires considerable amount of computation (square root) The drawing appearance is poor since the vertical spacing between drawn pixels is uneven. Appearance can be improved by changing the role of x and y whenever the absolute value of the slope of circle is crossing 1. But this requires more computation. Polar coordinates can be used with uniform stepping of θ. This spaces pixels evenly along circumference. Time consuming due to trigonometric computations.
March We can use large angular steps and connect the points by straight lines. For smoother boundary we can use angular steps of 1/r which plots pixels approximately one pixel apart of each other (r∙1/r =1). Any of the methods can use symmetry for efficiency. All methods involve expensive computations.
March
March Successive decision parameters are obtained by incremental calculations.
March
March kpkpk (x k+1,y k+1 )2x k+1 2y k (1,10) (2,10) (3,10)620 36(4,9) (5,9) (6,8) (7,7)14
March Ellipse Drawing Algorithms
March Unlike circles, symmetry exists only in quadrants. Midpoint Ellipse Algorithm is working similar to circle with a few adaptations.
March
March
March Polygon Fill Areas Convex polygons are easy to fill Concave polygons are more difficult to fill Some graphics packages support convex polygon filling only. How should polygon split into convex components? We’d like to avoid any trigonometric or division operations. We’ll use vector product a x b for convex / concave test.
March Polygon vertices are counterclockwise oriented. The cross product of successive edges is a perpendicular vector. Z component is positive for convex angle and negative for concave. Only multiplications are involved.
March
March The problem turns to filling of triangles Found concave followed by convex Tear off triangle
March Inside-Outside Tests ? Odd-even rule: Draw “infinite” ray and count the number of crossings. Odd is inside, even outside. Avoid passing through vertices. ? Nonzero winding-number rule: Draw “infinite” directed ray. Traverse edges and check for crossing direction (e.g. by cross product). Add ±1 accordingly. If it sums to zero point is outside, otherwise it is inside.
March Polygon Tables Objects are described by sets of polygon surface facets.
March In hardware implementation these tables translate into physical RW memories. For hardware implementations triangles are preferred, since it makes SURFACE-FACET MEMORY homogeneous. Data in memories needs to be organized to maximize pipeline processing of facets: –Vertices are stored such that vertex progression in VERTEX MEMORY completes new triangle for every vertex. –Vertex indices are their memory addresses. It is the SW application responsibility to triangulate objects and load HW memories in the right order.
March Plane Equations Graphics system processes input data through several steps: –Transformation of modeling through viewing pipeline. –Identification of visible surfaces. –Rendering of surface facets. Information about the spatial orientation of surfaces is needed –Plane equations are in order. –How to calculate those efficiently w/o divisions?
March
March Front and Back Polygon Faces Polygon surfaces enclose objects. –Need to know the outward an inward sides of polygon. Need to find the side of a polygon visible by an observer.
March Scan-Line Polygon-Fill Algorithms This is most time consuming operation in computer graphics. –Use only integer arithmetic with minimum operations Polygons are filled with scan-line –The sweep is vertical –A scan-line is the pixels of same y coordinates Pixels between odd-even intersections with border are inside. x 1234
March Scan-line y 2 11 Scan-line y’ A problem may occur at vertices. Scan-line y’ is okay, but y is not. The remedy is to traverse edges prior to filling and detect the values of three consecutive of two successive edges. If they are monotonic then one of the edges is shortened by one pixel at corner
March Polygon filling takes advantage of y increments by one unit. How to calculate efficiently the intersection of an edge with scan line? How to avoid division?
March
March
March Antialiasing Graphics primitives generated by raster algorithms have jagged (stair-step) appearance, called aliasing. –This is due to under sampling. –Antialiasing compensates for this. Sampling rate could increase by higher raster resolution. –Expensive, increase of frame buffer (memory). –More processing (time, hardware). –Jagging phenomena is not canceled, but only improved. Raster systems capable of gradual intensity of pixels can support antialiasing by modifying pixel intensity near boundary of primitives.
March Antialiasing by Supersampling Treat the screen as if it has finer grid than actual. Modify real pixel intensity according to the number of covered sub-pixels There are 4 possible intensities, depending on the count of covered pixels at every 3x3 superpixel (1,1) is covered by 3 subpixels (2,2) and ((3,2) are covered by 2 subpixels (2,1) and ((3,3) are covered by 1 subpixels
March Line was treated as zero width. In case of finite width we count the number of subpixels inside the polygon representing the line. Useful also for mixing foreground and background colors in a pixel. For instance, if foreground is red and background is blue:
March Central pixel is most important and has a weight of 1/4. Others has a weight of 1/8 and 1/16. Antialiasing by subpixel Weighting Masks Antialiasing compensates for line-intensity differences Diagonal lines are less instance than horizontal and vertical ones. Supersampling with higher weights for subpixels close to diagonal will intensify diagonal lines
March Antialiasing Area Boundaries Pixel intensities are adjusted along the boundary of area. Subdivide area of pixels and double scan- line. Count how many subpixels are inside. Scan-line 1 Scan-line 2 75% pixel intensity
March Percentage of pixel area within fill area by midpoint method (Pitteway & Watkinson).
March boundary line overlap area