CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Similar documents
Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Two-Dimensional Viewing. Chapter 6

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Part IV. 2D Clipping

From Vertices To Fragments-1

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

2D Viewing. Viewing Pipeline: Window-Viewport Transf.

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

CS452/552; EE465/505. Clipping & Scan Conversion

Chapter 8: Implementation- Clipping and Rasterization

CSCI 4620/8626. Coordinate Reference Frames

3D Rendering Pipeline (for direct illumination)

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

Computer Graphics: Two Dimensional Viewing

Unit 3 Transformations and Clipping

Clipping Lines. Dr. Scott Schaefer

MODULE - 9. Subject: Computer Science. Module: Line Clipping. Module No: CS/CGV/9

Realtime 3D Computer Graphics Virtual Reality

CS602 MCQ,s for midterm paper with reference solved by Shahid

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Topics. From vertices to fragments

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

(Refer Slide Time: 00:02:02)

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Computer Graphics Viewing Objective

Clipping and Scan Conversion

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

UNIT -8 IMPLEMENTATION

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Course Number: Course Title: Geometry

Practical Linear Algebra: A Geometry Toolbox

Chapter 3. Sukhwinder Singh

Viewing Transformation. Clipping. 2-D Viewing Transformation

A Procedure to Clip Line Segment

Two Dimensional Viewing

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

Part 3: 2D Transformation

Computer Science 474 Spring 2010 Viewing Transformation

RASTERIZING POLYGONS IN IMAGE SPACE

COMP3421. Vector geometry, Clipping

Computer Graphics. - Rasterization - Philipp Slusallek

Clipping and Intersection

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

521493S Computer Graphics Exercise 1 (Chapters 1-3)

Keywords Computer Graphics, Line Clipping, 2D geometry, 3D geometry.

Graphics (Output) Primitives. Chapters 3 & 4

form are graphed in Cartesian coordinates, and are graphed in Cartesian coordinates.

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Review for Mastery Using Graphs and Tables to Solve Linear Systems

Intersection of an Oriented Box and a Cone

Number/Computation. addend Any number being added. digit Any one of the ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9

Lecture 25: Bezier Subdivision. And he took unto him all these, and divided them in the midst, and laid each piece one against another: Genesis 15:10

CS 325 Computer Graphics

SE Mock Online Test 1-CG

4.5 VISIBLE SURFACE DETECTION METHODES

12.4 Rotations. Learning Objectives. Review Queue. Defining Rotations Rotations

1.6 Classifying Polygons

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Lab Manual. Computer Graphics. T.E. Computer. (Sem VI)

Figure 1: A positive crossing

Question 2: How do you solve a linear programming problem with a graph?

3.3 Optimizing Functions of Several Variables 3.4 Lagrange Multipliers

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

CS 450: COMPUTER GRAPHICS REVIEW: CLIPPING SPRING 2015 DR. MICHAEL J. REALE

Answer Key: Three-Dimensional Cross Sections

(Refer Slide Time: 00:02:00)

Pick s Theorem and Lattice Point Geometry

Prime Time (Factors and Multiples)

Polygon Triangulation

Mathematics Assessment Anchor Glossary Grades 3 & 4

Glossary of dictionary terms in the AP geometry units

Computational Geometry

MIT EECS 6.837, Teller and Durand 1

SHAPE AND STRUCTURE. Shape and Structure. An explanation of Mathematical terminology

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Windowing And Clipping (14 Marks)

Mrs. Daniel s Geometry Vocab List

Intro to Modeling Modeling in 3D

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

(a) rotating 45 0 about the origin and then translating in the direction of vector I by 4 units and (b) translating and then rotation.

MATH DICTIONARY. Number Sense. Number Families. Operations. Counting (Natural) Numbers The numbers we say when we count. Example: {0, 1, 2, 3, 4 }

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Indirect measure the measurement of an object through the known measure of another object.

CS 4204 Computer Graphics

Polar Coordinates. 2, π and ( )

Sung-Eui Yoon ( 윤성의 )

Chapter - 2: Geometry and Line Generations

Multivariate Calculus Review Problems for Examination Two

