© University of Wisconsin, CS559 Fall 2004

Slides:



Advertisements
Similar presentations
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Advertisements

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.
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.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
Graphics Programming: Polygon Filling
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)
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
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
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.
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
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.
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.
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.
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.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
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.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
Computer Graphics Filling.
Introduction to Polygons
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
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
University of New Mexico
Implementation III.
Chapter Three Part I Output Primitives CS 380.
Fill Area Algorithms Jan
Scan Conversion of Lines
Introduction to Computer Graphics with WebGL
CSCE 441 Lecture 2: Scan Conversion of Lines
Scan Conversion of Circles
Agenda Polygon Terminology Types of polygons Inside Test
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
Computer Graphics Implementation III
(c) 2002 University of Wisconsin, CS559
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Clipping Polygons Dr. Scott Schaefer.
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
Line Drawing Algorithms
Presentation transcript:

© University of Wisconsin, CS559 Fall 2004 Last Time Clipping Liang-Barksy Weiler-Atherton Drawing points Intro to drawing lines Midterm Oct 28 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Today Drawing lines Filling polygons 10/21/04 © University of Wisconsin, CS559 Fall 2004

Bresenham’s Algorithm Overview Input: Line with integer endpoints, slope 0<m<1 Aim: For each x, plot the pixel whose y-value is closest to the line Given (xi,yi), must choose from either (xi+1,yi+1) or (xi+1,yi) 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/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Midpoint Methods Consider the midpoint between (xi+1,yi+1) and (xi+1,yi) If it’s above the line, we choose (xi+1,yi), otherwise we choose (xi+1,yi+1) yi+1 yi+1 yi yi xi xi+1 xi xi+1 Choose (xi+1,yi) Choose (xi+1,yi+1) 10/21/04 © University of Wisconsin, CS559 Fall 2004

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 di = 2F(xi+1,yi+0.5) The factor of two makes the math easier 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 What Can We Decide? di negative => next point at (xi+1,yi) di positive => next point at (xi+1,yi+1) At each point, we compute di and decide which pixel to draw How do we update it? What is di+1? 10/21/04 © University of Wisconsin, CS559 Fall 2004

Updating The Decision Variable dk+1 is the old value, dk, plus an increment: If we chose yi+1=yi+1: If we chose yi+1=yi: What is d1 (assuming integer endpoints)? Notice that we don’t need c any more 10/21/04 © University of Wisconsin, CS559 Fall 2004

Bresenham’s Algorithm For integers, slope between 0 and 1: x=x1, y=y1, d=2dy - dx, draw (x, y) until x=x2 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 For floating point, initialization is harder, x and y will be floating point, but still no rounding required 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Example: (2,2) to (7,6) x=5, y=4 x y d 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Filling polygons Sampling polygons: When is a pixel inside a polygon? Given a pixel, which polygon does it lie in? Point location Polygon representation: Polygon defined by a list of edges - each is a pair of vertices All vertices are inside the view volume and map to valid pixels (clipping gave us this). Assume integers in window coordinates to simplify things for now 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 What is inside - 1? Easy for simple polygons - no self intersections or holes OpenGL requires these. Undefined for other cases OpenGL also requires convex polygons – easy triangulation For general polygons, three rules are possible: Non-exterior rule: A point is inside if every ray to infinity intersects the polygon Non-zero winding number rule: Draw a ray to infinity that does not hit a vertex, if the number of edges crossing in one direction is not equal to the number crossing the other way, the point is inside Parity rule: Draw a ray to infinity and count the number or edges that cross it. If even, the point is outside, if odd, it’s inside 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Inside/Outside Rules Polygon Non-exterior Non-zero Winding No. Parity 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 What is inside - 2? Assume sampling with an array of spikes If spike is inside, pixel is inside 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 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 Aim: A consistent rule that (almost) always results in one polygon “owning” the edge One Rule: if (x+, y+) is in, (x,y) is in (for arbitrarily small ) Another: edge belongs to polygon on same side as some off-screen point What if a pixel is on a vertex? Do our rules still work? 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Ambiguous Case 1 Rule 1: On edge? If (x+, y+) is in, pixel is in Which pixels are colored? Rule 2: If polygon is on same side as point (huge,huge) Which pixels? Corners? 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Ambiguous Case 2 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Ambiguous Case 2 ? ? ? or ? 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 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? 1 6 2 5 3 4 10/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 Exploiting Coherence When filling a polygon Several contiguous pixels along a row tend to be in the polygon - 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/21/04 © University of Wisconsin, CS559 Fall 2004

© University of Wisconsin, CS559 Fall 2004 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/21/04 © University of Wisconsin, CS559 Fall 2004