1 1 Lecture 1 2-D Raster Graphics • Graphics Pipeline Conversion to Pixel Values Conversion to Pixel Values Data Objects Display Device • Geometric • Vector Fields • Character • Projection • Illumination • Shading •Deflect Beam • Active Phosphor 2 Lecture 1 2-D Raster Graphics Continuous Real Coordinates x y Discrete Integer Coordinates x y Rasterization - Conversion of continuous, real valued, data to integer pixel values
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
1
1
Lecture12-D Raster Graphics
• Graphics Pipeline
Conversionto
Pixel Values
Conversionto
Pixel ValuesData
ObjectsDisplayDevice
• Geometric• Vector Fields• Character
• Projection• Illumination• Shading
•Deflect Beam• Active Phosphor
2
Lecture12-D Raster Graphics
ContinuousRealCoordinates
x
y
DiscreteIntegerCoordinates
x
y
Rasterization - Conversion of continuous, real valued, data tointeger pixel values
2
3
Lecture1Line Drawing
• Line Equations
Slope - Intercept Equation
Implicit Equation
Parametric Vector Equation
Blended (Interpolation) Equation
bmxy +=
0=++ CByAx
tPPPP )( 010
rrrr−= +
)()1( 10 tPtPPrrr
+−=
4
Lecture1Line Drawing Algorithms
• Brute Force Solution
Given: (x0, y0) and (x1, y1) as endpoints
Compute slope:
Compute y-intercept:
• Least Effective / Efficient• Error Accumulation
01
01
xxyy
xy
m−−=
∆∆=
00 mxyb −=
nxxn += 0 { },...3,2,1=n bmxy nn +=
)5.0int( += nxi )5.0int( += nyj
3
5
Lecture1Line Drawing Algorithms
• Basic Incremental Approach
•Digital Difference Analyzer (DDA)
bmxy nn +=
bmxy nn += ++ 11 xxx nn ∆+=+ 1where
bxxmy nn +∆+=+ )(1
xmbmxn ∆++=
1when1 =∆+=+ xmyy nn
6
Lecture1Line Drawing Algorithms
( ))5.0int(, +nn yx
( )nn yx ,
( )myx nn ++ ,1
( ))5.0int(,1 +++ myxn
bmxy +=
4
7
Lecture1Line Drawing Algorithms
• Midpoint Checking• Minimize Errors
•Bresenham Algorithm
ny
1+ny
1+nxnx
NEeEe
bmxy +=
12 13 14
7
8
8
Lecture1Line Drawing Algorithms
• Compute Error at Each Potential PixelpixelCurrentofsCoordinate),( =nn yx
pixelEastatError=Ee
nn
n
ybxmyy
−++=−=
)1(
bxmyyyy
nn
n
−+−+==−+=
)1(1linetheonpointawhere1
pixelNorthEastatError=NEe
5
9
Lecture1Line Drawing Algorithms
)y1,SetPixel(xelse
1)y1,SetPixel(x)e(eIf
nn
nn
NNE
+
++<
ny
1+ny
1+nxnx
NEeEe
bmxy +=
12 13 14
7
8
10
Lecture1Line Drawing Algorithms
• Define Decision Parameter,
• Based on Difference of Error Terms
np
)( NEEn eexp −∆≡
{ } { }bxmyybxmee nnnnNEE −+−+−−++=− )1(1)1(
122)1(2
122)1(2
−+−+∆∆
=
−−++=
byxx
yybxm
nn
nn
6
11
Lecture1Line Drawing Algorithms
• Set Pixel Based on the Sign of np{ }
{ }1)y1,SetPixel(x
else)y1,SetPixel(x
0)(pIf
nn
nn
N
++≤
+<<
ENE
NEE
ee
ee
Cxyyxxxbxyyyxp
nn
nnn
+∆−∆=∆−∆+∆−∆+∆=
222222
)12(2 −∆+∆= bxyCNote: C is Independent of Current Position
12
Lecture1Line Drawing Algorithms
Cxyyxp nnn +∆−∆= +++ 111 22
• Iterative Calculation for Decision Parameter
)(2)1(2)(2)(2
1
111
nnnn
nnnnnn
yyxxxyyyxxxypp
−∆−−+∆=−∆−−∆=−
+
+++
=−
−∆−∆+=
+
++
chosenwasNEPixelif
chosenwasEPixelif1where
11
10
)(
)(22
nn
nnnn
yy
yyxypp
≥∆−∆+<∆+=+
02202
1nn
nnn
pxyppyp
p
7
13
Lecture1Line Drawing Algorithms
• Bresenham Line Drawing Algorithm
xyppyx
yppyx
pxn
)y,(xxypxyyyyyxxx
)y,(x),y,(x
nn
nn
nn
nn
n
startstopstartstop
stopstopstartstart
∆−∆+=++
∆+=+
<−∆=
∆−∆=∆−∆∆−=∆−=∆
+
+
22)1,1(Plot
Else2
),1(Plot )0( If
)1(0For 4.Plot 3.
2,22,2,, :ConstantsCompute2.
:EndpointsEnter1.
1
1
00
0
L
1<m
14
Lecture1Line Drawing Algorithms
• Bresenham Example
)10,20(),(62422,162,8,10
)18,30(),10,20( :Endpoints
000 ==∆−∆=−=∆−∆=∆=∆=∆
yxxypxyyyx
),25(104
),24(143
),23(-22
),22(21
),21(60
),( 11 ++ nnn yxpn
),30(9
),29(8
),28(7
),27(6
),26(5
),( 11
10
14
2
2
6
-
++ nnn yxpn
11
12
12
13
14
8
15
Lecture1Line Drawing Algorithms
20 2522 23 2421 2926 27 28 30
10
11
12
13
14
15
16
17
18
16
Lecture1Line Drawing Algorithms
• Line Drawing Issues• Endpoint Order• Convention for p=0• Slope > 1