(Refer Slide Time 03:00)

Transcription:

CSCI 4620/8626 Computer Graphics Clipping Algorithms (Chapter 8-5 ) Last update: 2016-03-15 Clipping Algorithms A clipping algorithm is any procedure that eliminates those portions of a picture outside a specified region of space (usually a rectangle in standard position). Considered here are 2D clipping algorithms for Points Lines (straight-line segments) Fill areas Curves Text 2 1

2D Point Clipping Point clipping is reasonably obvious. If the point s coordinates (x,y) satisfy the following inequalities, then it is inside the clipping region: xw min x xw max yw min y yw max If any of the inequalities is not met, then the point is dropped (clipped). 3 2D Line Clipping (1) Assume a rectangular clipping window in standard position and a line segment (i.e. two vertices). The results of a line clipping algorithm can be (1) the line is entirely outside the clipping window; or (2) the line is entirely inside the clipping window; or (3) the line intersects the clipping window boundary; part is inside and part is outside. The most expensive part of the algorithm deals with result (3), so we seek algorithms that minimize the work needed for that result. 4 2

2D Line Clipping (2) If both endpoints of a segment are inside the clipping window (e.g. P 1 -P 2 in Fig. 8-9), the segment is entirely in the clipping window. If both endpoints of a segment are outside any one of the four boundaries of the clipping window (e.g. P 3 -P 4 ), the segment is entirely outside the clipping window. (P 9 -P 10 doesn t fit this case!) Otherwise the segment may intersect the boundary of the clipping window and may extend into its interior. 5 Figure 8-9 Clipping straight-line segments using a standard rectangular clipping window. 3

2D Line Clipping (3) One way to determine where a line segment crosses a clipping window edge: Assume (x 0,y 0 ) and (x end,y end ) are the line segment endpoints. Use these parametric equations of the line: x x 0 u x end x 0 y y 0 u y end y 0 0 u 1 Sequentially substitute the x/y window boundary values (4 of them) for the x/y variables and solve for u. If u is in [0,1], then solve for y/x (the other variable). If it s in the allowed range for the clipping window, then we clip the line. 7 Clipping Efficiency (1) The basic clipping algorithm just discussed is straightforward, but inefficient. Recall that floating point arithmetic is vastly slower than integer arithmetic, and floating point division is enormously slower than addition. For example, on a 2.66GHz Intel Xeon 10 8 fp additions (or subtractions) took 515 msec 10 8 fp multiplications took 584 msec 10 8 fp divisions took 1168 msec 8 4

Clipping Efficiency (2) Since real images typically have many line segments, and clipping is done frequently, we must be concerned about the time required to perform the clipping operation. Many clipping algorithms do more initial testing to reduce the processing time for a set of line segments. Some of these are designed specifically for 2D pictures, while others can be easily adapted to 3D. 9 Cohen-Sutherland Line Clipping In this algorithm, each line endpoint is first classified by assigning it a 4-bit region code (sometimes called an out code). Think of an infinite line through a clipping window edge as separating the plane into two half-planes. Each bit of the region code identifies the half-plane in which a line endpoint lies. 0 is used if the endpoint lies in the half-plane that contains the clipping region ( inside half space). 1 is used if the endpoint lies in the half-plane that is outside the clipping region ( outside half space). 10 5

Figure 8-10 A possible ordering for the clipping window boundaries corresponding to the bit positions in the Cohen- Sutherland endpoint region code. Figure 8-11 The nine binary region codes for identifying the position of a line endpoint, relative to the clipping-window boundaries. 6

Setting the Region Code Bits It should be easy to see how the bits in the region code for a line segment s endpoint are set. For example, given the region code bit arrangement shown in figure 8-10, the value of bit 1 is the result of evaluating x xw min The other three bits in the region code are set in a similar manner. The bits are easily computed by keeping just the sign bits of the differences; for example, the sign bit of x xw min would be used for bit 1. 13 Simple Cases Once region codes are established, it s easy to determine which line segments are completely inside or outside the clipping window. Any line that is completely within the clipping window will have a region code of 0000 for each endpoint. Any line that is completely outside the clipping window will have endpoint region codes with 1 in the same bit position. 14 7

