Sie sind auf Seite 1von 5

Lecture 4

Anti-Aliasing Line and Polygon Clipping

Anti-Aliasing
Overview
Super Sampling Area Sampling (prefiltering) Weighting (postfiltering)
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Antialiasing
Aliasing, jagged edges or staircasing can be reduced by:
Higher screen resolution
- Need a huge frame buffer

Antialiasing Techniques
Super Sampling
Compute intensities at sub-pixel grid positions and combine the results to obtain the pixel intensity.

Antialiasing techniques
- Vary pixel intensities along boundaries to smooth the edge.

Area Sampling
Find pixel intensity by calculating the areas of overlap of each pixel within the objects to be displayed.

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Supersampling (zero line width)


Example: a straight line on a gray scale display Divide each pixel into sub-pixels. The number of intensities are the max number of sub-pixels selected on the line segment within a pixel.

Supersampling (finite line width)


The intensity level for each pixel is proportional to the number of sub-pixels inside the polygon representing the line area. Line intensity is distributed over more pixels.

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Postfiltering
Equal areas can contribute to unequal intensity. A weighted avarage.

Filter Functions
Optimal filters are computationally more expensive. Cone filters are a very reasonable compromise between cost and quality.

Weigting Masks
Predefined table values for each subpixel

Filtering Techniques
Includes neighbouring pixels

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Anti-Aliasing
Line Intensity Differences:
The diagonal line appears less bright than the horizontal. Total intensity is proportional to their length.

Line and Polygon Clipping


Overview
Cohen-Sutherland line clipping algorithm Liang-Barsky line clipping algorithm Sutherland-Hogeman polygon clipping

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Clipping Algorithms
Line Clipping:
Cohen-Suterland (encoding)
- Oldest and most commonly used

Cohen-Sutherland Line-Clipping
1. Encode end points Bit 0 = point is left of window Bit 1 = point is right of window Bit 2 = point is below window Bit 3 = point is above window If C0 Cend 0 then P0Pend is trivially rejected If C0 Cend = 0 then P0Pend is trivially accepted Otherwise subdivide and go to step 1 with new segment.
Computer Graphics & Visualization

1001

1000

1010

Nicholl-Lee-Nicholl (encoding) (more efficient) Liang-Barsky (parametric) (more efficient)

0001

0000

0010

2.

Polygon Clipping:
Sutherland-Hodgeman
Divide and conquer strategy 4. 3.

0101

0100

0110

C0 =

Bit code of P0

Weiler-Atherton (modified for concave polygons)


Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Cend = Bit code of Pend


Pedher Johansson
Department of Computing Science, Ume University

Cohen-Sutherland Line-Clipping
Clip order: Left, Right, Bottom, Top 1) A1C1 2) B1C1 3) reject 1) 2) 3) 4) 5) A2E2 B2E2 1001 B2D2 B2C2 accept A1 0001 C1 B1 1000 C2 B2 0000 A3 A2 0101 D3
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Cohen-Sutherland Line-Clipping
E2

1010 D2

Will do unnecessary clipping. Efficient when most of the lines to be clipped are either rejected or accepted (not so many subdivisions). Easy to program

0010

1) 2) 3) 4)

A3D3 A3C3 A3B3 accept

C3

B3 0100

0110
Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Parametric form
A line segment with endpoints (x0, y0) and (xend, yend) we can describe in the parametric form x = x0 + ux y = x0 + uy where x = xend x0 y = yend y0
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Liang-Barsky Line-Clipping
More efficient than Cohen-Sutherland A line is inside the clipping region for values of u such that: xwmin x0 + ux xwmax x = xend x0 ywmin y0 + uy ywmax y = yend y0 Can be described as u pk qk, k = 1, 2, 3, 4
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

0u1

Liang-Barsky Line-Clipping
The infinitely line intersects the clip region edges when:
p1 = x p2 = x qk uk = where p3 = y pk p4 = y q1 = x0 xwmin q2 = xwmax x0 q3 = y0 ywmin q4 = ywmax y0

Liang-Barsky Line-Clipping
When pk < 0, as u increases
- line goes from outside to inside - entering

