Chapter 6 Windowing and clipping Window - The rectangle defining the part of the world we wish to display. Viewport - The rectangle on the raster graphics screen (or interface window for “window” displays) defining where the image will appear. (Default is usually entire screen or interface window.)
40
Embed
Chapter 6 Windowing and clipping Window - The rectangle defining the part of the world we wish to display. Viewport - The rectangle on the raster graphics.
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
Chapter 6
Windowing and clipping
Window - The rectangle defining the part of the world we wish to display.
Viewport - The rectangle on the raster graphics screen (or interface window for “window” displays) defining where the image will appear. (Default is usually entire screen or interface window.)
Chapter 6
Windowing & clipping
Windowing is showing on the viewport parts of the real seen that appears from the window.
Clipping is not showing on the viewport parts of the real seen outside the window boundaries.
Clipping needs to be fast, so often implemented in hardware. There are techniques for clipping primitive operations.
Chapter 6
TerminologyWorld Coordinate System (Object Space) -
Representation of an object measured in some physical units.
Screen Coordinate System (Image Space) - The space within the image is displayed
Interface Window - The visual representation of the screen coordinate system for “window” displays (coordinate system moves with interface window).
Viewing Transformation - The process of going from a window in world coordinates to a viewport in screen coordinates.
Chapter 6
Windows and ViewportsWindow
Interface Window
Viewport
Information outsidethe viewport isclipped away
Chapter 6
Viewing Transformation
Choose Window inWorld Coordinates
Clip to sizeof Window
Translate toorigin
Scale to size of Viewport Translate to proper position on screen (Interface Window)
Chapter 6
Notes on Viewing TransformationPanning - Moving the window about the worldZooming - Reducing the window sizeAs the window increases in size, the image in
the viewport decreases in size and vice versa
Beware of aspect ratio.
Chapter 6
Viewing Transformation Example(10, 30) (50, 30)
(10, 5) (50, 5)
(0,0)
(0, 1)
Viewportwanted
(0.5, 0.5)
(1, 0)
(0.5, 1)
(0, 0.5)
1 0 -100 1 -50 0 1
1) Translate window to origin
1 0 00 1 0.50 0 1
3) Translate to proper coordinates
1/80 0 00 1/50 00 0 1
2) Scale to correct size
X scale = 0.5/40 = 1/80
Chapter 6
Clipping Points to a WindowClipping Points to a Window
Notice P is inside and q is outside, so they q will be clipped
Suppose the window has (xmin, ymin) bottom left vertex & (xmax,ymax) as its upper right vertex, then a point (x,y) is
VISIBLE IF xmin < x < xmax; ymin < y < ymax
.
PQ
.
xmin
xmax
ymin
ymax
Chapter 6
Clipping Lines to a WindowClipping Lines to a Window
A
B
C
D
E
F G
H
I
J
Can we quickly recognise lines which need clipping?
Chapter 6
Clipping to a WindowClipping to a WindowLooking at end-points gives us a quick
classification:–Both ends visible => line visible (AB)–One end visible, other invisible => line partly
visible (CD)–Both ends invisible:
• If both end-points lie to same side of window edge, line is invisible (EF)
• Otherwise, line may be invisible (IJ) or partially visible (GH)
Chapter 6
Line Clipping Algorithms
Brute Force Method - Solve simultaneous equations for intersections of lines with window edges is impractical.
(everything is inside) and for small windows (everything is outside).
Each vertex is assigned a four-bit outcode.
Chapter 6
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Each end-point is coded according to its position relative to the window–Four-bit code assigned as follows:
Bit 1 Set if x < xmin
Bit 2 Set if x > xmax
Bit 3 Set if y < ymin
Bit 4 Set if y > ymax
1001 1000 1010
0001 0000 0010
0101 0100 0110
Chapter 6
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Notice: if – Both end-point codes 0000 => VISIBLE (trivially
accepted) – Logical AND = NOT 0000 => INVISIBLE (trivially
rejected)– Logical AND = 0000 => INVISIBLE or PART VISIBLE
To clip P1P2:– Check if P1P2 totally visible or invisible– If not, for each edge in turn (left/right/bottom/top):(i) Is edge crossed ? (the corresponding bit is set for ONE
of the points, say P1)(ii) If so, replace P1 with intersection with edge.
Chapter 6
ExampleExample
Clip againstleft, right,bottom, topboundaries in turn.
P1: 1001P2: 0100
P1
P2
x=xmin
P1’
First clip to leftedge, givingP1’P2
Chapter 6
ExampleExample
P2
x=xmin
P1’ P1’: 1000P2 : 0100
No need to clipagainst right edge
Clip againstbottom gives P1’P2’
Clip against topgives P1’’P2’
P2’
P1’’
Chapter 6
Calculating the IntersectionCalculating the IntersectionTo calculate intersection of P1P2 with, say left
edge:
Left edge: x = xmin
Line : y - y2 = m (x-x2)
where m = (y2 - y1) / (x2 -x1)
Thus intersection is (xmin, y*)
where y* = y2 + m (xmin - x2)
P1
P2
Chapter 6
Other Line ClippersOther Line ClippersCohen-Sutherland is efficient for quick
acceptance or rejection of lines.
Less so when many lines need clipping.
Other algorithms are:–Liang-Barsky–Nicholl-Lee-Nicholl
see:Hearn and Baker for details
Chapter 6
Line Parametric Equation Parametric equation of a line between twp points
(x1,y1) (x2,y2)
x = x1 + u (x2−x1) & y = y1 + u (y2−y1)
Where u Є [0, 1]. When u = 0 the point is the first (x1, y1) & if u =1 the point is (x2, y2)
Chapter 6
Line Parametric Equation
Find the range of the parameter [u1, u2] so that:xmin <= x <= xmax −> xmin <= x1+u(x2−x1) <=xmax
ymin <= y <= ymax −> ymin <= y1+u(y2−y1) <= ymax
0<= u <=1
The above inequalities allow us to find the final range of the parameter u −> [u1,u2] !!