CPCS 391 Computer Graphics 1 Lecture 5: Polygon Filling

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
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Lecture Notes #11 Curves and Surfaces II
Constructing Objects in Computer Graphics
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
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.
HCI 530 : Seminar (HCI) Damian Schofield.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Graphics Programming: Polygon Filling
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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)
Modeling and representation 1 – comparative review and polygon mesh models 2.1 Introduction 2.2 Polygonal representation of three-dimensional objects 2.3.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
Curve Modeling Bézier Curves
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
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
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
C O M P U T E R G R A P H I C S Stuff Jian Chen January 15, 2010 Transformations 1/10 Describing Shape By Andries van Dam.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
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.
Geometric Objects and Transformation
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
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.
In the name of God Computer Graphics Bastanfard. Curve Function(2) Other method is approximate it using a poly-line. Just locate a set of points along.
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.
Computer Graphics I, Fall 2010 Implementation II.
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
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 Drawing Line.
Computer Graphics Filling.
Constructing Objects in Computer Graphics
Introduction to Polygons
(c) 2002 University of Wisconsin, CS559
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Constructing Objects in Computer Graphics By Andries van Dam©
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Agenda Polygon Terminology Types of polygons Inside Test
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
Where We Stand At this point we know how to: Next thing:
Presentation transcript:

CPCS 391 Computer Graphics 1 Lecture 5: Polygon Filling Instructor: Dr. Sahar Shabanah

3-D Graphics Rendering Pipeline Primitives Object space Modeling Transformation World space Viewing Transformation Camera space (I added this step to the diagram) Culling Lighting & Shading Clipping Today Projection Normalized view space Scan conversion, Hiding Image space, Device coordinates Image

2D Object Definition Lines and Polylines: lines drawn between ordered points Same first and last point make closed polyline or polygon If it does not intersect itself, called simple polygon

2D Object Definition Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon. Concave: Not convex: some two points in the polygon are joined by a line not fully contained in the polygon. Special Polygons triangle square rectangle

2D Object Definition P1 Circles r P0 Circle as polygon y r x Consist of all points equidistant from one predetermined point (the center) (radius) r = c, where c is a constant On a Cartesian grid with center of circle at origin equation is r2 = x2 + y2 Circle as polygon A circle can be approximated by a polygon with many sides (>15) y x r

2D Object Definition (Aligned) Ellipses A circle scaled along the x or y axis 1 2 3 4 5 6 7 8 9 10 Example: height, on y-axis, remains 3, while length, on x-axis, changes from 3 to 6

2D Shape Representation: Vertex-Edge Table General purpose, simple overhead, reasonable efficiency Each vertex listed once Each edge is ordered pair of indices into vertex table Sufficient information to draw shape and perform simple operations. Order does not matter, convention is edges listed in counterclockwise order. Edges 1 (1,2) 2 (2,4) 3 (4,5) 4 (5,3) 5 (3,1) Vertexes 1 (0,0) 2 (1,0) 3 (0,1) 4 (1,1) 5 (0.5,1.5)

2D Shape Representation: Splines How they work: Parametric curves governed by control points Mathematically: Several representations to choose from. More complicated than vertex lists. Simple parametric representation: Advantage: Smooth with just a few control points Disadvantage: Can be hard to control Uses: representation of smooth shapes. Either as outlines in 2D or with Patches or Subdivision Surfaces in 3D animation Paths for tweening approximation of truncated Gaussian Filters

2D to 3D Object Definition Vertices in motion (“Generative object description”) Line is drawn by tracing path of a point as it moves (one dimensional entity) Square drawn by tracing vertices of a line as it moves perpendicularly to itself (two dimensional entity) Cube drawn by tracing paths of vertices of a square as it moves perpendicularly to itself (three-dimensional entity) Circle drawn by swinging a point at a fixed length around a center point 9

Building 3D Primitives Triangles and tri-meshes Parametric polynomials, like the aforementioned splines used to define surface patches. Curves Patches Boundaries are Polynomial curves In 3D

Triangle Meshes Most common representation of shape in three dimensions All vertices of triangle are guaranteed to lie in one plane (unlike quadrilaterals or other polygons) Uniformity makes it easy to perform mesh operations: subdivision, simplification, etc. Many different ways to represent triangular meshes: http://en.wikipedia.org/wiki/Polygon_mesh

3D Shape Representation Vertex-Triangle Tables Each vertex gets listed once Each triangle is ordered triple of indices into the vertex table Edges between vertices inferred from triangles Only need the triangular mesh representations to draw the shapes; Counterclockwise ordering of vertices for normals

Polygon Fill Algorithms A standard output primitive in general graphics package is a solid color or patterned polygon area. There are two basic approaches to filling on raster systems. Scan line polygon fill: determine overlap Intervals for scan lines that cross that area, mostly used in general graphics packages Seed fill: start from a given interior point and paint outward from this point until we encounter the boundary, used in applications having complex boundaries and interactive painting systems

