0% found this document useful (0 votes)
14 views13 pages

CG MODULE-1 Part2

Computer graphics

Uploaded by

Varun N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

CG MODULE-1 Part2

Computer graphics

Uploaded by

Varun N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Module 2 Fill Area Primitives

2.1 Fill area Primitives:


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.

2.1.1 Introduction
 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

VTUPulse.com
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.

1
Module 2 Fill Area Primitives

 Below figure shows the side and top surfaces of a metal cylinder approximated in an
outline form as a polygon mesh.

 Displays of such figures can be generated quickly as wire-frame views, showing only the
polygon edges to give a general indication of the surface structure

 Objects described with a set of polygon surface patches are usually referred to as standard
graphics objects, or just graphics objects.

2.1.2 Polygon Fill Areas


 A polygon is a plane figure specified by a set of three or more coordinate positions,
called vertices, that are connected in sequence by straight-line segments, called the edges

VTUPulse.com
or sides of the polygon.
 It is required that the polygon edges have no common point other than their endpoints.
 Thus, by definition, a polygon must have all its vertices within a single plane and there
can be no edge crossings
 Examples of polygons include triangles, rectangles, octagons, and decagons
 Any plane figure with a closed-polyline boundary is alluded to as a polygon, and one
with no crossing edges is referred to as a standard polygon or a simple polygon
Problem:
 For a computer-graphics application, it is possible that a designated
set ofpolygonvertices do not all lie exactly in one plane
 This is due to roundoff error in the calculation of numerical
values, o
t erors in selecting coordinate positions for the vertices, or, more typically, to
approximating a curved surface with a set of polygonal patches
Solution:
 To divide the specified surface mesh into triangles

2
Module 2 Fill Area Primitives

Polygon Classifications
 Polygons are classified into two types
✓ Convex Polygon and
✓ Concave Polygon
Convex Polygon:
 The polygon is convex if all interior angles of a polygon are less than or equal to 180◦,
where an interior angle of a polygon is an angle inside the polygon boundary that is
formed by two adjacent edges
 An equivalent definition of a convex polygon is that its interior lies completely on one
side of the infinite extension line of any one of its edges.
 Also, if we select any two points in the interior of a convex polygon, the line segment
joining the two points is also in the interior.
Concave Polygon:
 A polygon that is not convex is called a
concavepolygon. Te below figure shows convex and concave
polygon

VTUPulse.com
 The term degenerate polygon is often used to describe a set of vertices
thatare 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

3
Module 2 Fill Area Primitives

Identifying Concave Polygons


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

VTUPulse.com
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.

4
Module 2 Fill Area Primitives

Splitting Concave Polygons


 Split concave polygon it into a set of convex polygons using edge vectors and edge cross-
products; or, we can use vertex positions relative to an edge extension line to determine
which vertices are on one side of this line and which are on the other.

Vector method
 First need to form the edge vectors.
 Given two consecutive vertex positions, Vk and Vk+1, we define the edge vector between
them as
Ek = Vk+1 – Vk
 Calculate the cross-products of successive edge vectors in order around the polygon
perimeter.
 If the z component of some cross-products is positive while other cross-products have a
negative z component, the polygon is concave.
 We can apply the vector method by processing edge vectors in counterclockwise order If
any cross-product has a negative z component (as in below figure), the polygon is

VTUPulse.com
concave and we can split it along the line of the first edge vector in the cross-product pair

E1 = (1, 0, 0) E2 = (1, 1, 0)
E3 = (1, −1, 0) E4 = (0, 2, 0)
E5 = (−3, 0, 0) E6 = (0, −2, 0)

 Where the z component is 0, since all edges are in the xy plane.


 The crossproduct Ej × Ek for two successive edge vectors is a vector perpendicular to the
xy plane with z component equal to E jxEky − EkxE jy:
 The values for the above figure is as follows
E1 × E2 = (0, 0, 1) E2 × E3 = (0, 0, −2)
E3 × E4 = (0, 0, 2) E4 × E5 = (0, 0, 6)

5
Module 2 Fill Area Primitives

E5 × E6 = (0, 0, 6) E6 × E1 = (0, 0, 2)

 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 Vk
