0% found this document useful (0 votes)
5 views42 pages

Mod 2 Lecture 1_2 CG windowing clipping

The document discusses key concepts in computer graphics, focusing on windowing, clipping, and algorithms for hidden surface removal. It explains the use of display files for efficient image manipulation and outlines the Cohen-Sutherland and Sutherland-Hodgman algorithms for line and area clipping, respectively. These algorithms improve performance by reducing the number of calculations needed to determine visible portions of graphics within defined boundaries.

Uploaded by

shoovam123
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)
5 views42 pages

Mod 2 Lecture 1_2 CG windowing clipping

The document discusses key concepts in computer graphics, focusing on windowing, clipping, and algorithms for hidden surface removal. It explains the use of display files for efficient image manipulation and outlines the Cohen-Sutherland and Sutherland-Hodgman algorithms for line and area clipping, respectively. These algorithms improve performance by reducing the number of calculations needed to determine visible portions of graphics within defined boundaries.

Uploaded by

shoovam123
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/ 42

Module 2

Computer Graphics

Windowing and clipping


Hidden surface and solid removal
Lighting and shading
Color models
Two interactive operations that carried out in CAD:

* Redrawing of the display to “clean-up” unwanted clutter on the


screen or to restore parts of the image that have been corrupted.
* Selection of entities from the screen

In each of these cases, work is not just done with the base entity data, but with a
display file that stores the displayable vectors for an entity.

For example, in the selection of a surface without use of a display file it would be
necessary to recompute the surface display in order to identify which path is
nearest to the cursor. With a display file it is only necessary to find the nearest
displayed vector and to cross-reference back to the entity.

Display files also lend themselves to fast image manipulation or zoom facilities.
Instead of recomputing the entire image for a zoom within existing window
boundary, the display file vectors are used- leading to some loss in display
resolution for curves, but generally faster display control.

The display file is related to the rest of the data by cross-referencing between the
display file and the entity table.
• Windowing Concepts
• Clipping
– Introduction
– Brute Force
– Cohen-Sutherland Clipping Algorithm
• Area Clipping
– Sutherland-Hodgman Area Clipping Algorithm
Clipping
- is used in extracting the part of a scene and for
identifying visible surfaces in 3D views
- Displaying multi window environments
- Selecting object that can be applied with
necessary Geometric Transformations
(Zooming and panning of image is applied on
the necessary geometry)
Windowing
• A scene is made up of a collection of objects
specified in world coordinates

World Coordinates
Windowing
• When we display a scene only those objects
within a particular window are displayed
Window
wymax

wymin

wxmin wxmax
World Coordinates
Windowing
• Because drawing things to a display takes time
we clip everything outside the window
Window
wymax

wymin

wxmin wxmax
World Coordinates
Clipping
• For the image below consider which lines and
points should be kept and which ones should
be clipped
P4

Window P2
wymax
P6
P3
P1
P7 P5

P9
P8
wymin
P10

wxmin wxmax
Point Clipping
- a point (x,y) is not clipped if:
• wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax
• otherwise it is clipped
P4 Clipped
Clipped

Window P2
wymax
Clipped
P5
P1
P7 Points Within the Window
are Not Clipped
P9 P8
wymin
Clipped P10

wxmin wxmax
Line Clipping
• examine the end-points of each line to see if
they are in the window or not
Situation Solution Example

Both end-points inside


Don’t clip
the window

One end-point inside


the window, one Must clip
outside

Both end-points
Don’t know!
outside the window
Brute Force Line Clipping
• Brute force line clipping can be performed as
follows:
– 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
Brute Force Line Clipping (cont…)
– For lines with both end-
points outside the window
test the line for
intersection with all of the
window boundaries, and
clip appropriately

However, calculating line intersections is


computationally expensive
Because a scene can contain so many lines, the brute
force approach to clipping is much too slow
In case of intersection
x= x1 + u(x2 – x1 )
y= y1 + u(y2 – y1 )

Where 0< u < 1

- If u for an intersection with the clipping boundaries is


outside the range of 0 and 1, then the line is not inside the
clipping rectangle
- If between 0 and 1 then the line is inside the clipping
rectangle.

This method has to be applied to each of the edges of the


