Académique Documents
Professionnel Documents
Culture Documents
Graphics Programming
Java Threads
Agenda
Terminology Generalities Scan-Line Polygon Fill Algorithm Boundary-Fill Algorithm Flood-Fill Algorithm
A Polygon
Vertex = point in space (2D or 3D) + extra information in most cases Polygon = ordered list of vertices Each vertex connected with the next in the list Last is connected with the first Maybe more than one polygons with holes May contain self-intersections Simple polygon no holes or self-intersections These are of most interest in CG
Polygons in graphics
The main geometric object used for interactive graphics Efficient rendering algorithms exist Polygon scanline rendering Algorithms for making them look good exist Lighting, shading, texture mapping Lowest common denominator for all geometry Can get close to any reasonable shape if enough of them
Draw lines along polygon edges Use algorithms e.g Bresenham This is called wireframe mode Draw filled polygons new algorithms Shaded polygons (shading modes) Flat shaded constant color for whole polygon Gouraud shaded interpolate vertex colors across the polygon
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 infinity Count number of intersections with polygon edges If N is odd, point is inside If N is even, point is outside
Avoid drawing pixels more than once. 1. wastes computation 2. 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.
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.
Example 1
The boundary of a polygon: (In practice, a polygon is defined as a list of vertices.)
Example 2
Pixels closest to the polygon boundary derived from Bresenhams
Example 3
The scan extrema (blue) and interior (green) pixels that would be obtained if the span extrema were defined by the pixels closest to the boundary. Our convention excludes some of these.
Example 4
The scan extrema (blue) and interior (green) pixels that are obtained using our interior pixel convention for the given polygon (purple).
Polygon Fill
B
Parity 0 = even 1 = odd
Parity
1 0 A E
Polygon Fill 2
B
Parity 0 = even 1 = odd
C
F
Parity
1 0
A E
Subtleties