0% found this document useful (0 votes)
8 views71 pages

Cgip

The document discusses the concepts of window and viewport in 2D viewing transformations, explaining how a closed boundary (window) clips a scene and maps it to a defined display area (viewport). It outlines the steps involved in viewing transformations, including establishing a viewing coordinate system, mapping to normalized coordinates, and clipping algorithms for various primitive types. Additionally, it details line and polygon clipping techniques, particularly the Cohen-Sutherland and Sutherland-Hodgeman algorithms, for efficiently processing graphical data within defined boundaries.

Uploaded by

sisirakrishnaks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views71 pages

Cgip

The document discusses the concepts of window and viewport in 2D viewing transformations, explaining how a closed boundary (window) clips a scene and maps it to a defined display area (viewport). It outlines the steps involved in viewing transformations, including establishing a viewing coordinate system, mapping to normalized coordinates, and clipping algorithms for various primitive types. Additionally, it details line and polygon clipping techniques, particularly the Cohen-Sutherland and Sutherland-Hodgeman algorithms, for efficiently processing graphical data within defined boundaries.

Uploaded by

sisirakrishnaks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Module 3

WINDOW TO VIEW PORT


TRANSFORMATION
2D VIEWING
WINDOW AND VIEWPORT
• By defining a closed boundary or window the
enclosed portion of a world coordinate scene is
clipped against the window boundary and the
data to be clipped portion is extracted for
mapping to a separately defined region known as
viewport.

• While window selects a part of the scene,


viewport displays the selected part at desired
location on the display area.
VIEWING TRANSFORMATION
VIEWING PIPELINE
Viewing transformation is done in several steps:
• First we construct the scene in world
coordinates using the output primitives and
attributes.
• To obtain a particular orientation for the
window, we can set up a two dimensional
viewing coordinate system in the world
coordinate plane and define a window in the
viewing coordinate system.
• The viewing coordinate frame is used to
provide a method for setting up arbitrary
orientations for rectangular windows.
• Once the viewing reference frame is
established, we can transform descriptions in
world coordinates to viewing coordinates.
• We then define a view port in normalized
coordinates and map the viewing coordinate
description of the scene to normalized
coordinates.
• At the final step all parts of the picture that lie
outside the view port are clipped and the
contents of the viewport are transferred to
device coordinates.
• By changing the position of the view port, we
can view objects at different positions on the
display area of an object device.
• Also by varying the size of view ports we can
change the size and proportions of displayed
objects.
WINDOW TO VIEWPORT TRANSFORMATION
TRANSFORMATION MATRIX FOR WORLD
COORDINATES TO VIEW PORT COORDINATES
EXAMPLE
TRANSFORMATION MATRIX
EXAMPLE
CLIPPING
APPLICATIONS OF CLIPPING
• Clipping algorithms can be applied in world
coordinates so that only the contents of the
window interior are mapped to device
coordinates.
• Alternatively the complete world coordinate
picture can be mapped first to device coordinates
or normalized device coordinator, then clipped
against the view port boundaries.
• There be algorithms for clipping the following
primitive types :
*Point clipping * Line clipping * Curve clipping
* Area clipping (polygons) * Text clipping
POINT CLIPPING

Where the edges of the clip window (Xwmin, Xwmax, ywmin, ywmax) can be either the
world coordinate window boundaries or viewport boundaries.