in turn is at the coordinate origin.
 We rotate the polygon about the origin in a clockwise
direction so that the next vertex Vk+1 is on the x axis.
 If the following vertex, Vk+2, is below the x
axis, the polygon is concave.
 We then split the polygon along the x axis to form two

VTUPulse.com
new polygons, and we repeat the concave test for each
of the two new polygons

Splitting a Convex Polygon into a Set of Triangles


 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◦

6
Module 2 Fill Area Primitives

Identifying interior and exterior region of polygon


 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
Odd-Even rule and
The nonzero winding-number rule.

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

VTUPulse.com
 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 theline
in the direction from right to left, and we subtract 1 very time we intersect a segment that
crosses from left to right

7
Module 2 Fill Area Primitives

 If the winding number is nonzero, P is considered to be an interior point. Otherwise, P is


taken to be an exterior point

 The nonzero winding-number rule tends to classify as interior some areas that the odd-
even rule deems to be exterior.
 Variations of the nonzero winding-number rule can be used to define interior regions in
other ways define a point to be interior if its winding number is positive or if it is
negative; or we could use any other rule to generate a variety of fill shapes

VTUPulse.com
 Boolean operations are used to specify a fill area as a combination of two regions
 One way to implement Boolean operations is by using a
variation of the basic winding-number rule consider the
direction for each boundary to be counterclockwise, the
union of two regions would consist of those points
whose winding number is positive

 The intersection of two regions with


counterclockwise boundaries would contain those
points whose winding number is greater than 1,

8
Module 2 Fill Area Primitives

 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

Polygon Tables
 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:
Geometric tables and
Attribute tables
 Geometric data tables contain vertex coordinates and parameters to identify the spatial

VTUPulse.com
orientation of the polygon surfaces.
 Attribute information for an object includes parameters specifying the degree of
transparency of the object and its surface reflectivity and texture characteristics
 Geometric data for the objects in a scene are arranged conveniently in three lists: a vertex
table, an edge table, and a surface-facet table.
 Coordinate values for each vertex in the object are stored in the vertex table.
 The edge table contains pointers back into the vertex table to identify the vertices for
each polygon edge.
 And the surface-facet table contains pointers back into the edge table to identify the edges
for each polygon

9
Module 2 Fill Area Primitives

 The object can be displayed efficiently by using data from the edge table to
identifypolygon 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


VTUPulse.com
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 sothat 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
forcomplex 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,

10
Module 2 Fill Area Primitives

b) that every edge is part of at least one polygon,


c) that every polygon is closed,
d) that each polygon has at least one shared edge, and
e) that if the edge table contains pointers to polygons, every edge referenced by a
polygon pointer has a reciprocal pointer back to the polygon.

Plane Equations
 Each polygon in a scene is contained within a plane of infinite extent.
 The general equation of a plane is
Ax + B y + C z + D = 0
Where,
(x, y, z) is any point on the plane, and
The coefficients A, B, C, and D (called plane parameters) are constants
describing the spatial properties of the plane.
 We can obtain the values of A, B, C, and D by solving a set of three plane equations using
the coordinate values for three noncollinear points in the plane for the three successive

VTUPulse.com
convex-polygon vertices, (x1, y1, z1), (x2, y2, z2), and (x3, y3, z3), in a counterclockwise
order and solve the following set of simultaneous linear plane
equations for the ratios A/D, B/D, and C/D:
(A/D)xk + (B/D)yk + (C/D)zk = −1, k = 1, 2, 3
 The solution to this set of equations can be obtained in determinant form, using Cramer’s
rule, as

 Expanding the determinants, we can write the calculations for the plane coefficients n
i
the form

11
Module 2 Fill Area Primitives

 It is possible that the coordinates defining a polygon facet may not be contained withina
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, Dfor
each subset.

Front and Back Polygon Faces


 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.

VTUPulse.com
 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
theplane containing that polygon

12
Module 2 Fill Area Primitives

 The normal vector points in a direction from inside the plane to the outside; that is,
fromthe 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
thepositive x axis.
 That is, the normal vector is pointing from inside the cube to the outside andis
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

VTUPulse.com
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
Nas 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

13

You might also like