Top Banner
Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University
23

Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Dec 14, 2015

Download

Documents

Tatiana Ferring
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Basic Raster Graphics Algorithms for Drawing 2D Primitives

Prof. Lizhuang Ma

Shanghai Jiao Tong University

Page 2: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Contents

• Architecture of a Raster Display• Scan Converting Lines• Filling Rectangles• Filling Polygons• Clipping Lines• Clipping Polygons• Antialiasing

Page 3: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Architecture of a Raster Display Video

Page 4: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Definitions

• Pixel: a screen consists of N x M pixels

• Bilevel = monochrome, 1 bit / pixel

• Color: RGB/CYK/LUV…

• Bitmap / pixmap

• Frame buffer: an array of data in memory mapped to screen

Page 5: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Scan Converting Line

• A scan-converted line showing intensified pixels as black circles

Page 6: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

The Basic Incremental Algorithm

• A scan-converted line showing intensified pixels as black circles

Page 7: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

The Basic Incremental Algorithm

void Line (intx0, inty0, intx1, inty1, value) {intx;floatdy, dx, y, m;dy=y1-y0;dx=x1-x0;m=dy/dx;y=y0;for(x=x0; x<=x1; x++) {

WritePixel(x, (int)floor(y+0.5), value);y+=m;

} }

Page 8: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Midpoint Line Algorithm

Page 9: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Midpoint Line Algorithm

Page 10: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Midpoint Line Algorithm

void MidpointLine(intx0, inty0, intx1, inty1, value) {int dx, dy, incrE, incrNE, d, x, y;dy=y1-y0;dx=x1-x0;d=dy*2-dx;incrE=dy*2;incrNE=(dy-dx)*2;x=x0;y=y0;WritePixel(x, y, value);while(x<x1) {

if(d<=0) {d+=incrE;x++;} else {d+=incrNE;x++;y++;

}WritePixel(x, y, value);}

}

Page 11: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Filling Rectangles

for(y from ymin to ymax of the rectangle) {

for(x from xmin to xmax) {

WritePixel(x, y, value);

}

}

Page 12: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Filling Polygons

Page 13: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Filling Polygons

Page 14: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Filling Polygons

1. Find the intersections of the scan line with all edges of the polygon

2. Sort the intersections by increasing x coordinate

3. Fill in all pixels between pairs of intersections that lie interior to the polygon

Page 15: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Special Cases

Horizontal Edges Slivers

Page 16: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Clipping Lines

Page 17: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

The Cohen-Sutherland Algorithm

Page 18: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

The Cohen-Sutherland Algorithm

Page 19: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Clipping Polygons

Page 20: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

The Sutherland-HodgmanPolygon-Clipping Algorithm

Page 21: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.
Page 22: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.

Antialiasing

Page 23: Basic Raster Graphics Algorithms for Drawing 2D Primitives Prof. Lizhuang Ma Shanghai Jiao Tong University.