Simple Case Examples It should be easy to see why 0000 is associated with each endpoint of a segment within the clipping window. Imagine a line segment that begins to the left of the clipping window and extends to the upper left. Bit position 1 will be 1 for both endpoints, since each of them is in the half-plane to the left of the clipping window. Bit position 4 will be 0 in one endpoint and 1 in the other. 15 Implementation of Simple Cases If we do a bitwise OR operation on the two region codes and get 0000, then each region code must have been 0000, and the line segment is completely within the clipping region; keep it. If we do a bitwise AND operation on the two region codes and get a non-zero value, then one of the same bits in each region code must have been 1; discard the line segment as being completely outside the clipping region. Recall that zero/non-zero values are treated as false/true in C/C++. 16 8

Not So Simple Lines that can t be easily classified must be checked for intersection with the clipping window boundaries. This may require several intersection calculations. Note that a line segment can intersect several clipping window boundary lines (that is, cross between multiple of the half-planes) without necessarily entering the interior of the clipping window. 17 Figure 8-12 Lines extending from one clipping-window region to another may cross into the clipping window, or they could intersect one or more clipping boundaries without entering the window. 9

Does It Cross? To determine if a line segment crosses from one half-plane to another (and potentially into the clipping window), we examine the corresponding bit positions in the two region codes. If the value of the bits in corresponding positions differ, then the segment crosses the boundary line between the two half-planes. As each clipping-window edge is processed, a section of the line is clipped, and the remainder of the line is checked against the other borders. 19 Termination Conditions After each clip of a line segment, the modified segment is checked to see if it is totally inside or outside the clipping window. If so, we re done. Otherwise, the modified line segment is checked against the remaining clipping window borders. It is possible that an intersection position may be calculated at each of the four clipping boundaries, as illustrated in Figure 8-13. (This is because the order in which boundaries are checked may not match the order in which the segment intersects the boundaries.) 20 10

Figure 8-13 Four intersection positions (labeled from 1 to 4) for a line segment that is clipped against the window boundaries in the order left, right, bottom, top. Boundary Intersections (1) It s relatively easy to determine a boundary intersection for a line segment. Given (x 0, y 0 ) and (x end, y end ) as the line endpoints, and x is the position of a vertical clipping border line (i.e. xw min or xw max ), compute the y coordinate of the intersection as follows: m y end y 0 / x end x 0 y y 0 m x x 0 22 11

Boundary Intersections (2) If we re looking for the intersection with a horizontal border, then the x coordinate can be calculated as follows (where y is yw min or yw max ): x x 0 y y 0 m 23 Liang-Barsky Line Clipping Cyrus and Beck, then later Liang and Barsky, developed faster line-clipping algorithms based on additional line testing using the parametric form for lines. Given the usual endpoint definitions, the line can be parametrically described as follows (same as before): 24 12

Combine with Point-Clipping Conditions Liang-Barsky then combines the parametric line equations with the point-clipping conditions seen earlier. This yields these four inequalities (given in pairs): xw min x 0 u x xw max yw min y 0 u y yw max 25 Rewriting the Inequalities The four inequalities can be rewritten like this: up k q k k 1,2,3,4 p and q are defined as 26 13

Example: p 1 and q 1 Derivation Let s consider one inequality: Subtract uδx from each side: Subtract xw min from each side: If we now define p 1 = -Δx and q 1 = x 0 xw min, we obtain the expression given for the first inequality: up 1 q 1 The remaining inequalities can be rewritten to yield the other cases for up k q k. 27 Cases to Consider If p k = 0, then the line is parallel to a boundary. If q k < 0 for the same k, then the line can be discarded. If q k 0 then the corresponding pointclipping inequality is satisfied. If p k < 0, then the segment potentially enters the clipping window across the k-th boundary; call this case PE. If p k > 0, then the segment potentially leaves the clipping window across the k-th boundary; call this case PL. 28 14

