Windowing clipping

shwetashah62 676 views 30 slides May 24, 2021
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

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 ...


Slide Content

Windowing and Clipping

Windowing Concepts
Introduction to Clipping
Point Clipping
Line Clipping
Area Clipping
2

3
Window
Image Space
Viewport
Information
outside
theviewportis
clippedaway

•WorldCoordinateSystem(ObjectSpace)-
Representationofanobjectmeasuredinsome
physicalunits.
•Window-Therectangledefiningthepartofthe
worldwewishtodisplay.
•ImageCoordinateSystem(ImageSpace)-The
spacewithintheimageisdisplayed.
•Viewport-Therectangleareainimagespace
wheretheimagefromthewindowwillappear.
•ViewingTransformation-Theprocessofgoing
fromawindowinworldcoordinatestoa
viewportinimagecoordinates.
4

5
•In2D,a‘world’consistsofaninfiniteplane,
definedin‘world’coordinates,i.emetres,
angstromsetc.
•Weneedtopickanareaofthe2Dplanetoview,
referredtoasthe‘window’.
•Onourdisplaydevice,needtoallocateanareafor
display,referredtoasthe‘viewport’indevice
specificcoordinates.
–Clipobjectsoutsideofwindow.
–Translatetofitviewport.
–Scaletodevicecoordinates.

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

14
–Forlineswithbothend-
pointsoutsidethe
windowtestthelinefor
intersectionwithallof
thewindowboundaries,
andclipappropriately.
However,calculatinglineintersectionsis
computationallyexpensive.
Becauseascenecancontainsomanylines,
thebruteforceapproachtoclippingismuch
tooslow.

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?

Algorithm
Step1−Assignaregioncodeforeachendpoints.
Step2−Ifbothendpointshavearegioncode0000thenacceptthisline.
Step3−Else,performthelogicalANDoperationforbothregioncodes.
Step3.1−Iftheresultisnot0000,thenrejecttheline.
Step3.2−Elseyouneedclipping.
Step3.2.1−Chooseanendpointofthelinethatisoutsidethe
window.
Step3.2.2−Findtheintersectionpointatthewindowboundary
(baseonregioncode).
Step3.2.3−Replaceendpointwiththeintersectionpointand
updatethe regioncode.
Step3.2.4−Repeatstep2untilwefindaclippedlineeither
trivially acceptedortriviallyrejected.
Step4−Repeatstep1forotherlines.
16

Worldspaceisdividedintoregionsbasedonthe
windowboundaries.
Eachregionhasauniquefourbitregioncode.
Regioncodesindicatethepositionoftheregionswith
respecttothewindow.
17
abovebelowrightleft
3 2 1 0
Region Code Legend
100110001010
0001
0000
Window
0010
010101000110

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

Otherwise,comparetheremainderofthelineagainstthe
otherwindowboundaries.
Continueuntilthelineiseitherdiscardedorasegment
insidethewindowisfound.
Wecanusetheregioncodestodeterminewhich
windowboundariesshouldbeconsideredfor
intersection.
Tocheckifalinecrossesaparticularboundarywe
comparetheappropriatebitsintheregioncodesofits
end-points.
Ifoneoftheseisa1andtheotherisa0thentheline
crossestheboundary.
22

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

Polygonscanbeclippedagainsteachedgeofthe
windowoneedgeatatime.Window/edge
intersections,ifany,areeasytofindsincetheXor
Ycoordinatesarealreadyknown.
Verticeswhicharekeptafterclippingagainstone
windowedgearesavedforclippingagainstthe
remainingedges.Notethatthenumberofvertices
usuallychangesandwilloftenincrease.
25

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

Toclipanareaagainstanindividualboundary:
Considereachvertexinturnagainsttheboundary.
Verticesinsidetheboundaryaresavedforclipping
againstthenextboundary.
Verticesoutsidetheboundaryareclipped.
Ifweproceedfromapointinsidetheboundarytoone
outside,theintersectionofthelinewiththeboundaryis
saved.
Ifwecrossfromtheoutsidetotheinsideintersection
pointandthevertexaresaved.
27

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

Thank You !!!
30