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