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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
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.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
CS 376 Introduction to Computer Graphics 02 / 05 / 2007 Instructor: Michael Eckmann.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann.
Graphics Programming: Polygon Filling
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
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)
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
College of Computer and Information Science, Northeastern UniversitySeptember 12, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
Dr. S.M. Malaek Assistant: M. Younesi
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
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
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
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Lecture 13: Raster Graphics and Scan Conversion
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Instructor: Dr. Shereen Aly Taie If (P>0)
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.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Scan Conversion or Rasterization
CSCE 441 Lecture 2: Scan Conversion of Lines
CS G140 Graduate Computer Graphics
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
© University of Wisconsin, CS559 Fall 2004
Agenda Polygon Terminology Types of polygons Inside Test
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Agenda Polygon Terminology Types of polygons Inside Test
(c) 2002 University of Wisconsin, CS559
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Chapter 3 Graphics Output Primitives
(c) 2002 University of Wisconsin, CS559
Where We Stand At this point we know how to: Next thing:
Presentation transcript:

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 – sept1603.ppthttp:// sept1603.ppt

10/15/02 (c) 2002 University of Wisconsin, CS559 Sampling and Drawing Today we’ll talk about rasterization A regular, rectangular grid is referred to as a raster –A piece of history – there are also vector displays –The raster name comes from the ways the pixels are drawn to the screen – left to right, top to bottom Rasterization is the problem of determining which pixels to color – which samples to use – to draw an object

10/15/02 (c) 2002 University of Wisconsin, CS559 Drawing Points You can draw points at any continuous position, not just at a pixel center (a sample point) –How do we know which pixel to turn on?

10/15/02 (c) 2002 University of Wisconsin, CS559 Drawing Points You can draw points at any continuous position, not just at a pixel center (a sample point) –How do we know which pixel to turn on? Solution is the simple one –Find the closest sample and turn it on – fill the pixel –Can also specify a radius – fill a square of that size, or fill a circle Square is faster The best solution is anti-aliased points, where you partially color multiple pixels

10/15/02 (c) 2002 University of Wisconsin, CS559 Drawing Lines Lines have a similar problem to points: they are not likely to hit any pixel centers exactly What might we do instead? What are the aesthetic/perceptual issues in drawing lines?

10/15/02 (c) 2002 University of Wisconsin, CS559 Drawing Lines Task: Decide which pixels to fill (samples to use) to represent a line Issues: –If slope between -1 and 1, one pixel per column. Otherwise, one pixel per row –Constant brightness? Lines of the same length should light the same number of pixels (we normally ignore this) –Anti-aliasing? (Getting rid of the “jaggies”)

10/15/02 (c) 2002 University of Wisconsin, CS559 Line Drawing Algorithms Consider lines of the form y=m x + c, where m=  y/  x, 0<m<1, integer coordinates –All others follow by symmetry Variety of slow algorithms (Why slow?): –step x, compute new y at each step by equation, rounding: –step x, compute new y at each step by adding m to old y, rounding:

10/15/02 (c) 2002 University of Wisconsin, CS559 Bresenham’s Algorithm Overview Aim: For each x, plot the pixel whose y-value is closest to the line Given (x i,y i ), must choose from either (x i +1,y i +1) or (x i +1,y i ) Idea: compute a decision variable –Value that will determine which pixel to draw –Easy to update from one pixel to the next Bresenham’s algorithm is the midpoint algorithm for lines –Other midpoint algorithms for conic sections (circles, ellipses)

10/15/02 (c) 2002 University of Wisconsin, CS559 yiyi y i +1 x i +1 Midpoint Methods Consider the midpoint between (x i +1,y i +1) and (x i +1,y i ) If it’s above the line, we choose (x i +1,y i ), otherwise we choose (x i +1,y i +1) Amazing thing: You can do this with only integer add/subtract and if/then xixi Choose (x i +1,y i ) yiyi y i +1 x i +1xixi Choose (x i +1,y i +1)

10/15/02 (c) 2002 University of Wisconsin, CS559 Midpoint Decision Variable Write the line in implicit form: The value of F(x,y) tells us where points are with respect to the line –F(x,y)=0: the point is on the line –F(x,y)<0: The point is above the line –F(x,y)>0: The point is below the line The decision variable is the value of d i = 2F(x i +1,y i +0.5) –The factor of two makes the math easier

10/15/02 (c) 2002 University of Wisconsin, CS559 What Can We Decide? d i negative => next point at (x i +1,y i ) d i positive => next point at (x i +1,y i +1) At each point, we compute d i and decide which pixel to draw How do we update it? What is d i+1 ?

10/15/02 (c) 2002 University of Wisconsin, CS559 Updating The Decision Variable d k+1 is the old value, d k, plus an increment: If we chose y i+1 =y i +1: If we chose y i+1 =y i : What is d 1 (assuming integer endpoints)? Notice that we don’t need c any more

