Computer Graphics CC416 Week 14 Filling Algorithms.

Slides:



Advertisements
Similar presentations
Computer Graphics- SCC 342
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Graphics Scan Conversion Polygon Faculty of Physical and Basic Education Computer Science Dep Lecturer: Azhee W. MD.
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
CMPE 466 COMPUTER GRAPHICS
CSCE 441: Computer Graphics Scan Conversion of Polygons
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Graphics Programming: Polygon Filling
Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.
CS 454 Computer graphics Polygon Filling
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 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 7: From Vertices to Fragments Ed Angel Professor of Computer Science, Electrical.
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.
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
From Vertices to Fragments Chapter 7. Part I Objectives Introduce basic implementation strategies Introduce basic implementation strategies Clipping Clipping.
From Vertices to Fragments II Software College, Shandong University Instructor: Zhou Yuanfeng
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.
1 Filling Graphical Shapes. 2 We know how to draw outlines Can we just fill the “inside”? …but how do we know the difference between the inside and outside?
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
.. To transform something is to change it. In geometry, there are specific ways to describe how a figure is changed. The transformations you will learn.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Week 3 Lecture 1: Implementation Based on Interactive Computer Graphics (Angel) - Chapter.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
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.
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 Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Computer Graphics Filling.
Introduction to Polygons
Computer Graphics CC416 Week 13 Clipping.
Polygons.
(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
Polygon Filling Algorithms
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
Agenda Polygon Terminology Types of polygons Inside Test
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Computer Graphics Implementation III
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Where We Stand At this point we know how to: Next thing:
Implementation III Ed Angel Professor Emeritus of Computer Science
Polygons.
Presentation transcript:

Computer Graphics CC416 Week 14 Filling Algorithms

Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting

Polygon Scan Conversion Scan Conversion = Fill How to tell inside from outside –Convex easy –Nonsimple difficult –Odd even test Count edge crossings odd-even fill

Winding Number Count clockwise crossings as positive (the curve passing through the ray from left to right, as viewed from P) Count counterclockwise crossings as negative Alternate definition of inside: inside if winding number  0 (non-zero Rule) winding number = 2 winding number = 1

Filling in the Frame Buffer Fill at end of pipeline –Convex Polygons only –Nonconvex polygons assumed to have been tessellated –Shades (colors) have been computed for vertices (Gouraud shading) –March across scan lines interpolating shades Incremental work small

Using Interpolation C 1 C 2 C 3 specified by glColor or by vertex shading C 4 determined by interpolating between C 1 and C 3 C 5 determined by interpolating between C 2 and C 3 interpolate between C 4 and C 5 along span span C1C1 C3C3 C2C2 C5C5 C4C4 scan line

Scan Line Polygon Fill Determine overlap Intervals for scan lines that cross that area. –Requires determining intersection positions of the edges of the polygon with the scan lines –Fill colors are applied to each section of the scanline that lies within the interior of the region. –Interior regions determined as in odd-even test Interior pixels along a scan line passing through a polygon area

In the given example, four pixel intersections are at x=10, x=13, x=16 and x=19 These intersection points are then sorted from left to right, and the corresponding frame buffer positions between each intersection pair are set to specified color –10 to 13, and 16 to

Scan Line Polygon Fill Some scan line intersections at polygon vertices require special handling: –A scan line passing through a vertex intersects two polygon edges at that position

Intersection points along the scan lines that intersect polygon vertices. line y ’ properties: Scan line y ’ generates an even number of intersections (crosses even number of edges). The two intersecting edges are both above the scan line We can pair the intersections to identify correctly the interior pixel spans by counting the vertex intersection two points. line y properties: Scan line y crosses odd number of edges. The two intersecting edges sharing a vertex are on opposite sides of the scan line To identify the interior pixels for scan line y, we must count the vertex intersection as only one point Scan Line y’ Scan Line y

Scan Line Polygon Fill We can distinguish these cases by tracing around the polygon boundary either in clockwise or counterclockwise order and observing the relative changes in vertex y coordinates as we move from one edge to the next. Let (y1, y2) and (y2, y3) be the endpoint y values of two consecutive edges. If y1, y2, y3 monotonically increase or decrease, we need to count the middle vertex as a single intersection point for any scan line passing through that vertex.

Scan Line Polygon Fill One method for implementing the adjustment to the vertex intersection count is to shorten some polygon edges to split those vertices that should be counted as one intersection –When the end point y coordinates of the two edges are increasing, the y value of the upper endpoint for the current edge is decreased by 1 –When the endpoint y values are monotonically decreasing, we decrease the y coordinate of the upper endpoint of the edge following the current edge

Scan Line Polygon Fill Algorithm Adjusting endpoint values for a polygon, as we process edges in order around the polygon perimeter. The edge currently being processed is indicated as a solid line. In (a), the y coordinate of the upper endpoint of the current edge is decreased by 1. In (b), the y coordinate of the upper end point of the next edge is decreased by 1 (a)(b)

The scan conversion algorithm works as follows i.Intersect each scanline with all edges ii.Sort intersections in x iii.Calculate parity of intersections to determine in/out iv.Fill the “ in ” pixels Special cases to be handled: i.Horizontal edges should be excluded ii.Vertices lying on scanlines handled by shortening of edges, Coherence between scanlines tells us that -Edges that intersect scanline y are likely to intersect y + 1 -X changes predictably from scanline y to y + 1 (Incremental Calculation Possible)

The slope of the edge is constant from one scan line to the next: –let m denote the slope of the edge. Each successive x is computed by adding the inverse of the slope and rounding to the nearest integer

Integer operations Recall that slope is the ratio of two integers: So, incremental calculation of x can be expressed as

Integer operations How to compute x intercepts incrementally using integer operations: –Initialize a counter to 0 –Increment counter by  x each time we move up to a new scan line. –If counter becomes greater or equal to  y, decrease the counter by  y

Example: m=7/3 Initial scanline counter = 0 Next scanlines –Counter =3 –Counter =6 –Counter =9 Reset counter to x-  y (9-7 = 2)

ykyk xkxk Line with slope 7/3

y0y0 x0x decrement counter

Flood Fill Algorithm These algorithms assume that at least one pixel interior to a polygon or region is known -assume that the boundary is defined by Bresenham’s

Flood Fill – 4 connect Fill can be done recursively if we know a seed point (x,y) located inside (WHITE) Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); }

Flood Fill – 8 connect flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); flood_fill(x+1, y+1); flood_fill(x+1, y-1); flood_fill(x-1, y+1); flood_fill(x-1, y-1); }