Sei sulla pagina 1di 46

Two-Dimensional Viewing

COMPUTER GRAPHICS

Contents
The Viewing Pipeline Viewing Coordinate Reference Frame Window-To-Viewport Coordinate Transformation Clipping Operations Point Clipping Line Clipping Polygon Clipping
2

The Viewing Pipeline


Window(what is to be viewed): a word coordinate area selected for display is called window Viewport( where is to be displayed): an area display device to which window is mapped is called view port The mapping of the part of a world coordinate to device coordinate is referred to as Viewing Transformation
3

The Viewing Pipeline


Whats the viewing pipe line??
Viewing transformation in several steps

A viewing transformation using standard rectangles for the window and viewport
ywmax ywmin xvmin xvmax World Coordinates ywmax ywmin xvmin xvmax 4 Device Coordinate

The Viewing Pipeline


The two-dimensional viewingtransformation pipeline
MC Construct World Coordinate WC Scene Using Modeling-Coordinate Transformation Map Normalized NVC Viewport to Device Coordinates Convert World-Coordinates to Viewing Coordinates

DC

VC Map Viewing Coordinates to Normalized Viewing Coordinates using Window-Viewport Specifications

The Viewing Pipeline


Setting up a rotated world window in viewing coordinates and the corresponding normalizedcoordinate viewport
y world y0 1

Viewpoint

x0

x world

World Coordinates

1 Normalized Device Coordinates

Viewing Coordinate Reference Frame (1/2)


Used to provide a method for setting up arbitrary orientations for rectangular windows Matrix for converting world-coordinate positions to viewing coordinate

WC ,VC R
R: rotation matrix T: translation matrix
7

Viewing Coordinate Reference Frame (2/2)


The steps in this coordinate transformation A viewing coordinate frame is moved into coincidence with the world frame in two steps a) Translate the viewing origin to the world origin, then b) Rotate to align the axes of the two systems

Window-To-Viewport Coordinate Transformation (1/5)


Window-to-viewport mapping A point at position (xw, yw) in a designated window is mapped to viewport coordinates (xv, yv) so that relative positions in the two areas are the same

Window-To-Viewport Coordinate Transformation


To maintain the same relative placement
xv xvmin xvmax xvmin yv yvmin yvmax yvmin

xw xwmin xwmax xwmin yw ywmin ywmax ywmin

Solving these expressions for the viewport position (xv, yv)

xv xvmin ( xw xwmin ) sx

yv yvmin ( yw ywmin ) sy

10

Window-To-Viewport Coordinate Transformation (3/5)


The scaling factors

sx

xvmax xvmin xwmax xwmin yvmax yvmin ywmax ywmin

sy

Conversion sequence of transformation 1. Perform a scaling transformation using a fixed-point position of (xwmin, ywmin) that scales the window area to the size of the viewport 2. Translate the scaled window area to the position of the viewport 11

Window-To-Viewport Coordinate Transformation


The way of character string mapping Maintaining character size Using standard character fonts Changing character size Using characters formed with line segments Workstation transformation Opening any number of output devices in a particular application Performing another window-to-viewport transformation for each open output device
12

Window-To-Viewport Coordinate Transformation (5/5)


Mapping selected parts of a scene in normalized coordinates to different video monitors with Workstation transformation

13

Clipping Operations
Clipping
Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space

Applied in World Coordinates Adapting Primitive Types


Point Line Area (or Polygons) Curve, Text (omit!!)

14

Clipping application
Extracting the part of a defined scene for veiwing. Identify visible surface in 3 dimensional Antialiasing line segment or object boundries Creating objects using solid modelling procedure Dispalying a multiwindow environment and drawing and painting operation
15

Point Clipping
Assuming that the clip window is a rectangle in standard position Saving a point P=(x, y) for display
xwmin x xwmax ywmin y ywmax Appling Fields
Particles (explosion, sea foam)
16

Line Clipping (1/3)


Line clipping against a rectangular clip window

a) Before Clipping

b) After Clipping
17

Line Clipping (2/3)


Parametric representation of Line segment with endpoints (x1, y1) and (x2, y2)
x x 1 u(x 2 x 1 ) y y 1 u(y 2 y 1 ),

0 u 1

Exterior of the window


Intersection with outside the range u

Interior of the window


Intersection with inside the range u
18

Line Clipping (3/3)


Cohen-Sutherland Line Clipping Liang-Barsky Line Clipping NLN(Nicholl-Lee-Nicholl) Line Clipping Line Clipping Using Nonrectangular Clip Windows Splitting Concave Polygons
19

Cohen-Sutherland Line Clipping


Performing the initial test that reduce the number of intersection Assign a 4-digit binary code called region code Region code identifies the location of the point relative to the boundaries of clipping rectangles.

20

Cohen-Sutherland Line Clipping


Region Code Creation
Region Code Bit 1: left Bit 2: right Bit 3: below it 4: above 1 2 3 4 Any bit position have 1 value a point is that relative position Otherwise set bit position to 0 If point within clip rectangle Region code is 0000 If left and below have region code 0101 21

