收藏 分享(赏)

香港大学计算机图形学课件Chapter2.ppt

上传人:dzzj200808 文档编号:2310752 上传时间:2018-09-10 格式:PPT 页数:32 大小:405KB
下载 相关 举报
香港大学计算机图形学课件Chapter2.ppt_第1页
第1页 / 共32页
香港大学计算机图形学课件Chapter2.ppt_第2页
第2页 / 共32页
香港大学计算机图形学课件Chapter2.ppt_第3页
第3页 / 共32页
香港大学计算机图形学课件Chapter2.ppt_第4页
第4页 / 共32页
香港大学计算机图形学课件Chapter2.ppt_第5页
第5页 / 共32页
点击查看更多>>
资源描述

1、1,Chapter 2 Scan Conversions,The process of drawing 2-D primitive geometric objects on a frame buffer is called scan-conversion. These low level operations are often carried out by a display processor.,2,Overview Colors Setting pixel values Drawing lines Antialiasing Drawing polygons Clipping Drawin

2、g characters,3,One pixel The intensity of each color is represented by 1 byte in Frame buffer,4,Color A color is defined by three values: r, g and b, corresponding to the intensities of the three basic colors: red, green and blueEach of these values lies in 0.0, 1.0. 0 means no intensity; 1 means ma

3、ximum intensityConsider a 3-d Cartesian coordinate system where the three axes are r, g, and b. Every point in the unit cube shown in the RHScorresponds to a color.,5,The colors on the surface of the cube,Color Cube,6,The color cube from an opposite view point,7,To set the current color, callSetColo

4、r( r, g, b)All subsequent drawings will be set to this color until another call to this function.Black: setColor( 0.0, 0.0, 0.0); Red: setColor( 1.0, 0.0, 0.0); Green: setColor( 0.0, 1.0, 0.0); Blue: setColor( 0.0, 0.0, 1.0); Yellow: setColor( 1.0, 1.0, 0.0); Magenta: setColor( 1.0, 0.0, 1.0); Cyan:

5、 setColor( 0.0, 1.0, 1.0);White: setColor( 1.0, 1.0, 1.0);,8,To set the RGB values of a pixel to the current color, callsetPixel( x, y)x and y are integers. They specifya pixel on the screen. Eg, (0, 0) corresponds to the top-left pixel.(The graphics functions described in this chapter are primitive

6、 and simple. To the contrary, their counterparts in OpenGL are relatively higher level and more complicated. We will describe the counterparts in Chapter 3.),9,Drawing lines,Let (x1, y1) and (x2, y2) be the screen coordinates of the two end points of a line segment. x1 x2 Step through the x-coordina

7、te from x1 to x2. Set the pixels closest to the line.,(x1,y1),(x2,y2),10,int x1 = , x2 = , y1 = , y2 = ; /Given int x; float y = y1, y = (y2 - y1) / (x2 - x1); / y is the change of y when x move 1 step for (x = x1; x x2; +x) setPixel( x, round(y) ); y = y + y; ,Line Drawing (Version 1),11,A faster v

8、ersion (II) error is the distance between the centre of a pixel and the line)int x1 = , x2 = , y1 = , y2 = ; /Givenint x, y = y1; float error = 0.0, y = (y2 - y1) / (x2 - x1);for (x = x1; x x2; +x) setPixel( x, y ); error = error + y;if (error 0.5) +y; error = error - 1.0; ,12,Version III The floati

9、ng point arithmetic can be entirely eliminated by multiplying error and y by 2(x2-x1)int x1 = , x2 = , y1 = , y2 = ; /Givenint x, y = y1, dx = 2*(x2 - x1), y = 2*(y2 - y1), error = 0;for (x = x1; x x2; +x) setPixel( x, y ); error = error + y;if (error dx/2) +y; error = error - dx; ,13,Version IV The