clipping rectangle to identify the position of lines.
Cohen-Sutherland Clipping Algorithm
• An efficient line clipping
algorithm
• The key advantage of the
algorithm is that it vastly
reduces the number of line
intersections that must be Dr. Ivan E. Sutherland co-
developed the Cohen-
calculated Sutherland clipping
algorithm. Sutherland is a
graphics giant and includes
amongst his achievements
Cohen is something of a mystery – can the invention of the head
anybody find out who he was? mounted display.
Cohen-Sutherland: World Division
• World space is divided into regions based on
the window boundaries - TBRL
– Each region has a unique four bit region code
– Region codes indicate the position of the regions
with respect to the window
1001 1000 1010
3 2 1 0

Top below right left 0000


0001 0010
Window
Region Code Legend

0101 0100 0110


Cohen-Sutherland: Labelling
• Every end-point is labelled with the
appropriate region code
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland Algorithm
• 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
• A value of 1 in any bit position indicates that the point
is in that 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 that is below and to the left of
the rectangle has a region code of 0101.
Cohen-Sutherland Algorithm

• Bit values in the region code are determined by comparing


endpoint 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.
Cohen-Sutherland Algorithm

For languages in which bit manipulation is possible, region-


code bit values can be determined with the following two
steps:
(1) Calculate differences between endpoint coordinates and
clipping boundaries.
(2) 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 xwmin -x


Bit 2 is the sign bit of x- xwmax
bit 3 is the sign bit of ywmin-y and
bit 4 is the sign bit of y- ywmax .
Cohen-Sutherland Algorithm

• Intersection points with a clipping boundary can be calculated


using the slope-intercept form of the line equation. For a line
with endpoint 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 xwmax or
xwmin
• 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
Problem
• A Clipping window PQRS has bottom left corner at (3,4) and
upper right corner at (10,9). Find the section of the clipped
line AB shown in the Figure using Cohen Sutherland Line
Clipping algorithm E(7,11)
A(2,11)

S R(10,9)

F(11,7)
Q
P(3,4)
B(9,2)
Cohen-Sutherland: Labelling
• Every end-point is labelled with the
appropriate region code
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Lines In The Window
Lines completely contained within the window
boundaries have region code [0000] for both
end-points so are not clipped
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Lines Outside The Window
Any lines with a common set bit in the region
codes of both end-points can be clipped
– The AND operation can efficiently check this
P11 [1010]
P4 [1000]

Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]

wxmin wxmax
Cohen-Sutherland: Other Lines
• Lines that cannot be identified as completely
inside or outside the window may or may not
cross the window interior
• These lines are processed as follows:
– Compare an end-point outside the window to a
boundary (choose any order in which to consider
boundaries e.g. left, right, bottom, top) and
determine how much can be discarded
– If the remainder of the line is entirely inside or
outside the window, retain it or clip it respectively
Cohen-Sutherland: Other Lines (cont…)
– Otherwise, compare the remainder of the line against
the other window boundaries
– Continue until the line is either discarded or a
segment inside the window is found
• We can use the region codes to determine which
window boundaries should be considered for
intersection
– To check if a line crosses a particular boundary we
compare the appropriate bits in the region codes of its
end-points
– If one of these is a 1 and the other is a 0 then the line
crosses the boundary
Cohen-Sutherland Examples
• Consider the line P9 to P10 below
– Start at P10
Window
– From the region codes wymax
of the two end-points we
know the line doesn’t
cross the left or right wymin
P [0000]
9

P ’ [0000]
boundary 10

– Calculate the
P [0100]
10

wxmin wxmax
intersection of the line with the bottom boundary to
generate point P10’
– The line P9 to P10’ is completely inside the window so
is retained
Cohen-Sutherland Examples (cont…)

• Consider the line P3 to P4 below


– Start at P4 P ’ [1001]
4
4 P [1000]
Window
– From the region codes wy max

of the two end-points P [0001]


3

we know the line


crosses the left
boundary so calculate wymin
the intersection point to
generate P4’
– The line P3 to P4’ is completely outsidewxthe min
window sowxmax
is clipped
Cohen-Sutherland Examples (cont…)

• Consider the line P7 to P8 below


– Start at P7
Window
– From the two region wymax

codes of the two