10/15/02 (c) 2002 University of Wisconsin, CS559 Bresenham’s Algorithm For integers, slope between 0 and 1: –x=x 1, y=y 1, d=2dy - dx, draw (x, y) –until x=x 2 x=x+1 If d>0 then { y=y+1, draw (x, y), d=d+2  y - 2  x } If d<0 then { y=y, draw (x, y), d=d+2  y } Compute the constants (2  y-2  x and 2  y ) once at the start –Inner loop does only adds and comparisons Floating point has slightly more difficult initialization, but is otherwise the same Care must be taken to ensure that it doesn’t matter which order the endpoints are specified in (make a uniform decision if d==0)

10/15/02 (c) 2002 University of Wisconsin, CS559 Example: (2,2) to (7,6)  x=5,  y=4 xyd

10/15/02 (c) 2002 University of Wisconsin, CS559 Example: (2,2) to (7,6)  x=5,  y=4 xyd

10/15/02 (c) 2002 University of Wisconsin, CS559 Filling Triangles Sampling triangles: –When is a pixel inside a triangle? –Given a pixel, which triangle does it lie in? Point location Triangle representation: –Triangle defined by three vertices, in known order (clockwise, ccw) We care most about triangles for 3D graphics We care most about rectangles for 2D graphics Filling more general shapes is difficult

10/15/02 (c) 2002 University of Wisconsin, CS559 What is inside? Assume sampling with an array of spikes If spike is inside, pixel is inside

10/15/02 (c) 2002 University of Wisconsin, CS559 What is inside? Assume sampling with an array of spikes If spike is inside, pixel is inside

10/15/02 (c) 2002 University of Wisconsin, CS559 Ambiguous Case Ambiguous cases: What if a pixel lies on an edge? –Problem because if two polygons share a common edge, we don’t want pixels on the edge to belong to both –Ambiguity would lead to different results if the drawing order were different Rule: if (x+ , y+  ) is in, (x,y) is in (  is a small number) What if a pixel is on a vertex? Does our rule still work? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

10/15/02 (c) 2002 University of Wisconsin, CS559 Ambiguous Case 1 Rule: –On edge? If (x+ , y+  ) is in, pixel is in –Which pixels are colored?

10/15/02 (c) 2002 University of Wisconsin, CS559 Ambiguous Case 1 Rule: –Keep left and bottom edges –Assuming y increases in the up direction –If rectangles meet at an edge, how often is the edge pixel drawn? ?

10/15/02 (c) 2002 University of Wisconsin, CS559 Ambiguous Case 2

10/15/02 (c) 2002 University of Wisconsin, CS559 Ambiguous Case 2 ? ? ? ? or

10/15/02 (c) 2002 University of Wisconsin, CS559 Really Ambiguous We will accept ambiguity in such cases –The center pixel may end up colored by one of two polygons in this case –Which two?

10/15/02 (c) 2002 University of Wisconsin, CS559 Exploiting Coherence When filling a triangle (or polygon) –Several contiguous pixels along a row tend to be in the triangle - a span of pixels Scanline coherence –Consider whole spans, not individual pixels –The pixels required don’t vary much from one span to the next Edge coherence –Incrementally update the span endpoints

10/15/02 (c) 2002 University of Wisconsin, CS559 Sweep Fill Algorithms Algorithmic issues: –Reduce to filling many spans –Which edges define the span of pixels to fill? –How do you update these edges when moving from span to span? –What happens when you cross a vertex?

10/15/02 (c) 2002 University of Wisconsin, CS559 Spans Process - fill the bottom horizontal span of pixels; move up and keep filling Have x min, x max for each span Define: –floor(x): largest integer < x (not standard floor) –ceiling(x): smallest integer >=x Fill from ceiling(x min ) up to floor(x max ) Consistent with convention

10/15/02 (c) 2002 University of Wisconsin, CS559 Updating Edges Each edge is a line of the form: Next row is: So, each current edge can have it’s x position updated by adding a constant stored with the edge Other values may also be updated, such as depth or color information For max efficiency, use a version of the midpoint algorithm

10/15/02 (c) 2002 University of Wisconsin, CS559 When are Edges Relevant? Edge is relevant when y>=y min and y<y max of edge What about horizontal edges? –m’ is infinite

10/15/02 (c) 2002 University of Wisconsin, CS559 Avoiding Floating Point For edge, m=  x/  y, which is a rational number View x as xi+xn/  y, with xn<  y. Store xi and xn Then x->x+m’ is given by: –xn=xn+  x –if (xn>=  y) { xi=xi+1; xn=xn-  y } Advantages: –no floating point –can tell if x is an integer or not, and get floor(x) and ceiling(x) easily, for the span endpoints