Top Banner
Two dimensional viewing Mechanism for displaying views of a picture on the o/p device • Windowing Concepts • Clipping – Introduction – Point clipping – Line Clipping Cohen-Sutherland Clipping Algorithm – Polygon Clipping Sutherland-Hodgeman Area Clipping Algorithm
22

Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts....

Mar 14, 2018

Download

Documents

lyhanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Two dimensional viewingMechanism for displaying views of a picture on

the o/p device• Windowing Concepts• Clipping

– Introduction – Point clipping– Line Clipping

• Cohen-Sutherland Clipping Algorithm– Polygon Clipping

• Sutherland-Hodgeman Area Clipping Algorithm

Page 2: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

2

Windowing/Viewing in 2D

Window in world coordinates.

45

250

View port

Monitor(Output Device)

Page 3: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Windowing PipelineWindow -- A world coordinate selected for displayingView Port – An area on a display device to which a window is mapped

The window defines what to be viewed, the viewport defines where to be displayed

The mapping of window to viewport is called • Windowing Transformation• Viewing Transformation • Window to viewport Transformation

Page 4: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Clipping Window & Viewport

Page 5: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

minmax

min

minmax

min

minmax

min

minmax

min

ywywywyw

yvyvyvyv

xwxwxwxw

xvxvxvxv

Mapping of point (Xw,Yw) of window to point (Xv, Yv) of viewport

To maintain the relative placement

of the point

Page 6: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

minmax

minmax

xwxwxvxvsx

minmax

minmax

ywywyvyvsy

Sy * )ywyw(yv yv minmin

minmax

minmaxminmin xwxw

xvxv)xwxw(xv xv

Sx*)xwxw(xv xv minmin

minmax

minmaxminmin ywyw

yvyv)ywyw(yv yv

Where

Where

Mapping Equation

If Sx = Sy then relative proportion of the object’s are maintained else object will stretched or contracted in either X/Y direction

Page 7: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Clipping

Any procedure that identifies those portion of a picture that are inside or outside is called as clipping

• Point Clipping

• Line Clipping

• Polygon Clipping

Page 8: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Point Clipping A point (x , y) is not clipped if: WXmin ≤ x ≤ WXmax

WYmin ≤ y ≤ WYmax

otherwise it is clipped

wymax

wymin

wxmin wxmax

Window

P1

P2

P5

P7

P10

P9

P4

P8

Clipped

Points Within the Window are Not Clipped

Clipped

Clipped

Clipped

Page 9: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Line Clipping

• For the image below consider which lines should be kept and which ones should be clipped

wymax

wymin

wxmin wxmax

Window

P1

P3

P6

P5P7

P10

P9

P4

P8

Page 10: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Type of Line For line (x1,y1) to (x2,y2) the line falls into one of

the following type

Situation Type Example

Both end-points inside the window Visible

If Satisfies following inequalitiesX1,X2 > Xmax Y1,Y2 > YmaxX1,X2 < Xmin Y1,Y2 < Ymin

Not visible

Neither type1 or type2 Clipping Candidate

Page 11: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Cohen-Sutherland Clipping Algorithm

• An efficient line clipping algorithm

• Advantage - it vastly reduces the number of line intersections that must be calculated Dr. Ivan E. Sutherland co-

developed the Cohen-Sutherland clipping algorithm. Sutherland is a graphics giant and includes amongst his achievements the invention of the head mounted display.

Cohen is something of a mystery – can anybody find out who he was?

Page 12: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Steps Of Cohen-Sutherland algo

STEPS :-1. Identify the line to be clipped

a) Assign 4 bit code to end points of each lineb) Categories each line

2. Perform the clipping :- Using the slope intercept method or Mid point sub division method

Page 13: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Identify the line to be clipped • World space is divided into regions based on

the window boundaries– Each region has a unique four bit region code– Region codes indicate the position of the regions

with respect to the window

above below right left

3 2 1 0

Region Code Legend

1001 1000 1010

0001 0000Window

0010

0101 0100 0110

Page 14: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

a. Assign 4 bit code to end points of each line

wymax

wymin

wxmin wxmax

Window

Rule of assigning bit code :-

bit1 = sign(Y- Ymax) (+)ve ---> 1

bit2 = sign(Ymin- Y) (-)ve ---> 0

bit3 = sign(X- Xmax)

bit4 = sign(Xmin- X)P3 [0001]

P4 [1000]

P6 [0000]

P5 [0000]

P7 [0001]P8 [0010]

P11 [1010]

P12 [0010]

P9 [0000]

P10 [0100]P13 [0101] P14 [0110]

Page 15: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

b. Categories all the Lines• Visible - if both end pt code is 0000 bit wise OR is all o’s• Not Visible - If logical AND of end pt code is not 0000• Clipping Candidate - If logical AND of end pt code is 0000

wymax

wymin

wxmin wxmax

Window

P3 [0001]P6 [0000]

P5 [0000]P7 [0001]

P10 [0100]

P9 [0000]

P4 [1000]

P8 [0010]

P12 [0010]

P11 [1010]

P13 [0101] P14 [0110]

Page 16: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Perform Clipping

• Using slope Intercept Method Let line end pt is (X1,Y1) & (X2,Y2) It can intersect either Vertical / Horizontal boundary

– Let vertical Boundary at (X,Y) Hence X = WXmax / WXmin Y = Y1 + m * (X – X1) where m = slope of line– Let Horizontal Boundary at (X,Y) Hence Y = WYmax / WYmin X = X1 + (Y – Y1)/ m where m = slope of line

Page 17: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

wymax

wymin

wxmin wxmax

WindowP4’ [1001]

P3 [0001]

P4 [1000]

P3 [0001]

Exceptional Case

Page 18: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Mid point sub-division method(Based on binary Search)

• The line is divided at it’s mid point into 2 segment• the line type is found for those 2 segment

– for type1 (visible) – draw– for type2 (Not Visible) – discard– for type3 (clipping candidate) – apply the mid point sub-division

wymax

wymin

wxmin wxmax

Window

Page 19: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Polygon Clipping

Sutherland-Hodgman polygon clipping method

By line Clipping

By polygon Clipping

ClippingWindow

Polygon

Page 20: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Sutherland-Hodgman polygon clipping method

• Clip the polygon by processing the polygon edge as a whole against each window edge

• Beginning with initial vertex list

Clip the polygon w.r.t left boundary - Form new vertex list

Clip the polygon w.r.t right boundary - Form new vertex list

Clip the polygon w.r.t buttom boundary - Form new vertex list

Clip the polygon w.r.t top boundary - Form new vertex list

Page 21: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

4 Rule’s of clipping polygon edge’s against window boundary

SP

Save Points I & P

I

Rule 1 - if 1st vertex is outside & 2nd vertex is inside then save the intersection pt & 2nd vertex

Rule 2 - if both vertices are inside then save the 2nd vertex

S

P

Save Point PRule 3 - if 1st vertex is inside & 2nd vertex is outside then save the intersection pt

S

P

Save Point II

Page 22: Two dimensional viewing · PPT file · Web view · 2017-03-03Two dimensional viewing. Mechanism for displaying views of a picture on the o/p device. Windowing Concepts. Clipping.

Rule 4 - if both vertices are outside then don’t save any vertex

P

SNo Points Saved

Hence the clipped polygon is

e.g of clipped polygon