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.

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

SI23 Introduction to Computer Graphics
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Computer Graphics- SCC 342
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Polygon Rasterization
College of Computer and Information Science, Northeastern UniversityApril 17, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 9.
Convex Hull obstacle start end Convex Hull Convex Hull
Classes of Polygons Planar polygons Non-planar polygons Simple
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.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
Now Playing: Big Bird Eddie Floyd from The Complete Stax-Volt Singles Volume 1 ( ) Released April 30, 1991.
CS 454 Computer graphics Polygon Filling
Scan Conversion Week 6, Wed 8 Oct 2003
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
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.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
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
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
CS 551 / 645: Introductory Computer Graphics
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.
From Vertices to Fragments II Software College, Shandong University Instructor: Zhou Yuanfeng
Graphics Graphics Korea University cgvr.korea.ac.kr 1 2D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
College of Computer and Information Science, Northeastern UniversityMay 27, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 9 – September.
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.
Scan Conversion. Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines (done last class) – Polygons (fill polygons,
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
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.
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
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 Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
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.
Computer Graphics Filling.
Scan Conversion of Polygons
Introduction to Polygons
Polygons.
(c) 2002 University of Wisconsin, CS559
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Polygon Filling Algorithms
Computer Graphics Filling & Color.
Prof. Harriet Fell Spring 2007 Lecture 9 – January 29, 2007
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
(c) 2002 University of Wisconsin, CS559
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
NOTE.
Where We Stand At this point we know how to: Next thing:
Polygons.
Presentation transcript:

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 algorithm known as the scan-line algorithm

3 Polygon Ordered set of vertices (points) –Usually counter-clockwise Two consecutive vertices define an edge Left side of edge is inside Right side is outside Last vertex implicitly connected to first In 3D vertices are co-planar

Filling Polygons Three types of polygons 1.Simple convex2. simple concave 3. non-simple (self-intersection) Convex polygons have the property that intersecting lines crossing it either one (crossing a corner), two (crossing an edge, going through the polygon and going out the other edge), or an infinite number of times (if the intersecting line lies on an edge).

Some Problems 1. Which pixels should be filled in?2. Which happened to the top pixels? To the rightmost pixels?

Scan-Line Polygon Example Polygon Vertices Maxima / Minima Edge Pixels Scan Line Fill

Scan Line Algorithms Create a list of vertex events (bucket sorted by y)

Scan-Line Polygon Fill Algorithm Scan Line

Scan-Line Polygon Fill Algorithm The basic scan-line algorithm is as follows: –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 that lie interior to the polygon

10 Scanline Algorithms given vertices, fill in the pixels arbitrary polygons (non-simple, non-convex) build edge table for each scanline obtain list of intersections, i.e., AEL use parity test to determine in/out and fill in the pixels triangles split into two regions fill in between edges

Scan-Line Polygon Fill Algorithm (cont…)

Examples:

Solutions:

Scan Line Algorithms Create a list of the edges intersecting the first scanline Sort this list by the edge’s x value on the first scanline Call this the active edge list

Polygon Fill BC A F D E Parity 0 = even 1 = odd Parity010

Polygon Fill 2 BC A F D E Parity 0 = even 1 = odd Parity01010

Edge Tables edge table (ET) –store edges sorted by y in linked list at ymin, store ymax, xmin, slope active edge table (AET) –active: currently used for computation –store active edges sorted by x update each scanline, store ET values + current_x –for each scanline (from bottom to top) do EAT bookkeeping traverse EAT (from leftmost x to rightmost x) –draw pixels if parity odd

Scanline Rasterization Special Handling Intersection is an edge end point, say: (p0, p1, p2) ?? (p0,p1,p1,p2), so we can still fill pairwise In fact, if we compute the intersection of the scanline with edge e1 and e2 separately, we will get the intersection point p1 twice. Keep both of the p1.

Scanline Rasterization Special Handling But what about this case: still (p0,p1,p1,p2)

Edge Table

Active Edge Table (AET) A list of edges active for current scanline, sorted in increasing x y = 9 y = 8

Edge Table Bookkeeping setup: sorting in y –bucket sort, one bucket per pixel –add: simple check of ET[current_y] –delete edges if edge.ymax > current_y main loop: sorting in x –for polygons that do not self-intersect, order of edges does not change between two scanlines –so insertion sort while adding new edges suffices

Parity (Odd-Even) Rule Begin from a point outside the polygon, increasing the x value, counting the number of edges crossed so far, a pixel is inside the polygon if the number of edges crossed so far (parity) is odd, and outside if the number of edges crossed so far (parity) is even. This is known as the parity, or the odd-even, rule. It works for any kind of polygons. Parity starting from even odd even

Polygon Scan-conversion Algorithm Construct the Edge Table (ET); Active Edge Table (AET) = null; for y = Ymin to Ymax Merge-sort ET[y] into AET by x value Fill between pairs of x in AET for each edge in AET if edge.ymax = y remove edge from AET else edge.x = edge.x + dx/dy sort AET by x value end scan_fill

Rasterization Special Cases -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

For each scanline: 1. Maintain active edge list (using vertex events) 2. Increment edge’s x-intercepts, sort by x-intercepts 3. Output spans between left and right edges Scan Line Algorithms delete insert replace

Penetrating Polygons False edges and new polygons! Compare z value & intersection when AET is calculated

Flood Fill 4-fill –Neighbor pixels are only up, down, left, or right from the current pixel 8-fill –Neighbor pixels are up, down, left, right, or diagonal

4 vs 8 connected  Define: 4-connected versus 8-connected, its about the neighbors

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

Flood Fill Algorithm: 1. Draw all edges into some buffer 2. Choose some “seed” position inside the area to be filled 3. As long as you can 1. “Flood out” from seed or colored pixels » 4-Fill, 8-Fill

Flood Fill Algorithm void boundaryFill4(int x, int y, int fill, int boundary) { int curr; curr = getPixel(x, y); if ((current != boundary) && (current != fill)) { setColor(fill); setPixel(x, y); boundaryFill4(x+1, y, fill, boundary); boundaryFill4(x-1, y, fill, boundary); boundaryFill4(x, y+1, fill, boundary); boundaryFill4(x, y-1, fill, boundary); } void boundaryFill4(int x, int y, int fill, int boundary) { int curr; curr = getPixel(x, y); if ((current != boundary) && (current != fill)) { setColor(fill); setPixel(x, y); boundaryFill4(x+1, y, fill, boundary); boundaryFill4(x-1, y, fill, boundary); boundaryFill4(x, y+1, fill, boundary); boundaryFill4(x, y-1, fill, boundary); } Seed Position Fill “Color” Edge “Color”

Example Let’s apply the rules to scan line 8 below. We fill in the pixels from point a, pixel (2, 8), to the first pixel to the left of point b, pixel (4, 8), and from the first pixel to the right of point c, pixel (9, 8), to one pixel to the left of point d, pixel (12, 8). For scan line 3, vertex A counts once because it is the y min vertex of edge FA, but the y max vertex of edge AB; this causes odd parity, so we draw the span from there to one pixel to the left of the intersection with edge CB. odd even a b cd A B C D E F

Four Elaborations (cont.) A B C D E F G H I J E A B C D F G H I J

Halftoning 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.