Seed Fill Algorithm These algorithms assume that at least one pixel interior to a polygon or region is known Regions maybe interior or boundary defined Interior-defined region

Scan Line Polygon Fill Algorithm For each scan line crossing a polygon are then sorted from left to right, and the corresponding frame buffer positions between each intersection pair are set to the specified color. 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 In the example, four pixel intersections define stretches from x=10 to x=14 and x=18 to x=24 10 14 18 24 Xk+1,yk+1 Xk , yk Scan Line yk +1 Scan Line yk Interior pixels along a scan line passing through a polygon area

Scan Line Polygon Fill Algorithm Maintaining a data structure of all intersections of polygons with scan lines Sort by scan line Fill each span 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. Problem: Calculating intersections is slow. Solution: Incremental computation / coherence

Scan Line Polygon Fill Algorithm Edge Coherence Observation: Not all edges intersect each scanline. Many edges intersected by scanline i will also be intersected by scanline i+1 Formula for scanline s is y = s, for an edge is y = mx + b Their intersection is s = mxs+ b  xs= (s-b)/m For scanline s + 1, xs+1= (s+1 - b)/m= xs+ 1/m Incremental calculation: xs+1 = xs + 1/m

Scan Line Polygon Fill Algorithm Problem of Scan-Line intersections at polygon vertices: A scan Line passing through a vertex intersects two polygon edges at that position, adding two points to the list of intersections for the scan Line In the example, scan Line y intersects 5 polygon edges and the scan Line y‘ intersects 4 edges although it also passes through a vertex y‘ correctly identifies internal pixel spans, but y need some extra processing

Scan Line Polygon Fill Algorithm Solution 1: 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 (a) (b)

Scan Line Polygon Fill Algorithm When a scan line intersects an edge endpoint (vertex), it intersects two edges. Two cases: Case A: edges are monotonically increasing or decreasing Case B: edges reverse direction at endpoint In Case A, we should consider this as only ONE edge intersection In Case B, we should consider this as TWO edge intersections Scan-line Case A Scan-line Case B

Scan Line Polygon Fill Algorithm The Algorithm Steps: Intersect each scanline with all edges using the iterative coherence calculations to obtain edge intersections quickly Sort intersections in x Calculate parity of intersections to determine in/out Fill the “in” pixels Special cases to be handled: Horizontal edges should be excluded For vertices lying on scanlines, count twice for a change in slope. Shorten edge by one scanline for no change in slope

Scan Line Polygon Fill Algorithm Need 2 data structures: Edge Table and Active Edge Table Traverse Edges to construct an Edge Table In this table, there is an entry for each scan-line. Add only the non-horizontal edges into the table. For each edge, we add it to the scan-line that it begins with (that is, the scan-line equal to its lowest y-value). Each scan-line entry thus contains a sorted list of edges. The edges are sorted left to right. (To maintain sorted order, just use insertion based on their x value.) Add edge to linked-list for the scan line corresponding to the lower vertex. Store the following: y_upper: last scanline to consider x_lower: starting x coordinate for edge 1/m: for incrementing x; compute

Active Edge List Process the scan lines from bottom to top to construct Active Edge Table during scan conversion. Maintain an active edge list for the current scan-line. When the current scan line reaches the lower / upper endpoint of an edge it becomes active. When the current scan line moves above the upper / below the lower endpoint, the edge becomes inactive Use iterative coherence calculations to obtain edge intersections quickly. AEL is a linked list of active edges on the current scanline, y. Each active edge line has the following information y_upper: last scanline to consider x_lower: edge’s intersection with current y 1/m: x increment The active edges are kept sorted by x

Scan Line Polygon Fill Algorithm Set y to the smallest y coordinate that has an entry in the ET; i.e, y for the first nonempty bucket. Initialize the AET to be empty. Repeat until the AET and ET are empty: Move from ET bucket y to the AET those edges whose y_min = y (entering edges). Remove from the AET those entries for which y = y_max (edges not involved in the next scanline), the sort the AET on x (made easier because ET is presorted Fill in desired pixel values on scanline y by using pairs of x coordinates from AET. Increment y by 1 (to the coordinate of the next scanline). For each nonvertical edge remaining in the AET, update x for the new y.

Polygon fill example Set y to smallest y with entry in ET, i.e., y for the first non-empty bucket Init Active Edge Table (AET) to be empty Repeat until AET and ET are empty: Move form ET bucket y to the AET those edges whose ymin=y (entering edges) Remove from AET those edges for which y=ymax (not involved in next scan line), then sort AET (remember: ET is presorted) Fill desired pixel values on scan line y by using pairs of x-coords from AET Increment y by 1 (next scan line) For each nonvertical edge remaining in AET, update x for new y

Polygon fill example