CSCE 441: Computer Graphics Scan Conversion of Polygons

Slides:



Advertisements
Similar presentations
Polygon Scan Conversion – 11b
Advertisements

CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
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.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Drawing Geometric Objects
Graphics Programming: Polygon Filling
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
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)
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
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.
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
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 2D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
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.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
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.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
Lecture 15: Raster Graphics and Scan Conversion
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
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 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.
CS552: Computer Graphics Lecture 16: Polygon Filling.
CSCE 441 Lecture 2: Scan Conversion of Lines
CSC Graphics Programming
Computer Graphics Filling.
Scan Conversion of Polygons
Introduction to Polygons
Polygons.
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
Computer Graphics Filled Area Primitives II Lecture 09 Taqdees A
Fill Area Algorithms Jan
Polygon Filling Algorithms
Query Processing in Databases Dr. M. Gavrilova
Objectives OpenGL drawing primitives and attributes
Prof. Harriet Fell Spring 2007 Lecture 9 – January 29, 2007
CSCE 441 Lecture 2: Scan Conversion of Lines
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Agenda Polygon Terminology Types of polygons Inside Test
CSCE 441 Computer Graphics: Clipping Lines 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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Programming with OpenGL Part 4: Color and Attributes
Primitive Drawing Algorithm
Rasterizing Polygons Lecture 29 Wed, Dec 7, 2005.
Primitive Drawing Algorithm
Polygons.
Presentation transcript:

CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN

OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINE_STRIP GL_LINE_LOOP GL_POLYGON GL_LINES GL_POINTS GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN

Drawing General Polygons How to draw every interior pixels? ?

Drawing Curved Objects How to draw every interior pixels? ?

Outline Methods for drawing polygons or curved objects - Scanline conversion of polygons - Boundary-fill - Flood-fill Required readings: - HB 4-9 to 4-14

Which pixels should be filled? Drawing Rectangles Which pixels should be filled?

Drawing Rectangles Is this correct?

What if two rectangles overlap? Drawing Rectangles What if two rectangles overlap?

Drawing Rectangles Is this correct?

Drawing Rectangles Overlap!!! Is this correct?

Solution: Exclude pixels on top and right Drawing Rectangles Solution: Exclude pixels on top and right

Artifacts are possible Drawing Rectangles Artifacts are possible

General Polygons – Basic Idea How to draw every interior pixels?

General Polygons – Basic Idea How to draw every interior pixels for a scan line?

General Polygons – Basic Idea Intersect scan lines with edges Find ranges along x Fill interior of those ranges Don’t fill top/right Edges may NOT match with line drawing algo

General Polygons – Basic Idea Use coherence to speed up Intersect scan lines with edges Find ranges along x Fill interior of those ranges Don’t fill top/right Edges may NOT match with line drawing algo

General Polygons – Basic Idea Use coherence to speed up Intersect scan lines with edges Find ranges along x Fill interior of those ranges Edges intersecting one scan line are mostly same as those intersecting previous scan line

General Polygons – Basic Idea Use coherence to speed up Intersect scan lines with edges Find ranges along x Fill interior of those ranges The x-value of an intersection with one scan line is close to the intersection with the previous one

How to store polygon edges?

General Polygons – Data Structures Sorted Edge Table: Store a linked-list per scan-line. Insert edges into table at scan-line associated with lowest end-point. Scan Lines Edges

General Polygons – Example C Sorted Edge Table B D G F E A

General Polygons – Example C Sorted Edge Table B D G F E A

General Polygons – Example C Sorted Edge Table B D G AB AG F E A

General Polygons – Example C Sorted Edge Table B D G AB AG F E Exclude horizontal edges! A

General Polygons – Example C Sorted Edge Table B D G FG ED AB AG F E A

General Polygons – Example C Sorted Edge Table B D CD G FG ED AB AG F E A

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG F E A

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG F E Which edges are intersecting with the current scan line? A

General Polygons – Data Structures Active Edge List: List of all edges intersecting current scan-line sorted by their x-values Edges

General Polygons – Data Structures Active Edge List: List of all edges intersecting current scan-line sorted by their x-values Edges Implement active edge list with linked list

General Polygons – Data Structures Active Edge List: List of all edges intersecting current scan-line sorted by their x-values Edges Implement active edge list with linked list So what kind of information should be stored in the linked list for our polygon drawing algorithm?

General Polygons – Data Structures Edge: maxY: highest y-value currentX: x-value of end-point with lowest y-value xIncr: 1 / slope Edge mazY currentX xIncr

Scan line intersection Scan line yk+1 Scan line yk

Scan line intersection Scan line yk+1 Scan line yk

General Polygons – Data Structures Edge: maxY: highest y-value currentX: x-value of end-point with lowest y-value xIncr: 1 / slope Edge mazY currentX xIncr Horizontal edges will not be used!!!

General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment line

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E A

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG A maxY currentX xIncr

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List? F E A

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E FG ED A maxY currentX xIncr

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E FG ED A maxY Is it correct? currentX xIncr

General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment line

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY ? ? ? currentX ? xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Active Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment scan line

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG FG ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB ED CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB BC CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB BC CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E BC CD A maxY currentX xIncr

General Polygons – Example C Active Edge Table B BC D CD G FG ED AB AG Active Edge List F E BC CD A maxY currentX xIncr

General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment scan line

Pixel Fill-in Which intervals should we draw?

Pixel Fill-in Which intervals should we draw? - Odd intervals. But need to pay attention to scan lines passing through vertices.

General Polygons – Problems Sliver polygons may not be drawn correctly No simple solution Long, thin triangles cause problems Want triangles with good aspect ratio (close to equilateral)

Curved Boundaries How to deal with curved boundaries?

Boundary Fill Start with drawn boundaries and an interior point Recursively recolor outward from that point If neighbor different, then recolor and recur Everything within the boundary is changed to that color

Boundary Fill Start with drawn boundaries and an interior point Recursively recolor outward from that point If neighbor different, then recolor and recur Everything within the boundary is changed to that color

Boundary Fill Work for inner and outer boundaries

Boundary Fill Start with drawn outline of a polygon and an interior point Recursively recolor outward from that point If neighbor different, then recolor and recur Everything within the boundary is changed to that color

Boundary Fill How to define a neigbhbor? 8-connected 4-connected

Boundary Fill – Example Black pixels indicate boundary pixels

Boundary Fill – Example

Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Boundary Fill – Example Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Boundary Fill

How to deal with this? Multiple color boundaries? How to paint this region to yellow?

How to deal with this? Multiple color boundaries? Three keys: a start pixel a target color a paint color How to paint this region to yellow?

Flood Fill Start with a point Define color under that point as the interior color Recursively recolor outward from that point If neighbor is interior color, then recolor and recur Contiguous regions are recolored

Flood Fill – Example

Flood Fill – Example

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!

Flood Fill – Example Continue setting the colors for neighboring pixels if it is interior pixels!