Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics- SCC 342

Similar presentations


Presentation on theme: "Computer Graphics- SCC 342"— Presentation transcript:

1 Computer Graphics- SCC 342
Chapter 2: Overview of Graphics Systems Chapter 3: Graphics Output Primitives

2 Chapter 2: Overview of Graphics Systems
2.1 Video Display Devices 2.2 Raster-Scan Systems

3 Overview of a graphics system

4 Overview of a graphics system
Input devices include Pointing/locator devices: indicate location on screen – Mouse/trackball/spaceball – Data tablet – Joystick – Touch pad and touch screen Keyboard device: send character input Choice devices: mouse buttons, function keys

5 2.1 Video Display Devices Cathode-ray-tube (CRT)

6 2.1 Video Display Devices CRT basics:
The screen output is stored in the frame buffer and is converted into voltages across the reflection plates via a digital-to-analog converter (DAG) Light is emitted when electrons hit phosphor But light output from the phosphor decays exponentially with time, typically in 10 – 60 microseconds – Thus the screen needs to be redrawn or refreshed – Refresh rate is typically 60 Hz to avoid flicker (“twinkling”) – Flicker: when the eye can no longer integrate individual light pulses from a point on screen, e.g., due to low refresh rate

7 2.1 Video Display Devices Shadow-mask color CRTs
Three different colored phosphors (R, G, B) dots are arranged in very small groups (triads) on coating We see a mixture of three colors Three electron guns (R, G, B) emit electron beams in a controlled fashion so that only phosphors of the proper colors are excited

8 2.1 Video Display Devices Raster – Scan Display

9 2.1 Video Display Devices The Frame Buffer
Stores per-pixel information – Depth of a frame buffer: number of bits per pixel – E.g. for color representation, 1 bit => 2 colors, 8 bits => 256 colors, 24 bits => true color (16 million colors) Color buffer is only one of many buffers, other information, e.g., depth, can also be used Implemented with special type of memory in standard PCs or on a graphics card for fast redisplay Part of standard memory in earlier systems

10 2.1 Video Display Devices Raster-scan basics:
The screen is a rectangular array of picture elements, or pixels Resolution: determines the details you can see number of pixels in an image, e.g., 1024×768, 1280x1024, 1366 x 768, etc. also in ppi or dpi – pixel or dot per inch

11 2.1 Video Display Devices Raster-Scan Pattern:
Horizontal scan rate: # scan lines per second Interlaced (TV) vs. non-interlaced displays

12 2.1 Video Display Devices Random-Scan Display
Also called Vector-scan display Pictures are generated as line drawings

13 2.2 Raster-Scan Systems Simple raster-graphics system
Video controller (display processor) controls operations of display device.

14 2.2 Raster-Scan Systems Raster system with fixed portion of main memory reserved for the frame buffer.

15 2.2 Raster-Scan Systems Video controller

16 2.2 Raster-Scan Systems Raster – scan display processor
- Digitizes picture definition into a set of pixel values for storage in the frame buffer (scan conversion).

17 2.2 Raster-Scan Systems Additional functions for Raster – scan display processor - generating line styles - display color areas - transformations - interface with interactive devices.

18 Chapter 3: Graphics Output Primitives
3.5 Line Drawing Algorithms 3.9 Circle- Generating Algorithms 3.13 Pixel Addressing and Object Geometry 3.14 Fill Area Primitives 3.15 Polygon Fill Area

19 3.5 Line Drawing Algorithms
2D Graphics Primitives Graphics drawing is based on basic geometric structures called graphics primitives Points Lines Circles Conic Sections Representation of pictorial data = mathematical representation and In-Memory representation of graphical data Manipulation – Rotation, Movement, Transformation, Enhancement Creation Technologies – Software and hardware used for creating images (Motion Capture, Scanners 2D & 3D, Computational Algorithms)

20 3.5 Line Drawing Algorithms
Drawing Points Input specification Coordinates (x, y) of the point Color Specification Procedure Write the required color value to the corresponding position of the frame buffer Color can be specified depending upon the graphics hardware interface e.g. RGB For a black and white screen whenever a value of 1 is encountered the graphics system turns the corresponding pixel on Function Call setPixel (x,y): To turn the pixel (x,y) on getPixel (x,y): To get the pixel value for (x,y)

