Upload
bharti-vij
View
247
Download
0
Embed Size (px)
Citation preview
8/4/2019 Srno4_ conti....
1/30
Scan conversion
The scan conversion is digitation of picturedefinition into set of pixel intensity value forstorage in frame buffer .
E.g :- line drawing is accomplished bycalculating intermediate positions along theline path between two specific endpoint
positions.
8/4/2019 Srno4_ conti....
2/30
8/4/2019 Srno4_ conti....
3/30
The Problem (cont)
But what happens when we try to draw this on apixel based display?
How do we choose which pixels to turn on?
8/4/2019 Srno4_ conti....
4/30
Considerations
Considerations to keep in mind: The line has to look good
Avoid jaggies It has to be lightening fast!
How many lines need to be drawn in a typical scene? This is going to come back to bite us again and again
8/4/2019 Srno4_ conti....
5/30
Line Equations
Lets quickly review the equations involved indrawing lines
x
y
y0
yend
x end x 0
Slope-intercept line
equation:b xm y
where:
0
0
x x y ym
end
end
00 xm yb
8/4/2019 Srno4_ conti....
6/30
Lines & Slopes
The slope of a line ( m) is defined by its start andend coordinatesThe diagram below shows some examples of
lines and their slopes
m = 0
m = - 1/ 3
m = - 1/ 2
m = -1
m = -2 m = -4
m =
m = 1/ 3
m = 1/ 2
m = 1
m = 2 m = 4
m = 0
8/4/2019 Srno4_ conti....
7/30
A Very Simple Solution
We could simply work out the corresponding y coordinate for each unit x coordinate
Lets consider the following example:
x
y
(2, 2)
(7, 5)
2 7
2
5
8/4/2019 Srno4_ conti....
8/30
A Very Simple Solution (cont)
1
2
3
4
5
0
1 2 3 4 5 60 7
8/4/2019 Srno4_ conti....
9/30
8/4/2019 Srno4_ conti....
10/30
A Very Simple Solution (cont)
x
y
(2, 2)
(7, 5)
2 3 4 5 6 7
2
5
5
3
27
25m
5
42
5
32b
First work out m and b:
Now for each x value work out the y value:
5
32
5
43
5
3)3( y
5
13
5
44
5
3)4( y
5
435
455
3)5( y 5
245
465
3)6( y
8/4/2019 Srno4_ conti....
11/30
X y (y=mx+b)
2 2
3 =>(3/5)*3+(4/5)=>2.6
4 =>(3/5)*4+(4/5)=>3.2
5 =>(3/5)*5+(4/5)=>3.8
6 =>(3/5)*6+(4/5)
=>4.47 =>(3/5)*7+(4/5)
=>5
8/4/2019 Srno4_ conti....
12/30
A Very Simple Solution (cont)
Now just round off the results and turn on thesepixels to draw our line
35
32)3( y
35
13)4( y
45
43)5( y
45
24)6( y
0 1 2 3 4 5 6 7 8
0
12
3
4
5
6
7
8/4/2019 Srno4_ conti....
13/30
Which point will be scan converted bydirected method for a line whose end pointsare p1(2,3) and p2(8,5).
8/4/2019 Srno4_ conti....
14/30
8/4/2019 Srno4_ conti....
15/30
Which point will be scan converted bydirected method for a line whose end pointsare p1(2,3) and p2(5,9).
Sol: m=9-3/5-2=2 As slope is +ve y is incremented by 1 and
compute x by x=(y-b)/m
8/4/2019 Srno4_ conti....
16/30
A Very Simple Solution (cont)
However, this approach is just way too slow
In particular look out for:
The equation y = mx + b requires themultiplication of m by x Rounding off the resulting y coordinates
We need a faster solution
8/4/2019 Srno4_ conti....
17/30
A Quick Note About Slopes
In the previous example we chose to solve theparametric line equation to give us the y coordinate for each unit x coordinateWhat if we had done it the other way around?So this gives us:
where: andm
b y x
0
0
x x y y
mend
end 00 xm yb
8/4/2019 Srno4_ conti....
18/30
A Quick Note About Slopes (cont)
Leaving out the details this gives us:
We can see easily thatthis line doesnt look very good!We choose which wayto work out the linepixels based on theslope of the line
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
43
23)3( x 5
3
15)4( x
8/4/2019 Srno4_ conti....
19/30
A Quick Note About Slopes (cont)
If the slope of a line is between -1 and 1 then wework out the y coordinates for a line based on itsunit x coordinates
Otherwise we do the opposite x coordinates arecomputed based on unit y coordinates
m = 0
m = - 1/ 3
m = - 1/ 2
m = -1
m = -2 m = -4
m =
m = 1/ 3
m = 1/ 2
m = 1
m = 2 m = 4
m = 0
8/4/2019 Srno4_ conti....
20/30
8/4/2019 Srno4_ conti....
21/30
The DDA Algorithm
The digital differential analyzer (DDA) algorithmtakes an incremental
approach in order to speedup scan conversion
Simply calculate yk+1 based
on yk
The original differential analyzerw a s a p h y s i c a l m a c h i n edeveloped by Vannevar Bush atMIT in the 1930 s in order tosolve ordinary differentiale q u a t i o n s .
M o r e i n f o r m a t i o n h e r e .
http://scoter2.union.edu/~hemmendd/Encyc/Articles/Difanal/difanal.htmlhttp://scoter2.union.edu/~hemmendd/Encyc/Articles/Difanal/difanal.html8/4/2019 Srno4_ conti....
22/30
The DDA Algorithm (cont)
Consider the list of points that we determinedfor the line in our previous example:
(2, 2), (3, 2 3/ 5), (4, 3 1/ 5), (5, 3 4/ 5), (6, 4 2/ 5), (7, 5)
Notice that as the x coordinates go up by one,the y coordinates simply go up by the slope of the line
This is the key insight in the DDA algorithm
8/4/2019 Srno4_ conti....
23/30
The DDA Algorithm (cont)
When the slope of the line is between -1 and 1begin at the first point in the line and, byincrementing the x coordinate by 1, calculate the
corresponding y coordinates as follows:
When the slope is outside these limits, increment
the y coordinate by 1 and calculate thecorresponding x coordinates as follows:
m y y k k 1
m x x k k 1
1
8/4/2019 Srno4_ conti....
24/30
The DDA Algorithm (cont)
Again the values calculated by the equationsused by the DDA algorithm must be rounded tomatch pixel values
( x k , y k) ( x k+1, y k+m)
( x k , round( y k))
( xk+1, round( y
k+m))
( x k , y k) ( x k+1 / m , y k+1)
(round( x k), yk)
(round( x k+ 1 / m ), y k+1)
8/4/2019 Srno4_ conti....
25/30
DDA Algorithm Example
Lets try out the following examples:
x
y
(2, 2)
(7, 5)
2 7
2
5
x
y (2, 7)
(3, 2)
2 3
2
7
8/4/2019 Srno4_ conti....
26/30
DDA Algorithm Example (cont)
7
2
3
4
5
6
1 2 3 4 5 60 7
8/4/2019 Srno4_ conti....
27/30
The DDA Algorithm Summary
The DDA algorithm is much faster than ourprevious attempt
In particular, there are no longer anymultiplications involved
However, there are still two big issues: Accumulation of round-off errors can make the
pixelated line drift away from what was intended The rounding operations and floating point
arithmetic involved are time consuming
8/4/2019 Srno4_ conti....
28/30
8/4/2019 Srno4_ conti....
29/30
8/4/2019 Srno4_ conti....
30/30