When pk > 0,
Left boundary Right boundary Bottom boundary Top boundary - line goes from inside to outside - exiting

When pk = 0,
- line is parallel to an edge

If there is a segment of the line inside the clip region, a sequence of infinite line intersections must go: entering, entering, exiting, exiting
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Liang-Barsky Line-Clipping
Enter Exit Enter Enter Enter Exit Exit Exit Clip region

Liang-Barsky Line-Clipping
1. Set umin = 0 and umax = 1. 2. Calculate the u values: 3. If u < umin or u > umax ignore it. Otherwise classify the u values as entering or exiting. 4. If umin < umax then draw a line from:
( x0 + x umin, y0 + y umin ) to ( x0 + x umax, y0 + y umax )

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Example Liang-Barsky
P0(-5,3)

0,10

10,10 Pend(15,9)

Liang-Barsky Line-Clipping
We have uenter = 1/4 and uleave = 3/4

0,0

10,0 Entering Exiting uenter = 1/4 uleave = 3/4

uleft =

1 50 q1 x0 xwmin = = = (15 (5)) 4 x p1

Pend - P0 = (15+5,9-3) = (20,6)


x y

q xw x 10 (5) 3 = uright = 2 = max 0 = 15 (5) 4 x p2 3 0 1 q y ywmin = = ubottom = 3 = 0 (9 3) 2 y p3 utop = q4 ywmax y0 10 3 7 = = = 9 3 6 y p4


Computer Graphics & Visualization

If uenter < uleave , there is a line segment


- compute endpoints by substituting u values

u < 0 then ignore u > 1 then ignore


Pedher Johansson
Department of Computing Science, Ume University

Draw a line from (-5+(20)(1/4), 3+(6)(1/4)) to (-5+(20)(3/4), 3+(6)(3/4))


Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Example Liang-Barsky
P0(-8,2)

0,10

Pend(2,14)

10,10

Liang-Barsky Line-Clipping
We have uenter = 4/5 and uleave = 2/3
0,0 10,0
Entering uenter = 4/5

uleft =

q1 x0 xwmin 4 8 0 = = = p1 (2 (8)) 5 x q2 xwmax x0 10 (8) 9 = = = 2 (8) 5 p2 x

Pend - P0 = (2+8, 14-2) = (10, 12) uenter > uleave , there is no line segment do draw

uright =

u > 1 then ignore

ubottom = utop =

q3 y0 ywmin 20 1 = = = u < 0 then ignore 6 p3 y (14 2)


Exiting uleave = 2/3
Pedher Johansson
Department of Computing Science, Ume University

q4 ywmax y0 10 2 2 = = = 14 2 3 p4 y
Computer Graphics & Visualization

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Nicholl-Lee-Nicholl Line Clipping


Avoids multiple clipping of an individual line by creating more regions. Only three regions need to be considered.
P0 P0 P0

Nicholl-Lee-Nicholl Line Clipping


If P0 inside and Pend outside:
L
P0

T R B

If P0 is to the left:
LT
L

If P0 is to the left and above:


P0

inside

edge region

corner region

T L LR L LB
T

P0
L

TR

Find position of Pend relative to P0.


Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

LB

TB
Pedher Johansson

Computer Graphics & Visualization

Department of Computing Science, Ume University

Nicholl-Lee-Nicholl Line Clipping


To determine region
compare slopes, and boundaries of the NLN region.

Sutherland-Hodgeman Polygon Clipping


Four test cases:
1. 2. 3. 4. First vertex inside and the second outside (in-out pair) Both vertices inside clip window First vertex outside and the second inside (out-in pair) Both vertices outside the clip window

Concave polygons may be displayed with extra lines.


Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University

Computer Graphics & Visualization

Pedher Johansson
Department of Computing Science, Ume University

Weiler-Atherton Polygon Clipping


Clips concave polygons correctly. Instead of always going around the polygon edges, we also, want to follow window boundaries. For an outside-to-inside pair of vertices, follow the polygon boundary. For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction.
Computer Graphics & Visualization
Pedher Johansson
Department of Computing Science, Ume University