21 3.5 Line Drawing Algorithms
Drawing Points Output

22 3.5 Line Drawing Algorithms
Drawing lines What is a line? A set of connected points satisfying y = mx+c (x2,y2) Δy (x1,y1) c Δx

23 3.5 Line Drawing Algorithms
The digital differential analyzer (DDA) line drawing algorithm In graphics, usually we are given the end points (xa,ya) and (xb,yb) of the line for drawing A simple algorithm Calculate the slope Start with (xa,ya) k=1 and set xk+1=xk+1 Then find Put a pixel at (xk+1 , round(yk+1)) Continue till the other xb end point is reached |m|<1 ensures that the points will be continuous (xb,yb) (xa,ya)

24 3.5 Line Drawing Algorithms
For |m|>1 Gaps appear Solution Use Start with (xa,ya) and set yk+1=yk+1 Put a pixel at (round(xk+1) , yk+1) Continue until the end point y2 is reached (xb,yb) (xa,ya)

25 3.5 Line Drawing Algorithms
(xa,ya)

26 3.5 Line Drawing Algorithms
DDA Characteristics Efficiency Better than direct line drawing y=mx+c Eliminates Multiplication But uses rounding off which is an expensive operation Uses floating point operations Round off errors can cause the line to drift away from the true line segment Especially for long lines Can be a problem for systems with low precision numeric representation

27 3.5 Line Drawing Algorithms
Round off Error Accumulation for DDA Intended Line Drift caused by round-off error accumulation

28 3.5 Line Drawing Algorithms
The Bresenham Line Algorithm The Bresenham algorithm is another incremental scan conversion algorithm The big advantage of this algorithm is that it uses only integer calculations Jack Bresenham worked for 27 years at IBM before entering academia. Bresenham developed his famous algorithms at IBM in the early 1960s

29 3.5 Line Drawing Algorithms
Bresenham Algorithm: Main Idea Move across the x axis in unit intervals and at each step choose between two different y coordinates to select the point closest to original line 5 (xk+1, yk+1) For example, from position (2, 3) we have to choose between (3, 3) and (3, 4) We would like the point that is closer to the original line 4 (xk, yk) 3 (xk+1, yk) 2 2 3 4 5

30 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm At sample position xk+1 the vertical separations from the mathematical line are labelled dupper and dlower The y coordinate on the mathematical line at xk+1 is: y yk yk+1 xk+1 dlower dupper Our assumption here is that the line has a positive slope less than one

31 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm (cont…) So, dupper and dlower are given as follows: and: We can use these to make a simple decision about which pixel is closer to the mathematical line

32 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm (cont…) This simple decision is based on the difference between the two pixel positions: Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences between the end-points: Since in our case Δx is positive therefore this term has the same sign as dlower-dupper Constant terms collected in ‘c’

33 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm (cont…) So, a decision parameter pk for the kth step along a line is given by: The sign of the decision parameter pk is the same as that of dlower – dupper If pk is negative, then we choose the lower pixel, otherwise we choose the upper pixel

34 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm (cont…) Remember coordinate changes occur along the x axis in unit steps so we can do everything with integer calculations At step k+1 the decision parameter is given as: Subtracting pk from this we get:

35 3.5 Line Drawing Algorithms
Deriving The Bresenham Line Algorithm (cont…) But, xk+1 is the same as xk+1 so: where yk+1 - yk is either 0 or 1 depending on the sign of pk The first decision parameter p0 is evaluated at (x0, y0) is given as:

36 3.5 Line Drawing Algorithms
BRESENHAM’S LINE DRAWING ALGORITHM (for |m| < 1.0) Input the two line end-points, storing the left end-point in (x0, y0) Plot the point (x0, y0) Find: At each xk along the line, starting at k = 0, perform the following test. If pk < 0, the next point to plot is (xk+1, yk) and: Otherwise, the next point to plot is (xk+1, yk+1) and: Repeat step 4 (Δx – 1) times

