Computer Graphics - Windowing and Clipping

2,173 views 74 slides May 10, 2024
Slide 1
Slide 1 of 74
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74

About This Presentation

Computer Graphics - Windowing and Clipping


Slide Content

UNIT- 4 COMPUTER GRAPHICS Presented By : C. P. Divate

Two-Dimensional Viewing

Contents of Two-Dimensional Viewing Windowing And Clipping: Viewing Pipeline Viewing Transformations 2-D Clipping Algorithms Line Clipping Algorithms Cohen Sutherland Line Clipping Algorithm Liang Barsky Algorithm Line Clipping Against Non Rectangular Clip Windows Polygon Clipping Sutherland Hodgeman Polygon Clipping Weiler And Atherton Polygon Clipping Curve Clipping Text Clipping

Windowing and Clipping: It consider the formal mechanism for displaying views of a picture on an output device. For a two-dimensional picture, a view is selected by specifying a subarea of the total picture area.

Windowing and Clipping: A user can select a single area for display, or several areas could be selected for simultaneous display. Transformations from world to device coordinates involve translation, rotation, and scaling operations, as well as procedures for deleting those parts of the picture that are outside the limits of a selected display area.(clipping)

Windowing and Clipping: Transformations from world to device coordinates involve translation, rotation, and scaling operations, as well as procedures for deleting those parts of the picture that are outside the limits of a selected display area.( clipping )

Viewing Pipeline Window A w orld- coo r din at e a r ea se l ec t ed f or display is called a window. Viewport An area on a display device to which a window is mapped is called a viewport. The window defines what is to be viewed; the viewport defines where it is to be displayed.

Viewing Pipeline Viewing Transformation. The mapping of a part of a world- coordinate scene to device coordinates is referred to as a viewing transformation.

Viewing Pipeline Figu r e 6 - 1 i l l u s t r a t es t h e m a pping o f a pi c tu r e section t h a t f alls within a rectangular window onto a designated & angular viewport.

Viewing Pipeline It consist a sequence of steps used to perform two dimensional viewing transformations The major steps are as follows

Viewing Pipeline We construct the scene in world coordinates We then transform descriptions in world coordinates to viewing coordinates. We then define viewport in normalized coordinates (in the range from to 1) At the final step, all parts of the picture that he outside the viewport are clipped, and the contents of the viewport are transformed to device coordinates.

Viewing Pipeline

Normalized Coordinates Viewports are typically defined within the unit square (normalized coordinates). This provides a means for separating the viewing and other transformations from specific output- device requirements, so that the graphics package is largely device-independent.

Viewing Coordinate Reference Frame translate the viewing origin to the world origin, r o t a t e t o al i gn the a x es of the two systems.

Viewing Coordinate Reference Frame Th e c o m p o si t e t w o - d i m e nsi o n a l t r an s f o r m a tion to convert world coordinates to viewing coordinate is where T is the translation matrix that takes the viewing origin point P to the world origin, and R is the rotation matrix that aligns the axes of the two reference frames.

WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION W e mai n t ain t h e s a me r el a ti v e p l a c eme n t i n t h e v i e wport as i n t he window. If a c oo r d i n a t e positio n i s a t the ce n t er of the w orl d w i ndo w , f or instance, it will be displayed at the center of the viewport.

WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION A point at position (xw,yx) in the window is mapped into position (xv, yv) in the associated viewport.

WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION We maintain the same relative placement in the viewport as in the window.

WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

2-D Clipping Algorithms

2-D Clipping Algorithms Clipping - Any procedure that identifies those portions of a picture th a t a r e either inside o r outside o f a specified r e g i on o f space is referred to as a clipping algorithm, or simply clipping. Th e r egi o n a g ain s t whi c h an objec t i s t o cl i ppe d is window. c al le d a clip

Applications Of Clipplng Applications of clipping include Drawing and painting operations that allow parts of a picture to be selected for copying, moving, erasing, or duplicating. Extracting part of a defined scene for viewing; Identifying visible surfaces in three-dimensional vlews; Antialiasing line seg ments or object boundaries; Creating objects using solid-modeling procedures; Displaying a multi window environment;

