0% found this document useful (0 votes)
48 views

07.2D Viewing Clipping MCA

This document discusses 2D viewing and clipping in computer graphics. It defines key terms like windows, viewports, and viewing transformations which map parts of 3D scenes to 2D displays. It describes common viewing effects from zooming and panning. It also covers different clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping that identify object portions inside or outside a clip window for display. These clipping algorithms use outcodes and edge subdivision to efficiently clip objects against window borders with minimal intersection calculations.

Uploaded by

ashwini
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)
48 views

07.2D Viewing Clipping MCA

This document discusses 2D viewing and clipping in computer graphics. It defines key terms like windows, viewports, and viewing transformations which map parts of 3D scenes to 2D displays. It describes common viewing effects from zooming and panning. It also covers different clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping that identify object portions inside or outside a clip window for display. These clipping algorithms use outcodes and edge subdivision to efficiently clip objects against window borders with minimal intersection calculations.

Uploaded by

ashwini
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/ 37

2D Viewing

&
Clipping
Computer Graphics – M.C.A.
PG Wing of SBRR Mahajana FG College
Mysore
2017-18
Windows & Viewports
Windows & Viewports
➔Window
➔ A world-coordinate area selected for display.
➔ defines what is to be viewed
➔Viewport
➔ Anarea on a display device to which a window is
mapped.
➔ defines where it is to be displayed
➔Viewing transformation
➔ The mapping of a part of a world-coordinate scene
to device coordinates.
➔A window could be a rectangle to have any orientation.
Windows & Viewports
2D Viewing Transformation Pipeline
2D Viewing Transformation - Terminology
➔Window
➔ A world-coordinate area selected for display.
➔ defines what is to be viewed

➔Viewport
➔ An area on a display device to which a
window is mapped.
➔ defines where it is to be displayed

➔Viewing transformation
➔ The mapping of a part of a world-coordinate
scene to device coordinates.
2D Viewing Transformation - Terminology
➔Modelling Coordinate System – Representation
of an object measured in some physical units
➔World Coordinate System (Object Space) -
Representation of a set of objects, all measured in
the same 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).
2D Viewing Transformation – Viewing Effects
➔Zooming effects
➔ Successively mapping different-sized windows on a
fixed-sized viewports.
➔Panning effects
➔ Moving a fixed-sized window across the various
objects in a scene.
2D Viewing Normalised Coordinates
➔Viewports are typically defined within the unit square
(normalized coordinates). This makes them Device
independent
Window to Viewport Transformation
➔Need to maintain relative size and position between
clipping window and viewport.
Window to Viewport Transformation
Workstation Transformation
➔Sometimes, a single viewport (in normalised
coordinates) may be mapped to different video
monitors with
workstation
transformations.
Clipping
➔Any procedure that identifies those portions of a
picture that are either inside or outside of a specified
region of space is called as a clipping algorithm or
simply clipping.
➔The region against which an object is to be clipped is
called a clip window.
Clipping
➔Point Clipping
➔Line Clipping (straight line segments)
➔Area Clipping (Polygon Clipping)
➔Curve Clipping
➔Text Clipping
Line Clipping
➔Parametic equiation of a line segment from (x 1, y1) and
(x2, y2) :
x = x1 + u(x2 - x1 )
y = y1 + u(y2 - y1 ) where 0 ≤ u ≤ 1
Line Clipping
➔A line can be :
➔ Completely inside the clipping window
➔ Completely outside the window
➔ Partially inside the window
Cohen-Sutherland Line Clipping Algorithm
➔Intersection calculations are expensive.
➔Main Idea :
➔ Find first lines completely inside or certainly outside
clipping window.
➔ Apply intersection only to undecided lines.
➔ Perform cheaper tests before proceeding to
expensive intersection calculations.

