Clipping - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Clipping

Description:

A fundamental task in graphics is to keep those parts of an object that lie ... We chop each end-point of the line at the 'nearest' window boundary. 1. 2. 3. 4 ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 13
Provided by: isgC
Category:
Tags: chop | clipping

less

Transcript and Presenter's Notes

Title: Clipping


1
Clipping
  • A fundamental task in graphics is to keep those
    parts of an object that lie outside a selected
    view from being drawn
  • Clipping is the removal of all objects or part of
    objects in a modelled scene that are outside the
    real-world window.
  • Doing this on a pixel-by-pixel basis would be
    very slow, especially if most objects in the
    scene are outside the window
  • More practical techniques are necessary to speed
    up the task

2
Line Clipping
  • Lines are defined by their endpoints, so it
    should be possible just to examine these, and not
    every pixel on the line
  • We often have windows that are either very large,
    i.e. nearly the whole scene fits inside, or very
    small, i.e. most of the scene lies inside the
    window
  • Hence, most lines may be either trivially
    accepted or rejected

3
Cohen-Sutherland
  • The Cohen-Sutherland line-clipping algorithm is
    particularly fast for trivial cases, i.e. lines
    completely inside or outside the window.
  • Non-trivial lines, I.e. ones that cross a
    boundary of the window, are clipped by computing
    the coordinates of the new boundary endpoint of
    the line where it crosses the edge of the window

4
Outcodes
  • The window edges are assumed to be extended so
    that the whole picture is divided into 9 regions
  • Each region is assigned a four-bit code, called
    an outcode

5
Cohen Sutherland cont.
  • The outcode for each end of the line is computed,
    giving codes c1 and c2.
  • One of the following cases will occur
  • Both c1 and c2 are 0000. This means that both
    endpoints lie inside the window, so the line may
    be trivially accepted
  • If c1 and c2 have one or more bits in common,
    then the line must be wholly outside the window.
    Hence if (c1 AND c2) is not equal to zero, the
    line may be trivially rejected
  • If (c1 AND c2) is equal to zero, further
    processing is necessary.

6
  • Having decided that a line is non-trivial, it
    must be clipped
  • We chop each end-point of the line at the
    nearest window boundary

It may be necessary to repeat this process
several times until the line may be trivially
accepted or rejected.
1
2
3
4
7
  • When a line needs to be clipped, an endpoint
    outside the window is chosen (there will always
    be one)
  • The algorithm chooses one of the set bits, and
    uses this to determine which window edge to clip
    to.
  • In this case, The outcode of point d is 0000, and
    of point a is 1010 (bits for above and right
    are set.)
  • Algorithm first works on the above bit, and
    pushes the line to the top edge of the window,
    I.e. point b.

8
  • The outcodes of the line are again computed. This
    time, point b has outcode 0010 (I.e. bit for
    right is set), so the line is pushed to the
    right edge of the window (point c)
  • The outcodes are computed, both are 0, so line
    accepted

9
Computing intersection points
p2 (x2,y2)
wymax
(Slope)
A
ax wxmax
ay y1 (wxmax-x1) m
p1 (x1,y1)
wymin
NOTE Vertical lines are a special case
wxmin
wxmax
10
Other Clipping algorithms
  • The Cohen-Sutherland algorithm requires the
    window to be a rectangle, with edges aligned with
    the co-ordinate axes
  • It is sometimes necessary to clip to any convex
    polygonal window, e.g. triangular, hexagonal, or
    rotated.
  • The Cyrus-Beck, and Liang-Barsky line clippers
    use the concept of inside/outside half spaces
    generated by edges

11
Polygon Clipping
  • A polygon is usually defined by a sequence of
    vertices and edges
  • If the polygons are un-filled, line-clipping
    techniques are sufficient
  • However, if the polygons are filled, the process
    in more complicated
  • A polygon may be fragmented into several polygons
    in the clipping process, and the original colour
    associated with each one

12
Polygon Clipping Algorithms
  • The Sutherland-Hodgeman clipping algorithm clips
    any polygon against a convex clip polygon.
  • The Weiler-Atherton clipping algorithm will clip
    any polygon against any clip polygon. The
    polygons may even have holes
Write a Comment
User Comments (0)
About PowerShow.com