# CSCE 441: Computer Graphics Scan Conversion of Polygons

## Presentation on theme: "CSCE 441: Computer Graphics Scan Conversion of 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?

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!

Download ppt "CSCE 441: Computer Graphics Scan Conversion of Polygons"

Similar presentations