graphics programming windows viewports clipping n.
Skip this Video
Download Presentation
Graphics Programming: Windows, Viewports & Clipping

Loading in 2 Seconds...

play fullscreen
1 / 18

Graphics Programming: Windows, Viewports & Clipping - PowerPoint PPT Presentation

  • Uploaded on

Graphics Programming: Windows, Viewports & Clipping. Windows and Viewports. Window. Interface Window. Viewport. Information outside the viewport is clipped away. Terminology. Modelling Coordinate System – Representation of an object measured in some physical units

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Graphics Programming: Windows, Viewports & Clipping' - alina

Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
windows and viewports
Windows and Viewports


Interface Window


Information outside

the viewport is

clipped away

  • Modelling Coordinate System – Representation of an object measured in some physical units
  • World Coordinate System (Object Space) - Representation of a set of objects, all measured in the same physical units.
  • Window - The rectangle defining the part of the world we wish to display.
  • 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).
  • Viewport - The rectangle on the raster graphics screen (or interface window for “window” displays) defining where the image will appear. (Default is usually entire screen or interface window.)
  • Viewing Transformation - The process of going from a window in world coordinates to a viewport in screen coordinates.
the viewing pipeline
The Viewing Pipeline

Map viewing coordinates to normalized viewing coordinates using window-viewport specification

Construct world-coordinate scene using modeling coordinate transformations

Map normalized viewport to device coordinates

Convert world coordinates to viewing coordinates

Beginning with modelling coordinates, we go through a series of coordinate transformations which result in device coordinates that can be plotted

viewing transformation
Viewing Transformation

Clip to size

of Window

Translate to


Choose Window in

World Coordinates

Translate to proper position on screen

(Interface Window)

Scale to size of Viewport

notes on viewing transformation
Notes on Viewing Transformation
  • Panning - Moving the window about the world
  • Zooming - Reducing the window size
  • As the window increases in size, the image in the viewport decreases in size and vice versa
  • Beware of aspect ratio.
  • A line is visible if both of its end points are in the window.

(xl, yt)

(xr, yt)

A point is visible if

xl < X < xr


yb < Y < yt

(xl, yb)

(xr, yb)

cohen sutherland algorithm
Cohen-Sutherland Algorithm
  • Region Checks: Trivially reject or accept lines and points.
  • Fast for large windows (everything is inside) and for small windows (everything is outside).
  • Each vertex is assigned a four-bit outcode.
  • Bit 1 <-- sign bit of (yt-Y) -- point is above window
  • Bit 2 <-- sign bit of (Y-yb) -- point is below window
  • Bit 3 <-- sign bit of (xr-X) -- point is to right of window
  • Bit 4 <-- sign bit of (X-xl) -- point is to left of window
cohen sutherland clipping
Cohen-Sutherland Clipping




Bit 1: Above

Bit 2: Below

Bit 3: Right

Bit 4: Left

  • 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.) Can be computed with a logical AND.







clipping lines not accepted or rejected
Clipping Lines notAccepted 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 --> can’t accept or reject.

2) Calculate intersection point B, which is conceptually on

the window side of the dividing line. Form new line

segment AB and discard the rest of the line because it is

above the window.

3) Test outcodes of A and B. Reject.

line intersection
Line Intersection
  • For intersection with the clipping boundary
    • Use the slope-intercept form of the line equation.
    • Intercept with a vertical boundary:
      • y = y1 +m(x-x1)
    • where
      • x = xmin or x max, depending on the boundary in question
    • and
      • m = (y2 – y1) / (x2 – x1)
  • And similarly for a horizontal boundary, solving for x
other line clipping algorithms
Other Line Clipping Algorithms
  • Liang-Barsky Line Clipping
    • Uses the parametric equation of a line segment
      • x = x1 + u (x2 – x1)
      • y = y1 = u (y2-y1)
    • For each line, calculate values for u1 and u2 that define the part of the line that lies within the clip rectangle
  • Comparison with Cohen-Sutherland
    • Generally faster
      • Does fewer intersection calculations
        • Window intersections of a line of calculated once whereas Cohen-Sutherland can repeatedly calculate intersections along a line path, even though the line is completely outside of the window.
      • Does the intersections calculations faster
        • Calculates u1 and u2 by a single division
        • Cohen-Sutherland requires division and multiplication
polygon clipping
Polygon Clipping
  • Polygons can be clipped against each edge of the window one edge at a time. Window/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 increase.
polygon clipping algorithm
Polygon Clipping Algorithm
  • The window boundary determines a visible and invisible region.
  • The edge from vertex i to vertex i+1 can be one of four types:
  • Exit visible region - save the intersection
  • Wholly outside visible region - save nothing
  • Enter visible region - save intersection and endpoint
  • Wholly inside visible region - save endpoint











polygon clipping issues
Polygon clipping issues
  • The final output, if any, is always considered a single polygon.
  • The spurious edge may not be a problem since it always occurs on a window boundary, but it can be eliminated if necessary.
pipelined polygon clipping
Pipelined Polygon Clipping
  • Because 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.
  • This way four polygons can be at different stages of the clipping process simultaneously. This is often implemented in hardware.









further reading
Further Reading

See Rowe – p47 and following.

Note, Rowe doesn’t describe Liang-Barsky Line Clipping – see Hearn and Baker for a description.