2-D Clipping

download 2-D Clipping

of 25

Transcript of 2-D Clipping

  • 8/7/2019 2-D Clipping

    1/25

    1

    Topics to be Covered

    Two-Dimensional Viewing The 2-D Viewing transformation Pipeline

    Window-to-Viewport Coordinate Transformation

    Clipping Operations Line Clipping

    Polygon Clipping

    Text Clipping

    Shielding-Definition

  • 8/7/2019 2-D Clipping

    2/25

    2

    Two-Dimensional Viewing

    Window A world coordinate area selected for display

    Defines what is to be viewed

    Viewport An area on a display device to which a window ismapped

    Defines where it is to be displayed

    NDCS

    Normalized device coordinate system is deviceindependent tool, in which a unit (1 x 1) square whoselower left corner is at the origin of the coordinatesystem, defines the display are of a virtual device.

  • 8/7/2019 2-D Clipping

    3/25

    3

    The process that converts objectcoordinates in WCS to normalized device

    coordinates is called Normalization

    Mapping of a part of a world coordinate

    scene to device coordinates is referred to

    as viewing transformation or window to

    viewport transformation or windowing

    transformation

    Two-Dimensional Viewing

  • 8/7/2019 2-D Clipping

    4/25

    4

    The Two-Dimensional Viewing Transformation Pipeline

    Construct

    WCS

    Convert

    WCS to

    Viewing

    Coordinates

    MC WC Map VC to

    NVC

    VC NVC Map NVC

    to DC

    DC

  • 8/7/2019 2-D Clipping

    5/25

  • 8/7/2019 2-D Clipping

    6/25

    6

    A point at position (xw,yw) in the window is mapped into

    position (xv,yv) in the associated viewport.

    To maintain the same relative placement in the viewport as in

    the window, we require that

    minmax

    min

    minmax

    min

    minmax

    min

    minmax

    min

    ywyw

    ywyw

    yvyv

    yvyv

    xwxw

    xwxw

    xvxv

    xvxv

    !

    !

    Window to Viewport Transformation

  • 8/7/2019 2-D Clipping

    7/25

    7

    Solving the above expression, we have

    minmax

    minmax

    minmax

    minmax

    minmin

    minmin

    *)(

    *)(

    yy

    yvyv

    sy

    xx

    xvxvsx

    syyyyvyv

    sxxxxvxv

    !

    !

    !

    !

    Window to Viewport Transformation

  • 8/7/2019 2-D Clipping

    8/25

    8

    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, or

    simply clipping.

    The region against which an object is to be

    clipped is called a clip. window

  • 8/7/2019 2-D Clipping

    9/25

    9

    Applications of Clipping

    1. Extracting part of a defined scene for viewing

    2. Identifying visible surfaces in 3D views

    3. Antialiasing line segments or object

    boundaries

    4. Displaying a multiwindow environment

    5. Drawing and painting operations that allow

    parts of a picture to be selected for copying,

    moving, erasing or duplicating

  • 8/7/2019 2-D Clipping

    10/25

    10

    POINT CLIPPING

    Point Clipping is essentially the evaluation of the

    following inequalities

    xmin x xmax and ymin y ymax

    where xmin, xmax, ymin and ymax define theclipping window. A point (x, y) is considered

    inside the window when the inequalities all

    evaluate to true.

  • 8/7/2019 2-D Clipping

    11/25

    11

    The Cohen-Sutherland Algorithm

    One of the Oldest and Most popular procedure

    The method speeds up the processing o line segments by

    performing initial tests that reduce the number of intersectionsthat must be calculated

    Can be divided into two phases

    Step 1: Identify those lines which intersect the clipping window and

    so need to be clipped

    Step 2: Perform the Clipping

    LINE CLIPPING

  • 8/7/2019 2-D Clipping

    12/25

    12

    LINE CLIPPING

  • 8/7/2019 2-D Clipping

    13/25

    13

    Cohen-Sutherland Line Clipping Algorithm

    Step 1: Identify those lines which need to beclipped

    The lines fall into following four categories

    1. Visible Both endpoints of the line within the window

    2. Not Visible The line definitely lie outside the window.This will occur if the line from (x1,y1) to (x2,y2) satisfies

    any of the following inequalities

    x1,x2 > xmax y1,y2 > ymax

    X1,x2 < xmin y1,y2 < ymin3. Clipping candidate - The line in neither category 1 nor 2

  • 8/7/2019 2-D Clipping

    14/25

    14

    1. Assign a 4-bit region code to each endpoint of the line.

    2. Line is Visible - Both region codes are 0000

    3. Line is Invisible Logical AND of endpoints is not0000

    4. Clipping Candidate - Logical AND of endpoints is

    0000

    0000

    10001001

    0001

    0101 0100 0110

    0010

    1010ymax

    ymin

    xmax xmin

    Above, Below , left, right

    Step 1: Identify the Category

  • 8/7/2019 2-D Clipping

    15/25

    15xmax

    C(0100)

    D(1010)

    C

    D

    D

    xmin

    ymax

    ymin

    Step 2: Perform the Clipping

    Clipping can be performed in two ways

    Method 1: Clipping process begins by comparing outside point to a clipping

    boundary to determine how much of the line can be discarded

    Then remaining part of the line is checked against the other boundaries

    and the process is continued until either the line is totally discarded or asection is found inside the window.

  • 8/7/2019 2-D Clipping

    16/25

    16

    Consider the line CD as it is clipping candidate

    The coordinates of the intersection point are

    xi = x in or xmax for vertical boundary line

    yi = y1+m(xi-x1)

    Or

    xi = x1 + (yi-y1)/m for horizontal boundary line

    Yi = ymin or ymax

    where m =(y2-y1)/x2-x1) is the slope of the line.

    Step 2: Perform the Clipping

  • 8/7/2019 2-D Clipping

    17/25

    17

    Replace endpoint (x1,y1) with the

    intersection point (xi, yi)

    Assign region code to new endpoint (xi, yi) Re-categorize

    Iterate the process till the line segment is

    either in the category 1 or category 2

    Step 2: Perform the Clipping

  • 8/7/2019 2-D Clipping

    18/25

    18

    Based on Binary Search

    Divide the line segment into two at its midpoint

    Determine the Clipping categories

    Each segment in category 3 is divided again intoshorter segments and categorized

    This process continues until Each line segment that spans across a window boundary

    reaches a threshold for line size

    and all other segments are either in Category 1 or in Category2

    The midpoint coordinates (xm, ym ) of a line joining(x1,y1) and (x2,y2) are given by

    2

    21 xxxm

    !

    2

    21 yyym

    !

    Method 2: Midpoint Subdivision

  • 8/7/2019 2-D Clipping

    19/25

    19

    POLYGON CLIPPINGSutherland Hodgeman Algorithm

    L

    Pi

    Pi-1

    Output Pi

    R

    Pi-1

    Pi

    Output i

    I

    L R

    Nooutput

    Pi-1

    Pi

    L R

    Output I,Pi

    Pi-1Pi

    L R

    I

  • 8/7/2019 2-D Clipping

    20/25

    20

    Let P1,,Pn be the vertex list of Polygons to be clipped

    Let Edge E be any edge of the positively oriented convex clippingpolygon.

    We clip each edge of the polygon in turn against the edge E of the

    clipping polygon , forming a new polygon whose vertices are

    determined as follows

    Consider the edge Pi-1Pi1. If both Pi-1 and Pi are to the left of the edge, vertex Pi is placed on the

    vertex output list of the clipped polygon

    2. If both Pi-1 and Pi are to the right of the edge, nothing is placed on the

    vertex output list

    3. If Pi-1 is to the left and Pi to the right of E, the intersection point I of

    line segment Pi-1Pi with the extended edge E is calculated andplaced on the vertex output list

    4. If Pi-1 is to the right and Pi to the left of E, the intersection point I of

    line segment Pi-1Pi with the extended edge E is calculated and Both

    are placed on the vertex output list

    POLYGON CLIPPING

  • 8/7/2019 2-D Clipping

    21/25

    21

    Convex polygons are correctly clipped by

    the Sutherland-Hodgeman algorithm, butconcave polygons may be displayed with

    extraneous lines

    POLYGON CLIPPING

  • 8/7/2019 2-D Clipping

    22/25

    22

    TEXT CLIPPING

    Several techniques are used All or none-string Clipping

    Simplest method for processing strings relative to awindow boundary

    STRING 1

    STRING 1

    Before Clipping

    STRING 1

    After Clipping

  • 8/7/2019 2-D Clipping

    23/25

    23

    all- or-none character-clipping

    Discard only those characters that are not

    completely inside the window

    STRING 1

    STRING 3

    Before Clipping

    STRING2

    STRING 3

    STRING 1

    RING 3

    Before Clipping

    STRING 3

    TEXT CLIPPING

  • 8/7/2019 2-D Clipping

    24/25

    24

    A final method for handling text clipping is

    to clip the components of individual

    characters

    STRING 1

    Before Clipping

    STRING 1

    After Clipping

    STRING 1

    TEXT CLIPPING

  • 8/7/2019 2-D Clipping

    25/25

    25

    Exterior Clipping

    Clipping a picture to the interior of a region by

    eliminating everything outside the clipping

    region.

    Exterior clipping is saving the picture partsthat are outside the region.

    Applications

    Multiple Windowing System

    Where pictures overlap

    TEXT CLIPPING