he capability that show some part of object internal a specify window is called windowing and a rectangular region in a world coordinate system is called window. ... Points and lines which are outside the window are "cut off" from view. This process of "cutting off" parts of the ...
he capability that show some part of object internal a specify window is called windowing and a rectangular region in a world coordinate system is called window. ... Points and lines which are outside the window are "cut off" from view. This process of "cutting off" parts of the image of the world is called Clipping.
6
Choose Window in
World Coordinates
Clip to size
of Window
Translate to
origin
Scale to size of ViewportTranslate to proper position in
image
Anyprocedurethatidentifiesthoseportionsofa
picturethatareeitherinsideoroutsideofa
specifiedregionisreferredtoasaclipping
algorithmorclipping.
7
World Coordinates
8
•Whenwedisplayasceneonlythoseobjects
withinaparticularwindowaredisplayed.
wy
max
wy
min
wx
min
wx
max
Window or Clipping Region
World Coordinates
9
Becausedrawingthingstoadisplaytakestime
weclipeverythingoutsidethewindow.
wy
max
wy
min
wx
min
wx
max
Window or Clipping Region
World Coordinates
Fortheimagebelowconsiderwhichlinesand
pointsshouldbekeptandwhichonesshouldbe
clipped.
10
wy
max
wy
min
wx
min wx
max
Window
P
1
P
2
P
3
P
6
P
5P
7
P
10
P
9
P
4
P
8
Easy-apoint(x,y)isnotclippedif:
wx
min ≤ x ≤ wx
maxAND wy
min ≤ y ≤ wy
max
11
wy
max
wy
min
wx
min wx
max
Window
P
1
P
2
P
5
P
7
P
10
P
9
P
4
P
8
Clipped
Points Within the
Window are Not Clipped
Clipped
Clipped
Clipped
Harder-examinetheend-pointsofeachlineto
seeiftheyareinthewindowornot.
12
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!
Bruteforcelineclippingcanbeperformedasfollows:
Don’t clip lines with both
end-points within the
window.
For lines with one end-
point inside the window
and one end-point
outside, calculate the
intersection point (using the equation of the line) and
clip from this point out.
13
15
Anefficientlineclipping
algorithm.
Thekeyadvantageofthe
algorithmisthatitvastly
reducesthenumberofline
intersectionsthatmustbe
calculated.
Dr.IvanE.Sutherland
co-developed the
Cohen-Sutherland
clippingalgorithm.
Sutherlandisagraphics
giantandincludes
a m o n g s t h i s
achievements the
inventionofthehead
mounted display.
Cohenissomethingofamystery–can
anybodyfindoutwhohewas?
18
•Everyend-pointislabelledwiththe
appropriateregioncode.
wy
max
wy
min
wx
min wx
max
Window
P
3[0001]
P
6 [0000]
P
5[0000]
P
7[0001]
P
10[0100]
P
9[0000]
P
4 [1000]
P
8[0010]
P
12[0010]
P
11 [1010]
P
13[0101] P
14[0110]
19
Linescompletelycontainedwithinthewindow
boundarieshaveregioncode[0000]forbothend-
pointssoarenotclipped.TheORoperationcan
efficientlycheckthis.
wy
max
wy
min
wx
min wx
max
Window
P
3[0001]
P
6 [0000]
P
5[0000]
P
7[0001]
P
10[0100]
P
9[0000]
P
4 [1000]
P
8[0010]
P
12[0010]
P
11 [1010]
P
13[0101] P
14[0110]
20
Anylineswithacommonsetbitintheregion
codesofbothend-pointscanbeclipped.
–TheANDoperationcanefficientlycheckthis.
wy
max
wy
min
wx
min wx
max
Window
P
3[0001]
P
6 [0000]
P
5[0000]
P
7[0001]
P
10[0100]
P
9[0000]
P
4 [1000]
P
8[0010]
P
12[0010]
P
11 [1010]
P
13[0101] P
14[0110]
Linesthatcannotbeidentifiedascompletelyinside
oroutsidethewindowmayormaynotcrossthe
windowinterior.
These lines are processed as follows:
Compareanend-pointoutsidethewindowtoa
boundary(chooseanyorderinwhichtoconsider
boundariese.g.left,right,bottom,top)and
determinehowmuchcanbediscarded.
Iftheremainderofthelineisentirelyinsideor
outsidethewindow,retainitorclipitrespectively.
21
Intersectionpointswiththewindowboundariesare
calculatedusingtheline-equationparameters.
Consideralinewiththeend-points(x
1,y
1)and(x
2,y
2)
They-coordinateofanintersectionwithavertical
windowboundarycanbecalculatedusing:
y = y
1+ m (x
boundary-x
1)
where x
boundarycan be set to either wx
minor wx
max
23
Thex-coordinateofanintersectionwitha
horizontalwindowboundarycanbecalculated
using:
x = x
1+ (y
boundary-y
1)/m
wherey
boundarycanbesettoeitherwy
minorwy
max
mistheslopeofthelineinquestionandcanbe
calculatedas
m= (y
2-y
1) / (x
2-x
1)
24
Atechniqueforclippingareas
developedbySutherland&
Hodgman.
Putsimplythepolygonisclipped
bycomparingitagainsteach
boundaryinturn.
26
Sutherland
turns up
again. This
time with
Gary Hodgman
with whom he
worked at the first
ever graphics
company Evans &
Sutherland
Original Area Clip Left Clip Right Clip Top Clip Bottom
Eachexampleshows
thepointbeing
processed(P)andthe
previouspoint(S).
Savedpointsdefine
areaclippedtothe
boundaryinquestion.
28
S
P
Save Point P
S
P
Save Point I
I
P
S
No Points Saved
S
P
Save Points I& P
I
Instead of always
proceedingaround the
polygonedgesasverticesare
processed,wesometime
wanttofollowwindow
boundary.
Thisalgorithmisusedfor
clippingconcavepolygons.
V1,V2,V3,V4,V5arethe
verticesofthepolygon.
C1,C2,C3,C4arethe
verticesoftheclippolygon
I1,I2,I3,I4arethe
intersectionpointsof
polygonandclippolygon.
29