3 A Polygon Vertex = point in space (2D or 3D) + extra information in most casesPolygon = ordered list of verticesEach vertex connected with the next in the listLast is connected with the firstMaybe more than one – polygons with holesMay contain self-intersectionsSimple polygon – no holes or self-intersectionsThese are of most interest in CG
4 Polygons in graphicsThe main geometric object used for interactive graphicsEfficient rendering algorithms existPolygon scanline renderingAlgorithms for making them look good existLighting, shading, texture mappingLowest common denominator for all geometryCan get close to any reasonable shape if enough of them
5 Drawing modes for polygons Draw lines along polygon edgesUse algorithms e.g BresenhamThis is called wireframe modeDraw filled polygons – new algorithmsShaded polygons (shading modes)Flat shaded – constant color for whole polygonGouraud shaded – interpolate vertex colors across the polygon
6 Polygon interior Want to fill in (color) only pixels inside a polygon What is “inside” of a polygon ?Imagine a ray from the point to infinityCount number of intersections with polygon edgesIf N is odd, point is insideIf N is even, point is outside
7 Filling Polygons: Terminology Red arrow denotes a particular scan line.Blue disks denote span perimeter or ‘extrema’.Green disks denote other interior pixels in the span.
8 Filling Polygons: Generalities Avoid drawing pixels more than once.1. wastes computation2. may cause unwanted color change if xor graphics context is used.3. ugly artifacts can occur if two polygons share the same edge (e.g., dependence on drawing order).Exploit coherence: pixels that are nearby each other tend to share common attributes (color, illumination, normal vectors, texture, etc.).Span coherence: Pixels in the same scan line tend to be similar.Scan-line coherence: Pixels in adjacent scan line tend to be similar.Edge coherence: The corresponding span extrema in adjacent span lines tend to be near one another.
9 Interior Pixel Convention Pixels that lie in the interior of a polygon belong to that polygon, and can be filled.Pixels that lie on a left boundary or a lower boundary of a polygon belong to that polygon, and can be filled.Pixels that have centers that fall outside the polygon, are said to be exterior and should not be drawn.Pixels that lie on a right or an upper boundary do not belong to that polygon, and should not drawn.
10 Example 1The boundary of a polygon: (In practice, a polygon is defined as a list of vertices.)
11 Example 2Pixels closest to the polygon boundary – derived from Bresenham’s
12 Example 3The scan extrema (blue) and interior (green) pixels that would be obtainedif the span extrema were defined by the pixels closest to the boundary. Ourconvention excludes some of these.
13 Example 4The scan extrema (blue) and interior (green) pixels that are obtained using our interior pixel convention for the given polygon (purple).
14 Basic Scan-Fill Algorithm Do the following for every scan line:1. Compute the intersection of the current scan line with every polygon edge.2. Sort the intersections in increasing order of the x coordinate.3. Draw every pixel that lies between each pair of intersections, using a parity bit to designate the interior from the exterior. (Toggle the bit at each intersection.)
16 Polygon Fill 2BCParity0 = even1 = oddFDParity11AE
17 See: Rowe G. Computer Graphics with Java Chapter 1 pages 24 -34 Subtleties1. The x-coordinates of the intersections are rounded towards the interior of the polygon.2. If an intersection occurs precisely at an integer, following our convention, it is drawn if a piece of the polygon lies immediately above or to the right.3. If a scanline intersects the polygon at a vertex, then only one of the intersections is counted in the parity test. To conform with our convention, the vertex is assumed to belong only to the edge that lies above it. (Edges, like spans, are regarded as intervals that are open at their maximum values and closed at their minimum values.) N.B., horizontal edges, and their vertices, are ignored completely.See: Rowe G. Computer Graphics with Java Chapter 1 pages