Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.

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.
Computer Graphics- SCC 342
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Polygon Rasterization
Computer Graphics Scan Conversion Polygon Faculty of Physical and Basic Education Computer Science Dep Lecturer: Azhee W. MD.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Classes of Polygons Planar polygons Non-planar polygons Simple
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
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
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
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
CS 454 Computer graphics 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.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.
2-Dimension Viewing and Clipping
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
1/24/20061 Fill-Area Algorithms and Functions. 1/24/20062 Learning Objectives OpenGL state variables Color and gray scale Color functions Point attributes.
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:
CS 445 / 645 Introduction to Computer Graphics Lecture 8 Triangle Rasterization Lecture 8 Triangle Rasterization.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
Rasterization Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
1 CS 430/536 Computer Graphics I Polygon Clipping and Filling Week 3, Lecture 5 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
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.
Drawing Triangles CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Introduction to Computer Graphics CS 445 / 645 Lecture 9 Chapter 4: Rasterization L. McMillan MIT notes (Fall ’98)
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.
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.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Lecture 15: Raster Graphics and Scan Conversion
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
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 Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Computer Graphics Filling.
Introduction to Polygons
Polygons.
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Polygon Filling Algorithms
Computer Graphics Filling & Color.
Agenda Polygon Terminology Types of polygons Inside Test
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
عَلَّمَهُ الْبَيَانَ He has taught him speech (and intelligence).
Where We Stand At this point we know how to: Next thing:
Polygons.
Presentation transcript:

Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved

Polygons A polygon is a many-sided planar figure composed of vertices and edges. A polygon is bounded (finite area) and closed (includes boundary). Vertices are represented by points (x,y). Edges are represented as line segments which connect two points, (x1,y1) and (x2,y2). P = { (x i, y i ) } i=1,n E3 (x3,y3) E2 (x2,y2) E1 (x1,y1) Larry Hodges

Polygons: Complex vs Simple Zachary Wartell A simple polygon – edges only intersect a vertices, no coincident vertices A complex polygon – edges intersect and/or coincident vertices A B C C E F G H AB,E C D F A B C A B C D E

Simple Polygons: Convex and Concave Convex Polygon - For any two points P 1, P 2 inside the polygon, all points on the line segment which connects P 1 and P 2 are inside the polygon. –All points P = uP 1 + (1-u)P 2, u in [0,1] are inside the polygon provided that P 1 and P 2 are inside the polygon. Concave Polygon - A polygon which is not convex. Larry Hodges, Zachary Wartell

Inside vs Outside Polygon: Odd-Parity Test Larry Hodges, Zachary Wartell -Is point P inside polygon? -Count # times a ray from P intersects edge of polygon -odd count implies inside -When crossing a vertex, if the vertex’s two edges are on same side of line then count it twice, else count it once. Count onceCount twice or

Filling Concave Polygons Fill the polygon 1 scanline at a time Determine which pixels on each scanline are inside the polygon and set those pixels to the appropriate value. Look only for those pixels at which changes occur. Larry Hodges, Zachary Wartell

Scan-Line Algorithm Larry Hodges, Zachary Wartell For each scan-line: -Find the intersections of the scan line with all edges of the polygon. -Sort the intersections by increasing x-coordinate. -Fill in all pixels between pairs of intersections. Possible Problems 1.Horizontal edges ==> Ignore 2.Vertices ==> If local max or min, then count twice, else count once. (This is implemented by shortening one edge by one pixel.) 3.Calculating intersections is slow For scan-line number 7 the sorted list of x-coordinates is (1,3,7,9) Therefore fill pixels with x- coordinates 1-3 and 7-9.

Edge Coherence Larry Hodges, Zachary Wartell -Not all polygon edges intersect each scanline. -Many edges intersected by scanline y k will also be intersected by scanline y k+1 -Nearby pixels on given edge and span have similar coordinates, attributes and equation components

“scan-line aligned” trapezoids Zachary Wartell T1 T2 T3 T4 T5 T6 -break up problem into simpler ”scan-line aligned” trapezoids - only two side edges: left, right left edge of T2 right edge of T2

Edge Table Zachary Wartell T1 T2 T3 T4 T5 T6 -sort vertices by y coordinate building Edge Table (ET) y max y=0 A B C D F E G H y D,C yGyG yEyE yByB yHyH yAyA AH AB HG BC EF ED GF ET not needed

Scan AET with AEL Zachary Wartell T1 T2 T3 T4 T5 T6 -scan up through ET and track Active Edge Table (AET). At each scan-line fill in span of pixel for each edge pair. y max y=0 A C D F E G H yGyG yEyE yByB yHyH yAyA AH AB HG BC EF ED GF ET AET k (k = 1..10) [(AH,AB)] [(HG,AB)] [(HG,BC)] [(HG,EF), (DE,BC)] [(GF,EF), (DE,BC)] [(DE,BC)] B

How do we fill trapezoids? Zachary Wartell -Need to generate pixel coordinates of left and right edges of edge pair-- (lx,ly) and (rx,ry) -Need to fill pixel in span between current rx 0, lx 0 y0y0 rx 2 rx 3 lx 1, lx 2, lx 3 H G y1y1 y2y2 y3y3 rx 1

Rasterize Edge Zachary Wartell -From y=mx + b we have: y k+1 = y k +1, x k+1 = x k + 1 / m = x k + Δx / Δy - fractions yuck! -So split into integer and fraction and look at fraction numerator: x k+1 = x k + (Δx div Δy) + (Δx mod Δy) / Δy integer fraction x k = xi k + xn k / Δ y, xi is integer component xn is x’s fraction’s numerator x k=0 y k=0 ykyk y k+1 xkxk x k+1 … … B

