Post on 05-Dec-2021
1
EEL 5771-001
Introduction to Computer Graphics
Two-dimensional viewing
TEAM BENJAMIN
SHARATH VANAMALA
ID: U-6503-0085
DHARMIK PATEL
ID:U-13017694
BABER GAFOOR
ID: U-34190712
2
Team members’ contributions
• The Two-dimensional viewing pipeline• The lipping window• Normalization and viewport transformations• OpenGL two-dimensional viewing functions• Clipping algorithms• Two-dimensional point clipping• Two-dimensional line clipping• Polygon fill-area clipping• Curve clipping • Text clipping
3
2-D Viewing Pipeline
• Clipping window: a section of a two-dimensional scene that is selected for display
is called clipping window.
• Clipping window is also alluded to as world window or viewing window
• Graphics packages allow us to control the placement within the display window
using another window called as viewpoint
• Objects that are present in the clipping window are mapped to the viewpoint.
4
2-D Viewing Pipeline
• The viewpoint indicates where the selected object it to be viewed on the
output device.
• By changing the position of the viewpoint we can view the objects at different
positions on the display area of an output device
• We can use multiple viewports to display different sections at different screen
positions.
• Usually clipping window and viewpoints are rectangles in standard position
where the rectangle edges are parallel to the coordinate axes
5
The mapping of a two-dimensional, world-coordinate scene description to device
coordinates is called a two-dimensional viewing transformation
This transformation is also called as window to viewport transformation
1. Constructing the world coordinates scene using the modeling coordinate
transformations
2. Convert world coordinates to viewing coordinates
3. Transforming the viewing coordinates to normalized coordinates
4. Mapping the normalized coordinates to device coordinates
To make the viewing process independent of the requirement of any output device,
graphics systems convert object descriptions to normalized coordinates and apply
the clipping routines
6
THE CLIPPING WINDOW
• Clipping windows are generally used to achieve a particular viewing effect In an
application program
• Different patterns used for clipping are star, ellipse or spline figure.
• Clipping using polygon requires more processing than clipping using rectangle
• Graphics packages commonly allow only rectangular clipping windows aligned
with the x and y axis
• Clipping using different shapes require implantation of own clipping and
coordinate-transformation algorithms.
• Rectangular clipping window in standard positions are easily defined by giving
the coordinates of two opposite corners of each rectangle
• The clipping window are usually specified in world coordinates
7
Clipping algorithms
Viewing-coordinate clipping window
• This setup is generally used for the two-dimensional viewing transformation.
• The viewing frame in the clipping window provides a reference for
specifying a rectangular clipping window with any selected orientation and
position
8
• We need to transfer the scene description to viewing coordinates to obtain a view of the world coordinate scene of the above scene.
• This involves a sequence of transformations equivalent to superimposing the viewing frame on the world frame.
• The first step is to translate the viewing origin to the world origin.• Rotate the viewing system to align it with the world frame.• The objects positions in the world coordinates are converted to viewing
coordinates with the composite two-dimensional transformation matrix.
R=rotation matrixT=translation matrix
9
World-coordinate clipping window
• The routine for defining a standard, rectangular clipping window in world
coordinates is typically provided in a graphics programming library
• For this clipping window we needed to specify two world –coordinate
positions, which are then assigned to the two opposite corners of the
standard rectangle\
• After the clipping is established the scene description is processed through
the viewing routines to the output device
10
Normalization and viewport transformations
• The viewport coordinates are often given in the range from 0 to 1 so that the
viewport is positioned wit in the unit square.
• After clipping the unit square containing the viewport is mapped to the output
display device.
• In other systems the normalization and clipping routines are applied before the
viewport transformations.
Mapping the clipping window into a normalized viewport
• For tis mapping first we need to consider a viewport defined with normalized
coordinates values between 0 and 1
• Th object descriptions are transferred to this normalized space using a
transformation that maintains the same relative placement of a point
11
• In the above figure the position (xw,yw) in the clipping window is mapped to position (xv,yv) I he associated viewport.
• To transform the world-coordinate point into the same relative position within the viewport the following computation is required.
12
• after solving the expression we will be getting the below equation
13
We can obtain the transformation from world coordinates to viewport coordinates with the following sequence:1. Scaling the clipping window to the size of the viewport using a fixed
point of (XWmin,YWmin)2. Translate (XWWmin,YWmin)to(XVmin,YVmin)3. The scaling transmission in step(1) can be represented with the two-
dimensional matrix
14
• The two-dimensional matrix representation for the translation of the lower-left
corner of the clipping window to the lower left viewpoint corner is given below.
• The composite matrix representation for the transformation to the normalized viewport is given below.
15
Mapping the clipping window into a normalized square:
• Another approach to two-dimensional viewing is to transform the clipping
window into a normalized square and then transfer the scene description to a
viewport specified in screen coordinates
16
• Making these substitutions in the expressions for tx,ty,sx and sy we have the matrix represented as below.
• Similarly after the clipping algorithms have been applied, the normalized square with edge length equal to 2 is transformed into a specified viewport.
17
• The last step in the viewport process is to position the viewport area in the
display window
OpenGL Two-Dimensional Viewing Functions
• The basic OpenGL library has no functions specifically for twodimensional viewing because it is designed primarily for 3Dapplications. But we can adapt the three-dimensional viewingroutines to a two-dimensional scene, and the core library contains aviewport function. In addition, the GLU library provides a function forspecifying a two-dimensional clipping window, and we have GLUTlibrary functions for handling display windows. Therefore, we can usethese two-dimensional routines, along with the OpenGL viewportfunction, for all the viewing operations we need.
GLU Clipping-Window Function
• To define a two-dimensional clipping window, we can use the GLU function:
gluOrtho2D (xwmin, xwmax, ywmin, ywmax);
• Coordinate positions for the clipping-window boundaries are given asdouble-precision numbers. This function specifies an orthogonal projectionfor mapping the scene to the screen. For a three-dimensional scene, thismeans that objects would be projected along parallel lines that areperpendicular to the two-dimensional xy display screen. But for a two-dimensional application, objects are already defined in the xy plane.
Creating a GLUT Display Window
• Now the GLUT library interfaces with any window-management system sowe use the GLUT routines for creating and manipulating display windowsso that our example programs will be independent of any specific machine.To access these routines, we first need to initialize GLUT with the followingfunction:
glutInit (&argc, argv);
• We have three functions in GLUT for defining a display window andchoosing its dimensions and position:
glutInitWindowPosition (xTopLeft, yTopLeft);
glutInitWindowSize (dwWidth, dwHeight);
glutCreateWindow ("Title of Display Window");
Relocating and Resizing a GLUT Display Window
• We can reset the screen location for the current display window with
glutPositionWindow (xNewTopLeft, yNewTopLeft);
where the coordinates specify the new position for the upper-left display-window corner,relative to the upper-left corner of the screen. Similarly, the following function resets thesize of the current display window
glutReshapeWindow (dwNewWidth, dwNewHeight);
With the following command, we can expand the current display window to fill the screen:
glutFullScreen ( );
Managing Multiple GLUT Display Windows
• The GLUT library also has a number of routines for manipulating adisplay window in various ways. These routines are particularly usefulwhen we have multiple display windows on the screen and we wantto rearrange them or locate a particular display window. We use thefollowing routine to convert the current display window to an icon inthe form of a small picture or symbol representing the window:
glutIconifyWindow ( );
• The label on this icon will be the same name that we assigned to thewindow, but we can change this with the following command:
glutSetIconTitle ("Icon Name");
Viewing Graphics Objects in a GLUT Display Window
• If more than one display window has been created, we first designate theone we want as the current display window. Then we invoke the followingfunction to assign something to that window:
glutDisplayFunc (pictureDescrip);
• The argument is a routine that describes what is to be displayed in thecurrent window. This routine, called pictureDescrip for this example, isreferred to as a callback function because it is the routine that is to beexecuted whenever GLUT determines that the display-window contentsshould be renewed.
Executing the Application Program
• When the program setup is complete and the display windows havebeen created and initialized, we need to issue the final GLUTcommand that signals execution of the program:
glutMainLoop ( );
• At this time, display windows and their graphic contents are sent tothe screen. The program also enters the GLUT processing loop thatcontinually checks for new “events,” such as interactive input from amouse or a graphics tablet.
Two-Dimensional Clipping
• Clipping is the process of determining whichelements of the picture lie inside the window andare visible.
• By default, the “clip window” is the entire canvas• not necessary to draw outside the canvas
• for some devices, it is damaging (plotters)
• Sometimes it is convenient to restrict the “clipwindow” to a smaller portion of the canvas
• partial canvas redraw for menus, dialog boxes, otherobscuration
2D Clipping
2D Clipping
A scene is made up of a collection of objects specified in world coordinates
World Coordinates
2D Clipping
When we display a scene only those objects within a particular window are displayed
wymax
wymin
wxmin wxmax
Window
World Coordinates
2D Clipping
Because drawing things to a display takes time we clipeverything outside the window
wymax
wymin
wxmin wxmax
World Coordinates
Window
2D Clipping
Types of clipping:
• Three types of clipping techniques are used depending upon whenthe clipping operation is performed
a. Analytical clipping
• Clip it before you scan convert it
• used mostly for lines, rectangles, and polygons, where clippingalgorithms are simple and efficient
2D Clipping
b. Scissoring• Clip it during scan conversion• a brute force technique
• scan convert the primitive, only write pixels if inside the clipping region• easy for thick and filled primitives as part of scan line fill• if primitive is not much larger than clip region, most pixels will fall inside• can be more efficient than analytical clipping.
c. Raster Clipping • Clip it after scan conversion• render everything onto a temporary canvas and copy the clipping region
• wasteful, but simple and easy, • often used for text
2D Clipping
Foley and van Dam suggest the following:
• for floating point graphics libraries, try to use analytical clipping
• for integer graphics libraries
• analytical clipping for lines and polygons
• others, do during scan conversion
• sometimes both analytical and raster clipping performed
Applications:
• Extract part of a defined scene for viewing.
• Drawing operations such as erase, copy, move etc.
• Displaying multi view windows.
• Creating objects using solid modeling techniques.
• Anti-aliasing line segments or object boundaries.
• Identify visible surfaces in 3D views.
2D Clipping
Shielding:
• Shielding or exterior clipping is the reverse operation of clipping where window act as the block used to abstract the view.
• Examples
• A multi view window system
• The design of page layouts in advertising or publishing applications or for adding labels or design patterns to picture.
• Combining graphs, maps o schematics
2D Clipping
2D Clipping
wymax
wymin
wxmin wxmax
Window
World Coordinates
Shielding
Clipping Algorithms
• Generally, any procedure that eliminates those portions of a picture that areeither inside or outside a specified region of space is referred to as a clippingalgorithm or simply clipping. Usually a clipping region is a rectangle in standardposition, although we could use any shape for a clipping application.
• The most common application of clipping is in the viewing pipeline, whereclipping is applied to extract a designated portion of a scene (either two-dimensional or three-dimensional) for display on an output device.
• Clipping algorithms are applied in two-dimensional viewing procedures toidentify those parts of a picture that are within the clipping window. Everythingoutside the clipping window is then eliminated from the scene description that istransferred to the output device for display.
In the following sections, we explore two-dimensional algorithms for different levels of clipping
• Point clipping
• Line clipping (straight-line segments)
• Fill-area clipping (polygons)
• Curve clipping
• Text clipping
Point Clipping
• Simple and Easy
• a point (x,y) is not clipped if:
wxmin ≤ x ≤ wxmax
&
wymin ≤ y ≤ wymax
• otherwise it is clipped
wymax
wymin
wxmin wxmax
Window
P1
P2
P5
P7
P10
P9
P4
P8
Clipped
Points Within the Window are Not
Clipped
Clipped
Clipped
Clipped
Line Clipping
• It is Harder than point clipping
• We first examine the end-points of each line to see if they are in the window or not
• Both endpoints inside, line trivially accepted
• One in and one out, line is partially inside
• Both outside, might be partially inside
• What about trivial cases?
ymin
ymax
xmin xmax
Line Clipping
Situation Solution Example
Both end-points inside
the windowDon’t clip
One end-point inside the
window, one outsideMust clip
Both end-points outside
the windowDon’t know!
Trivial Accepts and Rejects
Big optimization: trivial accept/rejects
• How can we quickly determine whether a line segment is entirely inside the viewport?
A: test both endpoints.
• How can we know a line is outside viewport?
A: if both endpoints on wrong side of
same edge, can trivially reject line.
xmin xmax
ymax
ymin
One way to formulate the equation for a straight-line segment is to use the following parametric representation, where the coordinate positions (x0, y0) and (xend, yend) designate the two line endpoints:
x = x0 + u(xend − x0)
y = y0 + u(yend − y0) ; 0 ≤ u ≤ 1
Polygon Clipping
• Polygons have a distinct inside and outside…
• Decided by• Even/Odd• Winding Number
• Note the difference between clipping polygons and lines:
NOTE!
46
Cohen-Sutherland Clipping
• Assigned four digit value called Region code.• Sometimes, a region code is referred to as an “out” code because a
value of 1 in any bit position indicates that the spatial point is outside the corresponding clipping boundary. Each clipping-window edge divides two-dimensional space into an inside half space and an outside half space. Together, the four window borders create nine regions.
47
Cohen-Sutherland Clipping
Content outline:
• Pseudocode algorithm
48
Liang-Barsky Clipping
• Based on analysis of the parametric line equations
• The inequalities describing the range of the clipping window which is
used to determine the intersections between the line and the clip
window.
x = x0 + ux
y = y0 + uy 0 ≤ u ≤ 1
49
Liang-Barsky Clipping
50
Nicholl-Lee-Nicholl Clipping Algorithm
• Avoids multiple line-intersection calculations by creating more regions around the clipping window. Initial testing to determine whether a line segment is completely inside the clipping window or outside the window limits can be accomplished with Regionncode tests, as in the previous two algorithms.
• For a line with endpoints P0 and Pend, we first determine the position of point P0 for the nine possible regions relative to the clipping window.
• Compared to the previous algorithms, the Nicholl-Lee-Nicholl Algorithm fewer compositions and divisions.
• Nicholl-Lee-Nicholl Algorithm can be applied to two-dimensional dipping.
• Three possible positions for a line endpoint P0 in the NLN line-clipping algorithm.
51
Nicholl-Lee-Nicholl Line Clipping
52
Nicholl-Lee-Nicholl Line Clipping
NLN Clipping
53
54
Line Clipping Using Nonrectangular Polygon Clip Windows
• Desirable to clip lines against arbitrarily shaped.• Previous algorithms readily extended to clip
lines against convex polygon windows• Using the parametric equations for the
boundaries of the clipping region• A series of clipping operations can be applied
using the modified convex polygon components.
55
Polygon Fill-Area Clipping
• Same approach as in line clipping.
• A line segment is defined by its two endpoints, and these endpoints are processed through a line-clipping procedure by constructing a new set of clipped endpoints at each clipping-window boundary. Similarly, we need to maintain a fill area as an entity as it is processed through the clipping stages. Thus, we can clip a polygon fill area by determining the new shape for the polygon as each clipping-window edge is processed
• When we cannot identify a fill area as being completely
inside or completely outside the clipping window, we
then need to locate the polygon intersection positions with the clipping boundaries.
Polygon Fill-Area Clipping
56
Sutherland--Hodgman Polygon Clipping
• An efficient method for clipping a convex-polygon fill area, developed by Sutherland and Hodgman, is to send the polygon vertices through each clipping stage so that a single clipped vertex can be immediately passed to the next stage. This eliminates the need for an output set of vertices at each clipping stage, and it allows the boundary-clipping routines to be implemented in parallel. The final output is a list of vertices that describe the edges of the clipped polygon fill area.
• The general strategy in this algorithm is to send the pair of endpoints for each successive polygon line segment through the series of clippers (left, right, bottom, and top). As soon as a clipper completes the processing of one pair of vertices, the clipped coordinate values, if any, for that edge are sent to the next clipper. Then the first clipper processes the next pair of endpoints. In this way, the individual boundary clippers can be operating in parallel.
57
• Pseudocode
58
Sutherland--Hodgman Polygon Clipping
59
60
Weiler-Atherton Polygon Clipping
• This algorithm provides a general polygon-clipping approach that
can be used to clip a fill area that is either a convex polygon or a
concave polygon
• Processing done in clockwise and anticlockwise from the ordering of
the vertex list that defines a polygon fill area.
Curve Clipping• Areas with curved boundaries can be clipped with methods similar to those
discussed in the previous sections.
• Straight-line boundary sections, we use a polygon-clipping method
• Else, we use nonlinear equations
• An intersection calculation involves substituting a clipping-boundary position
61
62
Text Clipping
• Use the all-or-none string-clipping strategy• If all of the string is inside the clipping window, we display the entire
string. Otherwise, the entire string is eliminated
• An alternative is to use the all-or-none character-clipping strategy.
Here we eliminate only those characters that are not completely
inside the clipping window
• Another approach to text clipping is to clip the components of individual
characters. This provides the most accurate display of clipped
character strings, but it requires the most processing
63
Text Clipping
Text clipping relies on the concept of bounding rectangle
TYPES
1. All or None String Clipping
2. All or None Character Clipping
3. Component Character Clipping
Curve Clipping
• Areas with curved boundaries can be clipped with methods similar to line and polygon clipping.
• Curve clipping requires more processing as it involve non linear equations.
• Bounding Rectangles are used to test for overlap with rectangular clip window.
References
• https://www.cg.tuwien.ac.at/courses/CG1/textblaetter/englisch/03%202D%20Viewing%20(engl).pdf
• https://en.wikipedia.org/wiki/2D_computer_graphics
• https://www.slideshare.net/AdityaRaaz/2-d-viewing-computer-graphics