1/24/20061 Fill-Area Algorithms and Functions. 1/24/20062 Learning Objectives OpenGL state variables Color and gray scale Color functions Point attributes.

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.
Objectives Define Clipping Various clipping methods. Line clipping methods.
CHAPTER 3 2D GRAPHICS ALGORITHMS
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Two-Dimensional Viewing Jehee Lee Seoul National University.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
© 2001 By Default! A Free sample background from Slide 1 Attributes of Output Primitives Definition Parameter that affects.
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.
CMPE 466 COMPUTER GRAPHICS
The “Flood Fill” Algorithm A recursive graphics algorithm used to fill in irregular-shaped regions with a solid color.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Graphics Programming: Polygon Filling
Scan Conversion II Revision 1.4 2/13/07 Copyright 2006, Dr. Zachary Wartell, UNCC, All Rights Reserved.
CST 494/598 Computer Graphics Anshuman Razdan i3dea.asu.edu/razdan.
CS 454 Computer graphics Polygon Filling
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
IT- 601: Computer Graphics Lecture-04 Scan Conversion Jesmin Akhter Lecturer,IIT Jahangirnagar University, Savar, Dhaka,Bangladesh 9/3/2015.
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
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
1 Introduction Line attribute Color and gray scale Area filled attribute Anti-aliasing.
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.
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.
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.
Attributes of Graphics Primitives Chapter 4
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.
Chapter- 3 & Unit-2 Graphics PRIMITIVES 1. Objectives Introduction to Primitives Points & Lines Line Drawing Algorithms Digital Differential Analyzer.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Graphics PRIMITIVES Chapter- 3 & Unit-2.
Computer Graphics Filling.
Scan Conversion of Polygons
Introduction to Polygons
Computer Graphics CC416 Week 13 Clipping.
Polygons.
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Polygon Filling Algorithms
Concepts, algorithms for clipping
Agenda Polygon Terminology Types of polygons Inside Test
Computer Graphics, KKU. Lecture 7
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
ویژگیهای مبناهای گرافیکی
عَلَّمَهُ الْبَيَانَ He has taught him speech (and intelligence).
Rasterizing Polygons 2 Lecture 35 Mon, Nov 26, 2007.
CSE 411 Computer Graphics Lecture #4 Attributes of Output Primitives and Algorithms Prepared & Presented by Asst. Prof. Dr. Samsun M. BAŞARICI 1.
Primitive Drawing Algorithm
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
Primitive Drawing Algorithm
Polygons.
Presentation transcript:

1/24/20061 Fill-Area Algorithms and Functions

1/24/20062 Learning Objectives OpenGL state variables Color and gray scale Color functions Point attributes and functions Line attributes and functions Curve attributes and functions Fill-area algorithms Fill-area attribute functions Character attributes

1/24/20063 Fill-Area Algorithms Standard output primitives – solid, pattern, hollow Fill primitive – solid circle, rectangle, triangle, … Two ways of filling: –Find where each scanline overlaps area scan-line fill –Start from interior position and paint outward until boundary is reached Used in general purpose packages and paint programs.

Fill Methods Start with an inside position and paint it point by point out to the boundary Use recursion: –4-neighboring points  4-connected –8-neighboring points  8-connected Boundary Fill Algorithm when boundary has ONE specific color Flood Fill Algorithm

Fill Methods BOUNDARY We need to specify: –Interior point –Fill color –Border color Condition: –check current point color –Keep filling while not border color and not fill color FLOOD We need to specify: –Interior point –Fill color –Interior color Condition: –check current point color –Keep filling while interior color (and not fill color)

1/24/20066 Fill-Area Algorithms Scan-line polygon-fill algorithm –For convex polygons. Determine the intersection positions of the boundaries of the fill region with the screen scan lines. A F ED C B y

1/24/20067 Fill-Area Algorithms Scan-line polygon-fill algorithm –For convex polygons. Pixel positions between pairs of intersections between scan line and edges are filled with color, including the intersection pixels. A F ED C B y

1/24/20068 Fill-Area Algorithms Scan-line polygon-fill algorithm –For concave polygons. Scan line may intersect more than once: –Intersects an even number of edges –Even number of intersection vertices yields to pairs of intersections, which can be filled as previously A G E D C B y F

