1 / 17

Line Clipping

( x 1 , y 1 ). y max y min. ( x 0 , y 0 ). x min x max. Line Clipping. Line clipping against rectangles The problem : Given a set of 2D lines or polygons and a window, clip the lines or polygons to their regions that are inside the window. Motivations. Efficiency

Download Presentation

Line Clipping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. (x1, y1) ymax ymin (x0, y0) xmin xmax Line Clipping • Line clipping against rectangles The problem: Given a set of 2D lines or polygons and a window, clip the lines or polygons to their regions that are inside the window.

  2. Motivations • Efficiency • Display in portion of a screen • Occlusions Clip rectangle

  3. In: 3 vertices Out: 6 vertices Clip In: 1 polygon Out: 2 polygons Clip Clipping is tricky!

  4. ymax ymin xmin xmax ymax ymin xmin xmax Simple Cases • If x0 < xminandx1 < xmin • orx0 > xmaxandx1 > xmax • or y0 < yminandy1 < ymin • or y0 > ymaxandy1 > ymax • trivial rejection. • If xmin≤x ≤ xmax • and ymin ≤ y ≤ ymax • trivially accepted.

  5. The Cohen-Sutherland Line-Clipping Algorithm • Region and outcodes • First bit: above top edge y > ymax • Second bit: below bottom edge y < ymin • Third bit: to right of right edge x > xmax • Fourth bit: to left of left edge x < xmin

  6. The C-S Line-Clipping Algorithm (cont.) • Checking for trivial acceptance or rejection using outcodes • 1). Each endpoint of a line segment is assigned an outcode; • 2). If both 4-bit codes are zero, the line can be trivially accepted; • 3). A logical and is performed on both outcodes; • 4). If the result is nonzero, the line can be trivially rejected.

  7. D C 1000 1010 B 1001 I A H 0001 0000 0010 G F 0100 0101 0110 E Steps for Cohen-Sutherland Algorithm • End-points pairs are checked for trivial acceptance or rejection using outcode; • If not trivially accepted or rejected, divide the line segment into two at a clip edge; • Iteratively clipped by test trivial-acceptance or trivial-rejection, and divided into two segments until completely inside or trivial-rejection.

  8. Polygon Clipping • Sutherland-Hodgeman algorithm (A divide-and-conquer strategy) • Polygons can be clipped against each edge of the window one at a time. Edge intersections, if any, are easy to find since the X or Y coordinates are already known. • Vertices which are kept after clipping against one window edge are saved for clipping against the remaining edges. • Note that the number of vertices usually changes and will often increases.

  9. Right Clip Boundary Bottom Clip Boundary Top Clip Boundary Left Clip Boundary Clipping A Polygon Step by Step

  10. Sutherland-Hodgeman Algorithm Note the difference between this strategy and the Cohen-Sutherland algorithm for clipping a line: the polygon clipper clips against each window edge in succession, whereas the line clipper is a recursive algorithm. Given a polygon with n vertices, v1, v2,…, vn, the algorithm clips the polygon against a single, infinite clip edge and outputs another series of vertices defining the clipped polygon. In the next pass, the partially clipped polygon is then clipped against the second clip edge, and so on. Let’s considering the polygon edge from vertex vito vertex vi+1. Assume that start point vi has been dealt with in the previous iteration, four cases will appear.

  11. Inside Outside Inside Outside vi Polygon been clipped vi+1 Polygon been clipped vi i: output Clip Boundary vi+1: output i: first output Case 1 Case 2 Inside Outside vi vi+1 vi+1: second output Polygon been clipped vi Outside Inside Case 4 Case 3 (no output) Sutherland-Hodgeman Algorithm(cont.)

  12. An Example for the Polygon Clipping v5 v4 v1 v2 v3

  13. Solution: As we said, the Sutherland-Hodgeman algorithm clip the polygon against one at a time. We start with the right edge of the clip rectangle. In order to clip the polygon against the line, each edge of the polygon have to be considered. Starting with the edge, represented by a pair of vertices, v5v1: v5 v5 v4 v1 v1 v1 v2 v3 Clipping edge Clipping edge Clipping edge

  14. Solution (cont.): Now v1v2: v5 v4 v1 v1 v1 v2 v2 v3 v2 Clipping edge Clipping edge Clipping edge

  15. Solution (cont.): Now v2v3: v5 v4 v1 v1 v2 v3 v2 v2 v3 v2 v3 Clipping edge Clipping edge Clipping edge

  16. Solution (cont.): Now v3v4: v5 v4 v4 v1 v1 i1 v2 v3 v2 v3 v2 v3 Clipping edge Clipping edge Clipping edge

  17. Solution (cont.): Now v4v5: v5 v5 v5 v4 i2 v4 v1 v1 i1 v2 v3 v2 v2 v3 Clipping edge Clipping edge Clipping edge After these, we have to clip the polygon against the other three edges of the window in a similar way.

More Related