rasterization
play

Rasterization Werner Purgathofer Important Graphics Output - PDF document

Einfhrung in Visual Computing 186.822 186.822 Rasterization Werner Purgathofer Important Graphics Output Primitives in 2D points, lines polygons, circles, ellipses & other curves polygons circles ellipses & other curves (also


  1. Einführung in Visual Computing 186.822 186.822 Rasterization Werner Purgathofer Important Graphics Output Primitives in 2D points, lines polygons, circles, ellipses & other curves polygons circles ellipses & other curves (also filled) pixel array operations characters in 3D in 3D triangles & other polygons free form surfaces + commands for properties: color, texture, … 1 Werner Purgathofer 1

  2. Points and Lines point plotting instruction in display list (random scan) entry in frame buffer (raster scan) line drawing instruction in display list (random scan) intermediate discrete pixel positions calculated (raster scan) calculated (raster scan) “jaggies”, aliasing 2 Werner Purgathofer Lines: Staircase Effect Stairstep effect (jaggies) produced when a line is generated as a series of pixel positions 3 Werner Purgathofer 2

  3. Line-Drawing Algorithms line equation: y = m . x + b line path between y 1 two points: y 0 m = y 1  y 0 } b x 1  x 0 x 0 x x x 1 b = y 0  m . x 0 4 Werner Purgathofer DDA Line-Drawing Algorithm line equation: y = m . x + b sampling points with distance 1  y = m  x  y = m .  x for |m|<1 for |m|<1 y 1 m  y y 0  x = for |m|>1 ) m x x 0 1 1 x x 1 DDA (digital differential analyzer) for  x=1 , |m|<1 : y k+1 = y k  m 5 Werner Purgathofer 3

  4. DDA – Algorithm Principle dx = x1 – x0; dy = y1 – y0; m = dy / dx; x = x0; y = y0; drawPixel (round(x), round(y)); for (k = 0; k < dx; k++) { x += 1; y += m; { x += 1; y += m; drawPixel (round(x), round(y)} extension to other cases simple 6 Werner Purgathofer Bresenham’s Line Algorithm faster than simple DDA incremental integer calculations adaptable to circles, other curves y = m . (x k + 1) + b 13 for every column it is 12 decided which of the decided which of the two candidate pixels 11 is selected 10 10 11 12 13 7 Werner Purgathofer 4

  5. Bresenham’s Line Algorithm section of the screen grid showing a pixel in column x k on y = mx + b scan line y k that is to be plotted along the y k+2 path of a line y y k+1 segment with slope segment with slope 0<m<1 y k x k x k+1 x k+2 x k+3 8 Werner Purgathofer Bresenham’s Line Algorithm (1/4) y k+1 d upper y d lower y k x k+1 x k 9 Werner Purgathofer 5

  6. Bresenham’s Line Algorithm (1/4) y = m . (x k + 1) + b d lower = y  y k = = m . (x k + 1) + b  y k y k+1 d upper y d upper = (y k + 1)  y = d lower = y k + 1  m . (x k + 1)  b y k d lower  d upper = = 2m . (x k + 1)  2y k + 2b  1 x k+1 10 Werner Purgathofer Bresenham’s Line Algorithm (2/4) d lower  d upper = = 2m . (x k + 1)  2y k + 2b  1 m =  y /  x m =  y /  x y k+1 d upper  x = x 1 – x 0 ,  y = y 1 – y 0 ) y decision parameter: d lower p k =  x . (d l  x (d lower  d p k d upper ) ) = = 2  y . x k  2  x . y k + c y k → same sign as (d lower  d upper ) x k+1 11 Werner Purgathofer 6

  7. Bresenham’s Line Algorithm (3/4) current decision value: p k =  x . (d lower  d upper ) = 2  y . x k  2  x . y k + c next decision value: p k+1 = 2  y . x k+1   x . y k+1  c + 0 p k+1 = 2  y . x k+1   x . y k+1  c + p k+1 = 2  y . x k+1   x . y k+1  c p k+1 + p k – 2  y . x k + 2  x . y k – c = = p k + 2  y   x . (y k+1  y k ) 12 Werner Purgathofer Bresenham’s Line Algorithm (3/4) current decision value: p k =  x . (d lower  d upper ) = 2  y . x k  2  x . y k + c next decision value: = p k + 2  y   x . (y k+1  y k ) p k+1 starting decision value: p 0 = 2  y   x 13 Werner Purgathofer 7

  8. Bresenham’s Line Algorithm (4/4) 1. store left line endpoint in (x 0 ,y 0 ) 2. draw pixel (x 0 ,y 0 ) 3 calculate constants  x  y 2  y 2  y  2  x 3. calculate constants  x,  y, 2  y, 2  y  2  x , and obtain p 0 = 2  y   x 4. At each x k along the line, perform test: if p k <0 then draw pixel (x k +1,y k ); p k+1 = p k + 2  y else draw pixel (x k +1,y k +1); p k+1 = p k + 2  y  2  x 5. perform step 4 (  x   times. 14 Werner Purgathofer Bresenham: Example 46  x = 10,  y = 3 k p k (x k+1 ,y k+1 ) 45 (20,41) 44 43 43 0 0 -4 4 (21 41) (21,41) 42 1 2 (22,42) 41 2 -12 (23,42) 40 3 -6 (24,42) 20 21 22 23 24 25 26 27 28 29 30 4 0 (25,43) p 0 = 2  y   x 5 -14 ( (26,43) , ) if p k <0 if 0 6 -8 (27,43) then draw pixel (x k +1,y k ); 7 -2 (28,43) p k+1 = p k + 2  y 8 4 (29,44) 9 -10 (30,44) else draw pixel (x k +1,y k +1); p k+1 = p k + 2  y  2  x 15 Werner Purgathofer 8

  9. Attributes of Graphics Output Primitives in 2D points, lines characters characters in 2D and 3D triangles other polygons ((filled) ellipses and other curves) ((filled) ellipses and other curves) 16 Werner Purgathofer / Einf. in Visual Computing Points and Line Attributes color type: solid, dashed, dotted,… width, line caps, corners pen and brush options … 17 Werner Purgathofer / Einf. in Visual Computing 9

  10. Character Attributes text attributes font (e.g. Courier , Arial, Times , Roman , …) styles (regular bold italic underline styles (regular, bold , italic , underline,…) ) size (32 point, 1 point = 1/72 inch) proportionally sized vs. fixed space fonts v string attributes e r horizontal t orientation i c alignment (left, center, right, justify) a l Displayed primitives Displayed primitives Displayed primitives Displayed primitives generated by the generated by the generated by the generated by the raster algorithms raster algorithms raster algorithms raster algorithms discussed in Chapter 3 discussed in Chapter 3 discussed in Chapter 3 discussed in Chapter 3 have a jagged, or have a jagged, or have a jagged, or have a jagged, or stairstep, appearance. stairstep, appearance. stairstep, appearance. stairstep, appearance. 18 Werner Purgathofer / Einf. in Visual Computing Character Primitives font (typeface) design style for (family of) characters Sfzrn Sf Courier , Times , Arial, … A i l Ti i serif ( better readable ), Sfzrn sans serif (better legible) definition model bitmap font (simple to define and display) bitmap font (simple to define and display), needs more space (font cache) outline font (more costly, less space, geometric transformations) 19 Werner Purgathofer 10

  11. Example: Newspaper 20 Werner Purgathofer Character Generation Examples the letter B represented with an 8x8 bilevel bitmap pattern and with an outline shape defined with straight line and curve segments 21 Werner Purgathofer 11

  12. Area-Fill Attributes (1) fill styles hollow, solid fill, pattern fill fill options edge type, width, color pattern specification 4 0 4 0 4 0 4 0 through pattern tables 4 0 0 4 0 4 0 4 0 4 0 4 tiling (reference point) 4 0 4 0 4 0 4 0 0 0 4 0 0 4 0 4 0 4 0 4 0 4 4 0 4 0 4 0 4 0 0 4 0 4 0 4 0 4 22 Werner Purgathofer / Einf. in Visual Computing Area-Fill Attributes (2) combination of and fill pattern with background colors background colors pattern pattern back- back- or ground soft fill combination of colors xor antialiasing at object borders semitransparent brush simulation semitransparent brush simulation replace replace example: linear soft-fill F...foreground color P = tF + (1  t)B B...background color 23 Werner Purgathofer / Einf. in Visual Computing 12

  13. Triangle and Polygon Attributes color material t transparency texture surface details reflexion properties, … → defined illumination produces effects 24 Werner Purgathofer / Einf. in Visual Computing General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method clean borders between ( α , β , γ ) adjacent triangles adjacent triangles barycentric coordinates 25 Werner Purgathofer / Einf. in Visual Computing 13

  14. General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method “interior”, “exterior” for self-intersecting polygons? 26 Werner Purgathofer / Einf. in Visual Computing General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method interior pixels along a scan line passing through a polygon area 27 Werner Purgathofer / Einf. in Visual Computing 14

  15. General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method starting from a seed point fill until you reach a border 28 Werner Purgathofer / Einf. in Visual Computing Triangles: Barycentric Coordinates P 2 (x 2 , y 2 ) ( α , β , γ ) (0, 0, 1) P 0 (x 0 , y 0 ) (0.60, 0.13, 0.27) (1, 0 ,0) P 1 (x 1 , y 1 ) (0, 1, 0) P = α P 0 + β P 1 + γ P 2 triangle = {P| α + β + γ =1, 0< α <1, 0< β <1, 0< γ <1} 29 Werner Purgathofer / Einf. in Visual Computing 15

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend