168 471 Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.

Post on 17-Dec-2015

222 views 1 download

Transcript of 168 471 Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.

168 471 Computer Graphics, KKU. Lecture 8

1

Clipping on a Raster Display

168 471 Computer Graphics, KKU. Lecture 8

2

Approaches to Clipping

168 471 Computer Graphics, KKU. Lecture 8

3

Analytical Clipping

168 471 Computer Graphics, KKU. Lecture 8

4

Clipping Lines Against Rectangles

168 471 Computer Graphics, KKU. Lecture 8

5

Clipping Rules

168 471 Computer Graphics, KKU. Lecture 8

6

Computing Intersections

168 471 Computer Graphics, KKU. Lecture 8

7

- Cohen Sutherland Algorithm

168 471 Computer Graphics, KKU. Lecture 8

8

Outcodes

168 471 Computer Graphics, KKU. Lecture 8

9

Outcode Computation

typedef unsigned int outcode; enum {TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8}

outcode CompOutCode( double x, double y, double xmin, double xmax, double ymin, double ymax){ outcode code = 0; if ( y > ymax ) code |= TOP; else if ( y < ymin ) code |= BOTTOM; if ( x > xmax ) code |= RIGHT; else if ( x < xmin ) code |= LEFT; return code;

}

168 471 Computer Graphics, KKU. Lecture 8

10

- Cohen Sutherland Procedures

168 471 Computer Graphics, KKU. Lecture 8

11

- Cohen Sutherland Procedures

168 471 Computer Graphics, KKU. Lecture 8

12

- Cohen Sutherland Algorithm

168 471 Computer Graphics, KKU. Lecture 8

13

- Cohen Sutherland Algorithm (cont.)

168 471 Computer Graphics, KKU. Lecture 8

14

- Cohen Sutherland Procedures

168 471 Computer Graphics, KKU. Lecture 8

15

Parametric Line-Clipping Algorithm

0 1 0

0 1 0

0

1 0

[ ( ) ] 0

[ ( ) ] 0

[ ] [ ] 0

[ ]

( )

i Ei

i Ei

i Ei i

i Ei

i

N P t P

N P P P t P

N P P N P P t

N P Pt

N D

whereD P P

• 1978IntroducedbyCyrudandBeck i n• EEEEEEEEEEE EE EEEEEE EE EEEEE EEE EEEEEE• Essentially find the parameter t from P(t) = P

0 + (P

1-P0)

168 471 Computer Graphics, KKU. Lecture 8

16

- Parametric Line Clipping Algorith m (cont.)

• EEE EE EEEEEEEEEE EE EE EEEEEEEEEEEE E, ( ntering) and PL (potentially leaving) on the basis of the angle between P0

P1

and Ni

• E EEEEE EEE EE EE EL for each intersection• EEEEEE EEE EEEE EEEE EEE EEEE EEE E EEEE EE EE EEE EEEEEEE EL

• If tE E> L EEEE EEEEEEEEE EEEEEEEE,

0 ( 90)

0 ( 90)i

i

N D PE angle

N D PL angle

168 471 Computer Graphics, KKU. Lecture 8

17

- Parametric Line Clipping Algorith m (cont.)

168 471 Computer Graphics, KKU. Lecture 8

18

- Cyrus Beck Algorithm (Pseudocode)

168 471 Computer Graphics, KKU. Lecture 8

19

Clipping Circles and Ellipses

• Firstly, do a trivial accept/reject test by intersec ting the circle’s/elleipse’s extent with the clip re

ctengle.• If intersection occurs, divide it into and do the tr

ivial accept/reject test for each.• If scan conversion is fast or if the circle is not to

- - o large, scissoring on a pixel by pixel basis woul d be more efficient.

168 471 Computer Graphics, KKU. Lecture 8

20

Clipping Polygons

Example of polygon clipping, (a) Multiple components. (b) Simple convex case. (c) Concave case.

168 471 Computer Graphics, KKU. Lecture 8

21

Clipping Polygons (cont.)

Polygon clipping, edge by edge. (a) Before clipping. (b) Clip on right. (c) Clip on bottom. (d) Clip on left. (e) Clip on top; polygon is fully clipped