Você está na página 1de 23

The basis of 2D computer graphics display involves mapping the defined geometrical models (residing in the database) to the

represented images (as shown on the VDU)

There are essentially 4 steps in the mapping process.

Vectorizing

Transformation (to viewport)

Clipping

Drawing

~ a pipeline of operations between the data and the screen: ~ the order of the sequence is dependent on hardware used.
2

Vectorization converts geometrical objects as a series of lines (i.e., vectors). Reason is that only one type of geometric element the line is dealt by the graphical routines. The smoothness of Curves generated on screen depends on display tolerance.

Mapping/transforming vectors from model coordinate system to screens coordinate systems. This involves another two concepts: window and viewport.

Window is an imaginary rectangular frame thru which the user looks onto the model.

A viewport is the area on the screen in which the contents of the window are to be displayed.
4

Windowing transformation is the mapping from the model coordinate system to screen coordinate systems. This may involve scaling, rotation and translation.

Note: w ~ window, s ~ screen.

Clipping is the method to identify vectors or parts of vectors that are within the window, and to discard the rest.

Various clipping algorithms have been developed and the earliest one was the work of Sutherland.

Raster Scan Graphics


Conversion from a line vector into its equivalent pixel info. is an arduous task;
Entails large amount of computation;

A need to have a simplified method


Reducing computing o/head thru efficient processing.
DDA Algorithm Symmetrical DDA Bresenhams Algorithm

Line drawing is the final step that draws lines by setting the appropriate bits in the frame buffer.

Algorithms used to approximate the lines by deciding which pixels are near to the line segments and thus must be illuminated are as follows:
Simple DDA Symmetrical DDA Bresenham

Digital Differential Analyser (DDA) Algorithm


The equation of a straight line is; Y=mX+C; From the figure;

For small increments can also be written as;

A case of line drawing where m > 1, choose an increment for X as unit pixel, hence, X = 1, then,

The subscript i takes the values starting from 1 for the starting point till the end point is reached. computer graphics_1

DDA Algorithm(2)
If m 1, then the roles of x and y would have to be reversed.
Choose;

Then,

computer graphics_1

10

DDA Algorithm(3)
E.g., Vectorize a line to be drawn from (10,20) to (150,125) mm on a display which is mapped to approx. (300 x 250 mm). The resolution of the screen is 640 x 480 pixels. The mapping from user coordinates of (150, 125) to the device coordinates is calculated as; Scale factor for X direction: 640/300 = 2.1333 pixels/mm Scale factor for Y direction: 480/250 = 1.92 pixels/mm

Choose the value of 1.92 pixels/mm as it does not violate the requirement,

computer graphics_1

11

DDA Algorithm(4)
Use the scale factor to convert the start and end points into the pixel equivalents. For start point; (10 x 1.92, 20 x 1.92) = (19, 38) pixels,

Similarly for end point (150 x 1.92, 125 x 1.92)= (288, 240) pixels Thus, and X = (288 19) = 269 pixels

Y = (240 38) = 202 pixels


The slope, m = Y / X = 202/269 = 0.751
computer graphics_1

12

DDA Algorithm(5)
X
19 20

Y calculated
38 38.751

Y rounded
38 39

21
22 23

39.502
40.253 41.004

40
40 41

24
25 26 27 28

41.755
42.506 43.257 44.008 44.759

42
43 43 44 45

29
30 31

45.51
46.261 47.012

46
46 47

32
33 34 35 36

47.763
48.514 49.265 50.016 50.767

48
49 49 50 51

37
38

51.518
52.269

52
52

computer graphics_1

13

Bresenhams Algorithm
The DDA algorithm is still not very efficient;
it requires some amount of floating point arithmetic for each of the pixel positions.

Bresenham's method is an improvement;


it eliminates the floating point arithmetic except for the initial computations. all other computations are fully integer arithmetic and hence is more efficient for raster conversion

computer graphics_1

14

Bresenhams Algorithm(2)
The basic argument for positioning the pixel here is the amount of deviation by which the calculated position is from the actual position obtained by the line equation in terms of di and d2 shown.

where,

and

Use the 1st eqn. when Pi is negative, otherwise, 2nd eqn becomes valid. This procedure is for m>1. Interchange X and Y for m < 1.
computer graphics_1
15

Bresenhams Algorithm(3)
Note: from previous eg. P1 = 2 Y - X

= 2(202) 269
= 135

computer graphics_1

16

Drawing of an arc as a series of vectors: a worked example.


a) Calculate the number of lines required to display a circle of radius 25mm, which are centered at (100,150) and the maximum display tolerance is set at 1.0mm.

The no.of lines to represent the circle = 360/ a = 360/ 30 = 12


a
b

a= 2b = 2(16.26) = 32.52 = 30.00 (rounded) b=Cos-1 (24/25) = 16.26

17

Drawing of an arc as a series of vectors: a worked example.


b) Calculate corresponding screen coordinates of the end points of the first line.
window
(160,200)

screen

(480,450)

(121.65, 162.5) (x2, y2) = (327,300)

(125,150)

(x1, y1)

= (340,250)

(40, 100)

(0,50)

(480 0) 480 x1 = -------------- * (125 40) + 0 = ------ * 85 = 340; (160 40) 120 (480 0) 480 x2 = -------------- * (121.65 - 40) + 0 = ------ * 81.65 = 327; (160 40) 120

(450 50) 450 y1 = -------------- * (150 100) + 50 = ------ * 85 = 250 (200 100) 100 (450 50) 450 y2 = -------------- * (162.5 100) + 50 = ------ * 81.65 = 300 (200 100) 100

18

Antialiasing
The rasterisation algorithms generate the pixel points by rounding off to the nearest integer.
inclined lines have jagged effect: staircase effect
Effect will be more pronounced for lines with small angles, Improvement is by increasing the screen resolution.

computer graphics_1

19

Antialiasing(2)
the technique of minimizing the distortion by representing lines at high-resolution.
is used in digital photography, computer graphics, digital audio, and many other domains

computer graphics_1

20

Antialiasing (3)

~ anti-aliased the
~ visual distortion that occurs when anti-aliasing is not used.
checkerboard near the top blends into gray, which is usually the desired effect when the resolution is insufficient to show the detail.

~ sinc filter-based antialiasing algorithm, which is better than the 2nd algorithm used.

computer graphics_1

21

Antialiasing(4)

Each line has a certain thickness compared to the size of the pixel.
The line thickness is overlapping the pixel with different areas.
The intensity of the pixel is made proportional to the area of the pixel covered by the line thickness.

Improved appearance, but computationally is more intensive.

computer graphics_1

22

Antialiasing(5)

higher brightness
50% brightness

computer graphics_1

23

Você também pode gostar