CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.

Slides:



Advertisements
Similar presentations
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Advertisements

CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CP411 polygon Lecture 6 1. Scan conversion algorithm for circle 2. Draw polygons 3. Antialiasing.
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.
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
Now Playing: Big Bird Eddie Floyd from The Complete Stax-Volt Singles Volume 1 ( ) Released April 30, 1991.
CS 454 Computer graphics Polygon Filling
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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.
Polygon Scan Conversion and Z-Buffering
Geometric Objects Computer Graphics Lab. Sun-Jeong Kim.
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 고려대학교 컴퓨터 그래픽스 연구실.
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.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 9.4 – 9.7 Tools for Raster Displays S. M. Lea University of North Carolina.
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.
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.
Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes.
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.
University of North Carolina at Greensboro
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.
Lecture 13: Raster Graphics and Scan Conversion
CS552: Computer Graphics Lecture 17: Scan Conversion (Special Cases)
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
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.
Attributes of Graphics Primitives Hearn & Baker Chapter 4
Computer Graphics Filling.
Introduction to Polygons
Polygons.
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
University of New Mexico
Implementation III.
Fill Area Algorithms Jan
Midterm Review Computer Graphics Hardware Point and Line Drawing
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
Primitive Drawing Algorithm
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
Primitive Drawing Algorithm
Where We Stand At this point we know how to: Next thing:
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu

Announcement Project 5 help session today, 5-6pm in FL 320 Paolo has implemented project, will go over it, answer questions

So Far… Raster graphics: Image manipulation Line drawing algorithms (simple, Bresenham’s) Today: Defining and filling regions Polygon drawing and filling Antialiasing

Defining and Filling Regions of Pixels First, understand how to define and fill any defined regions Next, how to fill regions bounded by a polygon

Defining and Filling Regions of Pixels Methods of defining region Pixel-defined: specifies pixels in color or geometric range Symbolic: provides property pixels in region must have Examples of symbolic: Closeness to some pixel Within circle of radius R Within a specified polygon

Pixel-Defined Regions Definition: Region R is the set of all pixels having color C that are connected to a given pixel S 4-adjacent: pixels that lie next to each other horizontally or vertically, NOT diagonally 8-adjacent: pixels that lie next to each other horizontally, vertically OR diagonally 4-connected: if there is unbroken path of 4-adjacent pixels connecting them 8-connected: unbroken path of 8-adjacent pixels connecting them

Recursive Flood-Fill Algorithm Recursive algorithm Starts from initial pixel of color, intColor Recursively set 4-connected neighbors to newColor Flood-Fill: floods region with newColor Basic idea: start at “seed” pixel (x, y) If (x, y) has color intColor, change it to newColor Do same recursively for all 4 neighbors

Recursive Flood-Fill Algorithm Note: getPixel(x,y) used to interrogate pixel color at (x, y) void floodFill(short x, short y, short intColor) { if(getPixel(x, y) == intColor) { setPixel(x, y); floodFill(x – 1, y, intColor); // left pixel floodFill(x + 1, y, intColor); // right pixel floodFill(x, y + 1, intColor); // down pixel floodFill(x, y – 1, intColor); // fill up }

Recursive Flood-Fill Algorithm This version defines region using intColor Can also have version defining region by boundary Recursive flood-fill is somewhat blind and some pixels may be retested several times before algorithm terminates Region coherence is likelihood that an interior pixel mostly likely adjacent to another interior pixel Coherence can be used to improve algorithm performance A run is a group of adjacent pixels lying on same Exploit runs(adjacent, on same scan line) of pixels

Region Filling Using Coherence Example: start at s, initial seed

Region Filling Using Coherence Pseudocode: Push address of seed pixel onto stack while(stack is not empty) { Pop the stack to provide next seed Fill in the run defined by the seed In the row above find the reachable interior runs Push the address of their rightmost pixels Do the same for row below current run } Note: algorithm most efficient if there is span coherence (pixels on scanline have same value) and scan-line coherence (consecutive scanlines are similar)

Filling Polygon-Defined Regions Problem: Region defined by Polygon P with vertices Pi = (Xi, Yi), for i – 1…N, specifying sequence of P’s vertices P1 P7 P6 P5 P4 P3 P2

Filling Polygon-Defined Regions Solution: Progress through frame buffer scan line by scan line, filling in appropriate portions of each line Filled portions defined by intersection of scan line and polygon edges Runs lying between edges inside P are filled

Filling Polygon-Defined Regions Pseudocode: for(each scan Line L) { Find intersections of L with all edges of P Sort the intersections by increasing x-value Fill pixel runs between all pairs of intersections }

Filling Polygon-Defined Regions Example: scan line y = 3 intersects 4 edges e3, e4, e5, e6 Sort x values of intersections and fill runs in pairs Note: at each intersection, inside-outside (parity), or vice versa P1 P7 P6 P5 P4 P3 P2 e6 e5 e4 e3 3

Filling Polygon-Defined Regions What if two polygons A, B share an edge? Algorithm behavior could result in: setting edge first in one color and the another Drawing edge twice too bright Make Rule: when two polygons share edge, each polygon owns its left and bottom edges E.g. below draw shared edge with color of polygon B A B Read: Hill: , pg 571

Filling Polygon-Defined Regions How to handle cases where scan line intersects with polygon endpoints? Solution: Discard intersections with horizontal edges and with upper endpoint of any edge Hill: , pg. 572

Antialiasing Raster displays have pixels as rectangles Aliasing: Discrete nature of pixels introduces “jaggies”

Antialiasing Aliasing effects: Distant objects may disappear entirely Objects can blink on and off in animations Antialiasing techniques involve some form of blurring to reduce contrast, smoothen image Three antialiasing techniques: Prefiltering Postfiltering Supersampling

Prefiltering Basic idea: compute area of polygon coverage use proportional intensity value Example: if polygon covers ¼ of the pixel use ¼ polygon color add it to ¾ of adjacent region color Cons: computing pixel coverage can be time consuming

Supersampling Useful if we can compute color of any (x,y) value on the screen Increase frequency of sampling Instead of (x,y) samples in increments of 1 Sample (x,y) in fractional (e.g. ½) increments Find average of samples Example: Double sampling = increments of ½ = 9 color values averaged for each pixel Average 9 (x, y) values to find pixel color

Postfiltering Supersampling uses average Gives all samples equal importance Post-filtering: use weighting (different levels of importance) Compute pixel value as weighted average Samples close to pixel center given more weight 1/2 1/16 Sample weighting

Antialiasing in OpenGL Many alternatives Simplest: accumulation buffer Accumulation buffer: extra storage, similar to frame buffer Samples are accumulated When all slightly perturbed samples are done, copy results to frame buffer and draw

Antialiasing in OpenGL First initialize: glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_ACCUM | GLUT_DEPTH); Zero out accumulation buffer glClear(GLUT_ACCUM_BUFFER_BIT); Add samples to accumulation buffer using glAccum( )

Antialiasing in OpenGL Sample code jitter[] stores randomized slight displacements of camera, factor, f controls amount of overall sliding glClear(GL_ACCUM_BUFFER_BIT); for(int i=0;i < 8; i++) { cam.slide(f*jitter[i], f*jitter[i].y, 0); display( ); glAccum(GL_ACCUM, 1/8.0); } glAccum(GL_RETURN, 1.0);

References Hill, chapter 10