CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

Computer Graphics- SCC 342
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
CMPE 466 COMPUTER GRAPHICS
Polygon Rasterization
Computer Graphics Scan Conversion Polygon Faculty of Physical and Basic Education Computer Science Dep Lecturer: Azhee W. MD.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
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.
CPCS 391 Computer Graphics 1 Lecture 5: Polygon Filling
Query Processing in Databases Dr. M. Gavrilova.  Introduction  I/O algorithms for large databases  Complex geometric operations in graphical querying.
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
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
CS 454 Computer graphics Polygon Filling
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)
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
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.
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
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.
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.
College of Computer and Information Science, Northeastern UniversityMay 27, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 9 – September.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
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.
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.
Lecture 15: Raster Graphics and Scan Conversion
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
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
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.
Computer Graphics Clipping.
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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Fill Area Algorithms Jan
Polygon Filling Algorithms
© University of Wisconsin, CS559 Fall 2004
Agenda Polygon Terminology Types of polygons Inside Test
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
Prepared by Narendra V G CSE MIT
Agenda Polygon Terminology Types of polygons Inside Test
Lecture 13 Clipping & Scan Conversion
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
(c) 2002 University of Wisconsin, CS559
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
NOTE.
Primitive Drawing Algorithm
Where We Stand At this point we know how to: Next thing:
Polygons.
Presentation transcript:

CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE

DRAWING POLYGONS IN OPENGL

OPENGL POLYGONS There are 4 primitive types associated with polygons in OpenGL: GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN In ALL cases: Vertices MUST be specified in COUNTERCLOCKWISE order! If less than 3 vertices given  nothing drawn Deprecated/Legacy: GL_QUADS, GL_QUAD_STRIP

GL_POLYGON In legacy: glBegin(GL_POLYGON); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glVertex2iv(p6); glEnd(); Draws a polygon out of all vertices If not convex, no guarantee it will be filled properly

GL_TRIANGLES We’re going to reorder the vertices a bit… In legacy: glBegin(GL_TRIANGLES); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p6); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glEnd(); Draws a separate triangle every 3 vertices Any remaining vertices ignored For N (distinct) vertices  N/3 triangles

GL_TRIANGLE_STRIP Again, we’re going to reorder the vertices a bit… In legacy: glBegin(GL_TRIANGLE_STRIP); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p6); glVertex2iv(p3); glVertex2iv(p5); glVertex2iv(p4); glEnd(); Draws triangle with first 3 vertices For each new vertex  draw triangle with new vertex + last 2 vertices For N (distinct) vertices  (N – 2) triangles

GL_TRIANGLE_FAN Yet again, we’re going to reorder the vertices a bit… In legacy: glBegin(GL_TRIANGLE_FAN); glVertex2iv(p1); glVertex2iv(p2); glVertex2iv(p3); glVertex2iv(p4); glVertex2iv(p5); glVertex2iv(p6); glEnd(); Draws triangle with first 3 vertices All triangles share first vertex For each new vertex  draw triangle with new vertex + first vertex + last vertex For N (distinct) vertices  (N – 2) triangles

INSIDE-OUTSIDE TESTS

INTRODUCTION If we’re dealing with a more complex object (e.g., a self-intersecting polygon, for instance), how do we know what’s inside and outside the polygon? Two common approaches: Odd-Even Rule Nonzero Winding-Number Rule

A COUPLE OF NOTES We’re assuming these polygons are in the XY plane (e.g., after screen mapping) Also, both approaches involve drawing a line: Starting at some point P in a region we want to check Ending somewhere well outside the polygon …and checking what we cross with that line

ODD-EVEN RULE Also called odd-parity or even-odd rule Draw line from position P inside region to distant point Count how many edges we cross

ODD-EVEN RULE Can use to check other kinds of regions E.g., area between two concentric circles

NONZERO WINDING-NUMBER RULE Count number of times boundary of object “winds” around a particular point in the clockwise direction Again, draw line from position P inside region to distant point Start “winding number” W at 0 If interest with segment that crosses the line going from: Right-to-left (counterclockwise)  add 1 to W Left-to-right (clockwise)  subtract 1 from W Check value of W when done: If W == 0  EXTERIOR If W != 0  INTERIOR