10、 program runs even faster if we offset error by dx/2int x1 = , x2 = , y1 = , y2 = ; /Givenint x, y = y1, dx = 2*(x2 - x1), y = 2*(y2 - y1), error = -dx / 2;for (x = x1; x x2; +x) setPixel( x, y ); error = error + y;if (error 0) +y; error = error - dx; ,14,The Bresenhams line drawing algorithm(Text,

11、8.9, 8.10)Combine the operations error = error + y and error = error dx into one when error 0; int x1 = , x2 = , y1 = , y2 = ; /Givenint x, y = y1, dx = 2*(x2 - x1), y = 2*(y2 - y1), error = -dx / 2, dymx = y - dx;for (x = x1; x x2; +x) setPixel( x, y ); if (error 0) error = error + dy;else +y; erro

12、r = error + dymx; ,15,The above algorithm only works well when the angle between the line and the x-axis, , is less than 45o The left figure is resulted for a line with = 70o . The pixels on the line is too sparsely set. A more desirable one is shown on the right., = 70o,16,To draw lines of various

13、values of properly, modify the algorithm according to the following,17,Antianliasing,The jaggies appeared in the drawings of lines is called aliasing. It is due to the approximation of a continuous line with discrete pixels.,18,AntialiasingConceive that a line is 1 pixel wide which covers certain pi

14、xel squares. A simple drawing method sets the pixels in C, G, H and L to the current color. An antialiasing method first computes the overlapping proportions of the lines and the nearby pixel squares. Suppose that the overlapping proportion of a certain pixel is , the new pixel_color is then set to

15、current_color + (1- ) existing_color,19,Without antialiasing With antialiasing,To turn on anitaliasing (draw slower)enable( LINE_SMOOTH) To turn off antialiasing (draw faster)disable( LINE_SMOOTH),20,Drawing simple convex polygons,A polygon is simple if no edges cross each otherA polygon is convex i

16、f any line segment connecting two points in the polygon lies inside the polygon.,A non-simple polygon,A concave polygon,A simple convex polygon,21,Scan-Line Algorithm for drawing polygons (Text, 8.11.6) First find out the rows that intercept with the polygon. Calculate the overlapping segments. For

17、each row from top to bottom, set the pixels in the segment.,(x1,y1),(x3,y3),(x2,y2),22,Without antialiasing With antialiasing,Jaggies may occur along edges and can be smoothen in the same way as in the drawing of lines To turn on anitaliasing (draw much slower)enable( POLYGON_SMOOTH)To turn off anti

18、aliasing (draw much faster)disable( POLYGON_SMOOTH),23,Clipping A window is an rectangular area on a 2-D plane. Only objects within the window will be displayed Clipping is the process of eliminating the objects or parts of objects outside the window boundary,24,Clipping points,A point at (x, y) is

19、inside a window ifxmin x xmax and ymin y ymax,xmin,ymax,ymin,xmax,25,Clipping Lines (Cohen-Sutherland),First compute the outcodes , b0b1b2b3 , of the endpoints of a line segment,A point inside the window has an outcode of 0000,ymax,ymin,(Text, 8.4.1, p.375),26,Case 1: The entire line is inside the w

20、indow. The outcodes of both endpoints are 0000. No clipping is needed,Case 2: The entire line is on the outside of one window boundary. The outcodes of both endpoints are not 0000. The bitwise AND of the code is not zero. Clip the entire line,27,Case 3: One in and one out. Clip the line against the

21、corresponding boundaries (at most 2) one by one.,Case 4: All other cases. Clip the line against the four boundaries one by one.,28,Clip the polygon against the window boundaries one by one.,Clipping polygons (Sutherland and Hodgman),29,To clip a polygon against one window boundaryVisit the edges suc

22、cessively. Keep the parts on the inside of the boundary,30,Bitmap characters,A bit map is a rectangular array of 0s and 1s. When you overlay a bitmap on the frame buffer, the pixels that correspond to 1s are set to the current color. A bitmap that represents the character F byte rasters24 = 0xc0, 0x

23、00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0; /hexadecimal integer constants,31,Stroke characters Use lines to define a character,Outline characters Use lines or curves to define the outline of a character,32,Bitmap characters,Outline characters,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报