of 9
8/8/2019 06 2D Viewing
1/9
1 / NVortragender Computergraphik @ TU Wien
2 / NVortragender Computergraphik @ TU Wien
Viewing Pipeline:Viewing Pipeline:WindowWindow--ViewportViewport TransformationTransformation
clipping window: what to displayclipping window: what to display
viewportviewport: where to be viewed: where to be viewed
translation, rotation, scaling, clipping,...translation, rotation, scaling, clipping,...
world coordinates viewport coordinates
Clipping WindowViewport
3 / NVortragender Computergraphik @ TU Wien
constructworld-coordinate
scene usingmodeling-coordinate
transformations
22--dim. Viewingdim. Viewing--TransfTransf. Pipeline. Pipeline
constructworld-coordinate
scene usingmodeling-coordinate
transformations
convertworld-coordinates
to viewingcoordinates
WCMC
DCVCVCtransform viewing
coordinates tonormalizedcoordinates
map normalizedcoordinates to
devicecoordinates
NC
convertworld-coordinates
to viewing
coordinates
4 / NVortragender Computergraphik @ TU Wien
WCWC VC TransformationVC Transformationsetting up a rotated world window in
viewing coordinates and the corresponding
normalized-coordinate viewport
World Coordinates Viewing Coordinates
Viewport
8/8/2019 06 2D Viewing
2/9
5 / NVortragender Computergraphik @ TU Wien
ViewingViewing CoordCoord. Reference Frame. Reference Frame
TRM VCWC ,
A viewing-
coordinate
frame is
moved into
coincidence
with the world
frame in two
steps:
(a) translate the viewing origin to the world origin
(b) rotate to align the axes of the two systems.
6 / NVortragender Computergraphik @ TU Wien
WC
convert
world-coordinatesto viewingcoordinates
22--dim. Viewingdim. Viewing--TransfTransf. Pipeline. Pipeline
construct
world-coordinatescene usingmodeling-coordinate
transformations
convert
world-coordinatesto viewing
coordinates
transform viewingcoordinates to
normalizedcoordinates
map normalizedcoordinates to
devicecoordinates
MC
VC DC
WC
NCNC
transform viewingcoordinates to
normalizedcoordinates
7 / NVortragender Computergraphik @ TU Wien
WindowWindow -- ViewportViewport Transform (1)Transform (1)
point (xw,yw) in a designated window is mapped
to viewport coordinates (xv,yv) so that relative
positions in the two areas are the same.
8 / NVortragender Computergraphik @ TU Wien
WindowWindow -- ViewportViewport Transform (2)Transform (2)linear in x and y
(xwmin/ywmin) (xvmin/yvmin)(xwmax/ywmax) (xvmax/yvmax)
8/8/2019 06 2D Viewing
3/9
9 / NVortragender Computergraphik @ TU Wien
xw = xwmin + (xwmaxxwmin) where 01xv = xvmin + (xvmaxxvmin)
= xvmin + xwxwmaxxwmin
xwmin(xvmaxxvmin)
xwmaxxwmin
xvmaxxvmin
xwmaxxwmin
xwxwmin =
xv = xvmin + (xvmaxxvmin)xwmaxxwmin
xwxwmin
tx sxwindow-viewport
transformation: xv = sxxw+tx yv = sy.yw+ty
10/ NVortragender Computergraphik @ TU Wien
transform viewingcoordinates to
normalizedcoordinates
22--dim. Viewingdim. Viewing--TransfTransf. Pipeline. Pipeline
construct
world-coordinatescene usingmodeling-coordinate
transformations
convert
world-coordinatesto viewingcoordinates
transform viewingcoordinates to
normalizedcoordinates
map normalizedviewport to
devicecoordinates
MC WC
NC DCVCVC
map normalizedcoordinates to
devicecoordinates
DC
11/ NVortragender Computergraphik @ TU Wien
Workstation TransformationWorkstation Transformation
Mapping
selected parts
of a scene in
normalizedcoordinates to
different video
monitors with
workstation
transformations
12/ NVortragender Computergraphik @ TU Wien
ClippingClipping
partly visible or completely invisible partspartly visible or completely invisible parts
must not be ignored and must not be drawnmust not be ignored and must not be drawn
must be cut offmust be cut off(if possible in world coordinates)(if possible in world coordinates)
ignored
vertices edges
scrolled
8/8/2019 06 2D Viewing
4/9
13/ NVortragender Computergraphik @ TU Wien
Clipping OperationsClipping Operations
remove objects outside a clip windowremove objects outside a clip window
clip window: rectangle, polygon, curvedclip window: rectangle, polygon, curvedboundariesboundaries
applied in world or viewing coordinatesapplied in world or viewing coordinates
combined with scan conversioncombined with scan conversion
objects to clip: points, lines, polygons,objects to clip: points, lines, polygons,curves, text, ...curves, text, ...
14/ NVortragender Computergraphik @ TU Wien
3 Possibilities for Clipping3 Possibilities for Clipping
analyticallyanalytically= in world coordinates= in world coordinates
reduces WCreduces WC
DC transformationsDC transformations
during raster conversationduring raster conversation
= as part of the= as part of the rasterizationrasterization algorithmalgorithm
efficient for complex primitivesefficient for complex primitives
pixel by pixelpixel by pixeltesttest biggest effort, very primitive algorithmbiggest effort, very primitive algorithm
15/ NVortragender Computergraphik @ TU Wien
Line Clipping (1)Line Clipping (1)
line clipping against a rectangular clip window
before clipping after clipping
16/ NVortragender Computergraphik @ TU Wien
Line Clipping (2)Line Clipping (2)
goalsgoals
eliminate simple cases fasteliminate simple cases fast
avoid intersection calculationsavoid intersection calculations
for endpoints (x0,y0), (xend,yend)intersect parametric representation
x = x0 + u(xend x0)y = y0 + u(yend y0)
with window borders:
intersection 0 < u < 1
8/8/2019 06 2D Viewing
5/9
17/ NVortragender Computergraphik @ TU Wien
CohenCohen--Sutherland Line ClippingSutherland Line Clipping
assignment of region codes to lineassignment of region codes to line
endpointsendpoints
bit1: leftbit1: left
bit2: rightbit2: right
bit3: belowbit3: below
bit4: abovebit4: above
binary region codes assigned to line endpoints
according to relative position with respect to the
clipping rectangle18/ NVortragender Computergraphik @ TU Wien
CohenCohen--Sutherland Line ClippingSutherland Line Clipping oror of codes of bothof codes of both
points 0000points 0000
line entirelyline entirely visiblevisible andand of codes of bothof codes of both
pointspoints 00000000 line entirelyline entirely invisibleinvisible
all othersall others intersect!intersect!
19/ NVortragender Computergraphik @ TU Wien
CohenCohen--Sutherland Line ClippingSutherland Line Clipping
lines extending
from one
coordinate region
to another maypass through the
clip window, or
they may intersect
clipping
boundaries
without entering
the window
20/ NVortragender Computergraphik @ TU Wien
CohenCohen--Sutherland Line ClippingSutherland Line Clipping
remaining linesremaining lines
intersection test with bounding lines ofintersection test with bounding lines ofclipping windowclipping window
left, right, bottom, topleft, right, bottom, top discard an outside partdiscard an outside part
repeat intersection test up to four timesrepeat intersection test up to four times
}yw,{ywy,/)(
}xw,{xwx),(
maxmin00
maxmin00
+=
+=
myyxx
xxmyyvertical
horiz.
8/8/2019 06 2D Viewing
6/9
21/ NVortragender Computergraphik @ TU Wien
CohenCohen--
SutherlandSutherland
Line ClippingLine Clipping passes throughclipping window
intersects boundaries
without entering
clipping window
}yw,{ywy,/)(
}xw,{xwx),(
maxmin00
maxmin00
+=
+=
myyxx
xxmyyvertical
horiz.
22/ NVortragender Computergraphik @ TU Wien
Polygon ClippingPolygon Clipping
modification of line clippingmodification of line clipping
goal: one or more closed areasgoal: one or more closed areas
display of a correctly
clipped polygon
display of a polygon
processed by a line-
clipping algorithm
23/ NVortragender Computergraphik @ TU Wien
processing polygon boundary as aprocessing polygon boundary as awhole against each window edgewhole against each window edge
output: list of verticesoutput: list of vertices
clipping a polygon against successive
window boundaries
original
polygonclip left clip right
clip
bottomclip top
SutherlandSutherland--HodgmanHodgman Polygon ClippingPolygon Clipping
24/ NVortragender Computergraphik @ TU Wien
SutherlandSutherland--HodgmanHodgman Polygon ClippingPolygon Clipping
four possible edge casesfour possible edge cases
successive processing of pairs of polygon
vertices against the left window boundary
out inoutput: V1, V2
in inV2
in outV1
out outno output
8/8/2019 06 2D Viewing
7/9
25/ NVortragender Computergraphik @ TU Wien
V2:= 1st vertexfor1 edge:
Sutherland-
Hodgman Alg.
V1:=V2V2:=next vertex V2 result list
V2 visible?no
V1 visible?
yes
yesV1 visible?
no
V1 = clip edge V1V2 result list
yes no
26/ NVortragender Computergraphik @ TU Wien
clipping a polygon
against the leftboundary of a
window, starting with
vertex 1. Primed
numbers are used to
label the points in
the output vertex listfor this window
boundary
SutherlandSutherland--HodgmanHodgman Polygon ClippingPolygon Clipping
27/ NVortragender Computergraphik @ TU Wien
SutherlandSutherland--HodgmanHodgman Polygon ClippingPolygon Clipping
finished!
28/ NVortragender Computergraphik @ TU Wien
SutherlandSutherland--HodgmanHodgman Algorithm:Algorithm:
Combination of the 4 PassesCombination of the 4 Passes
the polygon is clipped against each of the 4the polygon is clipped against each of the 4
borders separately,borders separately,that would produce 3 intermediate results.that would produce 3 intermediate results.
by calling the 4 testsby calling the 4 tests recursivelyrecursively,,
(or by using a clipping pipeline)(or by using a clipping pipeline)
every result point is immediately processedevery result point is immediately processed
on, so that onlyon, so that only oneone result list is producedresult list is produced
8/8/2019 06 2D Viewing
8/9
29/ NVortragender Computergraphik @ TU Wien
2
2
3
3
1
1
2 pipeline ofpipeline of
boundaryboundary
clippers toclippers toavoidavoid
intermediateintermediate
vertex listsvertex lists
Processing the vertices of the polygon through
a boundary-clipping pipeline.
SutherlanSutherlandd--HodgmanHodgman Clipping ExampleClipping Example
1st clip:
left
30/ NVortragender Computergraphik @ TU Wien
2
2
3
3
1
1
2
After all vertices are processed through the
pipeline, the vertex list for the clipped polygon is[1, 2, 2, 2]
SutherlanSutherlandd--HodgmanHodgman Clipping ExampleClipping Example
2nd clip:
bottom
31/ NVortragender Computergraphik @ TU Wien
extraneous lines for concave polygons:extraneous lines for concave polygons:
split into separate convex parts orsplit into separate convex parts or
final check of output vertex listfinal check of output vertex list
clipping the
concave polygon
with the
Sutherland-
Hodgeman clipper
produces twoconnected areas
SutherlandSutherland--HodgmanHodgman Polygon ClippingPolygon Clipping
32/ NVortragender Computergraphik @ TU Wien
Text Clipping (1)Text Clipping (1)
1. text clipping using a bounding
rectangle about the entire string
8/8/2019 06 2D Viewing
9/9
33/ NVortragender Computergraphik @ TU Wien
Text Clipping (2)Text Clipping (2)
2. text clipping using a bounding
rectangle about individual characters
34/ NVortragender Computergraphik @ TU Wien
Text Clipping (3)Text Clipping (3)
3. text clipping performed on the
components of individual characters
35/ NVortragender Computergraphik @ TU Wien
SummarySummary:: ClippingClipping
CohenCohen--SutherlandSutherland lineline clippingclipping
HodgmanHodgman--SutherlandSutherland polygonpolygon clippingclipping
texttext clippingclipping