Anda di halaman 1dari 49

Two-Dimensional Viewing

McGraw-Hill

2D Viewing
To display a picture on the screen, we must determine what part of the "world" is to be displayed where it should be displayed on the screen

Windows and Viewports


Window

Interface Window

Viewport Information outside the viewport is clipped away

Terminology
World Coordinate System (Object Space) Representation of an object measured in some 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

Choose Window in World Coordinates

Clip to size of Window

Translate to origin

Scale to size of Viewport

Translate to proper position on screen (Interface Window)

The Viewing Pipeline


Pictures must undergo a series of transformations before they can be displayed: Modeling coordinates --> World coordinates --> Viewing coordinates --> Normalized viewing coordinates --> Display coordinates

The Viewing Pipeline


Geometric transformations position graphical objects (models) in the "world" Window determines what part of the "world" is to be displayed, expressed in world coordinates Viewport determines where on the display the picture should be displayed, expressed in display coordinates

Viewing Pipeline

2D Viewing Transformation Pipeline


MC

Construct World Construct World Coordinate Scene Using Coordinate Scene Using Modeling Coordinate Modeling Coordinate Transformation Transformation

WC

Convert World Convert World Coordinates to Coordinates to Viewing Coordinates Viewing Coordinates
VC

Transform Viewing Transform Viewing Coordinates to Coordinates to Normalized Normalized Coordinates Coordinates
NC

Map Normalized Map Normalized Coordinates to Device Coordinates to Device Coordinates Coordinates
DC

Two-Dimensional Viewing
Two dimensional viewing transformation
From world coordinate scene description to device (screen) coordinates

Window-to-View port Coordinate Transformation


Transformation maintains same relative placement of objects

Window-to-Viewport Coordinate Transformation


xv xvmin xw xw min = xvmax xvmin xw xw max min

yv yvmin yw ywmin = yvmax yvmin ywmax ywmin

xv = xvmin + ( xw xwmin ) sx

xvmax xvmin sx = xwmax xwmin yvmax yvmin sy = ywmax ywmin

yv = yvmin + ( yw ywmin ) sy

This conversion is performed by 1.Perform scaling using fixed point (xwmin,ywmin) that scales window to size of viewport 2.Translate scaled window area to position of viewport

Clipping
Remove portion of output primitives outside clipping window

Two-Dimensional Clipping
Point clipping Line clipping
Cohen-Sutherland Liang-Barsky

Fill-area clipping
Sutherland-Hodgeman Weiler-Atherton

Curve clipping Text clipping

Line Clipping

Basic calculations: Is an endpoint inside or outside the clipping window? Find the point of intersection, if any, between a line segment and an edge of the clipping window.

Both endpoints inside: trivial accept One inside: find intersection and clip Both outside: either clip or reject

Cohen-Sutherland Line Clipping


To clip a line, we need to consider only its endpoints . If both endpoints of a line lie inside the window, the entire line lies inside the window. It is trivially accepted and needs no clipping. On the other hand, if both endpoints of a line lie entirely to one side of the window, the line must lie entirely outside of the window. It is trivially rejected and needs to be neither clipped nor displayed.

Cohen-Sutherland Line Clipping


nine regions are created - the eight "outside" regions and the one "inside"region. Each of the nine regions associated with the window is assigned a 4-bit code to identify the region. Each bit in the code is set to either a 1(true) or a 0(false).

Cohen-Sutherland Line Clipping


One of the earliest algorithms for fast line clipping Identify trivial accepts and rejects by bit operations
1001 0001 0101 1000
Clipping window

1010
< Region code for each endpoint >

0000 0100

0010 0110

above below

right

left

Cohen-Sutherland Line Clipping


For any endpoint ( x , y ) of a line, the code can be determined that identifies which region the endpoint lies. The code's bits are set according to the following conditions:

Cohen-Sutherland Line Clipping


The sequence for reading the codes' bits is LRBT (Left, Right, Bottom, Top). Once the codes for each endpoint of a line are determined, the logical AND operation of the codes determines if the line is completely outside of the window. If the logical AND of the endpoint codes is not zero, the line can be trivially rejected. For example, if an endpoint had a code of 1001 while the other endpoint had a code of 1010, the logical AND would be 1000 which indicates the line segment lies outside of the window. On the other hand, if the endpoints had codes of 1001 and 0110, the logical AND would be 0000, and the line could not be trivially rejected.

Cohen-Sutherland Line Clipping