Definitions Let K PE = { k : p k < 0 } denote the set of indices of clipping boundaries across which the line potentially enters the clip rectangle. Similarly let K PL = { k : p k > 0 } denote the set of indices of clipping boundaries across which the line potentially leaves the clip rectangle. Let u k = q k / p k represent the parameter value at the k-th boundary crossing. 29 Visible Segment With those definitions, the visible portion of the line segment is that where the parameter value u is in the range u min u u max where u min = max kîk PE [ ] u max = min [ ] 0,u k kîk PL 1,u k If u min > u max then the entire segment is clipped. 30 15

Example of Liang-Barsky In the fullness of time there will be a slide or two that demonstrates Liang-Barsky with a specific set of lines and a specific clipping window. 31 Nicholl-Lee-Nicholl Line Clipping The Nicholl-Lee-Nicholl (NLN) line clipping algorithm creates more regions around the clipping window to avoid multiple line-intersection calculations, thus using fewer comparisons and divisions. The tradeoff is that Cohen-Sutherland and Liang- Barsky can be easily extended to three dimensions, but NLN cannot. 32 16

NLN Rationale In general, a line segment (being clipped) can intersect all four of the (extended) clipping window boundaries (review fig. 8-13). At most two of these intersections are relevant to the clipping problem. We assume most of the computational overhead is associated with finding intersections, so it follows that irrelevant intersection computations should be avoided. Only three cases need to be considered. 33 NLN - Initial Testing Initially, a line s endpoints are assigned region codes as before. Then the easy tests to determine if the line is entirely inside or outside the clipping region are performed. Obviously we re done (as before) if one of the easy tests succeeds. Otherwise NLN proceeds to set up additional clipping regions. 34 17

Endpoint Positions to Consider One of the endpoints (called P 0 ) of each line considered by NLN must be in one of three positions. That is, P 0 must have one of three region codes: 0000 = inside the clipping region 0001 = immediately left of the clipping region 1001 = left and above the clipping region If P 0 isn t in one of those regions, but P end is, then P 0 and P end can be swapped. The other endpoint positions can be mapped into one of the three positions by rotating the line and the clipping region by 90, 180, or 270 degrees. 35 90 or 180 or 270 CCW Rotation A 90, 180 or 270 counterclockwise rotation of a point (x,y) about the origin can be easily accomplished: For a 90 rotation, replace (x,y) with (-y,x) For a 180 rotation, replace (x,y) with (-x,y) For a 270 rotation, replace (x,y) with (-y,-x) So, for NLN, rotating the clipping region and the line segment (from P 0 to P end ) requires 12 assignments and some negations. We ll also need to do the reverse rotation after clipping is completed. 36 18

Figure 8-14 Three possible positions for a line endpoint P 0 in the NLN line-clipping algorithm. NLN: P 0 inside the window If P 0 is inside the clipping window, and P end is outside, then four regions are defined as shown in figure 8-15. These regions are defined by the semi-infinite lines beginning with P 0 and extending through the four vertices defining the corners of the clipping window. The region containing P 0 P end is easily identified by comparing the line s slope with the slopes of the lines bordering the regions (more later). 38 19

Figure 8-15 The four regions used in the NLN algorithm when P 0 is inside the clipping window and P end is outside. NLN: P 0 left of the window As before, four lines are drawn from P 0 through the vertices of the clipping window (see fig. 8-16). We now have four regions, labeled for the clipping window edges the line could intersect: L (inside the window), LT, LR, and LB. If P end is in L, it is easily identified by its region code (0000). The other regions are identified, as before, by comparing the slope of P 0 P end with the slopes of the region boundary lines. 40 20

Figure 8-16 The four clipping regions used in the NLN algorithm when P 0 is directly to the left of the clip window. NLN: P 0 above left of the window The regions in this case depend on whether P 0 is closer to the (extended) left boundary edge or the top boundary edge of the clipping window. These two cases are shown in fig. 8-17 (a) and (b), along with the various regions they define; labeled for the edges the clipped line intersects. The region containing P end and therefore the edge(s) of the clipping window that are intersected is(are) identified by comparing the slope of P 0 P end with the slope of the boundary lines of the regions. 42 21