NONZERO WINDING-NUMBER RULE To check the direction of the edge relative to the line from P: Make vectors for each edge (in the correct winding order)  vector E i Make vector from P to distant point  vector U Two options: Use cross product: If ( U x E i ) = +z axis  right-to-left  add 1 to winding number If ( U x E i ) = –z axis  left-to-right  subtract 1 from winding number Use dot product: Get vector V that is 1) perpendicular to U, and 2) goes right-to-left  ( -u y, u x ) If ( V · E i ) > 0  right-to-left  add 1 to winding number Otherwise  left-to-right  subtract 1 from winding number

ODD-EVEN VS. NONZERO WINDING- NUMBER For simple objects (polygons that don’t self-intersect, circles, etc.), both approaches give same result However, more complex objects may give different results Usually, nonzero winding-number rule classifies some regions as interior that odd-even says is exterior Odd-Even RuleNonzero Winding-Number Rule

INSIDE-OUTSIDE PROBLEM Caveat: need to check we don’t cross endpoints (vertices) Otherwise, ambiguous

CURVED PATHS? For curved paths, need to computer intersection points with underlying curve For nonzero winding-number  also have to get tangent vectors

VARIATIONS OF NONZERO WINDING- NUMBER RULE Can be used to define Boolean operations (i.e., sets) Positive W only, both counterclockwise  union of A and B W > 1, both counterclockwise  intersection of A and B Positive W only, B clockwise  A - B

POLYGON FILLING ALGORITHMS

INTRODUCTION Two basic ways to fill in a polygon: Scan-line approach For each scan line the polygon touches, check which pixels on scan line are within polygon boundaries Flood-fill or Boundary fill approaches Start at interior pixel  “paint” outwards until we hit boundaries

GENERAL SCAN-LINE POLYGON FILLING ALGORITHM

BASIC IDEA General scan-line polygon filling algorithm Find intersection points of polygon with scan lines Sort intersections from left to right For each scan line Fill in interior pixels along scan line Determine interior pixels using odd-even rule Polygons easiest to fill  edges are linear equations  intersecting with y = constant

PROBLEM: CROSSING VERTICES What happens if we cross a vertex? In some cases, want to “count” it once, but in others you want it to count twice…

SOLUTION TO CROSSING VERTICES Look at y coordinates of previous vertex, middle vertex (the one we’re intersection), and the next vertex If y values monotonically increase or decrease  edges on opposition sides of scan line  count vertex as one Otherwise  edges on same side of scan line  vertex is a local max/min  count vertex twice

IMPLEMENTATION CROSSING VERTEX SOLUTION Go through all edges, winding around polygon Check if any set of vertices v k-1, v k, and v k+1 have y values that monotonically increase/decrease Option 1: if yes, short one of the edges Inherently assumes that polygon is a set of lines, each with their own vertices So, if you do nothing, crossing a vertex  really crossing two vertices  already counts as two Option 2: if not, separate into two vertices Inherently assumes that edges already share vertices So, if you do nothing, crossing a vertex counts as one Min/max vertices become two vertices with same location

COMPUTING INTERSECTIONS Similar to DDA and Bresenham, we can compute the intersection points of each edge with each scan line by adding some value to x and y as we move along: Given that the slope is a fraction of integers, we can instead have a counter w Every time we increment y, we add Δx to w If (w >= Δy)  subtract Δy from w, and increment/decrement x Basically same as keeping track of integer and fractional parts

IMPLEMENTING SCAN-LINE FILLING To do this efficiently, we need to know which edges we need to work with for each scanline Thus, we will have two lists: Sorted edge table Create this before we start fill Active edge table Create and update this as we fill the polygon

SORTED EDGE TABLE List for each scanline in window/screen  array of lists scanList[] Each list should be sorted by the x values (smallest to largest) For each edge E in the polygon Determine/compute the following: Smallest y value (ymin) and corresponding x value Largest y value Inverse of slope (or Δx and Δy) Insert edge E into SORTED scanList[ymin] I.e., when the edge starts Only need to add non-horizontal edges Also, if you’re going to shorten any edges, this is a good time to do so

SORTED EDGE TABLE: EXAMPLE

ACTIVE EDGE TABLE List also sorted by x values (left to right) For each scanline y: Add corresponding list from sorted edge table to active list I.e., add any new edges Again, must add new edges so that the active list is still sorted by x! Fill in appropriate areas along scanline using active list for x coordinate boundaries I.e., odd-even rule Remove any edges that are complete I.e., y = ymax for that edge Update x values for next iteration I.e., add inverse slope Resort edges by x values