Graphics Primitive Drawing Algorithm Graphics Laboratory Korea University
Graphics Primitive Drawing Algorithm Graphics Laboratory Korea University http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Contents n Output Primitives n n KUCG How can we describe shapes with primitives? Color Models n How can we describe and represent colors? http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Output Primitives n Points n Lines n n DDA algorithm n Bresenham’s algorithm KUCG Polygons n Scan-line polygon fill n Inside-outside tests n Boundary-fill algorithm n Anti-aliasing http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Points n KUCG Single coordinate position n Set the color of the specified screen position o Within the frame buffer y x http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Lines n KUCG Intermediate positions between two endpoints n DDA, Bresenham’s line algorithms Jaggies / Aliasing http: //kucg. korea. ac. kr Graphics Lab @ Korea University
DDA Algorithm n Digital differential analyzer (DDA) n Scan-conversion line algorithm for o n KUCG Based on calculating either y or x Algorithm overview n Sample the line at unit intervals in one coordinate If |m| is below 1, sample in x coordinate o Else, sample in y coordinate o Determine corresponding integer values in other coordinate n Until the final endpoint is reached n http: //kucg. korea. ac. kr Graphics Lab @ Korea University
In the Case of |m| < 1 y KUCG y x <When we sample in x coordinate> http: //kucg. korea. ac. kr : Lost Pixel x <When we sample in y coordinate> Graphics Lab @ Korea University
Bresenham’s Line Algorithm (1 / 3) n KUCG Accurate and efficient n Use only incremental integer calculations o Can be adapted to circles and other curves Specified Line Path 12 11 A 10 B 10 11 12 Which pixel is appropriate, A or B? http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Bresenham’s Line Algorithm (2 / 3) n KUCG Vertical pixel separation as d 1, d 2 From the mathematical line path n If d 1 -d 2 < 0, 0 yk is selected n Else, yk+1 is selected n |m| < 1 yk+1 y yk d 2 d 1 xk+1 http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Bresenham’s Line Algorithm (3 / 3) n KUCG Decision parameter pk n The sign of pk is same as the sign of d 1 -d 2 Due to x > 0 o Parameter c is constant o o n Independent of pixel position Incremental representation http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Polygons n KUCG Filling polygons n Scan-line fill algorithm o n Boundary fill algorithm Inside-outside test 1 2 3 4 http: //kucg. korea. ac. kr 5 6 7 8 9 11 10 5 6 7 8 9 4312 Graphics Lab @ Korea University
Scan-Line Polygon Fill n KUCG Topological difference between 2 scan lines y: intersection edges are opposite sides n y’: intersection edges are same side n y y’ 1 2 2 1 http: //kucg. korea. ac. kr 1 Graphics Lab @ Korea University
Scan-Line Polygon Fill (cont. ) n KUCG Edge Sorted Table B y. C y. B x. C 1/m. CB y. D y. C’ x. D 1/m. DC y. E x. D 1/m. DE y. A y. E x. A 1/m. AE y. B x. A 1/m. AB C C’ E D A 1 Scan-Line Number 0 http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Inside-Outside Tests n KUCG Self-Intersections n Odd-Even rule n Nonzero winding number rule exterior interior http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Boundary-Fill Algorithm n KUCG Proceed to Neighboring Pixels 4 -Connected n 8 -Connected n http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Antialiasing n KUCG Supersampling (postfiltering) n Pixel-weighting masks Area Sampling (prefiltering) n Pixel phasing n Shift the display location of pixel areas n Micropositioning the electron beam in relation to object geometry n http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Supersampling KUCG Subpixels increase resolution n Maximum intensity level: 9 n 22 (10, 20): Level 3 Intensity (11, 20): Level 1 Intensity 21 (11, 21): Level 2 Intensity (12, 20): Level 3 Intensity 20 10 http: //kucg. korea. ac. kr 11 12 Graphics Lab @ Korea University
Weighted Supersampling n KUCG Pixel-weighting masks More weights to subpixels near the center n Maximum intensity level: 16 n o More variations in pixel intensity http: //kucg. korea. ac. kr 1 2 4 2 1 Graphics Lab @ Korea University
Weighted Supersampling 22 KUCG (10, 20): Level 7 Intensity (11, 20): Level 1 Intensity 21 (11, 21): Level 3 Intensity (12, 20): Level 5 Intensity 20 10 http: //kucg. korea. ac. kr 11 12 Graphics Lab @ Korea University
Area Sampling n KUCG Intensity is proportional to overlapped area of each pixel n 2 adjacent vertical (or horizontal) screen grid lines trapezoid 22 (10, 20): 90% 21 (10, 21): 10% 20 10 http: //kucg. korea. ac. kr 11 12 Graphics Lab @ Korea University
Filtering Techniques n KUCG Filter Functions (Weighting Surface) Box Filter http: //kucg. korea. ac. kr Cone Filter Gaussian Filter Graphics Lab @ Korea University
Contents n Output Primitives n n KUCG How can we describe shapes with primitives? Color Models n How can we describe and represent colors? http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Color Frame Buffer 255 150 255 255 150 150 75 750 255 150 75 750 255 150 75 0 http: //kucg. korea. ac. kr 75 750 0 0 KUCG 0 0 Blue channel Green channel Red channel Graphics Lab @ Korea University
Color Models KUCG RGB n CMY n HSV n http: //kucg. korea. ac. kr Graphics Lab @ Korea University
RGB Color Model n Colors are additive KUCG R G 0. 0 1. 0 0. 0 1. 0 B Color 0. 0 Black 0. 0 Red 0. 0 Green 1. 0 Blue 0. 0 Yellow 1. 0 0. 0 1. 0 Magenta 0. 0 1. 0 Cyan 1. 0 White http: //kucg. korea. ac. kr Graphics Lab @ Korea University
RGB Color Cube http: //kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
CMY Color Model n Colors are subtractive KUCG C M 0. 0 1. 0 0. 0 1. 0 Y Color 0. 0 White 0. 0 Cyan 0. 0 Magenta 1. 0 Yellow 0. 0 Blue 1. 0 0. 0 1. 0 Green 0. 0 1. 0 Red 1. 0 Black http: //kucg. korea. ac. kr Graphics Lab @ Korea University
CMY Color Cube http: //kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
HSV Color Model KUCG Spectral color (Hue) n Amount of white (Saturation) n Black (Value) n Saturation Hue Angle http: //kucg. korea. ac. kr Graphics Lab @ Korea University
HSV Color Model http: //kucg. korea. ac. kr KUCG H S 0 60 120 180 240 300 * * * 1. 0 1. 0 0. 0 * V Color 1. 0 Red 1. 0 Yellow 1. 0 Green 1. 0 Cyan 1. 0 Blue 1. 0 Magenta 1. 0 White 0. 5 Gray 0. 0 Black Graphics Lab @ Korea University
HSV Color Model n KUCG Cross section of the HSV hexcone http: //kucg. korea. ac. kr Graphics Lab @ Korea University
- Slides: 31