Figure 8-17 The two possible sets of clipping regions used in the NLN algorithm when P 0 is above and to the left of the clipping window. Slopes Assume the line being clipped has endpoint coordinates (x 0,y 0 ) and (x end,y end ). The slope of this line is easily seen to be y end - y 0 x end - x 0 In the case illustrated in fig. 8-16, the slopes of the lines bounding the top regions (L and LT) are y T - y 0 y T - y and 0 x R - x 0 x L - x 0 44 22

Slope Comparisons If the line being clipped is in region L or LT, then we must have y T - y 0 y - y end 0 y - y T 0 x R - x 0 x end - x 0 x L - x 0 Look at the first (left) inequality (as an example). It can be rewritten as y T - y 0 ( )( x end - x 0 ) ( y end - y 0 )( x R - x 0 ) Note this involves no divisions! 45 Intersection Calculations Once the clipping window edge(s) that intersect the line being clipped is(are) identified, the intersection point can be determined using only a single division for each intersection. The coordinate difference calculations and product calculations used in the slope comparisons are saved and reused in the intersection calculations. Although only a single region was used here as an example, the work for other regions is very similar. 46 23

Non-Rectangular Polygon Clip Windows Dealing with other polygonal (read as: with line-segment edges) clip windows can be done with methods like Cyrus- Beck or Liang-Barsky these use parametric forms for the line segments. To do this: First see if clip line endpoints are inside or outside a rectangular polygon that encloses the non-rectangular one (i.e. the bounding box). This can easily exclude lines that don t intersect. Represent the lines of the polygon boundary in parametric forms (in addition to the line being clipped). Solve for the parameter representing intersection of the line with the boundary; if not in [0,1], there is no intersection. Otherwise, we easily find part of the line to keep. Repeat as necessary. 47 Concave Polygonal Clip Windows As expected, we can use the parametric procedures for concave clip regions if we split them into several convex regions. Alternately, we can add one or more edges to the concave polygon to make it a convex polygon. Then a series of clipping operations can be done using the modified convex components. 48 24

Figure 8-18 A concave- polygon clipping window (a), with vertex list (V 1, V 2, V 3, V 4, V 5 ), is modified to the convex polygon (V 1, V 2, V 3, V 4 ) in (b). The external segments of line P 1 P 2 are then snipped off using this convex clipping window. The resulting line segment, P' 1 P' 2, is next processed against the triangle (V 1, V 5, V 4 ) (c) to clip off the internal line segment P' 1 P'' 2 to produce the final clipped line P'' 1 P' 2. Nonlinear Clipping Window Boundaries We can (obviously) also use non-linear (not straight line segments) clipping window boundaries to clip against circular or curved clipping regions. Also (obviously) such clipping operations will be more costly (more computation). 50 25

Polygon Fill-Area Clipping As noted earlier, most graphics packages only support filling polygonal area, and then often only convex polygonal areas. A problem with clipping the boundary lines of such areas is that the resulting (clipped) lines may not represent a closed polygon, and therefore cannot have a fill algorithm applied to them. 51 Figure 8-19 A line-clipping algorithm applied to the line segments of the polygon boundary in (a) generates the unconnected set of lines in (b). 26

Polygon Fill Area: What s Needed? Traditional line clipping of a polyline against a clipping area may produce multiple non-connected line segments, as noted. What is needed is a procedure that will generate one or more closed polylines for the boundaries of the clipped fill area. The next slide (8-20) illustrates the proper clipping of a filled area. 53 Figure 8-20 Display of a correctly clipped polygon fill area. 27

Algorithm Basics As usual, the algorithm will clip each line of the polygon s border resulting in a new set of clipped endpoints at each clipping-window boundary. The fill area also needs to be maintained as a separate entity, determining the new shape for the polygon(s) as each clipping-window edge is processed. The next slide illustrates this idea. 55 Figure 8-21 Processing a polygon fill area against successive clippingwindow boundaries. 28

First, The Simple Cases The easiest cases to handle are those where we can immediately clip the entire filled area: Determine the rectangular area that encloses the object to be clipped (the bounding box all we need are the minimum and maximum coordinate extents). Then determine if the enclosing rectangle and the rectangular clipping area intersect. If these do not intersect, we toss out the entire filled object. Figure 8-22 illustrates this idea. 57 Figure 8-22 A polygon fill area with coordinate extents outside the right clipping boundary. 29