➔How ?
➔ Assign code to every endpoint of line segment.
Cohen-Sutherland Line Clipping Algorithm
➔Assign code to every endpoint of line segment.
➔ Borderlines of clipping window divide the plane into 9
regions.
➔ A point can be characterized by a 4-bit code according
to its location with respect to each of the borderlines.
➔ Location bit is 0 if the
point is inside,
1 otherwise.
➔ Code assignment
involves comparisons
or subtractions.
Cohen-Sutherland Line Clipping Algorithm
➔How to calculate OutCodes ?
➔ Calculate differences between endpoint coordinates
and clipping boundaries.
➔ Use the resultant
sign bit of each
difference
calculation to set
the corresponding
bit value.
Cohen-Sutherland Line Clipping Algorithm
➔Endpoint codes are 0000 for both iff line is completely
inside.
➔If endpoint codes has 1 in same bit, line is certainly
outside.
➔Lines that cannot be decided are intersected with
window border lines.
Cohen-Sutherland Line Clipping Algorithm
➔Case 1:
➔ Both endpoints of line segment inside all four lines
➔ Draw (accept) line segment as is
➔ AB: outcode(A) = outcode(B) = 0000
Cohen-Sutherland Line Clipping Algorithm
➔Case 2: Both endpoints outside all lines and on same
side of a line
➔ Discard (reject) the line segment
➔ EF: outcode(E) logically ANDed with outcode(F)
(bitwise) ≠ 0
➔ Both outcodes have a 1 bit in the same place
➔ Line segment is outside of corresponding side of
clipping window
Cohen-Sutherland Line Clipping Algorithm
➔Case 3: One endpoint inside, one outside
➔ Must do at least one intersection
➔CD: outcode (C) = 0, outcode(D) ≠ 0
➔ Location of 1 in outcode(D) determines which edge to
intersect with
➔ Note if there were a segment from C to a point in a
region with 2 ones in outcode, we might have to do
two interesections
Cohen-Sutherland Line Clipping Algorithm
➔Case 4: Both outside
➔ May have part inside. Must do at least one intersection
➔GH and IJ: same outcodes, neither zero but logical AND
yields zero
➔ Shorten line segment by intersecting with one of sides
of window Compute outcode of intersection
(newendpoint of shortened line segment)
➔ Reexecute
algorithm
Cohen-Sutherland Line Clipping Algorithm
➔Efficiency :
➔ Brute-Force approach :
➔ Compute intersections with all sides of clipping
window
➔ Inefficient: one division per intersection
➔ Cohen-Sutherland Algorithm - Advantages:
➔ In many applications, the clipping window is small
relative to the size of the entire data base
➔ Most line segments can be eliminated based on
their outcodes.
➔ Intersections calculated only for remaining lines.
Cohen-Sutherland Line Clipping Algorithm
➔Cohen-Sutherland Algorithm – Disadvantages :
➔ For undecided lines, we still have to perform upto 4
intersection calculations.
➔ Worst case scenario : A very long line, that lies totally
outside the clipping window, but not on the same side,
will require upto 4 intersection calculations before we
reject that line.
Mid-Point Subdivision Algorithm
➔This method is normally used along with Cohen-
Sutherland algorithm.
➔Cohen-Sutherland algorithm will accept those lines that
are totally inside and reject those lines that are totally
outside (on one side of the window).
➔For undecided lines, instead of computing the
intersection points, this Mid-Point Subdivision method
uses binary search method to search for the intersection
point.
➔ Divide the line in the middle and check if each of the
line segments is inside or outside.
Mid-Point Subdivision Algorithm
➔Divide the line in the middle and run Cohen-Sutherland
algorithm on each of the new line segments.
➔ If the segment is totally inside, accept it, and return.
➔ If it is totally outside, reject it, and return
➔ If undecided (i.e., case 3 and case 4), again divide
that line into two segments in the middle.
➔This goes on till segments are
either accepted or rejected.
Mid-Point Subdivision Algorithm
➔Advantage :
➔ No multiplication/division for intersection calculation.
➔ The subdivision search for the intersection point is of
order of logarithmetic complexity.
Polygon Clipping
➔Not as simple as line segment clipping
➔ Clipping a line segment yields at most one line
segment
➔ Clipping a polygon can yield multiple polygons

➔ However, clipping a convex polygon can yield at most


one other polygon
Polygon Clipping
➔One strategy is to replace nonconvex (concave)
polygons with a set of triangular polygons (a tessellation)
➔ Also makes fill easier
Sutherland-Hodgman Polygon Clipping
➔Efficient algorithm for clipping convex polygons.
➔Edges are clipped against every border line of clipping
window.
➔Edges are processed successively.
➔Allows pipelining of edge clipping of polygons, as well as
pipelining of different polygons.
Sutherland-Hodgman Polygon Clipping
➔The four possible outputs generated by the left clipper,
depending on the relative position of pair of edge
endpoints.
Sutherland-Hodgman Polygon Clipping
Sutherland-Hodgman Polygon Clipping
➔The four clippers can work in parallel.
➔ Once a pair of endpoints it output by the first clipper,
the second clipper can start working.
➔ The more edges in a polygon, the more effective
parallelism is.
➔Processing of a new polygon can start once first clipper
finished processing.
➔ No need to wait for polygon completion.
Sutherland-Hodgman Polygon Clipping
➔Convex polygons are correctly clipped.
➔ If the clipped polygon is concave
➔ Split the concave polygon
Sutherland-Hodgman Polygon Clipping
➔Advantages :
➔ Efficient algorithm for clipping convex polygons.
➔ The 4 clippers can work in parallel.
➔ Allows pipelining of edge clipping of polygons, as well
as pipelining of different polygons.
➔Disadvantages :
➔ Not good for concave
polygons
➔ Display of extraneous line

You might also like