Presentation is loading. Please wait.

Presentation is loading. Please wait.

Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.

Similar presentations


Presentation on theme: "Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from."— Presentation transcript:

1 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt
The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from 更新时间2019年2月19日星期二5时35分45秒

2 Solution Involves Selection of Discrete Representation Values
Edited from

3 Scan Converting Lines: Characterizing the Problem
ideal line i.e. for each x, choose y i.e. for each y, choose x Edited from

4 Scan Converting Lines: The Strategy
Pick pixels closest to endpoints Select in between pixels “closest” to ideal line Objective: To minimize the required calculations. Pixels can be displayed in multiple shapes and sizes. In OpenGL, the centers of pixels are located at values halfway between intergers. Edited from

5 Scan Converting Lines: DDA (Digital Differential Analyzer) Algorithm
Calculate ideal line equation Starting at leftmost point: for each xi Calculate Select pixel at Selected Not Selected Edited from

6 Scan Converting Lines: DDA Algorithm, Incremental Form
Therefore, rather than recomputing y in each step, simply add m. The Algorithm: void Line(int x0, int y0, int xn, int yn) { int x; float dy, dx, y, m; dy = yn - y0; dx = xn - x0; m = dy/dx; y = y0; for (x = x0; x<=xn,x++){ WritePixel(x, round(y)); y += m; } Edited from

7 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt
We assume m ≤1 in the above. For larger slope, the separation between pixels can be large, generating an unacceptable rendering of the line segment. We swap the roles of x and y for line segments with larger slopes. Edited from

8 Bresenham’s Algorithm: Allowable Pixel Selections
DDA requires a floating-point addition. Bresenham derived an algorithm that avoids all floating-point claculations. Option NE Option E Not Allowed Last Selection 0 <= Slope <= 1 Edited from

9 Bresenham’s Algorithm: Iterating
0 <= Slope <= 1 Select NE Select E Edited from

10 Bresenham’s Algorithm Decision Function:
(implicit equation of the line) Edited from

11 Bresenham’s Algorithm: Calculating the Decision Function
Edited from

12 Bresenham’s Algorithm: Incremental Calculation of di
Option NE Option E Edited from

13 Bresenham’s Algorithm: The Code
void BresenhamLine(int x0, int y0, int xn, int yn) { int dx,dy,incrE,incrNE,d,x,y; dx=xn-x0; dy=yn-y0; d=2*dy-dx; /* initial value of d */ incrE=2*dy; /* decision funct incr for E */ incrNE=2*dy-2*dx; /* decision funct incr for NE */ x=x0; y=y0; DrawPixel(x,y) /* draw the first pixel */ while (x<xn){ if (d<=0){ /* choose E */ d+=incrE; x++; /* move E */ }else{ /* choose NE */ d+=incrNE; x++; y++; /* move NE */ } DrawPixel (x,y); Edited from

14 Bresenham’s Algorithm An example
12 11 10 9 8 7 4 5 6 7 8 9 Edited from

15 Bresenham’s Algorithm An example
12 11 10 9 8 7 4 5 6 7 8 9 Edited from

16 Bresenham’s Algorithm An example
12 11 10 9 8 7 4 5 6 7 8 9 Edited from

17 Another derivation: comparing d1 and d2
Allowed Option NE 0 <= Slope <= 1 d1 d2 Last Selection Option E Ref. [HA], Section 3.2.2 Edited from


Download ppt "Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from."

Similar presentations


Ads by Google