cp0450_01-aug-2011_rm01
TRANSCRIPT
-
8/2/2019 CP0450_01-Aug-2011_RM01
1/34
CAD/CAM
Rasterisation
Scan conversion of lines
-
8/2/2019 CP0450_01-Aug-2011_RM01
2/34
What you will learn today!!
Convert vector straight lines to raster images
to be displayed on a raster terminal utilizing
the pixel information
Understand the problems associated with
displaying vectorial information on a raster
terminal
-
8/2/2019 CP0450_01-Aug-2011_RM01
3/34
Contents
In todays lecture well have a look at:
Vector and Raster Graphics
Bresenhams line drawing algorithm
Line drawing algorithm comparisons
Polygon fill algorithms
Anti-aliasing
Summary of raster drawing algorithms
-
8/2/2019 CP0450_01-Aug-2011_RM01
4/34
4
Representations in graphics
Vector Graphics
Image is represented by continuous geometric
objects: lines, curves, etc.
Raster Graphics
Image is represented as an rectangular grid ofcoloured squares
-
8/2/2019 CP0450_01-Aug-2011_RM01
5/34
5
Vector graphics
Graphics objects: geometry + colour
Complexity ~ O(number of objects)
Geometric transformation possible withoutloss of information (zoom, rotate, )
Diagrams, schemes, ...
Examples: PowerPoint, CorelDraw, ...
-
8/2/2019 CP0450_01-Aug-2011_RM01
6/34
6
Raster graphics
Generic
Image processing techniques
Geometric Transformation: loss of information
Complexity ~ O(number of pixels)
Jagged edges, anti-aliasing Realistic images, textures, ...
Examples: Paint, PhotoShop, ...
-
8/2/2019 CP0450_01-Aug-2011_RM01
7/34
7
Conversion
Vector graphics
Rasterization, Pattern recognition
Scan conversion
Raster graphics
-
8/2/2019 CP0450_01-Aug-2011_RM01
8/34
Rasterization
Rasterization (scan conversion)
Determine which pixels that are inside primitivespecified by a set of vertices
Produces a set of fragments Fragments have a location (pixel location) and
other attributes such color and texturecoordinates that are determined by interpolating
values at vertices Pixel colors determined later using color,
texture, and other vertex properties
8
-
8/2/2019 CP0450_01-Aug-2011_RM01
9/34
Line Drawing
Assuming:
Clipped (to fall within the window)
2D screen coordinates
Each pixel covers a square region
where is its center?
Rounding (X, Y) implies center at (0.0, 0.0).
Truncating implies center at (0.5, 0.5).
-
8/2/2019 CP0450_01-Aug-2011_RM01
10/34
DDA
DDA or Digital Differential Analyser is one of
the first algorithms developed for rasterising
the vectorial information.
The equation of a straight line is given by
Y = m X + C
-
8/2/2019 CP0450_01-Aug-2011_RM01
11/34
-
8/2/2019 CP0450_01-Aug-2011_RM01
12/34
Problem
DDA = for each x plot pixel at closest y
Problems for steep lines
12
-
8/2/2019 CP0450_01-Aug-2011_RM01
13/34
Using Symmetry
Use for 1 m 0
For m > 1, swap role of x and y
For each y, plot closest x
13
-
8/2/2019 CP0450_01-Aug-2011_RM01
14/34
The Solution
Move across thex axis in unit intervals and ateach step choose between two differenty
coordinates
2 3 4 5
2
4
3
5 For example, fromposition (2, 3) we have
to choose between (3,
3) and (3, 4)
We would like the
point that is closer to
the original line
(xi,yi)
(xi+1,yi)
(xi+1,yi+1)
-
8/2/2019 CP0450_01-Aug-2011_RM01
15/34
They coordinate on the mathematical line atxi+1
is:
Deriving The Bresenham Line Algorithm
At sample positionxi+1 the verticalseparations from the
mathematical line arelabelled d2 and d1
bxmy i )1(
y
yi
yi+1
xi+1
d1
d2
-
8/2/2019 CP0450_01-Aug-2011_RM01
16/34
So, d2 and d1 are given as follows:
and:
We can use these to make a simple decision
about which pixel is closer to the mathematical
line
Deriving The Bresenham Line Algorithm (cont)
iyyd 1
ii ybxm
)1(
yyd i )1(2
bxmy ii )1(1
-
8/2/2019 CP0450_01-Aug-2011_RM01
17/34
This simple decision is based on the differencebetween the two pixel positions:
Lets substitute m with y/xwhere x and
y are the differences between the end-points:
Deriving The Bresenham Line Algorithm (cont)
122)1(221 byxmdd ii
)122)1(2()( 21
byxx
yxddx ii
)12(222 bxyyxxy ii
cyxxy ii 22
-
8/2/2019 CP0450_01-Aug-2011_RM01
18/34
So, a decision parameterpi for the ith stepalong a line is given by:
The sign of the decision parameterpi is thesame as that ofd1d2
Ifpi is negative, then we choose the lowerpixel, otherwise we choose the upper pixel
Deriving The Bresenham Line Algorithm (cont)
cyxxy
ddxp
ii
i
22
)(21
-
8/2/2019 CP0450_01-Aug-2011_RM01
19/34
Remember coordinate changes occur along
thex axis in unit steps so we can doeverything with integer calculations
At step i+1 the decision parameter is given as:
Subtractingpi from this we get:
Deriving The Bresenham Line Algorithm (cont)
cyxxyp iii 111 22
)(2)(2111 iiiiii yyxxxypp
-
8/2/2019 CP0450_01-Aug-2011_RM01
20/34
But,xi+1 is the same asxi+1 so:
whereyi+1 - yi is either 0 or 1 depending onthe sign ofpi
The first decision parameter p0 is evaluated at
(x0, y0) is given as:
Deriving The Bresenham Line Algorithm (cont)
)(2211 iiii yyxypp
xyp 20
-
8/2/2019 CP0450_01-Aug-2011_RM01
21/34
The Bresenham Line Algorithm
BRESENHAMS LINE DRAWING ALGORITHM(for |m| < 1.0)
1. Input the two line end-points, storing the left end-point in
(x0, y0)
2. Plot the point (x0, y0)
3. Calculate the constants x, y, 2y, and (2y - 2x) andget the first value for the decision parameter as:
4. At eachxi along the line, starting at i = 0, perform the
following test. Ifpi < 0, the next point to plot is
(xi+1, yi) and:
xyp 20
C
ypp ii
21
21
-
8/2/2019 CP0450_01-Aug-2011_RM01
22/34
The Bresenham Line Algorithm (cont)
The algorithm and derivation above assumes
slopes are less than 1. for other slopes we
need to adjust the algorithm slightly
Otherwise, the next point to plot is (xi+1, yi+1) and:
5. Repeat step 4 (x 1) timesxyC
xypp ii
222
221
-
8/2/2019 CP0450_01-Aug-2011_RM01
23/34
-
8/2/2019 CP0450_01-Aug-2011_RM01
24/34
Bresenham Example
Lets plot the line from (20, 10) to (30, 18)
First off calculate all of the constants:
x: 10
y: 8
C1 =2y: 16
C2 =2y - 2x: -4
Calculate the initial decision parameterp0:
p0= 2yx = 6
-
8/2/2019 CP0450_01-Aug-2011_RM01
25/34
Bresenham Example (cont)
17
16
15
14
13
12
11
10
18
292726252423222120 28 30
i pi (xi+1,yi+1)
0
1
2
3
4
56
7
8
9
6
2
-2
14
10
62
-2
14
10
(20, 10)
(21, 11)
(22, 12)
(23, 12)
(24, 13)
(25, 14)(26, 15)
(27, 16)
(28, 16)
(29, 17)
-
8/2/2019 CP0450_01-Aug-2011_RM01
26/34
Bresenham Exercise
Go through the steps of the Bresenham line
drawing algorithm for a line going from
(21,12) to (29,16)
-
8/2/2019 CP0450_01-Aug-2011_RM01
27/34
Bresenham Exercise (cont)
17
16
15
14
13
12
11
10
18
292726252423222120 28 30
i pi (xi+1,yi+1)
0
1
2
3
4
5
6
7
8
-
8/2/2019 CP0450_01-Aug-2011_RM01
28/34
Bresenham Line Algorithm Summary
The Bresenham line algorithm has the followingadvantages:
An fast incremental algorithm
Uses only integer calculations Comparing this to the DDA algorithm, DDA has
the following problems:
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/2/2019 CP0450_01-Aug-2011_RM01
29/34
Anti-Aliasing
-
8/2/2019 CP0450_01-Aug-2011_RM01
30/34
Resolution
-
8/2/2019 CP0450_01-Aug-2011_RM01
31/34
Scan-Line Polygon Fill Algorithm
2
4
6
8
10 Scan Line
02 4 6 8 10 12 14 16
-
8/2/2019 CP0450_01-Aug-2011_RM01
32/34
Scan-Line Polygon Fill Algorithm
The basic scan-line algorithm is as follows:
Find the intersections of the scan line with all
edges of the polygon
Sort the intersections by increasing x coordinate
Fill in all pixels between pairs of intersections that
lie interior to the polygon
-
8/2/2019 CP0450_01-Aug-2011_RM01
33/34
Scan-Line Polygon Fill Algorithm (cont)
-
8/2/2019 CP0450_01-Aug-2011_RM01
34/34
What next?
Co-ordinate Systems and
Transformations