Computer Graphics IS F311 - Computer Science & Information

Computer Graphics IS F311 BITS Pilani
Pilani | Dubai | Goa | Hyderabad
Sundaresan Raman Vector vs Raster Display 2 Raster Graphics: Advantages • 
• 
• 
• 
Lower cost (cheaper memory) Well suited for realis7c display and shading Refresh process is independent of complexity Flicker not perceivable for over 70Hz (vector displays flicker when the number of primi7ves in the buffer becomes too large) 3 ApproximaBng smooth line ApproximaBng smooth line Raster Graphics: Disadvantages Aliasing or stair-­‐case effect Raster Graphics: Disadvantages •  Approximates smooth lines with pixels on the raster grid •  Visual ar)facts -­‐ jaggies or staircasing effect owing to sampling error called aliasing •  Need an7-­‐aliasing techniques – e.g. specifying grada7ons in intensity of neighboring pixels at edges of primi7ves 7 Raster Graphics: Disadvantages •  Primi7ves such as lines and polygons are specified in terms of end points; hence must be scan converted •  Scan conversion is commonly done with soPware in personal computers and low-­‐end work sta7ons where CPU is responsible for for all graphics •  Real 7me dynamics -­‐ far more computa7onally demanding on raster systems than over vector systems E.g. Consider transforming 1000 lines •  Need for transforma7on and scan-­‐conversion hardware; thanks to VLSI 8 Problem Consider a noninterlaced monitor with a resoluBon of n by m ( m scan lines and n pixels per scan line), a refresh rate of r frames per second, a horizontal retrace Bme of thoriz, and a verBcal retrace Bme of tvert. What is the fracBon of the total refresh Bme per frame spent in retrace of the electron beam? Computer Graphics SoluBon •  Refresh Bme per frame = 1/r seconds •  Total retrace Bme during refresh of each frame tretrace = tvert + m . thoriz •  FracBon of Bme spent in retrace = r . tretrace Computer Graphics Color CRT •  Beam penetra7on method •  Shadow mask method Color CRT •  Beam penetra7on method –  Displaying color pictures with random-­‐scan monitors –  Two layers of phosphor – red and green coated on inside of CRT screen –  Color depends on the extent of electron beam penetra7on –  Inexpensive but only few colors possible –  Quality of pictures not good Color CRT •  Shadow mask method –  Commonly used in raster-­‐scan systems –  Much wider range of colors –  Three phosphor color dots at each pixel posi7on -­‐ RGB –  Three electron guns, one for each color dot –  Triangular vs inline arrangement –  Color varia7on produced by varying the intensity of the electron beams CS F111 Flat Panel Display •  Reduced volume, weight and power req. as compared to CRT •  Thinner than CRT •  Emissive displays –  Convert electrical energy into light –  E.g. Plasma panel, thin-­‐film electroluminescent display, LED, Flat CRTs •  Non-­‐emissive displays –  Use op7cal effects to convert sunlight into graphics pa^ern –  E.g. Liquid Crystal Display (LCD) CS F111 Region filled with phosphor instead of gas Eg. ZnS doped with Mn CS F111 CS F111 Stereoscopic & Virtual Reality Systems •  Stereoscopic views to represent 3D objects •  Two views generated with different viewing direc7ons •  Virtual reality – use stereoscopic views + addi7onal sensing system; user can thus interact with the environment [Electronics.howstuffworks.com] An interacBve graphics framework ApplicaBon model ApplicaBon Program Graphics system Input (keyboard, mouse …) Output (monitor ..) 20 An interacBve graphics framework •  Applica7on model – independent of display system •  Applica7on program must extract geometry and convert to primi7ves of graphics system •  Primi7ves: points, lines, rectangles, ellipses, text, polygons, polyhedra, spheres, curves, surfaces •  A^ributes (line style, color, line width, fill style) Graphics Packages •  Applica7on Packages –  CAD, paint programs, medical/visualiza7on programs –  Appropriate coordinate frames –  For non-­‐programmers •  Programming packages –  Provides extensive graphics func7ons –  can be used in a high-­‐level programming language such as C or FORTRAN –  Generally cartesian coordinate frame –  PHIGS, GKS, OpenGL Coordinate RepresentaBons •  Many cartesian frames used to construct and display a scene –  Modeling coordinate
–  World coordinate –  Normalized device coordinate –  Device coordinate (screen coordinate) Graphics FuncBons • 
• 
• 
• 
• 
• 
• 
Output primi7ves A^ributes Geometric transforma7ons Modeling transforma7ons Viewing transforma7ons Input func7ons Control opera7ons Soaware Portability •  Slow development in graphics soPware from machine dependent to device independent packages •  3D Core Graphics System by ACM SIGGRAPH (70s) •  The first graphics specifica7on to be officially standardized (GKS) •  3D GKS (nes7ng of logically related primi7ves into segments) Soaware Portability •  PHIGS (hierarchical grouping of 3D primi7ves into structures) •  SRGP (borrows from Quickdraw and X-­‐
Window system and PHIGS) •  For a mathema7cal 2D, 3D geometric transforma7on and for parallel and perspec7ve projec7ons -­‐ SPHIGS Describing a picture •  Output primi7ves •  Device-­‐level algorithms •  Scan conversion methods Basic Raster Graphics •  Scan Conver7ng Lines –  These algorithms compute the coordinates of the pixels that lie on or near an ideal, infinitely thin straight line imposed on 2D raster grid. •  1 pixel thick approxima7on ideal line –  For lines with slopes between –1 and 1 inclusive, exactly 1 pixel should be illuminated in each column; for lines with slopes outside this range, exactly 1 pixel should be illuminated in each row. –  All lines should be drawn with constant brightness, independent of length and orienta7on, and as rapidly as possible. –  Provision to draw lines with more than 1 pixel wide (a^ributes) Basic Raster Graphics [cs.utah.edu] Plocng points Slope Intercept form y = m*x + b Δy = m Δx •  Basis for deflecBon voltages in analog devices DDA Algorithm •  Digital DifferenBal Analyzer •  Sample the line at unit interval in one coordinate •  Determine the corresponding integer value nearest the line path in the other coordinate •  For |m|≤1, yk+1 = yk + m •  For |m|>1, xk+1 = xk + 1/m Line DDA #include <stdlib.h> #include <math.h> inline int round (const float a) { return int (a + 0.5); } void lineDDA (int x0, int y0, int xEnd, int yEnd) { int dx = xEnd -­‐ x0, dy = yEnd -­‐ y0, steps, k; float xIncrement, yIncrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx); else steps = fabs (dy); xIncrement = float (dx) / float (steps); yIncrement = float (dy) / float (steps); setPixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xIncrement; y += yIncrement; setPixel (round (x), round (y)); } } Line DDA •  Faster than using the equaBon directly •  Round-­‐off error •  Time consuming floaBng point arithmeBc Next Topic •  Bresenham’s line drawing algorithm BITS Pilani
Pilani | Dubai | Goa | Hyderabad