end-points we know P7 [0001]
P7’ [0000]
P8 [0010]
the line crosses the P8’ [0000]
wymin
left boundary so
calculate the
intersection point to wxmin wxmax
generate P7’
Cohen-Sutherland Examples (cont…)

• Consider the line P7’ to P8


– Start at P8 Window
wymax
– Calculate the
intersection with the P7’ [0000]
right boundary to P7 [0001]
P8’ [0000]
P8 [0010]

generate P8’ wymin

– P7’ to P8’ is inside


the window so is wxmin wxmax
retained
Cohen-Sutherland Worked Example

Window
wymax

wymin

wxmin wxmax
Calculating Line Intersections
• Intersection points with the window
boundaries are calculated using the line-
equation parameters
– Consider a line with the end-points (x1, y1) and (x2,
y2)
– The y-coordinate of an intersection with a vertical
window boundary can be calculated using:
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or wxmax
Calculating Line Intersections (cont…)

– The x-coordinate of an intersection with a


horizontal window boundary can be calculated
using:
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
– m is the slope of the line in question and can be
calculated as m = (y2 - y1) / (x2 - x1)
Area Clipping
• Similarly to lines, areas
must be clipped to a
window boundary
• Consideration must be
taken as to which
portions of the area
must be clipped
Sutherland-Hodgman Area Clipping
Algorithm
Sutherland
• A technique for clipping areas turns up
again. This
developed by Sutherland & time with
Gary Hodgman with
Hodgman whom he worked at
• Put simply the polygon is clipped the first ever graphics
company Evans &
by comparing it against each Sutherland

boundary in turn

Original Area Clip Left Clip Right Clip Top Clip Bottom
Sutherland-Hodgman Polygon Clipping:
Four possible scenarios at each clipper

outside inside outside inside outside inside outside inside

v2 v2 v2 v2

v1’ v1’
v1 v1
v1 v1

Outside to inside: Inside to inside: Inside to outside: Outside to outside:


Output: v1’ and v2 Output: v2 Output: v1’ Output: nothing
Sutherland-Hodgman Polygon Clipping

Input each edge (vertex pair) successively.


Output is a new list of vertices.
Each edge goes through 4 clippers.
The rule for each edge for each clipper is:
- If first input vertex is outside, and second is inside, output the
intersection and the second vertex
- If first both input vertices are inside, then just output second
vertex
- If first input vertex is inside, and second is outside, output is
the intersection
- If both vertices are outside, output is nothing
Sutherland-Hodgman Polygon Clipping

v2’ v2
v3
v2’’
v1’
v3’
Left Right Bottom Top
v1 Clipper Clipper Clipper Clipper

v1v2 v2 v2v2’ v2’ v2’v3’ v2” v2”v1’ v1’


v2v3 v2’ v2’v3’ v3’ v3’v1 v1’v2 v2
v3v1 v3’v1 v3’v1 v1 v1v2 v1’v2 v2v2’ v2’
v1v2 v2 v2v2’ v2’ v2’v2” v2”
Edges Output Edges Output Edges Output Edges Output
Final
Sutherland-Hodgman Area Clipping
Algorithm (cont…)
• To clip an area against an individual boundary:
– Consider each vertex in turn against the boundary
– Vertices inside the boundary are saved for clipping
against the next boundary
– Vertices outside the boundary are clipped
– If we proceed from a point inside the boundary to
one outside, the intersection of the line with the
boundary is saved
– If we cross from the outside to the inside intersection
point and the vertex are saved
Sutherland-Hodgman Example
• Each example S
shows the point
being processed (P) P
I
S

and the previous P


point (S) Save Point P Save Point I

• Saved points define P S


area clipped to the I P

boundary in
question
S
No Points Saved Save Points I & P
Other Area Clipping Concerns
• Clipping concave areas can be a little more tricky
as often superfluous lines must be removed

Window Window
Window Window
• Clipping curves requires more work
– For circles we must find the two intersection points on
the window boundary
Summary
• Objects within a scene must be clipped to
display the scene in a window
• Because there are can be so many objects
clipping must be extremely efficient
• The Cohen-Sutherland algorithm can be used
for line clipping
• The Sutherland-Hodgman algorithm can be
used for area clipping

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy