Lecture13d-2D_ViewingVisibleSurfaceDetection-Extra
Lecture13d-2D_ViewingVisibleSurfaceDetection-Extra
Chapter 7
7.1 Overview
Generally, any procedure that eliminates those portions
of a picture that are either inside or outside of a specified
region of space is referred to as a clipping algorithm or
simply clipping. Usually a clipping region is a rectangle,
although we could use any shape for a clipping
application.
The most common application of clipping is in the viewing
pipeline, where clipping is applied to extract a designated
portion of a scene (either two-dimensional or three-
dimensional) for display on an output device. Clipping
methods are also used to anti-alias object boundaries, to
construct objects using solid-modeling methods, to
manage multi-window environments, etc.
7.1 Overview
Clipping algorithms are applied in two-dimensional
viewing procedures to identify those parts of a picture that
are within the clipping window (i.e. viewport). Everything
outside the clipping window is then eliminated from the
scene description that is transferred to the output device
for display. An efficient implementation of clipping in the
viewing pipeline is to apply the algorithms to the
normalized boundaries of the clipping window. This
reduces calculations, because all geometric and viewing
transformation matrices can be concatenated and applied
to a scene description before clipping is carried out. The
clipped scene can then be transferred to screen
coordinates for final processing.
7.1 Overview
Pipelines
Graphics hardware uses a pipelined approach to process
vertices and convert primitives into the final image. The
pipeline basically involves the following steps:
• Modeling
• Geometry Processing
• Rasterization
• Fragment Processing
7.1 Overview
Modeling
The conversion of analog (real world) objects into
discrete data
i.e. creating vertices and connectivity via range scanning
The design of a complex structure from simpler primitives
i.e. architecture and engineering designs
Done Offline
We will ignore this step for now
7.1 Overview
Application programmer pipes modeling output into…
Geometry Processing
– Animate objects
– Move objects into camera space
– Project objects into device coordinates
– Clip objects external to viewing window
7.1 Overview
Rasterization
– Conversion of geometry in device coordinates into
fragments (or pixels) in screen coordinates
– After this step there is no notion of a “polygon”, just
fragments
7.1 Overview
Fragment Processing
– Texture lookups
– Coloring
– Programmable GPU steps
7.1 Overview
These last 3 steps need to be FAST
• Developed 20-40 years ago… but little has changed
• Efficient memory use speeds things up
– Cache, cache, cache
• Integers and bit ops over floating point
• Fewer bits usually faster
– float over double, half over float
• Parallel processing
7.1 Overview
Rasterization is very expensive
– More or less linear w/ number of fragments created
– Consists of adds, rounding and logic branches per pixel
– Only rasterize objects that are in viewable region
A few operations now needed to remove invisible onjects
saves many later.
7.1 Overview
Geometry Processing
• Apply modelview and projection matrix.
• Not all primitives map to inside window
– Cull those that are completely outside
– Clip those that are partially inside
• 2D vs. 3D
– Projection plane v. projection cube
– Clipping can occur in either space
– Choice of visible surface algorithm used forces one or the
other
7.1 Overview
Clipping algorithms are available for basic primitives used
in computer graphics, such as
– Point clipping
– Line clipping (straight-line segments)
– Fill-area clipping (polygons)
– Curve clipping
– Text clipping
In the following, we will assume that the clipping region is
a rectangular window with boundary edges at xmin, xmax,
ymin, and ymax.
(x1, y1)
ymax
(x0, y0)
ymin
xmin xmax
The problem: Given a set of 2D lines or polygons and a window, clip the lines or
polygons to their regions that are inside the window.
F
G D
0101 I
0100 0110
B
G D
0101 0100
B 0110
B’
0101 0100
B 0110
A’ 0001 B’ 0100
B’ 0100 B 0100
OR 0100
remove AND 0100
reject
vi
Polygon is Polygon is
clipped vi+1
clipped
Clip vi
Boundary i: output
vi+1: output
Point-to-Plane test
Point-to-Plane test
A very general test to determine if a point p is “inside” a plane P,
defined by q and n:
(p - q) • n < 0: p inside P
(p - q) • n = 0: p on P
(p - q) • n > 0: p outside P
Remember: p • n = |p| |n| cos (q)
q = angle between p and n
q q q
n n n
p p p
P P P
L0
(L(t) - q) • n = 0
L1
q
t = [(q - L0) • n] / [(L1 - L0) • n] n
v5
v4
v1
v2 v3
v5 v5
v4
v1
v1 v1
v2 v3
v5
v4
v1 v1 v1
v2 v3 v2 v2
v5
v4
v1
v1
v2 v3 v2 v3 v2 v3
v5
v4 v4
v1
v1
i1
v2 v3 v3 v2 v3
v5 v5 v5
v4 v4 i2
v1
v1
i1
v2 v3 v2 v3
After these, we have to clip the polygon against the other three edges of the
window in a similar way.
add clip pt. add end pt. add clip pt. follow clip edge until
and end pt. cache old dir. a) new crossing found
b) reach pt. already
added
continue from add clip pt. add clip pt. follow clip edge until
cached location and end pt. cache dir. a) new crossing found
b) reach pt. already
added
text clipping
STRING2 STRING2
STRING1 ING1
All or none
character clipping STRING3 TRING3
STRING4 STRING4
STRING1 STRING1
Clipping individual
character
left
Far clipping plane.
7.7 3D Clipping
We extend the Cohen-Sutherland algorithm.
– Now 6-bit code instead of 4 bits.
– Trivial acceptance where both endpoint codes are all zero.
– Perform logical AND, reject if non-zero.
– Find intersect with a bounding plane and add the two new
lines to the line queue.
– Line-primitive algorithm.
7.7 3D Clipping
Sutherland-Hodgman Algorithm
7.7 3D Clipping
• Sutherland-Hodgman extends easily to 3D
• Call ‘CLIP’ procedure 6 times rather than 4
• Polygon-primitive algorithm
S’
S and S’ do not intersect in the image plane S