• Eg : applied to scenes involving explosions or sea foam that are modeled with particles
(points) distributed in some region of the scene.
LINE CLIPPING
LINE CLIPPING
• A line clipping procedure involves several parts.
• First we can test a given line segment to
determine whether it lies completely inside the
clipping window.
• If it does not, we try to determine whether it lies
completely outside the window.
• Finally, we cannot identify a line as completely
inside or completely outside, we must perform
intersection calculations with one or more
clipping boundaries.
The figure illustrates possible relationships between line
positions and a standard rectangular clipping region
Intersection calculations for multiple
intersection points
• For a line segment with end points (X1,Y1) and
(X2,Y2) and on or both endpoints outside the
clipping rectangle, the parametric
representation;
X = X1 + u (X2 – X1)
Y = Y1 + u (Y2 – Y1) ,0≤u≤1
could be used to determine values of parameter
‘u’ for intersections with the clipping boundary
coordinates.
Cases for the parameter ‘u’
• If the value of ‘u’ for an intersection with a
rectangular boundary edge is outside the range 0
to 1, the line does not enter the interior of the
window at that boundary.
• If the value of ‘u’ is within the range from 0 to 1,
the line segment does indeed cross into the
clipping area.
• This method can be applied to each clipping
boundary edge in turn to determine whether any
part of the line segment is to be displayed.
• Line segments that are parallel to window edges
can be handled as special cases.
COHEN – SUTHERLAND LINE CLIPPING
• Each bit position in the region code is used to
indicate one of the four relative coordinate
positions of the point with respect to the clip
window to the left, right, top or bottom.
• By numbering the bit positions in the region code as
1 through 4 from right to left, the coordinate
regions can be correlated with the bit positions as;
Bit 1 : Left
Bit 2 : Right
Bit 3 : Below
Bit 4 : Above
• This rule is also called TBRL code (Top-Bottom-
Right-Left)
COHEN – SUTHERLAND LINE CLIPPING
• A value of 1 in any bit position indicates that the
point is in the relative position; otherwise, the
bit position is set to 0.
• If a point is within the clipping rectangle, the
region code is 0000.
• A point ie., below and to the left of the
rectangle has a region code of 0101.
• Bit values in the region code are determined by
comparing end point coordinate values (x,y) to
the clip boundaries.
• Bit 1 is set to 1 if x < xwmin.
• The other three bit values can be determined
using similar comparisons.
• Thus, region-code bit values can be
determined with the following two steps:
i. Calculate differences between endpoint
coordinates and clipping boundaries.
ii. Use the resultant sign bit of each difference
calculation to set the corresponding value in
the region code.
• Bit 1 is the sign bit of x – xwmin ;
• Bit 2 is the sign bit of xwmax – x;
• Bit 3 is the sign bit of y – ywmin ; and
• Bit 4 is the sign bit of ywmax – y;
Any lines that are completely contained within
the window boundaries have a region code of
0000 for both end points, and we trivially
accept these lines.
Any lines that have a 1 in the same bit
position in the region codes for each end point
are completely outside the clipping rectangle
and we trivially reject these lines.
We discard the line that has a region code of
1001 for one end point and a code of 0101 for
the other end point.
Both end points of this line are left of the
clipping rectangle as indicated by 1 in the first
bit position of each region code.
• A method that can be used to test lines for
total clipping is to perform the logical AND
operation with both region codes.
• If the result is not 0000, the line is completely
outside the clipping region.
• Lines that cannot be identified as completely
inside or completely outside a clip window by
these tests are checked for intersection with
the window boundaries.
• We begin the clipping process for a line by
comparing an outside end point to a clipping
boundary to determine how much of the line
can be discarded.
• Then the remaining part of the line is checked
against the other boundaries and we continue
until either the line is totally discarded or a
section is found inside the window.
• As shown in fig, such lines may or may not
cross into the window interior.
• Intersection points with a clipping boundary
can be calculated using the slope – intercept
form of the line equation.
• For a line with end point coordinates (x1,y1)
and (x2,y2), the y coordinate of the
intersection point with a vertical boundary can
be obtained with the calculation.
y = y1 + m(x – x1)
Where the x value is set either to xwmin or to
xwmax and the slope of the line is calculated as,
m = (y2 –y1) / (x2 –x1)
• Similarly, if we are looking for the intersection
with a horizontal boundary, the x coordinate
can be calculated as
x = x1 + ((y – y1)/ m)
With y set either to ywmin or to ywmax.
Other Example
ALGORITHM
Example
POLYGON CLIPPING
POLYGON CLIPPING
• A polygon boundary processed with a line
clipper may be displayed as a series of
connected line segments
Before Clipping After Clipping
• For polygon clipping, we require an algorithm
that will generate one or more closed areas
that are then scan converted for the
appropriate area fill.
• The output of a polygon clipper should be a
sequence of vertices that defines the clipped
polygon boundaries.
SUTHERLAND – HODGEMAN
POLYGON CLIPPING
Sutherland – Hodgeman polygon
clipping
• We can correctly clip a polygon by processing
the polygon boundary as a whole against each
window edge.
• This can be accomplished by processing all
polygon vertices against each clip rectangle
boundary in turn.
Original Polygon
• There are 4 possible cases when processing
vertices in sequence around the perimeter of
a polygon.
• As each pair of adjacent polygon vertices is
passes to a window boundary clipper, we
make the following tests:
Out -> In
Save v1’, v2
In -> In
Save v2
In -> Out
Save v1 ‘
Out -> Out
Save none
• Once all vertices have been processed for one clip
window boundary, the output list of vertices is clipped
against the next window boundary
• Implementing the algorithm we have just described
requires setting up storage for an output list of vertices
at each step and passing the clipped vertices onto the
next boundary clipper.
• This can be done with parallel processors or a single
processor and a pipeline of clipping routines.
• A point (either an input vertex or a calculated
intersection point) is added to the output vertex list
only after it has been determined to be inside or
outside on a window boundary by all four boundary
clippers. Otherwise the point does not continue in the
pipeline.

You might also like