37 3.5 Line Drawing Algorithms
Bresenham Example Let’s have a go at this Let’s plot the line from (20, 10) to (30, 18) First off calculate all of the constants: Δx: 10 Δy: 8 2Δy: 16 2Δy - 2Δx: -4 Calculate the initial decision parameter p0: p0 = 2Δy – Δx = 6

38 3.5 Line Drawing Algorithms
Bresenham Example k pk (xk+1,yk+1) 1 2 3 4 5 6 7 17 16 15 14 13 12 11 10 18 29 27 26 25 24 23 22 21 20 28 30

39 3.5 Line Drawing Algorithms
Generalization of the Bresenham Line Drawing Algorithm For lines with slopes greater than 1 Inter-change the roles of the x and y directions Take a unit step in y direction and calculate x values nearest to the line path For lines with negative slopes Procedure is generally similar except that now one coordinate decreases as the other increases Vertical, Horizontal and Diagonal lines Can be drawn as special cases without processing by the line plotting method Interchange of the starting and ending points can be checked

40 3.5 Line Drawing Algorithms
Characteristics of Bresenham Line Drawing Algorithm Uses only integer calculations More efficient Paves the way for making more complex curves based upon a similar logic Take the screen pixel closest to the original curve

41 3.9 Circle- Generating Algorithms
Properties of circles: A Circle is the set of points that are all at a given distance r (called radius) from a center point (xc,yc) The equation for a circle is: The circle is a frequently used component in pictures and graphics