1/24/20069 Fill-Area Algorithms Scan-line polygon-fill algorithm –For concave polygons. Scan line may intersect more than once: –Intersects an even number of edges –Even number of intersection vertices yields to pairs of intersections, which can be filled as previously A F E D C B y G

1/24/ Fill-Area Algorithms Scan-line polygon-fill algorithm –For concave polygons. Scan line may intersect more than once: –Intersects an odd number of edges –Not all pairs are interior: (3,4) is not interior. A G F D C B y12345 E

1/24/ Fill-Area Algorithms Scan-line polygon-fill algorithm –For concave polygons. Generate 2 intersections when at a local minimum, else generate only one intersection. Algorithm to determine whether to generate one intersection or 2 intersections. –If the y-coordinate is monotonically increasing or decreasing, decrease the number of vertices by shortening the edge. –If it is not monotonically increasing or decreasing, leave the number of vertices as it is.

1/24/ Fill-Area Algorithms y increasing: decrease by 1 scan line y+1 y y-1 y decreasing: decrease by 1 The y-coordinate of the upper endpoint of the current edge is decreased by 1. The y-coordinate of the upper endpoint of the next edge is decreased by 1.

1/24/ Fill-Area Algorithms y increasing: decrease by 1 scan line y+1 y y-1 y decreasing: decrease by 1 The y-coordinate of the upper endpoint of the current edge is decreased by 1. The y-coordinate of the upper endpoint of the next edge is decreased by 1.

1/24/ Fill-Area Algorithms y increasing: decrease by 1 scan line y+1 y y-1 y decreasing: decrease by 1 The y-coordinate of the upper endpoint of the current edge is decreased by 1. The y-coordinate of the upper endpoint of the next edge is decreased by 1.

1/24/ Fill-Area Algorithms Scan-line polygon-fill algorithm –Sequential fill algorithm with incremental coordinate calculations

1/24/ Fill-Area Algorithms Example: m = 7/3 (slope of the edge) at initial scan line, set counter to 0 set increment (∆x) to 3 move to next 3 scan lines set counter successively to 3, 6, 9 at first scan line > ∆y (7), increment x and decrease the counter by 7: x = x+1, counter = 9-7 = 2

1/24/ Fill-Area Algorithms Polygon fill-in algorithm store the edges in a sorted edge table where each entry corresponds to a scan line (sorted on the smallest y value on each edge) shorten the edges that have vertex-intersection issues process scan lines from bottom of polygon to top (active edge list) for each scan line, fill-in the pixel spans for each pair of x intercepts.

1/24/ Fill-Area Algorithms Other Fill-Area Algorithms –For regions with curved boundaries Process scan line intersections with curve and fill-in with color between the two intersections