Cohen-Sutherland Line Clipping


Bit value in region code are determine the by comparing endpoints coordinate values (x,y) to clip boundary To determine the region code bit value Calculate differences between endpoint coordinates and clipping boundaries Use the resultant sign bit of each difference calculation to set the corresponding value in the region code Bit 1 is the sign bit of x -xwmin Bit 2 is the sign bit of xwmax - x Bit 3 is the sign bit of y - ywmin 22 Bit 4 is the sign bit of ywmax - y

Cohen-Sutherland Line Clipping


Outside Line Removal Test
A method that can be used to test lines total clipping is to perform the logical AND operation with both region codes 0000
Completely inside the clipping region!!

Not 0000
Completely outside the clipping region!!

Lines that cannot be identified as completely inside or outside a clip window by this test
23

Cohen-Sutherland Line Clipping (3/3)


Calculate Intersection Point
Using the slope-intercept form Vertical Boundary

y y1 m( x x1 )

Horizontal Boundary

m ( y2 y1 ) /( x2 x1 )
24

y y1 x x1 m

Liang-Barsky Line Clipping (1/4)


Developed that are based on analysis of the parametric equation of line segment
x x1 ux

x x2 x1

0 u 1

y y1 uy, y y2 y1

From pre-condition in the parametric form xwmin x1 ux xwmax ywmin y1 uy ywmax


27

Liang-Barsky Line Clipping (2/4)


Inequalities can be expressed as
tpk qk ,

k = 1, 2, 3, 4
q1 x1 xwmin q2 xwmax x1

Definition of parameter p, q
p1 x, p2 x,

p3 y, q3 y1 ywmin p4 y q4 ywmax y1
28

Liang-Barsky Line Clipping (3/4)


pk = 0
qk = 0: boundary qk < 0: rejection qk > 0: test!!

pk < 0
Line proceeds from outside to inside

pk > 0
Line proceeds from inside to outside
29

Liang-Barsky Line Clipping (4/4)


pk < 0
t1 = max(t)

pk > 0
t2 = min(t)

qk t pk

t1 > t2
Rejection

t1 < t2 or t1 = t2
Draw
30

NLN Line Clipping(1/4)


Three possible position for a line end point P1
Equal position with rotation or translation
Consider four lines shot from the P0 endpoint of a line segment P0-Pend through each of the four corners of clipping region. Determine which of these four new regions Pend lives in by comparing slopes of P0Pend with those of four other lines. Now use the at most two boundary edges to do clipping

34

NLN Line Clipping (2/4)


The four clipping region when P1 is inside the clip window The four clipping region when P1 is directly left of the clip window The two possible sets of clipping regions when P1 is above and to the left of the clip window

35

NLN Line Clipping (3/4)


Region Determination
P1 is left of the clipping rectangle, then P2 is in the region LT if
Slope P1PTR < slope P1P2 < slope P1PTL

or

yT y1 y2 y1 yT y1 xR x1 x2 x1 xL x1

Clipping the entire line ( yT y1 )( x2 x1 ) ( xL x1 )( y2 y1 )


36

NLN Line Clipping (4/4)


Intersection Position Calculation x x1 ( x2 x1 )u y y1 ( y2 y1 )u
Left Boundary x xL

u ( xL x1 ) /( x2 x1 ) Top Boundary y yT u ( yT y1 ) /( y2 y1 )

y2 y1 y y1 ( xL x1 ) x2 x1 x2 x1 x x1 ( yT y1 ) y2 y1
37

Splitting Concave Polygons (2/2)


Rotational Method
After rotating V3 onto the x axis, we find the V4 is below the x axis So we split the polygon along the line of V2V3

38

Polygon Clipping (1/2)


Display of polygon processed by a lineclipping algorithm

Display of a correctly clipped polygon


39

Sutherland-Hodgeman Polygon Clipping Four case 1: if first vertex outside and second inside then intersection point with the windows boundary 2: both vertex are inside save the second point 3: if first vertex inside and second outside then intersection point with the windows boundary 40 4: both vertex are outside do not save point

Polygon Clipping (2/2)

Sutherland-Hodgeman Polygon Clipping (1/2)


Clipping a polygon against successive window boundary

Successive processing of pairs of polygon vertices against the left window boundary

41

Sutherland-Hodgeman Polygon Clipping (2/2)


A polygon overlapping a rectangular clip window Processing the vertices of the polygon

42

Algorithm : 1. Read coordinates of all vertices of polygon 2. Read coordinates of clipping windows 3.Consider the left edges 4. Compare the vertices of each of the polygon individually with clipping plane 5. Save the resulting intersection and vertices in the new list of vertices according to four possible relationship between the edge and the clipping boundary

6. Repeate the steps 4 and 5 for remaining edges of the clipping windows . 7 stops

Weiler-Atherton Polygon Clipping (1/2)


Problem of Sutherland-Hodgeman clipping
Displaying extraneous line

??
45

Weiler-Atherton Polygon Clipping (2/2)


Rules

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 clockwise direction
Correct Result

46

Potrebbero piacerti anche