Where We Stand At this point we know how to: Next thing:

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
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.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
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.
CS 376 Introduction to Computer Graphics 02 / 05 / 2007 Instructor: Michael Eckmann.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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)
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Polygon Scan Conversion and Z-Buffering
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
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
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.
Lecture 15: Raster Graphics and Scan Conversion
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.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Computer Graphics Filling.
Introduction to Polygons
Computer Graphics CC416 Week 13 Clipping.
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.
Fill Area Algorithms Jan
© University of Wisconsin, CS559 Spring 2004
Zhen Jiang West Chester University
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
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
Chapter 3 Graphics Output Primitives
Sweep Fill Details For row = min to row=max
(c) 2002 University of Wisconsin, CS559
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation III Ed Angel Professor Emeritus of Computer Science
Line Drawing Algorithms
Presentation transcript:

Where We Stand At this point we know how to: Next thing: Convert points from local to window coordinates Clip polygons and lines to the view volume Next thing: Determine which pixels are covered by any given line or polygon Anti-Aliasing

Drawing Lines Task: Decide which pixels to fill (samples to use) to represent a line We know that all of the line lies inside the visible region (clipping gave us this!) Issues: If slope between -1 and 1, one pixel per column. Otherwise, one pixel per row Constant brightness? Anti-aliasing? (Getting rid of the “jaggies”)

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:

Bresenham’s Algorithm Overview 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

Decision Variable Decision variable is: yi+1 d2 d1 yi xi xi+1

What Can We Decide? d1<d2 => pi negative => next point at (xi+1,yi) d1>d2 => pi positive => next point at (xi+1,yi+1) So, we know what to draw based on the decision variable How do we update it? What is pk+1?

Updating The Decision Variable If yi+1=yi+1: If yi+1=yi: What is p1 (assuming integer endpoints)?

Bresenham’s Algorithm For integers, slope between 0 and 1: x=x1, y=y1, p=2 dy - dx, draw (x, y) until x=x2 x=x+1 p>0 ? y=y+1, draw (x, y), p=p+2 y - 2 x p<0? y=y, draw (x, y), p=p+2 y Compute the constants once at the start Only does add and comparisons Floating point has slightly more difficult initialization

Example: (2,2) to (7,6) x=5, y=4 i x y p 1 2 2 3 2 3 3 1 3 4 4 -1 1 2 2 3 2 3 3 1 3 4 4 -1 4 5 4 7 5 6 5 5 6 7 6 3 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8

Filling polygons Sampling polygons: Polygon issues: When is a pixel inside a polygon? Given a pixel, which polygon does it lie in? Polygon issues: 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.) Also, assume integers in window coordinates

What is inside - 1? Easy for simple polygons - no self intersections OpenGL requires these. Undefined for other cases OpenGL also requires convex polygons For general polygons, three rules are possible: non-exterior rule non-zero winding number rule parity rule

Parity Non-zero Winding No. Polygon Non-exterior

What is inside - 2? Assume sampling with an array of spikes If spike is inside, pixel is inside

What is inside - 2? Assume sampling with an array of spikes If spike is inside, pixel is inside

Rules Ambiguous cases: On edge? if (x+d, y+e) is in, pixel is in Keeps left and bottom edges What if it’s on a vertex? Which do we want to keep?

Ambiguous Case 1 Rule: On edge? If (x+d, y+e) is in, pixel is in Which pixels are colored?

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?

Ambiguous Case 2

Ambiguous Case 2 ? ? ? or ? ? ?

Really Ambiguous

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

Sweep Fill Algorithms Watt Sect 6.4.2 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?

Spans Process - fill the bottom horizontal span of pixels; move up and keep filling Have xmin, xmax for each span Define: floor(x): largest integer < x ceiling(x): smallest integer >=x Fill from ceiling(xmin) up to floor(xmax) Consistent with convention

Algorithm For each row in the polygon: Issues: Throw away irrelevant edges Obtain newly relevant edges Fill span Update current edges Issues: How do we update existing edges? When is an edge relevant/irrelevant? All can be resolved by referring to our convention about what polygon pixel belongs to

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

When are Edges Relevant (1) Use figures and convention to determine when edge is irrelevant For y<ymin and y>=ymax of edge Similarly, edge is relevant when y>=ymin and y<ymax of edge What about horizontal edges? m’ is infinite

When are Edges Relevant (2) Convex polygon: Always only two edges active 1,2 1 1,3 3 3,4 4

When are Edges Relevant (3) 2 2? Horizontal edges Ignore them! 1 3 1,3 4? 4

Sweep Fill Details For row = min to row=max Maintain a list of active edges in case there are multiple spans of pixels - known as Active Edge List. For each edge on the list, must know: x-value, maximum y value of edge, m’ Maybe also depth, color… Keep edges in a table, indexed by minimum y value - Edge Table For row = min to row=max AEL=append(AEL, ET(row)); remove edges whose ymax=row sort AEL by x-value fill spans update each edge in AEL