Otherwise If we can t discard it entirely, then we must process each edge of the polygon. One way is to use a separate clipper for each clipping window boundary, and have these clippers pass vertex lists along a pipeline. The result (output) of the final clipper is the vertex list for the clipped polygon (see the next slide). For concave polygons, multiple vertex lists may be generated. 59 Figure 8-23 A convex-polygon fill area (a), defined with the vertex list {1, 2, 3}, is clipped to produce the fill-area shape shown in (b), which is defined with the output vertex list {1', 2', 2'', 3', 3'', 1''}. 30

Sutherland-Hodgman Polygon Clipping This method has multiple stages, one for each clipping window boundary. Polygon vertices are sent through each clipping stage, with the output of one passed immediately to the next. The algorithm cannot handle all concave polygons, but can handle those that result in a single vertex list. 61 General Strategy Endpoint pairs for each successive polygon line segment sent through clippers (left, right, bottom, top). As soon as a clipper does its work, the clipped coordinate values (if any) are sent to the next clipper. Then the first clipper processes the next pair of endpoints. The individual clippers can operate in parallel, making for fast hardware implementation! 62 31

Four Cases As shown in the next slide (figure 8-24), there are four cases to consider for each clipping stage. Assume the two vertices being considered are named V 1 and V 2. Consider the position of these relative to a clipping window edge, not the whole window: V 1 outside, V 2 inside: intersection point (V 1 ) and V 2 passed on. V 1 inside, V 2 inside: only V 2 passed on. V 1 inside, V 2 outside: only the intersection point (V 1 ) is passed on. V 1 outside, V 2 outside: nothing is passed on. 63 Figure 8-24 The four possible outputs generated by the left clipper, depending on the position of a pair of endpoints relative to the left boundary of the clipping window. 32

Do It Now 2 2' 3 3' 2'' 1' 1 65 A Complete Example Consider this example: For the left clipping window edge: {1,2}: in, in: pass {2} {2,3}: in, out: pass {2 } {3,1}: out, in: pass {3,1} For the right clipping window edge: {2,2 }: in, in: pass {2 } {2,3 }: in, in: pass {3 } {3,1}: in, in: pass {1} {1,2}: in, in: pass {2} For the bottom clipping window edge: {2 } {2,3 }: in, out: pass {2 } {3,1}: out, out: pass { } {1,2}: out, in: pass {1,2} {2,2 }: in, in: pass {2 } 66 3 2' 3' 2'' 1 Top Edge {2,1 }: in, in: pass {1 } {1,2}: in, in: pass {2} {2,2 }: in, in: pass {2 } 1' {2,2 }: in, in: pass 2 33

Figure 8-25 Processing a set of polygon vertices, {1, 2, 3}, through the boundary clippers using the Sutherland- Hodgman algorithm. The final set of clipped vertices is {1', 2, 2', 2''}. Concave Polygons As noted, Sutherland-Hodgman might be used for concave polygons. In some cases, however, extraneous lines may appear (see the next slide, figure 8-26). What to do? Split the concave polygon into two or more concave polygons, then use Sutherland-Hodgman on each. Check for multiple vertex positions on any clipping boundary, then separate into multiple vertex lists may require extensive analysis. Use a different algorithm designed for concave polygons! 68 34

Figure 8-26 Clipping the concave polygon in (a) using the Sutherland-Hodgman algorithm produces the two connected areas in (b). Weiler-Atherton Polygon Clipping Advantage 1: It can handle concave filled polygons! Advantage 2: It can clip a polygon against a polygonal clipping window! It was originally developed to identify visible surfaces in a 3D scene. Basic idea: trace around the perimeter of the polygon being clipped, searching for borders that enclose a clipped fill region. Thus the appropriate result (2 regions) would be found for the concave polygon in the previous slide. 70 35

Prerequisites The processing direction (i.e. the order in which the vertices are visited) must be strictly CW or CCW. This means the vertices of the polygons should have been ordered appropriately. We must be able to identify when an edge of the polygon being clipped crosses to the outside of the clipping polygon. The cross-product of two successive edge vectors that form a convex angle can identify the front of the polygon (normal vector from back to front). 71 The Algorithm Part 1 (CCW) [1] Process edges of polygon being clipped in CCW order until inside-outside pair of vertices is encountered (at one of the clipping boundaries); first vertex is inside, second vertex is outside. [2] Follow clipping window boundaries CCW to another intersection with the polygon. If this was previously processed, go to step 3. Otherwise continue processing polygon edges until a previously processed vertex is encountered. 72 36

The Algorithm Part 2 [3] Form the vertex list for this section of the clipped fill area [4] Return to the exit intersection point (found in step 2) and continue processing the polygon vertices in CCW order. 73 Illustration Rectangular Window On the next slide, a rectangular clipping window is used with a convex polygon. If we start at point 1, we detour around the clipping window at point 1, eventually returning to point 1 (giving vertices 1, 1, 1, and 1 ). Resuming from point 1, we visit 2, then 2. But this edge is outside the window, as is 2 3, and 3 4. From 4 we encounter the clipping window at 4 (4 4 outside the window), proceed to 5, detour to 5, then to 4 which ends the detour (giving 4, 5, 5 ). We resume at 5 and return to 1, which is the last of the vertices. 74 37

Figure 8-27 A concave polygon (a), defined with the vertex list {1, 2, 3, 4, 5, 6}, is clipped using the Weiler-Atherton algorithm to generate the two lists {1, 1', 1'', 1'''} and {4', 5, 5'}, which represent the separate polygon fill areas shown in (b). Nonrectangular Polygon Clip Windows Parametric line clipping methods (e.g. Liang Barsky) are well-suited for processing polygon fill areas against convex-polygon clipping windows. Parametric representation of the edges of the fill area and the clipping window are used, each represented as a vertex list. The usual rectangular exclusion test is performed. Then pairs of simultaneous parametric equations are solved to find intersection points. 76 38

Nonrectangular Windows (2) Inside-outside tests may be needed to determine if a fill-area vertex is inside or outside a particular clipping-window boundary. This approach can be used in constructive solidgeometry applications to identify the result of a union, intersection, or difference operation on two polygons. In particular, intersection == clipping! 77 Illustration Nonrectangular Window The next slide shows a CCW traversal with a nonrectangular clipping window. Starting at 1, the first inside->outside traversal is at the bottom of the clipped area (shown in green), where we detour (CCW again) around the clipping window s polygon. We eventually return to the point at the top of the clipped area. We then go to step 3 (to form the vertex list), then return to the bottom vertex and follow the polygon vertices, back to vertex 1. 78 39

Figure 8-28 Clipping a polygon fill area against a concave-polygon clipping window using the Weiler-Atherton algorithm. Curve Clipping (1) Same procedures as with polygonal clipping when part of the curved object are line segments. For curved parts, non-linear equations must be used, and the intersection calculations are more difficult. To begin, however, the same exclusion tests used with polygons are employed. If the curved object is entirely outside the clipping region, then it is excluded! 80 40

Figure 8-29 A circle fill area, showing the quadrant and octant sections that are outside the clipping-window boundaries. Curve Clipping (2) Another technique, useful if the curved object has a regular geometry, is to use symmetry to simplify the calculation. In the example shown on the next slide, for example, much of the circle fill area (3 quadrants) is outside the clipping window. Once specific intersection positions are found, they are saved for later use by the scan-line fill procedures. 82 41

Figure 8-30 Clipping a circle fill area. Figure 8-31 Text clipping using the coordinate extents for an entire string. 42

Figure 8-32 Text clipping using the bounding rectangle for individual characters in a string. Figure 8-33 Text clipping performed on the components of individual characters. 43

Table 8-1 Summary of OpenGL Two-Dimensional Viewing Functions Table 8-1 (continued) Summary of OpenGL Two-Dimensional Viewing Functions 44

Table 8-1 (continued) Summary of OpenGL Two-Dimensional Viewing Functions 45