42 3.9 Circle- Generating Algorithms
A circle can be drawn by using the following equation by moving in unit steps from xc-r to xc+r and calculating the corresponding y value at each position void drawCircle(float xc, float yc, float r) { float y1,y2,x; glBegin(GL_POINTS); for (x=xc-r; x<=xc+r; x++){ y1=yc+sqrt(r*r-(x-xc)*(x-xc)); y2=yc-sqrt(r*r-(x-xc)*(x-xc)); glVertex2f (round (x), round (y1)); glVertex2f (round (x), round (y2)); } glEnd();

43 3.9 Circle- Generating Algorithms
Problems with this approach Computations Spacing between points is not uniform Reason Absolute value of the slope exceeds 1 Solution-1 Switch the roles of x and y when the absolute value of slope exceeds 1 Increment y by one unit and calculate corresponding x Still computationally complex

44 3.9 Circle- Generating Algorithms
Problems… Solution-2 Use parametric polar form of the circle Start with initial angle equal to zero and increment the angle to get and then plot the next point The increment in the angle should be small (1/r) to ensure a continuous boundary or if a large step is used then the points can be connected by straight lines to approximate a circular boundary void drawCircle2(float xc, float yc, float r) { float y,x,t,tr; glBegin(GL_POINTS); for (t=0; t<=360; t=t+1/r){ tr=t* /180; x=xc+r*cos(tr); y=yc+r*sin(tr); glVertex2f (round (x), round (y)); } glEnd();

45 3.9 Circle- Generating Algorithms
Reducing computational complexity Using 8-way symmetry However, both the algorithms described earlier involve complex floating point calculations

46 3.9 Circle- Generating Algorithms
The Midpoint Circle Drawing Algorithm The midpoint circle algorithm has been developed and patented by J. Bresenham Characteristics of MPCA Incremental in nature Uses a decision parameter to find the pixel closest to the circumference of the original circle Uses (almost all) integer operations Uses 8-way symmetry to reduce computations

47 3.9 Circle- Generating Algorithms
Main Idea Assume we are drawing the 2nd octant of the circle Assume we have just plotted point (xk,yk) We have two choices for the next point (xk+1,yk) and (xk+1,yk-1) This decision is made by calculating whether (xk+1,yk-1/2) is outside the circle or inside it

48 3.9 Circle- Generating Algorithms
Main Idea This can be done by using the circle function based on the equation of the circle Thus our decision parameter is

49 3.9 Circle- Generating Algorithms
Main Idea We decide yk+1 on the basis of pk pk+1 is given by, - 1

50 3.9 Circle- Generating Algorithms

51 3.9 Circle- Generating Algorithms
The initial decision parameter can be obtained by evaluating the circle function at (x0,y0-1/2)=(0,r-1/2) - 1 If the redius is an integer then 5/4 can be rounded off to 1 to ensure integer operations

52 The Mid-Point Circle Algorithm…
Input radius r and circle centre (xc, yc), then set the coordinates for the first point on the circumference of a circle centred on the origin as: Calculate the initial value of the decision parameter as: Starting with k = 0 at each position xk, perform the following test. If pk < 0, the next point along the circle centred on (0, 0) is (xk+1, yk) and:

53 The Mid-Point Circle Algorithm…
Otherwise the next point along the circle is (xk+1, yk-1) and: Determine symmetry points in the other seven octants Move each calculated pixel position (x, y) onto the circular path centred at (xc, yc) to plot the coordinate values: Repeat steps 3 to 5 until x >= y

54 3.9 Circle- Generating Algorithms
Mid-Point Circle Algorithm Example To see the mid-point circle algorithm in action lets use it to draw a circle centred at (0,0) with radius 10

55 Mid-Point Circle Algorithm Example (cont…)
9 7 6 5 4 3 2 1 8 10 k pk (xk+1,yk+1) 2xk+1 2yk+1 1 2 3 4 5 6

56 Mid-Point Circle Algorithm Exercise
Use the mid-point circle algorithm to draw the circle centred at (0,0) with radius 15

57 3.13 Pixel Addressing and Object Geometry
For displaying objects, their mathematical points are converted into pixel coordinates. For preserving object geometry, display objects to correspond to dimensions given by mathematical points. Screen grid coordinstes

58 3.13 Pixel Addressing and Object Geometry
Raster-scan algorthims refrenced the center of screen pixel position Anothe refrencing method: pixel boundary Area occubied by pixel at (x,y) = area of unit square with diagonally oppsite corners at (x,y) and (x+1,y+1) Advatages: Avoids half-integer pixel boundries Facilitats precies object representation Simplifies processing of many scan-conversion steps.

59 3.14 Fill Area Primitives Most graphics routins require the fill area to specified as polygon - their boundries are described by linear equations. - most surface can be approximated by polygons (called surface tessellation)

60 3.15 Polygon Fill Area Polygons: plane figure specified by three or more vertices and connected by edges Has all vertices within plane- no edge crossing Polygon classification: - Convex: interior angle = or less than 180 degrees - Concave: interior angle greater than 180 degrees Implementations for filling algorithms are complicated for concave polygons convex concave

61 3.15 Polygon Fill Area Identifying concave polygons - extension of some edges will intersect other edges - take a look at the polygon vertex positions relative to the extension line of any edge: some vertices are on one side and some are on the other

62 3.15 Polygon Fill Area Splitting concave polygons
Split concave polygons into a set of convex polygons Using edge vectors and edge cross products Use vertex position relative to edge extension line.

63 3.15 Polygon Fill Area Splitting concave polygons
Assume all polygons in xy plane Ek = Vk+1 – Vk Calculate cross product of successive edge vectors - if at least z component of one vector is negative, then concave polygon. - no successive vertices are collinear. Split along the line of the first edge vector in the cross product pair.

64 3.15 Polygon Fill Area Splitting concave polygons

65 3.15 Polygon Fill Area Splitting concave polygons

66 3.15 Polygon Fill Area Splitting concave polygons
Another method is a rotational method

67 3.15 Polygon Fill Area Splitting convex polygons into triangle (tessellation) - define any sequence of three consecutive vertices to a triangle. - delete middle vertex from the original list - continue forming triangle - stop when only three vertices are remaining.

68 3.15 Polygon Fill Area Inside-Outside test Also called odd-even test P
Q

69 3.15 Polygon Fill Area Winding-Number test
Count counterclockwise encirclements of point P Q

70 3.15 Polygon Fill Area Polygon tables
objects in a scene are described as sets of polygon surface facets Object description includes: - Coordinate information (geometry for the polygon facets) - Surface parameters(color, transparency, and light-reflection properties) Object information are organized in tables.

71 3.15 Polygon Fill Area Polygon tables

72 3.15 Polygon Fill Area Polygon tables
Important for check for consistency and completeness: 1. each pixel is an end point for at least two edges. 2. every edge is part of at least one polygon 3. every polygon is closed 4. each polygon has at least one shared edge


Download ppt "Computer Graphics- SCC 342"

Similar presentations


Ads by Google