1/24/ Fill-Area Algorithms Other Fill-Area Algorithms –For areas with irregular boundaries Boundary-fill algorithm start at an inside position and paint color point by point until reaching the boundary (of different color): void boundaryFill4 (int x, int y, int fillColor, int borderColor) { int interiorColor; /* Set current color to fillColor, then perform following oprations. */ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) { setPixel (x, y); // Set color of pixel to fillColor. boundaryFill4 (x + 1, y, fillColor, borderColor); boundaryFill4 (x - 1, y, fillColor, borderColor); boundaryFill4 (x, y + 1, fillColor, borderColor); boundaryFill4 (x, y - 1, fillColor, borderColor) }

1/24/ Fill-Area Algorithms Other Fill-Area Algorithms –For areas with irregular boundaries Flood-fill algorithm start at an inside position and reassign all pixel values currently set to a given interior color with the desired fill color. void floodFill4 (int x, int y, int fillColor, int interiorColor) { int color; /* Set current color to fillColor, then perform following operations. */ getPixel (x, y, color); if (color = interiorColor) { setPixel (x, y); // Set color of pixel to fillColor. floodFill4 (x + 1, y, fillColor, interiorColor); floodFill4 (x - 1, y, fillColor, interiorColor); floodFill4 (x, y + 1, fillColor, interiorColor); floodFill4 (x, y - 1, fillColor, interiorColor) }

1/24/ Fill-Area Attributes OpenGL fill-area routines for convex polygons only. Four steps: –Define a fill pattern –Invoke the polygon-fill routine –Activate the polygon-fill feature –Describe the polygons to be filled.

1/24/ Fill-Area Attributes Define a fill pattern –Store pattern in a 32 x 32 byte array (fillPattern) –Bytes are numbered from right to left Invoke the polygon-fill routine gl.glPolygonStipple ( fillPattern) Activate the polygon-fill feature gl.glEnable ( GL.GL_POLYGON_STIPPLE ) Describe the polygons to be filled gl.glBegin ( GL.GL_POLYGON ) At the end gl.glDisable ( GL.GL_POLYGON_STIPPLE )

1/24/ Fill-Area Attributes

1/24/ Fill-Area Attributes

1/24/ (from the redbook)

1/24/ Fill-Area Attributes byte fly[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x80, (byte) 0x01, (byte) 0xC0, (byte) 0x06, (byte) 0xC0, (byte) 0x03, (byte) 0x60, (byte) 0x04, (byte) 0x60, (byte) 0x06, (byte) 0x20, (byte) 0x04, (byte) 0x30, (byte) 0x0C, (byte) 0x20, (byte) 0x04, (byte) 0x18, (byte) 0x18, (byte) 0x20, (byte) 0x04, (byte) 0x0C, (byte) 0x30, (byte) 0x20, (byte) 0x04, (byte) 0x06, (byte) 0x60, (byte) 0x20, (byte) 0x44, (byte) 0x03, (byte) 0xC0, (byte) 0x22, (byte) 0x44, (byte) 0x01, (byte) 0x80, (byte) 0x22, (byte) 0x44, (byte) 0x01, (byte) 0x80, (byte) 0x22, (byte) 0x66, (byte) 0x01, (byte) 0x80, (byte) 0x66, (byte) 0x33, (byte) 0x01, (byte) 0x80, (byte) 0xCC, (byte) 0x19, (byte) 0x81, (byte) 0x81, (byte) 0x98, (byte) 0x0C, (byte) 0xC1, (byte) 0x83, (byte) 0x30, (byte) 0x07, (byte) 0xe1, (byte) 0x87, (byte) 0xe0, (byte) 0x03, (byte) 0x3f, (byte) 0xfc, (byte) 0xc0, (byte) 0x03, (byte) 0x31, (byte) 0x8c, (byte) 0xc0, (byte) 0x03, (byte) 0x33, (byte) 0xcc, (byte) 0xc0, (byte) 0x06, (byte) 0x64, (byte) 0x26, (byte) 0x60, (byte) 0x0c, (byte) 0xcc, (byte) 0x33, (byte) 0x30, (byte) 0x18, (byte) 0xcc, (byte) 0x33, (byte) 0x18, (byte) 0x10, (byte) 0xc4, (byte) 0x23, (byte) 0x08, (byte) 0x10, (byte) 0x63, (byte) 0xC6, (byte) 0x08, (byte) 0x10, (byte) 0x30, (byte) 0x0c, (byte) 0x08, (byte) 0x10, (byte) 0x18, (byte) 0x18, (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x08 };

1/24/ Fill-Area Attributes gl.glPolygonStipple (stripe); gl.glEnable (GL.GL_POLYGON_STIPPLE); gl.glBegin (GL.GL_POLYGON); for (k = 0; k < 6; k++) { gl.glColor3f (1.0f, 0.0f, 0.0f); gl.glVertex2d (vertex[k].getX(), vertex[k].getY()); }; gl.glEnd ( ); gl.glDisable (GL.GL_LINE_STIPPLE);

Boundary Fill Algorithm void boundaryFill4 (int x, int y, int fillColor, int borderColor) { int interiorColor; /* Set current color to fillColor, then perform following oprations. */ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) { setPixel (x, y); // Set color of pixel to fillColor. boundaryFill4 (x + 1, y, fillColor, borderColor); boundaryFill4 (x - 1, y, fillColor, borderColor); boundaryFill4 (x, y + 1, fillColor, borderColor); boundaryFill4 (x, y - 1, fillColor, borderColor) }

Flood Fill Algorithm void floodFill4 (int x, int y, int fillColor, int interiorColor) { int color; /* Set current color to fillColor, then perform following operations. */ getPixel (x, y, color); if (color == interiorColor) { setPixel (x, y); // Set color of pixel to fillColor. floodFill4 (x + 1, y, fillColor, interiorColor); floodFill4 (x - 1, y, fillColor, interiorColor); floodFill4 (x, y + 1, fillColor, interiorColor); floodFill4 (x, y - 1, fillColor, interiorColor) }