Upload
lyhanh
View
221
Download
2
Embed Size (px)
Citation preview
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
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
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
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
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
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
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
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
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?
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
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
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]
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]
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
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
Polygon Clipping
Sutherland-Hodgman polygon clipping method
By line Clipping
By polygon Clipping
ClippingWindow
Polygon
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
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