1 of 13

Unit-4�Clipping

PREPARED BY: SUSHANT BHATTARAI

2 of 13

Clipping

SUSHANT BHATTARAI

3 of 13

  • Process of discarding the parts of the picture that are outside of a specific region is called clipping
  • Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is referred to as a clipping algorithm
  • The region against which an object is clipped is called a clip window

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

3

4 of 13

Applications of Clipping

  • Extracting part of a defined scene for viewing
  • Identifying visible surfaces in three-dimensional views
  • Antialiasing line segments or object boundaries
  • Creating objects using solid-modeling procedures
  • Displaying a multi-window environment
  • Drawing and painting operations that allow parts of a picture to be selected for copying, moving, erasing, or duplicating

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

4

5 of 13

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

xwmin ≤ x ≤ xwmax

ywmin ≤ y ≤ ywmax

  • where the edges of the clip window (xwmin, xwmax, ywmin, ywmax) 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)

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

5

6 of 13

Line Clipping

  • Lines that donot intersect clipping window are either completely inside or outside the window.
  • Line clipping can be sub divided on the basis of the alignment of the line segment as:
  • Visible
    1. Both end point of line segment lie inside the window
    2. No clipping necessary
  • Non –visible
    • Lines are completely outside the window
    • Discard the line segment

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

6

7 of 13

Line Clipping

  • Partially Visible (Clipping Candidate)
    1. A line is partially visible when it lies within a window
    2. Here we need to compute the intersection point and clip at intersection point

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

7

8 of 13

Cohen Sutherland Line Clipping Algorithm

  • Oldest and most popular line clipping algorithm
  • Co-ordinate system is divided into 9 regions. All regions have associated codes.
  • Endpoint of every line is assigned a four digit binary code.
  • Each bit in the code is set to either 1 or 0.
  • Region code for point inside clipping window is 0000.

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

8

9 of 13

Cohen Sutherland Line Clipping Algorithm

  • For any endpoint(x,y) can be identified as follows:
    1. First bit(left most) is set to 1 if the point lies towards left of window
    2. Second bit is set to 1 if the point lies towards right of window
    3. Third bit is set to 1 if the point lies towards bottom/below of window
    4. Fourth bit is set to 1 if the point lies towards top/above of window

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

9

10 of 13

  • Algorithm
    • Step 1 : Assign a region code for two endpoints of given line
    • Step 2 : If both endpoints have a region code 0000 then given line is completely inside and we will keep this line
    • Step 3 : If step 2 fails, perform the logical AND operation for both region codes.

Step 3.1 : If the result is not 0000, then given line is completely outside.

Step 3.2 : Else line is partially inside.

Step 3.2.a : Choose an endpoint of the line that is outside the given rectangle.

Step 3.2.b : Find the intersection point of the rectangular boundary (based on region code).

Step 3.2.c : Replace endpoint with the intersection point and update the region code.

Step 3.2.d : Repeat step 2 until we find a clipped line either trivially accepted or rejected.

    • Step 4 : Repeat step 1 for all lines

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

10

11 of 13

Liang-Barsky Line Clipping

  • Taught in class

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

11

12 of 13

Sutherland-Hodgeman Polygon Clipping Algorithm

  • Uses divide and conquer strategy.
  • Clips polygon successively against the edge of the given clip window.

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

12

13 of 13

Sutherland-Hodgeman Polygon Clipping Algorithm

  • There are four possible cases for any given edge of given polygon against current clipping edge e.
  • Both vertices are inside : Only the second vertex is added to the output list
  • First vertex is outside while second one is inside : Both the point of intersection of the edge with the clip boundary and the second vertex are added to the output list
  • First vertex is inside while second one is outside : Only the point of intersection of the edge with the clip boundary is added to the output list
  • Both vertices are outside : No vertices are added to the output list

Prepared By:Sushant Bhattarai (Department of CSIT,MMAMC)

13