Rasterize Edge Larry Hodges, Zachary Wartell -Base Case: xi = x 0, xn = 0 -Iteration Case: xi is integer component, xn is fraction numerator xi := xi + (Δx div Δy) xn := xn + (Δx mod Δy) if xn ≥ Δy then xi := xi + 1 xn := xn – Δy endif A=(6,1) B=(13,4) Δx=7 Δy=3 Δx div Δy= 2 Δx mod Δy= 1 k y xi xn x (=xi+xn/Δy) / / /3 (8,2) (10,3) Warning: H&B doesn’t handle Δx > Δy

Rasterization Special Cases Larry Hodges, Zachary Wartell -Previous slide truncated to obtain integer x coordinate, alternatively use rounding -you end up with a fraction (comparing xn to Δy/2) and must multiply xn by 2 to get all integer operations -Often polygons share edges, to avoid writing the same pixel twice possibly: -horizontal edge – only drawn when on top -right edge – round up -left edge – round down, if xn = 0

Rasterization Special Cases Larry Hodges, Zachary Wartell -Edge Shortening Trick: -Recall Odd-Parity Rule Problem: -Implement “Count Once” case with edge shortening: C B A B C B A B' B B' x A,y B’,1/m AB x C,y B’,1/m CB

Splitting Concave Polygons – Concept  Concave can be split into Convex Polygons – this simplifies Edge Table and Active Edge Table in polygon rasterizer (only one scan-line trapezoid is active at a time!)  Identify: look for interior angle greater than 180º - cross product signs will differ X Y E1E1 E2E2 E3E3 E4E4 E5E5 E6E6 (E 1 X E 2 ) z > 0 (E 2 X E 3 ) z > 0 (E 3 X E 4 ) z < 0 (E 4 X E 5 ) z < 0 (E 5 X E 6 ) z > 0 (E 6 X E 1 ) z > 0 i j k x0 y0 z0 x1 y1 z1 ©Zachary Wartell - 1/26/2005

Splitting Concave Polygons  Edge Vector: Compute Edge Vectors (E k = V k+1 - V k ) traversing polygon counter- clockwise. If cross product of consecutive edge is negative, then split polygon along the embedding line of first edge in cross product  Rotational: put successive edges on x-axis. If next edge has negative x coordinate split polygon on x-axis. X Y E1E1 E2E2 E3E3 E4E4 E5E5 E6E6 X Y E1E1 E2E2 E3E3 E4E4 E5E5 E6E6 X Y X Y ©Zachary Wartell - 1/26/2005

Splitting Convex Polygon to Triangles  Triangle rasterizing is even simpler. Only 3 edges to “sort”. Only fill in 1 or 2 scan-line aligned triangles. Pretty much what all graphics hardware does.  Pick 3 vertices of convex polygon. Split off triangle. Repeat with remaining vertices. Continue until only 3 vertices left. v0v0 v1v1 v2v2 v3v3 v4v4 v0v0 v1v1 v2v2 v3v3 v4v4 v0v0 v1v1 v2v2 v3v3 v4v4 A)B) C) ©Zachary Wartell - 1/26/2005

Filling Irregular Boundaries Larry Hodges, Zachary Wartell  boundary fill: expand and fill region until you reach boundary color  flood fill: expand and fill region while you find interior color Boundary Fill Interior Fill

4 vs 8 connected Larry Hodges, Zachary Wartell  Define: 4-connected versus 8-connected, its about the neighbors

4 vs 8 connected Zachary Wartell  Fill Result: 4-connected versus 8-connected “seed pixel”

Recursive Pixel Boundary Fill  void boundaryFill4(int x, int y){ if(getPixel(x,y)!=borderColor && getPixel(x,y)!=fillColor ){ setPixel(x,y); boundaryFill4(x+1,y); boundaryFill4(x-1,y); boundaryFill4(x,y+1); boundaryFill4(x,y-1); } }

Recursive Scan-line (boundary) fill Zachary Wartell A B C D Stack

Fill Patterns Larry Hodges, Zachary Wartell Fill patterns can be used to put a noticeable “texture” inside a polygon. A fill pattern can be defined in a 0-based, m x n array. A pixel (x,y) is assigned the value found in: pattern((x mod m), (y mod n)) PatternPattern filled polygon

Halftoning Larry Hodges, Zachary Wartell For 1-bit (B&W) displays, fill patterns with different fill densities can be used to vary the range of intensities of a polygon. The result is a tradeoff of resolution (addressability) for a greater range of intensities and is called halftoning. The pattern in this case should be designed to avoid being noticed. These fill patterns are chosen to minimize banding.

Dithering Larry Hodges, Zachary Wartell Another method to increasing the number of apparent intensities on a 1-bit (B&W) display is dithering. In an ordered dither the decision to turn a pixel on or off at point (x,y) depends on the desired intensity I(x,y) at that point and on an (n by n) dither matrix D n. The dither matrix is indexed from 0 to (n-1) along its rows and columns. Each of the integers 0 to n 2 -1 appears once in the matrix. For instance when n = 4, we have D 4 = To process the point at (x,y), we first compute i = x MOD 4, j = y MOD 4 Then if I(x,y) > D 4 (i, j) the point (x,y) is turned on; otherwise it is not.

Revisions Larry Hodges, Zachary Wartell Removed slide 17 “Antialiasing Polygons” (putting anti-aliasing from H&B in separate.ppt) Fixed error in slide –Added Slide 23 ‘Recursive Pixel Boundary Fill’ –clarified diagram in slide 24 and noted subtly/error found in textbook.