Graphics System Input Devices Processor Memory Frame Buffer Output Display Array of pixels Resolution: # of pixels Depth: # of bits/pixel
Input Devices Physical Devices: Keyboard, Mouse, Tablet, etc. Logical Devices: High level interface with the user program Locator Valuator Pick Choice String Tablet Dial Light Pen Function Keys Keyboard 3D Input Devices: Spaceball, Data glove
Input Devices Reading Assignment: Foley van Dam Chapter 4 Hearn & Baker Chapter
Drawing Algorithms Rasterization Pixelization Scan Conversion Continuous Discrete
Line Drawing Algorithms Line Equation: (x,y ) y mx B y m dy dx y x - - y x 1 1 y x (x 1,y 1 ) x DDA (Digital Differential Analyzer)
Line Drawing Algorithms DDA (Digital Differential Analyzer) (x,y ) y y y y (x 1,y 1 ) x i mx i B mx i 1 B m( x x) i 1 i 1 i B
Line Drawing Algorithms (x 1,y 1 ) DDA (Digital Differential Analyzer) x (x,y ) y if x y x i 1 i 1 1 x y i i 1 m
Line Drawing Algorithms DDA (Digital Differential Analyzer) (x i, round(y i ) ) y y1 for (x x1; x x; x ) { Writepi xel(x, round (y)); y m; }
Line Drawing Algorithms DDA (Digital Differential Analyzer) m < 1 m > 1 Exchange the role of x and y
Line Drawing Algorithms Midpoint Line Algorithm Find on what side of the line the mid point is: above NE M Line If below then NE is closer to line If above then E is closer to line below E
Midpoint Line Algorithm NE M M M Line P(x p,y p ) E F(x, F(x, F(x, y) y) y) 0 : (x, > 0 : (x, < 0 : (x, y) y) y) on line below line above line
Midpoint Line Algorithm NE M Line P(x p,y p ) E M M Let 0 < m < 1 Consider line dy y x B dx F ( x, y ) ax by c 0 xdy - ydx Bdx 0 (a dy, b -dx, c Bdx)
Midpoint Line Algorithm NE M Line P(x p,y p ) E M M 1 F( M) F( xp 1, y p ) d 1 d a( xp 1) b( y p ) c if d > 0 Mis below the line,choosene if d < 0 Mis above the line,choosee
Midpoint Line Algorithm P(x p,y p ) NE E M M M Line WhenE : 1 dnew F( M') F( xp, y p ) 1 dnew a( xp ) b( y p ) c 1 dold a( xp 1) b( y p ) c dnew - dold a dy E
Midpoint Line Algorithm Line dx dy b a d d c y b x a d c y b x a d y x F M F d old new NE p p old p p new p p new - - ) 1 ( 1) ( ) 3 ( ) ( ) 3, ( '') ( WhenNE : M NE E M M P(x p,y p )
Midpoint Line Algorithm ) ( ), ( (division) dy - ) 1 ( 1) ( ) 1 1, ( At start : 0 0 0 0 0 0 c by ax y x F dx b a d b a c by ax d c y b x a y x F d start start start
Midpoint Line Algorithm dx x - x1; dy y - y1; d dy - dx; E dy; NE (dy - x x1; y y1; Writepixel(x,y); While (x < x) if d 0 d E; x 1; else d NE; x 1; y 1; end Writepixel(x,y); end While dx);
Midpoint Line Algorithm NE Line above M below E F(x,y) ax by c
Midpoint Line Algorithm above NE M Line NE M M M Line below E P(x p,y p ) E F(x,y) ax by c
Midpoint Circle Algorithm (x,y) x y R
Midpoint Circle Algorithm (x,y) x y R
Midpoint Circle Algorithm (x,y)
Midpoint Circle Algorithm (-x,y) (x,y) (-y,x) (-y,-x) (-x,-y) (x,-y) (y,x) (y,-x) 8-way symmetry: drawing in one octant is enough
Midpoint Circle Algorithm Consider II octant P(x p, y p ) E M SE M M F ( x, y ) x y R For a given point (x,y) F(x, y) 0 : (x,y) on circle F(x, y) > 0 : (x,y) outside circle F(x, y) < 0 :(x,y)inside circle
Midpoint Circle Algorithm Consider II octant P(x p, y p ) E M SE M M Evaluate F(M) If <0 (Minside circle) Choose E If >0 (Moutside circle) Choose SE
3 ) 1 ( ) ( ) 1, ( ') ( 0) WhenE (d ) 1 ( 1) ( ) 1 1, ( ) ( old < p old new E p p p p new p p p p old x d d R y x y x F M F d R y x y x F M F d Midpoint Circle Algorithm Consider II octant Raster Graphics M E SE M M P(x p, y p )
Midpoint Circle Algorithm Consider II octant Raster Graphics P(x p, y p ) E M SE M M When SE (d d ( x new SE p ) old F( M'') d new ( y d 0) F( x p, y 3 ) R x y old p p p p 3 ) 5
Midpoint Circle Algorithm Consider II octant Raster Graphics P(x p, y p ) E M SE M M Initial Condition (0, R) start point, next mid point (1, R - F(1, R 1 ) 5 4 R 1 )
Midpoint Circle Algorithm Consider II octant x 0; y R;d 5 4 Writepixel(x, y); - R; While (y > x) do if d < 0 d x 3; x 1; else d x - y 5; x 1; y- end Writepixel(x, y); end While 1;
Ellipse Drawing Algorithm E SE x a y b 1 S SE
Clipping Extraction of data/primitives inside a region of interest window > Discard (parts of ) primitives outside window. Point Clipping: Remove points outside window. A point is either entirely inside the window or not P (x L, y B ) Q (x R, y T ) x L < x < x R y B < y < y T Q is inside P is outside
Clipping Line Clipping: Remove portion of line segment outside window Can we use point clipping for the end points? 1 Point clipping works
Clipping Line Clipping: Remove portion of line segment outside window How about these lines? 3 5 4 Point clipping does not work
Clipping Cohen and Sutherland
Clipping Cohen and Sutherland 4 bit code to indicate the zone of end points of line with respect to window 1xxx xxx1 0000 xx1x x1xx
Clipping Cohen and Sutherland 4 bit code to indicate the zone of end points of line with respect to window 1001 1000 1010 0001 0000 0010 0101 0100 0110
Clipping Cohen and Sutherland Trivially accept case line is totally visible if both ends of the line have outcode as 0000 Trivially accept
Clipping Cohen and Sutherland Trivially reject case line is totally invisible logical AND of the two end points outcodes Trivially reject
Clipping Cohen and Sutherland If not trivially reject and accept case line is potentially visible Potentially visible
Clipping Cohen and Sutherland If potentially visible subdivide into segments and apply trivial acceptance and rejection test segments by intersection with window edges edges in any order but consistent (e.g., top-bottom, right-left) D B B A A Result
Clipping Cohen and Sutherland simple, still popular limited to rectangular region extension to 3D clipping using 3D orthographic view volume is straightforward