Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 20101 Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.

Similar presentations


Presentation on theme: "March 20101 Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty."— Presentation transcript:

1 March 20101 Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty

2 March 20102 Display Window World –coordinate limits 0 1 2 3 4 5 012345 Screen –coordinates (4,2) pixel coordinate

3 March 20103 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

4 March 20104 In raster systems lines are plotted with pixels and step sizes in the horizontal and vertical directions must be sampled at nearest pixel positions.

5 March 20105

6 6

7 7

8 8

9 9

10 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.

11 March 201011 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.

12 March 201012 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.

13 March 201013

14 March 201014 Successive decision parameters are obtained by incremental calculations.

15 March 201015

16 March 201016 123456789010 1 2 3 8 9 0 5 6 7 4 kpkpk (x k+1,y k+1 )2x k+1 2y k+1 0- 9(1,10)220 1- 6(2,10)420 2- 1(3,10)620 36(4,9)818 4- 3(5,9)1018 58(6,8)1216 65(7,7)14

17 March 201017 Ellipse Drawing Algorithms

18 March 201018 Unlike circles, symmetry exists only in quadrants. Midpoint Ellipse Algorithm is working similar to circle with a few adaptations.

19 March 201019

20 March 201020

21 March 201021 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.

22 March 201022 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.

23 March 201023

24 March 201024 The problem turns to filling of triangles Found concave followed by convex Tear off triangle

25 March 201025 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.

26 March 201026 Polygon Tables Objects are described by sets of polygon surface facets.

27 March 201027 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.

28 March 201028 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?

29 March 201029

30 March 201030 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.

31 March 201031 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

32 March 201032 1112 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

33 March 201033 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?

34 March 201034

35 March 201035

36 March 201036 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.

37 March 201037 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

38 March 201038 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:

39 March 201039 1 1 1 1 2 2 22 4 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

40 March 201040 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

41 March 201041 Percentage of pixel area within fill area by midpoint method (Pitteway & Watkinson).

42 March 201042 boundary line overlap area


Download ppt "March 20101 Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty."

Similar presentations


Ads by Google