Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles.

Similar presentations


Presentation on theme: "Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles."— Presentation transcript:

1 Scan Conversion A. Samal

2 Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles Hardware implementations preferable

3 Lines Compute the coordinate of the pixels that lie on a line on a 2D raster Defined by the coordinates of the end points Criteria – Thin – As close to ideal as possible – 1 pixel wide If -1<= slope <= 1 exactly 1 pixel in one column Else exactly 1 pixel in one row – Constant brightness, independent of the length & orientation – Should be drawn fast

4 Scan Conversion of Lines

5 Basic Incremental Algorithm

6 Problem for each x plot pixel at closest y – Problems for steep lines

7 Basic Incremental Algorithm Desired Line

8 Basic Incremental Algorithm Brute force algorithm Inefficient Each iteration – Floating point multiply – Floating point addition – Rounding

9 Basic Incremental Algorithm Eliminate the multiplication Incremental computation Digital Differential Analyzer (DDA)

10 Basic Incremental Algorithm If the magnitude of the slope is more than 1 change the role of x and y in the algorithm – y increases faster than x Simple but inefficient – Still there are floating point operations Bresenham’s algorithm – Uses only integer arithmetic – Avoids round function – Extended to drawing circles

11 Midpoint Line Algorithm E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

12 Midpoint Line Algorithm Compute the distance between – Q and E – Q and NE See which side of the line M lies M lies below the line – Choose NE M lies above the line – Choose E M lies on the line – Choose either E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

13 Midpoint Line Algorithm

14

15 E NE M Previous Pixel Current Pixel Choices Next Pixel Choices

16 Midpoint Line Algorithm What happens at the next grid point? – Depends on whether we choose N or NE If E is chosen E NENE M Previo us Pixel Current Pixel Choices Next Pixel Choices

17 Midpoint Line Algorithm If NE is chosen E NENE M Previo us Pixel Current Pixel Choices Next Pixel Choices

18 Midpoint Line Algorithm Summary – Choose between the two pixels (E/NE) based on the sign of the decision variable d=F(M) – Update the decision variable by adding the change along that direction – Repeat this process until the end point is reached

19 Midpoint Line Algorithm

20 Fractional arithmetic still problematic Should be avoided if possible Redefine F(x,y) by multiplying by 2 Thus F(x,y) = 2(ax+by+c) Replace all constants and the decision variable by 2 Removes all multiplications; only additions left

21 Midpoint Line Algorithm

22 MidpointLine(x0,y0,x1,y1,color) { int dx,dy,dE,dNE,d,x,y; dx=x1-x0; dy=y1-y0; d=2*dy-dx; dE=2*dy; dNE=2*(dy-dx); x=x0;y=y0; DrawPixel(x,y,color); for(x=x0;x<x1; x++) { if (d<=0) d+=dE ; else {d+=dNE; y++;} DrawPixel(x,y,color); }

23 Bresenham’s Algorithm An example 456789 7 8 9 10 11 12

24 Bresenham’s Algorithm An example 456789 7 8 9 10 11 12

25 Bresenham’s Algorithm An example 456789 7 8 9 10 11 12


Download ppt "Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles."

Similar presentations


Ads by Google