


























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























































An useful construct for describing components of a picture is an area that is filled with some solid color or pattern. A picture component of this type is typically referred to as a fill area or a filled area. Any fill-area shape is possible, graphics libraries generally do not support specifications for arbitrary fill shapes Figure below illustrates a few possible fill-area shapes.
Graphics routines can more efficiently process polygons than other kinds of fill shapes because polygon boundaries are described with linear equations. When lighting effects and surface-shading procedures are applied, an approximated curved surface can be displayed quite realistically. Approximating a curved surface with polygon facets is sometimes referred to as surface tessellation, or fitting the surface with a polygon mesh.
2.1.1 Introduction 2.1.2 Polygon fill-areas, 2.1.3 OpenGL polygon Fill Area Functions, 2.1.4 Fill area attributes, 2.1.5 General scan line polygon fill algorithm, 2.1.6 OpenGL fill-area Attribute functions.
Polygons are classified into two types
The term degenerate polygon is often used to describe a set of vertices that are collinear or that have repeated coordinate positions.
Problems in concave polygon: Implementations of fill algorithms and other graphics routines are more complicated Solution: It is generally more efficient to split a concave polygon into a set of convex polygons before processing
Characteristics: A concave polygon has at least one interior angle greater than 180◦. The extension of some edges of a concave polygon will intersect other edges, and Some pair of interior points will produce a line segment that intersects the polygon boundary
Identification algorithm 1 Identifying a concave polygon by calculating cross-products of successive pairs of edge vectors. If we set up a vector for each polygon edge, then we can use the cross-product of adjacent edges to test for concavity. All such vector products will be of the same sign (positive or negative) for a convex polygon. Therefore, if some cross-products yield a positive value and some a negative value, we have a concave polygon
Identification algorithm 2 Look at the polygon vertex positions relative to the extension line of any edge. If some vertices are on one side of the extension line and some vertices are on the other side, the polygon is concave.
Since the cross-product E2 × E3 has a negative z component, we split the polygon along the line of vector E2. The line equation for this edge has a slope of 1 and a y intercept of −1. No other edge cross-products are negative, so the two new polygons are both convex.
Rotational method Proceeding counterclockwise around the polygon edges, we shift the position of the polygon so that each vertex V k in turn is at the coordinate origin. We rotate the polygon about the origin in a clockwise direction so that the next vertex V k +1 is on the x axis. If the following vertex, V k +2, is below the x axis, the polygon is concave. We then split the polygon along the x axis to form two new polygons, and we repeat the concave test for each of the two new polygons
Once we have a vertex list for a convex polygon, we could transform it into a set of triangles. First define any sequence of three consecutive vertices to be a new polygon (a triangle). The middle triangle vertex is then deleted from the original vertex list. The same procedure is applied to this modified vertex list to strip off another triangle. We continue forming triangles in this manner until the original polygon is reduced to just three vertices, which define the last triangle in the set. Concave polygon can also be divided into a set of triangles using this approach, although care must be taken that the new diagonal edge formed by joining the first and third selected vertices does not cross the concave portion of the polygon, and that the three selected vertices at each step form an interior angle that is less than 180◦
We may want to specify a complex fill region with intersecting edges. For such shapes, it is not always clear which regions of the xy plane we should call “interior” and which regions. We should designate as “exterior” to the object boundaries. Two commonly used algorithms
Inside-Outside Tests Also called the odd-parity rule or the even-odd rule. Draw a line from any position P to a distant point outside the coordinate extents of the closed polyline. Then we count the number of line-segment crossings along this line. If the number of segments crossed by this line is odd, then P is considered to be an interior point Otherwise, P is an exterior point We can use this procedure, for example,to fill the interior region between two concentric circles or two concentric polygons with a specified color.
Nonzero Winding-Number rule This counts the number of times that the boundary of an object “winds” around a particular point in the counterclockwise direction termed as winding number, Initialize the winding number to 0 and again imagining a line drawn from any position P to a distant point beyond the coordinate extents of the object. The line we choose must not pass through any endpoint coordinates. As we move along the line from position P to the distant point, we count the number of object line segments that cross the reference line in each direction We add 1 to the winding number every time we intersect a segment that crosses the line in the direction from right to left, and we subtract 1 very time we intersect a segment that crosses from left to right
To set up a fill area that is the difference of two regions (say, A − B), we can enclose region A with a counterclockwise border and B with a clockwise border
The objects in a scene are described as sets of polygon surface facets The description for each object includes coordinate information specifying the geometry for the polygon facets and other surface parameters such as color, transparency, and light- reflection properties. The data of the polygons are placed into tables that are to be used in the subsequent processing, display, and manipulation of the objects in the scene These polygon data tables can be organized into two groups:
The object can be displayed efficiently by using data from the edge table to identify polygon boundaries. An alternative arrangement is to use just two tables: a vertex table and a surface-facet table this scheme is less convenient, and some edges could get drawn twice in a wire- frame display. Another possibility is to use only a surface-facet table, but this duplicates coordinate information, since explicit coordinate values are listed for each vertex in each polygon facet. Also the relationship between edges and facets would have to be reconstructed from the vertex listings in the surface-facet table. We could expand the edge table to include forward pointers into the surface-facet table so that a common edge between polygons could be identifiedmore rapidly the vertex table could be expanded to reference corresponding edges, for faster information retrieval
Because the geometric data tables may contain extensive listings of vertices and edges for complex objects and scenes, it is important that the data be checked for consistency and completeness. Some of the tests that could be performed by a graphics package are (1) that every vertex is listed as an endpoint for at least two edges,
It is possible that the coordinates defining a polygon facet may not be contained within a single plane. We can solve this problem by dividing the facet into a set of triangles; or we could find an approximating plane for the vertex list. One method for obtaining an approximating plane is to divide the vertex list into subsets, where each subset contains three vertices, and calculate plane parameters A , B , C , D for each subset.
The side of a polygon that faces into the object interior is called the back face, and the visible, or outward, side is the front face. Every polygon is contained within an infinite plane that partitions space into two regions. Any point that is not on the plane and that is visible to the front face of a polygon surface section is said to be in front of (or outside ) the plane, and, thus, outside the object. And any point that is visible to the back face of the polygon is behind (or inside ) the plane. Plane equations can be used to identify the position of spatial points relative to the polygon facets of an object. For any point ( x , y , z ) not on a plane with parameters A , B , C , D , we have Ax + B y + C z + D != 0 Thus, we can identify the point as either behind or in front of a polygon surface contained within that plane according to the sign (negative or positive) of Ax + By + Cz + D : if Ax + B y + C z + D < 0, the point ( x , y , z ) is behind the plane if Ax + B y + C z + D > 0, the point ( x , y , z ) is in front of the plane Orientation of a polygon surface in space can be described with the normal vector for the plane containing that polygon
The normal vector points in a direction from inside the plane to the outside; that is, from the back face of the polygon to the front face. Thus, the normal vector for this plane is N = ( 1, 0, 0 ) , which is in the direction of the positive x axis. That is, the normal vector is pointing from inside the cube to the outside and is perpendicular to the plane x = 1. The elements of a normal vector can also be obtained using a vector crossproduct Calculation. We have a convex-polygon surface facet and a right-handed Cartesian system, we again select any three vertex positions,V1,V2, and V3, taken in counterclockwise order when viewing from outside the object toward the inside. Forming two vectors, one from V1 to V2 and the second from V1 to V3, we calculate N as the vector cross-product: N = ( V2 − V1 ) × ( V3 − V1 ) This generates values for the plane parameters A , B , and C .We can then obtain the value for parameter D by substituting these values and the coordinates in Ax + B y + C z + D = 0 The plane equation can be expressed in vector form using the normal N and the position P of any point in the plane as N · P = − D
glVertex2iv (p2); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glVertex2iv (p6); glEnd ( ); A polygon vertex list must contain at least three vertices. Otherwise, nothing is displayed.
(a) A single convex polygon fill area generated with the primitive constant GL POLYGON. (b) Two unconnected triangles generated with GL TRIANGLES. (c) Four connected triangles generated with GL TRIANGLE STRIP. (d) Four connected triangles generated with GL TRIANGLE FAN.
Triangles Displays the trianlges.
Three primitives in triangles, GL_TRIANGLES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP glBegin (GL_TRIANGLES); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p6); glVertex2iv (p3); glVertex2iv (p4); glVertex2iv (p5); glEnd ( );
In this case, the first three coordinate points define the vertices for one triangle, the next three points define the next triangle, and so forth. For each triangle fill area, we specify the vertex positions in a counterclockwise order triangle strip glBegin (GL_TRIANGLE_STRIP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p6); glVertex2iv (p3); glVertex2iv (p5); glVertex2iv (p4); glEnd ( ); Assuming that no coordinate positions are repeated in a list of N vertices, we obtain N − 2 triangles in the strip. Clearly, we must have N ≥ 3 or nothing is displayed. Each successive triangle shares an edge with the previously defined triangle, so the ordering of the vertex list must be set up to ensure a consistent display. Example, our first triangle ( n = 1) would be listed as having vertices (p1, p2, p6). The second triangle ( n = 2) would have the vertex ordering (p6, p2, p3). Vertex ordering for the third triangle ( n = 3) would be (p6, p3, p5). And the fourth triangle ( n = 4) would be listed in the polygon tables with vertex ordering (p5, p3, p4).
Rearranging the vertex list in the previous quadrilateral code example and changing the primitive constant to GL QUAD STRIP, we can obtain the set of connected quadrilaterals shown in Figure (b): glBegin (GL_QUAD_STRIP); glVertex2iv (p1); glVertex2iv (p2); glVertex2iv (p4); glVertex2iv (p3); glVertex2iv (p5); glVertex2iv (p6); glVertex2iv (p8); glVertex2iv (p7); glEnd ( );
For a list of N vertices, we obtain N/ 2− 1 quadrilaterals, providing that N ≥ 4. Thus, our first quadrilateral ( n = 1) is listed as having a vertex ordering of (p1, p2, p3, p4). The second quadrilateral ( n =2) has the vertex ordering (p4, p3, p6, p5), and the vertex ordering for the third quadrilateral ( n =3) is (p5, p6, p7, p8).
We can fill any specified regions, including circles, ellipses, and other objects with curved boundaries
A basic fill-area attribute provided by a general graphics library is the display style of the interior. We can display a region with a single color, a specified fill pattern, or in a “hollow” style by showing only the boundary of the region
We can also fill selected regions of a scene using various brush styles, color-blending combinations, or textures. For polygons, we could show the edges in different colors, widths, and styles; and we can select different display attributes for the front and back faces of a region. Fill patterns can be defined in rectangular color arrays that list different colors for different positions in the array. An array specifying a fill pattern is a mask that is to be applied to the display area. The mask is replicated in the horizontal and vertical directions until the display area is filled with nonoverlapping copies of the pattern. This process of filling an area with a rectangular pattern is called tiling, and a rectangular fill pattern is sometimes referred to as a tiling pattern predefined fill patterns are available in a system, such as the hatch fill patterns