2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers

Embed Size (px)

DESCRIPTION

1) Scan-Line Filling (scan conversion) Problem: Given the vertices or edges of a polygon, which are the pixels to be included in the area filling?

Citation preview

2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers Filling area Polygons are considered! 1)Scan-Line Filling (between edges) 2)Interactive Filling (using an interior starting point) 1) Scan-Line Filling (scan conversion) Problem: Given the vertices or edges of a polygon, which are the pixels to be included in the area filling? Scan-Line filling, contd Main idea: locate the intersections between the scan-lines and the edges of the polygon sort the intersection points on each scan-line on increasing x-coordinates generate frame-buffer positions along the current scan-line between pairwise intersection points Main idea Scan-Line filling, contd Problems with intersection points that are vertices: Basic rule: count them as if each vertex is being two points (one to each of the two joining edges in the vertex) Exception: if the two edges joining in the vertex are on opposite sides of the scan-line, then count the vertex only once (require some additional processing) Vertex problem Scan-Line filling, contd Time-consuming to locate the intersection points! If an edge is crossed by a scan-line, most probably also the next scan-line will cross it (the use of coherence properties) Scan-Line filling, contd Each edge is well described by an edge- record: y max x 0 (initially the x related to y min ) x/ y (inverse of the slope) (possibly also x and y) x/ y is used for incremental calculations of the intersection points Edge Records Scan-Line filling, contd The intersection point (x n,y n ) between an edge and scan-line y n follows from the line equation of the edge: y n = y/ x. x n + b (cp. y = m. x + b) The intersection between the same edge and the next scan-line y n+1 is then given from the following: y n+1 = y/ x. x n+1 + b and also y n+1 = y n + 1 = y/ x. x n + b +1 Scan-Line filling, contd This gives us: x n+1 = x n + x/ y, n = 0, 1, 2, .. i.e. the new value of x on the next scan- line is given by adding the inverse of the slope to the current value of x Scan-Line filling, contd An active list of edge records intersecting with the current scan-line is sorted on increasing x-coordinates The polygon pixels that are written in the frame buffer are those which are calculated to be on the current scan-line between pairwise x-coordinates according to the active list Scan-Line filling, contd When changing from one scan-line to the next, the active edge list is updated: a record with y max < the next scan-line is removed in the remaining records, x 0 is incremented and rounded to the nearest integer an edge with y min = the next scan-line is included in the list Scan-Line Filling Example 2) Interactive Filling Given the boundaries of a closed surface. By choosing an arbitrary interior point, the complete interior of the surface will be filled with the color of the users choice. Interactive Filling, contd Definition: An area or a boundary is said to be 4-connected if from an arbitrary point all other pixels within the area or on the boundary can be reached by only moving in horizontal or vertical steps. Furthermore, if it is also allowed to take diagonal steps, the surface or the boundary is said to be 8-connected. 4/8-connected Interactive Filling, contd A recursive procedure for filling a 4- connected (8-connected) surface can easily be defined. Assume that the surface shall have the same color as the boundary (can easily be modified!). The first interior position (pixel) is choosen by the user. Interactive Filling, algorithm void fill(int x, int y, int fillColor) { int interiorColor; interiorColor = getPixel(x,y); if (interiorColor != fillColor) { setPixel(x, y, fillColor); fill(x + 1, y, fillColor); fill(x, y + 1, fillColor); fill(x - 1, y, fillColor); fill(x, y - 1, fillColor); } } Inside-Outside test When is a point an interior point? Odd-Even Rule Draw conceptually a line from a specified point to a distant point outside the coordinate space; count the number of polygon edges that are crossed if odd => interior if even => exterior Note! The vertices! Text Representation: * bitmapped (raster) + fast - more storage - less good for styles/sizes * outlined (lines and curves) + less storage + good for styles/sizes - slower Other output primitives * pattern (to fill an area) normally, an n x m rectangular color pixel array with a specified reference point * polymarker (marker symbol) a character representing a point * (polyline) a connected sequence of line segments Attributes Influence the way a primitive is displayed Two main ways of introducing attributes: 1)added to primitives parameter list e.g. setPixel(x, y, color) 2)a list of current attributes (to be updated when changed) e.g setColor(color); setPixel(x, y); Attributes for lines Lines (and curves) are normally infinitely thin type dashed, dotted, solid, dot-dashed, pixel mask, e.g width problem with the joins; line caps are used to adjust shape pen/brush shape color (intensity) Lines with width Line caps Joins Attributes for area fill fill style hollow, solid, pattern, hatch fill, color pattern tiling Tiling Tiling = filling surfaces (polygons) with a rectangular pattern Attributes for characters/strings style font (typeface) color size (width/height) orientation path spacing alignment Text attributes Text attributes, contd Color as attribute Each color has a numerical value, or intensity, based on some color model. A color model typically consists of three primary colors, in the case of displays Red, Green and Blue (RGB) For each primary color an intensity can be given, either (integer) or 0-1 (float) yielding the final color 256 different levels of each primary color means 3x8=24 bits of information to store Color representations Two different ways of storing a color value: 1)a direct color value storage/pixel 2)indirectly via a color look-up table index/pixel (typically 256 or 512 different colors in the table) Color Look-up Table 37 Frame Buffers A frame buffer may be thought of as computer memory organized as a two-dimensional array with each (x,y) addressable location corresponding to one pixel. Bit Planes or Bit Depth is the number of bits corresponding to each pixel. A typical frame buffer resolution might be 640 x 480 x 8 1280 x 1024 x 8 1280 x 1024 x 24 38 Monochrome Display (Bit-map Display) 39 3-Bit Color Display 40 True Color Display 24 bit planes, 8 bits per color gun = 16,777,216 41 Color Map Look-Up Tables Extends the number of colors that can be displayed by a given number of bit-planes RG B RED GREEN BLUE Pixel displayed at x', y' Pixel in bit map at x', y' 0 x 0 y x max y Bit mapLook-up tableDisplay Video look-up table organization: each table entry is a 12 bit per entry. A pixel with value 67 is displayed on the screen with the red electron gun at 8/15 (binary 1000) of maximum, green at 2/15, and the blue is 1/15. Antialiasing Aliasing the fact that exact points are approximated by fixed pixel positions Antialiasing = a technique that compensates for this (more than one intensity level/pixel is required) Antialiasing, a method A polygon will be studied (as an example). Area sampling (prefiltering): a pixel that is only partly included in the exact polygon, will be given an intensity that is proportional to the extent of the pixel area that is covered by the true polygon Area sampling P = polygon intensity B = background intensity f = the extent of the pixel area covered by the true polygon pixel intensity = P*f + B*(1 - f) Note! Time consuming to calculate f