Window Viewport and Clipping - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Window Viewport and Clipping

Description:

... Transformation - The process of going from a window in world coordinates to ... If a pixel is square, we can map NDC to the largest square region of the screen. ... – PowerPoint PPT presentation

Number of Views:477
Avg rating:3.0/5.0
Slides: 28
Provided by: pradondet
Category:

less

Transcript and Presenter's Notes

Title: Window Viewport and Clipping


1
Window Viewport and Clipping
  • Pradondet Nilagupta
  • Dept. of Computer Engineering
  • Kasetsart University

2
Terminology (1/4)
  • World Coordinate System (Object Space) the
    coordinate system used to describe the objects
    being displayed
  • Window - The rectangle defining the part of the
    world we wish to display.

3
Terminology (2/4)
  • Screen Coordinate System (Image Space) - The
    space within the image is displayed
  • Interface Window - The visual representation of
    the screen coordinate system for window
    displays (coordinate system moves with interface
    window).

Interface Window
Viewport
4
Terminology (3/4)
Maximum Values Of Screen Co-ordinates
  • Viewport - a rectangular region in the image
    space
  • Viewing Transformation - The process of going
    from a window in world coordinates to a viewport
    in screen coordinates.

Viewport 2
Viewport 1
Screen Co-ordinates
5
Terminology (4/4)
  • Clipping

y
6
Device Coordinates
  • The integer (x,y) pixel coordinates are called
    device coordinates.

7
Normalized device coordinates
  • Normalised device coordinates (NDC) space is a
    square region with 0 ? x ? 1 and 0 ? y ? 1.
    The origin (0,0) is the lower left hand corner of
    the square.

8
Mapping NDC to Device Coordinate (1/3)
  • If a pixel is square, we can map NDC to the
    largest square region of the screen.
  • For example, if the screen has device coordinates
    (X,Y) with 0 ? X ? 1023 and 0 ? Y ? 767, then we
    could map the NDC (x,y) using
  • Xmax 1023
  • Ymax 767
  • X0 (Xmax - Ymax)/2
  • Y0 0
  • and
  • X Ymax x X0
  • Y Ymax y Y0

9
Mapping NDC to Device Coordinate(2/3)
  • If pixels are not square, define the aspect ratio
    R as the ratio of the height to width of a pixel.
  • Assuming the horizontal width of a pixel is 1,
    the horizontal size of the screen is (Xmax1) and
    the vertical size is (Ymax1).

10
Mapping NDC to Device Coordinate(3/3)
  • Suppose tbe vertical size is less than the
    horizontal size, the corresponding mapping from
    NDC (x,y) to DC (X,Y) is
  • Xmax 1023
    Ymax 767 X0
    (Xmax - RYmax)/2 Y0 0
  • X RYmax x X0
    Y Ymax y Y0
  • Can map a non-square region of NDC to DC so that
    all of the device coordinates are used.

11
Viewing Transformation
12
Mathematic (1/4)
y
First translate the window
World Co-ordinates
13
Mathematic (2/4)
Mwv T(?) . S(?) . T(??)
T(?) T(umin, vmin)
T(??) T(-xmin, -ymin)
S(?) S
Putting it together.
14
Mathematic (3/4)
15
Mathematic (4/4)
16
Line clipping
  • A line clipping algorithm needs to determine if a
    line is inside, outside, or across the window.
  • The whole line is accepted, If it is inside.
  • The whole line is rejected, If it is outside.
  • If it is across the window, the intersections of
    the line and the window boundaries need to be
    calculated and the line clipped to the
    boundaries.

17
Cohen Sutherland Algorithm (1/2)
  • The region code has four bits with meanings
  • bit 0 1 if endpoint to on outside of left
    boundary.
  • bit 1 1 if endpoint on outside of right
    boundary.
  • bit 2 1 if endpoint on outside of bottom
    boundary.
  • bit 3 1 if endpoint on outside of top boundary.

Region Outcodes
18
Cohen Sutherland Algorithm (2/2)
  • A line can be trivially accepted if both
    endpoints have an outcode of 0000.
  • A line can be trivially rejected if any
    corresponding bits in the two outcodes are both
    equal to 1. (This means that both endpoints are
    to the right, to the left, above, or below the
    window.)
  • if (outcode 1 outcode 2) ! 0000, trivially
    reject!

19
Clipping Lines Not Accepted or Rejected
  • In the case where a line can be neither trivially
    accepted nor rejected, the algorithm uses a
    divide and conquer method.

Line AD 1) Test outcodes of A and D --gt cant
accept or reject. 2) Calculate intersection point
B, which is on the dividing line between the
window and the above region. Form new line
segment AB and discard BD because above the
window. 3) Test outcodes of A and B.
Reject. Line EH ??
20
Polygon Clipping
21
Pipelined Polygon Clipping
Clip Top
Clip Right
Clip Bottom
Clip Left
Clipping against one edge is independent of all
others, it is possible to arrange the clipping
stages in a pipeline. the input polygon is
clipped against one edge and any points that are
kept are passed on as input to the next stage of
the pipeline.
22
Sutherland Hodgman Algorithm (1/4)
  • clips polygons by clipping the polygon to each
    window boundary in turn.
  • The output of the algorithm is a set of vertices
    defining an area that is to be shaded.

The polygon is defined as an ordered sequence of
vertices
p4
23
Sutherland Hodgman Algorithm (2/4)
  • Each vertex is tested in turn against an extended
    window boundary.
  • Vertices inside the window boundary are saved
    for clipping against the next boundary
  • Vertices outside are discarded.

24
Sutherland Hodgman Algorithm (3/4)
q1
P6
q2
New vertices q1,q2 are added
25
Sutherland Hodgman Algorithm (4/4)
  • If proceeding from inside the window to outside
  • keep the inside vertex,
  • add a new vertex where the edge crosses the
    window boundary,
  • discard the outside vertex.
  • If proceeding from outside to inside
  • add a new vertex where the edge intersects the
    boundary,
  • discard the outside vertex,
  • keep the inside vertex.

26
Canonical View Volume
  • 3-D Extension of 2-D Cohen-Sutherland Algorithm,
    Outcode of six bits. A bit is true (1) when the
    appropriate condition is satisfied
  • Bit 1 - Point is above view volume y gt -z
  • Bit 2 - Point is below view volume y lt z
  • Bit 3 - Point is right of view volume x gt -z
  • Bit 4 - Point is left of view volume x lt z
  • Bit 5 - Point is behind view volume z lt -1
  • Bit 6 - Point is in front of view volume z gt zmin

27
3D Line Clipping
  • A line is trivially accepted if both endpoints
    have a code of all zeros.
  • A line is trivially rejected if the bit-by-bit
    logical AND of the codes is not all zeros.
  • Otherwise Calculate intersections.
  • On the y z plane from parametric equation of
    the line
  • y0 t( y1 - y0) z0 t( z1 z0)
  • Solve for t and calculate x and y. Already know
    z y
Write a Comment
User Comments (0)
About PowerShow.com