Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

Polygon Scan Conversion – 11b
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
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.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
CPCS 391 Computer Graphics 1 Lecture 5: Polygon Filling
Raster conversion algorithms for line and circle
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Polygon Scan Conversion and Z-Buffering
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Primitives: line. Pixel Position
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.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Scan Conversion. Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines (done last class) – Polygons (fill polygons,
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
Rendering.
Scan Conversion.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
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.
Primitive graphic objects
Computer Graphics Filling.
Introduction to Polygons
CS G140 Graduate Computer Graphics
(c) 2002 University of Wisconsin, CS559
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
University of New Mexico
Implementation III.
Chapter Three Part I Output Primitives CS 380.
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Rasterization and Antialiasing
Computer Graphics Implementation III
Rasterization and Antialiasing
Chapter 3 Graphics Output Primitives
Where We Stand At this point we know how to: Next thing:
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 122 Drawing lines Plot line from (x 1, y 1 ) to (x 2, y 2 ) y = mx + b  m = (y 2 - y 1 ) / (x 2 - x 1 )  b = y 1 - mx 1 Straight-forward approach:  for x = x 1 to x 2 do  y = m * x + b  WritePixel (x, round(y))

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 123 Digital differential analyzer Straight-forward approach involves one multiplication and one addition per iteration of the loop Recognize  y = m  x Choose  x to be 1;  y = m; y i+1 = y i + m Digital differential analyzer (DDA):  y = y 1  for x = x 1 to x 2 do  WritePixel (x, round(y))  y = y + m Have removed the multiplication from the loop

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 124 Effect of slope The DDA algorithm shown assumes left- to-right processing (i.e., x 1 < x 2 ) and |slope| <= 1 For |slope| > 1 reverse x and y roles  step along y  change x by 1 / m

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 125 Remaining problems There are still two problems that remain to be removed:  one real addition per iteration of the loop  one rounding per iteration of the loop Would like to get the algorithm down to only integer operations Bresenham’s algorithm will do this

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 126 Bresenham’s algorithm An algorithm for drawing lines with only integer operations Consider the case where 0  slope  1 Suppose (x i, y i ) is plotted Which y value do you plot at x i +1? Is it y i or y i +1? The true value is y

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 127 Error terms Let e 1 = y i +1 - y = y i +1 - (m(x i +1) + b) Let e 2 = y - y i = m(x i +1) + b - y i e 1 -e 2 = 2y i - 2m(x i +1) - 2b + 1 = 2y i - 2(  y/  x)(x i +1) - 2b + 1 If this difference is negative, e 2 > e 1 so y i + 1 is closer to true value than y i

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 128 Definition of p i Multiply through by  x to get rid of fraction p i =  x(e 1 -e 2 ) = 2y i  x - 2  y(x i +1) - 2b  x +  x = 2  xy i - 2  yx i - 2  y -  x(2b-1) p i+1 = 2  xy i  yx i  y -  x(2b-1)

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 129 Updating equation for p i p i+1 -p i = 2  xy i  xy i - 2  yx i  yx i = 2  x(y i+1 -y i ) - 2  y(x i+1 -x i ) = 2  x(y i+1 -y i ) - 2  y p i+1 = p i + 2  x(y i+1 -y i ) - 2  y

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1210 Handling the y i+1 -y i term y i+1 -y i = 0 or 1, depending on whether we move up a scan line or not If p i is positive (i.e., we don’t move up, so y i+1 =y i and y i+1 -y i = 0), then p i+1 = p i - 2  y If p i is negative (i.e., we move up, so y i+1 =y i +1 and y i+1 -y i = 1), then p i+1 = p i + 2  x - 2  y

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1211 Only integer operations Note that  x and  y are both integers, are constant for a line segment, and can be computed before entering the loop The drawing loop now only contains integer addition operations

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1212 p1p1 Need a value for p 1 to get started with Use (x 1, y 1 ) in the equation for p i p 1 =2  xy  yx  y -  x(2b-1) = 2  xy  yx  y -  x(2y 1 -2(  y/  x)x 1 - 1) = 2  xy  yx  y - 2  xy  yx 1 +  x =  x - 2  y

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1213 Other cases How would you handle each of the following cases with Bresenham’s algorithm?  -1  slope  0  slope > 1  slope < -1

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1214 Circles Cartesian coordinates  Polar coordinates 

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1215 A Bresenham algorithm for circles Assume center of circle is (0, 0) Recognize symmetry of circle (only need to consider 1/8 of circle) Choose region to consider as (0, r) to (r  2, r  2) along circumference  slope of circle is between 0 and -1  can do work stepping along x-axis

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1216 The error terms for circles Suppose (x i, y i ) is plotted Next point is either (x i +1, y i ) or (x i +1, y i -1) Compute two error terms, using y 2 instead of y  let e 1 be error for point above circle  let e 2 be error for point below circle

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1217 p i for circles Define p i as e 1 - e 2 If p i < 0 then (x i +1, y i ) is plotted, otherwise x i +1, y i -1) is plotted p i = 2(x i +1) 2 + y i 2 + (y i -1) 2 - 2r 2 p i+1 = p i + 4x i (y i y i 2 ) - 2(y i+1 - y i ) If p i <0 then p i+1 = p i + 4x i + 6 else p i+1 = p i + 4(x i - y i ) + 10 p 1 = 3 - 2r (at (0, r))

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1218 Compositing Blending together of values from different objects at the same pixel This is the use of the alpha channel (the A in RGBA) Like R, G, and B, A is defined over [0.0, 1.0] A = 1.0 implies a completely opaque surface, while A = 0.0 implies a completely transparent surface

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1219 How to do compositing When an object is rendered into the frame buffer, both the object’s pixel and the current pixel value in the frame buffer are scaled by appropriate constants and the products added together There are 4 scale factors for the object’s pixel, 1 each for RGBA, and 4 for the buffer’s pixel

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1220 Blending in OpenGL glBlendFunc (sfactor, dfactor) The sfactor tells how to scale the object being processed The dfactor tells how to scale what’s currently in the buffer The table in the OpenGL Reference Manual for glBlendFunc gives the symbolic constants you can use for sfactor and dfactor Note that you need to glEnable (GL_BLEND);

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1221 Example program alpha.c is an example using blending Can you derive the colors that should be displayed in each quadrant?

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1222 Scan line approach to filling a polygon For each scan line in range of polygon:  find intersections of scan line with all edges of polygon  sort intersections in increasing x  fill in all pixels between pairs of intersections that lie interior to polygon, using the odd-parity rule to determine that a point is inside:  parity is initially even  each intersection encountered inverts the parity  draw when parity is odd

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1223 Edge coherence To find intersections of each scan line with the edges of the polygon we take advantage of edge coherence - many of the edges that intersect scan line i will also intersect scan line i+1 Will also take advantage of the incremental changes in x and y so we don’t have to solve equations to find intersections

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1224 Global edge table Contains each edge of the polygon, sorted by their smaller y coordinate Use buckets for each scan line, and store edges in increasing x coordinate order Each edge contains y max, x min, dy, dx, and x-increment in going from one scan line to the next

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1225 Active edge table For each scan line we construct the active edge table, where the set of edges a scan line intersects is kept sorted on the x intersection values When we move to the next scan line, the active edge table is updated

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1226 The complete algorithm Set y to the smallest y coordinate that has an entry in the ET Initialize the AET to be empty Repeat until AET and ET are empty:  Move from ET bucket y to the AET those edges whose y min = y (entering edges), then sort the AET on x (made easier because the ET is presorted)  Fill in desired pixel values on scan line y by using pairs of x coordinates from AET  Remove from AET those entries for which y = y max (edges not involved in next scan line)  Increment y by 1 (go to next scan line)  For each edge remaining in AET, update x for the new y

Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 1227 Patterns Define a pattern in a small matrix Fix a reference point (usually lower left corner) As you fill an area, pick the corresponding pixel from the pattern matrix The pattern usually repeats, so use a mod operation to get the repeating effect