Types of clipping We consider algorithms for clipping the following primitive types Point Clipping Line Clipping (straight-line segments) Area Clipping (polygons) Curve Clipping Text Clipping

Point Clipping we save a point P = (x, y) if it is inside the clipping window.

Point Clipping Assuming that the clip window is a rectangle in standard position, we save a point P = (x, y) for display if the following inequalities are satisfied: where the edges of the clip window can be either the world-coordinate window boundaries or viewport boundaries. If any one of these four inequalities is not satisfied, the point is clipped (not saved for display).

Line Clipping Algorithms

Line Clipping Algorithms A line clipping procedure involves several parts. First, we can test a given line segment to determine whether it lies completely inside the clipping window. If it does not, we try to determine whether it lies completely outside the window. Finally, we must perform intersection calculations with one or more clipping boundaries.

Cohen Sutherland Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm Every line end point in a picture is assigned a four-digit binary code, called a region code, that identifies the location of the point relative to the boundaries of the clipping rectangle.

Cohen Sutherland Line Clipping Algorithm Find color codes of the points P1(5,6) P2 (25,15) P2 (25,15) P4(15,60) P5 (15,15) P6 (25,40)

Cohen Sutherland 32 0101 1010

Cohen Sutherland 33 0101 0010

Cohen Sutherland 34 0001 0010

Cohen Sutherland 35 0001 0000

Cohen Sutherland 36 0000 0000

Cohen Sutherland Line Clipping Algorithm Trivial Acceptance If the logical OR is zero , the line can be trivially accepted. For example, if the endpoint codes are 0000 and 0000, the logical OR is 0000 - the line can be trivially accepted. If the endpoint codes are 0000 and 0110, the logical OR is 0110 and the line can not be trivally accepted.

Cohen Sutherland Line Clipping Algorithm Trivial Rejection If the logical AND of the endpoint codes is not zero , the line can be trivally rejected. For example, if an endpoint had a code of 1001 while the other endpoint had a code of 1010, the logical AND would be 1000 which indicates the line segment lies outside of the window. On the other hand, if the endpoints had codes of 1001 and 0110, the logical AND would be 0000, and the line could not be trivally rejected.