The logical OR of the endpoint codes determines if the line is completely inside the window. If the logical OR is zero, the line can be trivially accepted. For example, if the endpoint codes are 0000 and 0000, the logical OR is 0000 - the line can be trivially accepted. If the endpoint codes are 0000 and 0110, the logical OR is 0110 and the line can not be trivially accepted.

Cohen-Sutherland Line Clipping


Compute region codes for two endpoints If (both codes = 0000 ) trivially accepted If (bitwise AND of both codes 0000) trivially rejected Otherwise, divide line into two segments test intersection edges in a fixed order. (e.g., top-to-bottom, right-to-left)

1001 0001 0101

1000
Clipping window

1010 0010 0110

0000 0100

Cohen-Sutherland Line Clipping Fixed order testing and clipping cause needless clipping (external intersection)

Cohen-Sutherland Line Clipping This algorithm can be very efficient if it can accept and reject primitives trivially
Clip window is much larger than scene data
Most primitives are accepted trivially

Clip window is much smaller than scene data


Most primitives are rejected trivially

Good for hardware implementation

Cohen-Sutherland Line Clipping


Will do unnecessary clipping. Not the most efficient. Clipping and testing are done in fixed order. Efficient when most of the lines to be clipped are either rejected or accepted (not so many subdivisions). Easy to program. Parametric clipping are the most efficient. (LiangBarsky and Cyrus-Beck)

Cyrus-Beck Line Clipping


Use a parametric line equation

P(t ) = P0 + t (P P0 ), 0 t 1 1
Reduce the number of calculating intersections by exploiting the parametric form Notations Ei : edge of the clipping window Ni : outward normal of Ei An arbitrary point PEi on edge Ei

Cyrus-Beck Line Clipping


N i ( P (t ) PEi ) < 0 a point in the inside halfplane N i ( P (t ) PEi ) = 0 a point on the line containing the edge N i ( P (t ) PEi ) > 0 a point in the outside halfplane

Cyrus-Beck Line Clipping


Solve for the value of t at the intersection of P0P1 with the edge Ni [P(t) - PEi] = 0 and P(t) = P0 + t(P1 - P0) letting D = (P1 - P0),

Where Ni 0 D 0 (that is, P0 P1) Ni D 0 (if not, no intersection)

N i [ P0 PEi ] t= Ni D

Cyrus-Beck Line Clipping


Given a line segment P0P1, find intersection points against four edges Discard an intersection point if t [0,1] Label each intersection point either PE (potentially entering) or PL (potentially leaving) Choose the smallest (PE, PL) pair that defines the clipped line

N i P0 P < 0 PE 1 N i P0 P > 0 PL 1

Cyrus-Beck Line Clipping


Cyrus-Beck is efficient when many line segments need to be clipped Can be extended easily to convex polygon (rather than upright rectangle) clip windows

Liang-Barsky Line Clipping


Liang-Barsky optimized CyrusBeck for upright rectangular clip windows
Q(x2.y2) tT P(x1,y1) tB tL tR
x = x1 + t ( x2 x1 ) = x1 + tdx y = y1 + t ( y2 y1 ) = y1 + tdy
t = 0 P( x1 , y1 ) t = 1 Q ( x2 , y 2 )

Liang-Barsky Line Clipping


More efficient than Cohen-Sutherland Clipping conditions: A line is inside the clipping region for values of t such that:

Liang-Barsky Line Clipping


The infinitely line intersects the clip region edges when:

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

Liang-Barsky Line Clipping

General Clipping Window


Line clipping using nonrectangular polygon clip windows Convex polygon Cyrus-Beck algorithm can be readily extended Concave polygon Split the concave polygon into convex polygons

Vector Method for Concave Splitting Calculate edge-vector cross products in a counterclockwise order If any z component turns out to be negative, the polygon is concave

Polygon Fill-Area Clipping


Polyline vs polygon fill-area

Early rejection is useful


Bounding box of polygon fill area Clipping Window

Sutherland-Hodgman Polygon Clipping Clip against 4 infinite clip edges in succession

Sutherland-Hodgman Polygon Clipping Accept a series of vertices (polygon) and outputs another series of vertices Four possible outputs

Sutherland-Hodgman Polygon Clipping The algorithm correctly clips convex polygons, but may display extraneous lines for concave polygons

Weiler-Atherton Polygon Clipping


For an outside-to-inside pair of vertices, follow the polygon boundary For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction

Weiler-Atherton Polygon Clipping Polygon clipping using nonrectangular polygon clip windows

Text Clipping
All-or-none text clipping Using boundary box for the entire text All-or-non character clipping Using boundary box for each individual character Character clipping Vector font: Clip boundary polygons or curves Bitmap font: Clip individual pixels

Anda mungkin juga menyukai