Computer Graphics- SCC 342

Slides:



Advertisements
Similar presentations
Contents In today’s lecture we’ll have a look at:
Advertisements

Computer Graphics- SCC 342
Computer Graphics- SCC 342
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
In the name of God Computer Graphics Bastanfard.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Output Primitives Computer Graphics.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
Objectives Differentiate between raster scan display and random scan display.
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
INT 840E Computer graphics Introduction & Graphic’s Architecture.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Lecture 15: Raster Graphics and Scan Conversion
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics CC416 Lecture 02: Overview of Graphics Systems: Raster & Random Displays – Chapter 2 Dr. Manal Helal – Fall 2014.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Presentation transcript:

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

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

Overview of a graphics system

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

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

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

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

2.1 Video Display Devices Raster – Scan Display

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

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

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

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

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

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

2.2 Raster-Scan Systems Video controller

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).

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

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

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)

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)

3.5 Line Drawing Algorithms Drawing Points Output

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

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)

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)

3.5 Line Drawing Algorithms (xa,ya)

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

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

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

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

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

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

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’

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

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:

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:

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

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

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

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

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

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

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();

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

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*3.14125/180; x=xc+r*cos(tr); y=yc+r*sin(tr); glVertex2f (round (x), round (y)); } glEnd();

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

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

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

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

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

3.9 Circle- Generating Algorithms

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

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:

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

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

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

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

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

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.

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)

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

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

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.

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.

3.15 Polygon Fill Area Splitting concave polygons

3.15 Polygon Fill Area Splitting concave polygons

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

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.

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

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

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.

3.15 Polygon Fill Area Polygon tables

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