Docsity

Viewing In 2D - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Viewing In 2D - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Viewing In 2D

Contents

• Windowing Concepts

• Clipping

– Introduction

– Brute Force

– Cohen-Sutherland Clipping Algorithm

• Area Clipping

– Sutherland-Hodgman Area Clipping Algorithm

Windowing II

• When we display a scene only those objects

within a particular window are displayed

wy max

wy min

wx min wx max

Window

World Coordinates Docsity.com

Windowing III

• Because drawing things to a display takes time

we clip everything outside the window

wy max

wy min

wx min wx max

World Coordinates

Window

Point Clipping

• Easy - a point ( x,y ) is not clipped if:

• wx min ≤ x ≤ wx max AND wy min ≤ y ≤ wy max

• otherwise it is clipped

wy max

wy min

wx min wx max

Window

P 1

P 2

P 7 P^5

P 10

P 9

P 4

P 8

Clipped

Points Within the Windoware Not Clipped

Clipped

Clipped

Clipped

Line Clipping

• Harder - examine the end-points of each line

to see if they are in the window or not

Situation Solution Example

Both end-points inside

the window Don’t clip

One end-point inside

the window, one

outside

Must clip

Both end-points

outside the window Don’t know!

Brute Force Line Clipping (cont…)

– For lines with both end-

points outside the window

test the line for

intersection with all of the

window boundaries, and

clip appropriately

However, calculating line intersections is

computationally expensive

Because a scene can contain so many lines,

the brute force approach to clipping is much

too slow Docsity.com

Cohen-Sutherland Clipping Algorithm

  • An efficient line clipping algorithm
  • The key advantage of the algorithm is that it vastly reduces the number of line intersections that must be calculated

Dr. Ivan E. Sutherlandco-developed the Cohen- S u t h e r l a n dalgorithm. Sutherland is c l i p p i n g aincludes graphics amongst giant andhis a c h i e v e m e n t sinvention of the headt h e m o u n t e d d i s p l a y.

Cohen is something of a mystery – cana n y b o d y f i n d o u t w h o h e w a s?

Cohen-Sutherland: Labelling

• Every end-point is labelled with the

appropriate region code

wy max

wy min

wx min wx max

Window

P 3 [0001] P P^6 [0000]

P 7 [0001]^5 [0000]

P 10 [0100]

P 9 [0000]

P 4 [1000]

P 8 [0010]

P 12 [0010]

P 11 [1010]

P 13 [0101] P 14 [0110]

Cohen-Sutherland: Lines In The Window

Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped

wy max

wy min

wx min wx max

Window

P 3 [0001] P P^6 [0000]

P 7 [0001]^5 [0000]

P 10 [0100]

P 9 [0000]

P 4 [1000]

P 8 [0010]

P 12 [0010]

P 11 [1010]

P 13 [0101] P 14 [0110]

Cohen-Sutherland: Other Lines

• Lines that cannot be identified as completely

inside or outside the window may or may not

cross the window interior

• These lines are processed as follows:

– Compare an end-point outside the window to a

boundary (choose any order in which to consider

boundaries e.g. left, right, bottom, top) and

determine how much can be discarded

– If the remainder of the line is entirely inside or

outside the window, retain it or clip it respectively

Cohen-Sutherland: Other Lines (cont…)

  • Otherwise, compare the remainder of the line against the other window boundaries
  • Continue until the line is either discarded or a segment inside the window is found
  • We can use the region codes to determine which window boundaries should be considered for intersection
  • To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points
  • If one of these is a 1 and the other is a 0 then the line crosses the boundary Docsity.com

Cohen-Sutherland Examples (cont…)

  • Consider the line P 3 to P 4 below
    • Start at P 4
    • From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 4 ’
    • The line P 3 to P 4 ’ is completely outside the window so is clipped

wy max

wy min

wx min wx max

P 4 ’ [1001] Window

P 3 [0001]

P 4 [1000]

P 3 [0001]

Cohen-Sutherland Examples (cont…)

  • Consider the line P 7 to P 8 below
    • Start at P 7
    • From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 7 ’

wy max

wy min

wx min wx max

Window

P 7 [0001] P^7 ’ [0000] P 8 [0010]

P 8 ’ [0000]