sr-01-07
TRANSCRIPT
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 1/37
Scan Conversion
2001.1.10
Graphics Lab.
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 2/37
ContentsScene DisplayWhat is Scan Conversion?
Line Drawing AlgorithmsCircle AlgorithmFilled-Area Primitives- Scan-Line Fill Algorithm
- Boundary Fill Algorithm- Flood-Fill Algorithm- Inside-Outside Test
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 3/37
Scene Display
Scene Displayimage
pixel H/W Device(monitor)?
Scene Display - pixel arrays frame buffer load- basic geometric structures pixel patterns
scan convert
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 4/37
Wh at is Scan Conversion?
Image display CRT H/W Device
scanning display image(approximately) pixel convert
* Graphics System,Package .
Constraint- Digital Device(raster graphics system)
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 5/37
Wh at is Scan Conversion?
Assumptionpixel position : X : Scan line number
Y : Columnnumber
0 1 2 3 4 5012
34
ScanLine
Number
Pixel Column
Number
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 6/37
L ine Drawing Algorit hm s Cartesian slope-intercept equation forstraight line
y = mx + b
x1 x2
y1
y2Slope m =x2 ±x1y2 ±y1
X I nterval xY I nterval y
y = m x -----(1)
x = -----(2)my
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 7/37
L ine Drawing Algorit hm s DDA (D igital D ifferential A nalyzer)- left endpoint right endpoint
if slope m <= 1 thenunit x interval x ( x = 1)Yk+1 = Y k + m -------------------(3)
if slope m >= 1 thenunit y interval y ( y = 1)
Xk+1 = X k + -------------------(4)- right endpoint left endpoint
x = -1, y = -1
m1
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 8/37
L ine Drawing Algorit hm s# include ³device.h´
# define ROUN D (a) ((int) (a+0.5))
void line DDA (int xa, int ya, int xb, int yb)
{ int dx = xb ± xa, dy = yb ± ya, steps, k;float x I ncrement, yincrement, x = xa, y = ya;
if (abs(dx) > abs(dy)) steps = abs(dx);else steps = abs(dy);xI ncrement = dx/(float) steps; y I ncrement = dy/(float) steps;
setPixel (ROUN D (x), ROUN D (y));for (k=0; k < steps ; k++) {
x += x I ncrement; y += y I ncrement;setPixel (ROUN D (x), ROUN D (y));}
}
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 9/37
L ine Drawing Algorit hm s
DDA A lgorithm- : Cartesian slope equation .
-Roundoff error line pathdrift pixel position .
Cartesian slope equation ,
Rounding, floating point time-consuming
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 10/37
L ine Drawing Algorit hm s Bresenham ¶s Line Algorithm
- only incremental integer calculation
- Specified Line Pathpixel Line Path
pixel position
10 11 12 13 14 1510
11121314
S pecifiedLine Path
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 11/37
L ine Drawing Algorit hm s
Y k+ 3
Y k+ 2
Y k+ 1
Y k
X k X k+ 1X k+ 2
y = mx + b
X k + 1
Y k
yY k + 1
d2
d1
y = m(X k +1) + bd1 = y - Y k
= m(X k + 1) + b ±Y k
d2 = (Y k + 1) ± y= (Y k + 1) ± m(X k + 1) ± b
I f d1 ± d2 > 0 then Y k + 1
else Y k
� Bresenham ¶s Line D rawing A lgorithm for |m| < 1
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 12/37
L ine Drawing Algorit hm s D ecision Parameter P k = x(d1 ± d2)
= 2 y* X k - 2 x* Y k + c ----(5)P k+1 = 2 y* X k+1 - 2 x* Y k+1 + c
P k+1 - P k = 2 y(X k+1 ± X k ) - 2 x(Y k+1 - Y k )unit step x direction Xk+1 = X k + 1P k+1 = P k + 2 y - 2 x(Y k+1 - Y k )
Yk+1 ± Y k 0, 1 , (5)
first decision parameter P 0 = 2 y ± xstarting pixel position (X 0, Y 0), m = y / x
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 13/37
L ine Drawing Algorit hm s� Bresenham ¶s Line D rawing A lgorithm for |m| < 1
1. I nput the two line endpoint and store the left endpointin (X 0, Y 0 ).
2. Load (X 0, Y 0 ) into the frame buffer, that is,plot the first point.3. Calculate constants x, y, and 2 y - 2 x, and
obtain the starting value for decision parameter asP 0 = 2 y ± x
4.A
t each Xk
along the line, starting at k= 0, perform thefollowing test: I f P k < 0, the next point to plot is(X k + 1, Y k ) and P k+1 = P k + 2 y
otherwise, the next point to plot is (X k + 1, Y k + 1) andP k+1 = P k + 2 y - 2 x
5. Repeat step 4 x times.
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 14/37
L ine Drawing Algorit hm sExample
endpont (20,10), (30,18) , slope = 0.8
x = 10, y = 8initial decision parameter P 0 = 2 y ± x = 6
P k < 0 : P k+1 = P k + 2 yP k >= 0 : P k+1 = P k + 2 y - 2 xk
01234
P k
62
-21410
(X k+1 , X k+1 )
(21, 11)(22, 12)(23, 12)(24, 13)(25, 14)
k
56789
P k
62
-21410
(X k+1 , X k+1 )
(26, 15)(27, 16)(28, 16)(29, 17)(30, 18)
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 15/37
L ine Drawing Algorit hm s
20 25 3010
15
18
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 16/37
L ine Drawing Algorit hm s� |m| > 1 , x, y
, |m| < 1 , unit step x directionXk+1 = X k + 1, yunit step y direction , x
� right endpoint left endpointx, y value decrease
� Horizontal Line( y = 0)Vertical Line( x = 0)diagonal Line(| x| = | y|)
F rame buffer load
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 18/37
Circle Algorit hm s� Midpoint Circle A lgorithm
- Bresenham ¶s line A lgorithm circle
f circle (x, y) = X + Y - r2 2 2
Y k
Y k -1
X k X k+ 1Midpoint
f circle (x, y)< 0 inside circle= 0 on circle> 0 outside circle
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 19/37
Circle Algorit hm s� Midpoint Circle A lgorithm
1. Input radius r and circle center ( X C,Y C), and obtain thefirst point on the circumference of a circle center on the
origin as (X
0,Y
0) = ( 0, r)2. Calculate the initial value of the Decision parameter asP0 = - r P 0 = 1 ± r (for r an integer)5
43. At each X k , starting k = 0 :
If P k < 0, next point ( X k+ 1, Y k ) and P k+ 1 = P k + 2X k+ 1 + 1else, next point ( X k+ 1, Y k -1) and P k+ 1 = P k + 2X k+ 1 + 1- 2 Y k+ 1
where 2X k+ 1 = 2X k + 2, 2Y k+ 1 = 2Y k - 2,4. Determine s ymmetr y points in the other seven octants.5. Move acutual circle center (x, y)6 . Repeat step 3 through 5 until x >= y.
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 20/37
Circle Algorit hm sExample
r = 10, (X c,Y c) = ( 0, 0)
P0 = 1 ± r = 9(X 0,Y 0) = ( 0, 10) 2X 0 = 0, 2Y 0 = 20k 012345
6
P k
-9-6-16
-38
5
(X k+1 , X k+1 )(1, 10)(2, 10)(3, 10)(4, 9)(5, 9)(6, 8)
(7, 7)
2X k+1
2468
1012
14
2Y k+1
202020181816
14
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 22/37
F illed-Area Pri m itives
Area filling on raster system- scan-line fill algorithm
: polygon, circle, ellipses, simple curves
- boundary fill algorithm: more complex boundaries,
interactive system
- flood fill algorithm
Inside ± Outside Test- odd-even rule- nonzero winding number rule
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 23/37
Scan-Line Fill Algorithm
Check the intersection points of the scan line withthe polygon edgesVertices handling
Store the sorted edge table- maximum y value for that edge- x-intercept value at lower vertex for the edge- the inverse slop of the edge
Produce the active edge list
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 24/37
Scan-Line Fill Algorithm
Chec k the intersection points
y
x
Vertices handling
: scan line passing through a vertex intersects t wo edges.: trace around pol ygon boundar y
cloc k wise or countercloc k wise: observe relative change in vertex y coordinates as we
move one edge to the next.
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 25/37
Scan-Line Fill Algorithm
Scan line y´
Scan line y
Scan line y ´ intersect vertex two intersectingedge Scan line
intersection list
Scan line y ´ intersect vertex two intersectingedgehandling
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 26/37
Scan-Line Fill Algorithmhandling : shortening lower edge to split vertices.- y value increasing : edge upper endpoint 1- y value decreasing : edge upper endpoint 1
Scan line y+ 1Scan line yScan line y-1
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 27/37
Scan-Line Fill Algorithm
Scan Line Y A
Scan Line Y D
Scan Line Y CC
C´D
A
B
01
Y A
Y D
Y C Y B X C 1/M CB
Y C X D1/M DC
Y E X D1/M DE
Y E X A1/M AE
Y B X A1/M AB
store Sorted edge tableproduce Active edge list
E
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 28/37
B oundary Fill Algorithm
Point inside a region BoundaryI nput interior point(x, y)
Test neighboring positionsuntil all pixels up to boundary color- boundary color then stop- otherwise, fill color
4-connected boundary fill algorithm8-connected boundary fill algorithmHorizontal pixel spans across scan lines
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 29/37
B oundary Fill Algorithm
4-connected 8-connected
4 ± connected, 8-connected algorithm
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 30/37
B oundary Fill Algorithm
Start position 4-connected 8-connected
stac k ing of neighboring points .
horizontal pixel spans- horizontal pixel span beginning
position
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 31/37
B oundary Fill Algorithm
12
21
stac k
1
3
31
stac k
1
5
6
541
stac k
4
6
1
5
541
stac k
4
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 32/37
B oundary Fill Algorithm
F lood- F ill A lgorithmSingle color boundaryinterior fill method- start from a interior point- reassign all pixel values
: given interior color desired fill color- more than one interior color
all interior color same color reassign- 4 ± connected, 8 ± connected
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 33/37
Inside-Outside Test
Odd ± even rule- polygon P polygon
line drawing.
- line polygon edge number counting.- odd number : P interior point- even number : P exterior point
8/6/2019 SR-01-07
http://slidepdf.com/reader/full/sr-01-07 34/37
Inside-Outside Test
A
B
C
D
EF
GP 1P
1 1exterior
interior