Cohen Sutherland Line Clipping Example Consider the line segment AD . Point A has an outcode of 0000 and point D has an outcode of 1001 . Th e lo g i c al A N D o f the s e ou t c od e s is z e r o ; therefore, the line cannot be trivally rejected. Also, the logical OR of the outcodes is not zero; therefore, the line cannot be trivally accepted . The algorithm then chooses D as the outside point (its outcode contains 1's). By our testing order, we first use the top edge to clip AD at B . The algorithm then recomputes B 's outcode as 0000 . With the next iteration of the algorithm, AB is tested and is trivially accepted and displayed.

Cohen Sutherland Line Clipping Example Consider the line segment EI. Point E has an outcode of 0100, while point I's outcode is 1010. The results of the trivial tests show that the line can neither be trivally rejected or accepted. Point E is determined to be an outside point, so the algorithm clips the line against the bottom edge of the window. Now line EI has been clipped to be line FI. Line FI is tested and cannot be trivially accepted or rejected. Point F has an outcode of 0000, so the algorithm chooses point I as an outside point since its outcode is1010.

Cohen Sutherland Line Clipping Example Line FI is tested and cannot be trivially accepted or rejected. Point F has an outcode of 0000, so the algorithm chooses point I as an outside point since its outcode is1010. The line FI is clipped against the window's top edge, yielding a new line FH. Line FH cannot be trivally accepted or rejected. Since H's outcode is 0010, the next iteration of the algorthm clips against the window's right edge, yielding line FG. The next iteration of the algorithm tests FG, and it is trivially accepted and display.

Cohen Sutherland Line Clipping Algorithm Numerical Find visible portion of the line between points P1(x0,y0) = (12,8) P2(x1,y1) = (15,15)

Curve Clipping c u r v ed bou n da ries c an be Areas cl i pp e d with with m e t h od s sim i lar t o those discussed in the previous sections. Cu r v e - cli p pin g p r o ced u r es will i n v ol v e nonlinear equations, however, and this requires more processing than for objects with linear boundaries.

Curve Clipping : Complete accept or reject If the bounding rectangle for the object is completely inside the window, we save the object. If the rectangle is determined to be completely outside the window, we discard the object. But if the bounding rectangle test fails, we can look for other computation-saving approaches.

Curve Clipping : Complete accept or reject For a circle, we can use the coordinate extents of individual quadrants and then octants for preliminary testing (outside or inside) and then calculate curve-window intersections.

Text Clipping

Text Clipping V arious t ec h ni q ue s a r e use d t o p r ovid e t e x t cl i pp i n g i n a c om p u t er graphics. It depend s o n t h e m e th o d s use d t o g ene r a t e c h a r a c t e r s and the requirements of a particular application. There are three methods for text clipping which are listed below − All or none string clipping All or none character clipping Text clipping

All or none string clipping In all or none string clipping method , either we keep the entire string or we reject entire string based on the clipping window.

All or none character clipping In this method if the string is partially outside the window, then − You reject only the portion of the string being outside If the cha r a c t er i s on t h e b o u n da ry of t h e cl ip pi n g win d o w , then we discard that entire character and keep the rest string.

Text clipping If it is partially outside the window, then You reject only the portion of string being outside. If the character is on the boundary of the clipping window, then we discard only that portion of character that is outside of the clipping window.

Two-Dimensional Viewing Windowing And Clipping: Viewing Pipeline Viewing Transformations 2-D Clipping Algorithms Line Clipping Algorithms Cohen Sutherland Line Clipping Algorithm Liang Barsky Algorithm Line Clipping Against Non Rectangular Clip Windows Polygon Clipping Sutherland Hodgeman Polygon Clipping Weiler And Atherton Polygon Clipping Curve Clipping Text Clipping

Two-Dimensional Viewing 2-D Clipping Algorithms Liang Barsky Algorithm Line Clipping Against Non Rectangular Clip Windows Polygon Clipping Sutherland Hodgeman Polygon Clipping Weiler And Atherton Polygon Clipping

Liang-Barsky Algorithm The Liang-Barsky algorithm is a line clipping algorithm. This algorithm is more efficient than Cohen–Sutherland line clipping algorithm and can be extended to 3-Dimensional clipping. This algorithm is considered to be the faster parametric line-clipping algorithm.

Liang-Barsky Algorithm The following concepts are used in this clipping: The parametric equation of the line. X = x0 + u(x1-x0) Y = y0 + u(y1-y0) The inequalities describing the range of the clipping window which is used to determine the intersections between the line and the clip window. xwmax <= x0 + u(x1-x0) <= xwmin ywmax <= y0 + u(y1-y0) <= ywmin

Liang-Barsky Algorithm Numerical Find visible portion of the line between points P1(x0,y0) = (6,12) P2(x1,y1) = (24,18) P1(x0,y0) = (12,30) P2(x1,y1) = (16,4)

Polygon Clipping For polygon clipping, we require an algorithm that wiIl generate one or more closed areas that are then scan converted for the appropriate area fill. What we reaIly want to display is a bounded area after clipping.

Sutherland Hodgeman Polygon Clipping Beginning with the initial set of polygon vertices, we could first clip the polygon against the left rectangle boundary to produce a new sequence of vertices. The new set of vertices could then k successively passed to a right boundary clipper, a bottom boundary clipper, and a top boundary clipper.

Four Cases Out-In, In-In, In-out, Out-out

Sutherland Hodgeman Polygon Clipping As each pair of adjacent polygon vertices is passed to a window boundary clipper, we make the following tests: Out-In - If the first vertex is outside the window boundary and the second vertex is inside, both the intersection point of the polygon edge with the window boundary and the second vertex are added to the output vertex list. In-In If both input vertices are inside the window boundary, only the second vertex is added to the output vertex list. In-Out- If the first vertex is inside the window boundary and second vertex is outside the boundary, only the edge intersection with the window boundary is added to the output vertex list. Out-Out- If both input vertices are outside the window boundary, nothing is added to the output list.

Example
Tags