Top Banner
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm (3d)
32

Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Dec 22, 2015

Download

Documents

Linda Weaver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Computer Graphics

Clipping• Cohen Sutherland Algorithm (Line)• Cyrus-Back Algorithm (Line)• Sutherland-Hodgeman Algorithm (Polygon)• Cohen Sutherland Algorithm (3d)

Page 2: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Clipping-When we want to study the picture but not whole picture, study some part, enlarge the part make study(X-ray) Selecting and enlarging the part known-Windowing, We select the portion of image and making visible and invisible-Clipping(cutting of the line which is outside View port)Image in object spaceImage in View spaceTransformation is required(Translate and scale) Translate the origin and Scale the object and translate it back to original

Page 3: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

maxmin

maxmin

yyy

xxx

For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::

(xmin , ymin )

(xmax , ymax )

x = xmin x = xmax

y = ymin

y = ymax

cliprectangle

Point Clipping

Page 4: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

(xmin , ymin )

(xmax , ymax )

x = xmin x = xmax

y = ymin

y = ymax

(x1, y1)

cliprectangle

maxmin

maxmin

yyy

xxx

For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::

Point Clipping

Page 5: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

(Wx-Wxmin)/(Wxmax-Wxmin)=(Vx-Vxmin)/(Vxmax-Vxmin)

(Wy-Wymin)/(Wymax-Wymin)=(Vy-Vymin)/(Vymax-Vymin)

Viewing Transformation (N)V=N * WWhere N=Tv * S * T-vAspect ratioAw=(Wxmax-Wxmin)/(Wymax-Wymin)Av=(Vxmax-Vxmin)/(Vymax-Vymin)

Page 6: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

cliprectangle

Cases for clipping linesCases for clipping lines

Line Clipping

Page 7: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Cases for clipping linesCases for clipping lines

A

B

A

B

cliprectangle

Line Clipping

Page 8: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Cases for clipping linesCases for clipping lines

D

A

BC

D'

A

BC

D'

cliprectangle

Line Clipping

Page 9: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Cases for clipping linesCases for clipping lines

D

E

F

A

BC

D'

A

BC

D'

cliprectangle

Line Clipping

Page 10: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Cases for clipping linesCases for clipping lines

D

E

F

A

BC

D'

G

H

G'

H'A

BC

D'

G'

H'

cliprectangle

Line Clipping

Page 11: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Cases for clipping linesCases for clipping lines

D

E

F

A

BC

D'

G

H

G'

H'

I

J

I'

J'

A

BC

D'

G'

H'

cliprectangle

Line Clipping

Page 12: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Line Clipping-Midpoint subdivision - Cohen Sutherland Algo

Midpoint- Check the lineIf it is entirely insideIt is entirely outside (discard)It is partially inside and partially outside

then Find mid point of two endpoints then divide line into two line segement and check both segments and continue

Page 13: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Algo for Midpoint1- Check line Completely outside the window

• Completely inside the window• Partially inside window (Line intersect

boundary, divide it from mid point)2-check again for both segemnts3- Repeat step-1 until whole part of line inside

the window

Page 14: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Clipping Lines by Solving Simultaneous EquationsClipping Lines by Solving Simultaneous Equations

cliprectangle

(xa, ya)(xb , yb)

(xc, yc) (xd , yd)

(x0, y0)

(x1, y1)

(x , y )

cliprectangle

(xa, ya)(xb , yb)

(xc, yc) (xd , yd)

(x0, y0)

(x1, y1)

(x , y )

abedgeaabedgea

lineline

yytyyxxtxx

yytyyxxtxx

,

, 010010

Line Clipping

Page 15: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided.1. First, end-point pairs are checked for Trivial

Acceptance.2. If the line cannot be trivially accepted, region

checks are done for Trivial Rejection.3. If the line segment can be neither trivially

accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected.These three steps are performed iteratively until what remains can be trivially accepted or rejected.

Cohen-Sutherland Algorithm

Page 16: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

0000

1000

0100

1001 1010

0001 0010

0101 0110clip

rectangle

Region outcodesRegion outcodes

min

max

yy

yy

:1bit

: 0bit

min

max

xx

xx

:3bit

: 2bit

Cohen-Sutherland Algorithm

Page 17: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

1. A line segment can be trivially accepted if the outcodes of both the endpoints are zero.

2. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero.

3. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.

Cohen-Sutherland Algorithm

Page 18: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Algo1-Compute the codes for the Two end points2-Enter in loop, check if both outcodes are zero(0000 and 0000) put line in display file for display and exit loop, return3-if both outcodes are not zero then take logical AND of both codes, check result for nonzero if so reject line exit loop, return4-if result is zero then subdivide the line from intersection point of line and clipping boundary and repeat step 2,3,4

Page 19: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

cliprectangle

AB

C

D

E

An ExampleAn Example

Cohen-Sutherland Algorithm

Page 20: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

An ExampleAn Example

cliprectangle

B

C

D

E

Cohen-Sutherland Algorithm

Page 21: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

An ExampleAn Example

cliprectangle

B

C

D

Cohen-Sutherland Algorithm

Page 22: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

An ExampleAn Example

cliprectangle

B

C

Cohen-Sutherland Algorithm

Page 23: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

ExampleExample

Polygon Clipping

Page 24: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

ExampleExample

Polygon Clipping

Page 25: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

ExampleExample

Polygon Clipping

Page 26: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Sutherland-Hodgeman Algo.

The Clipped PolygonThe Clipped Polygon

Page 27: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Clipping of the polygon -Clip Left --Clip right --Clip bottom ---

Clip top --- View transformationConsider Any Edge (P1P2)1.If both p1,p2 are left to edge, p2 is placed

vertex output list of clipped poly2. If p1,p2 are right to edge discard3. If p1,p2 cross edge and find intersection

point (I) if p1 is left to edge then I will be in

output list of vertex of clipped poly if p1 is right then both p1 and I in

output list

Page 28: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Determination of point if is left right to lineAB is line segement(x1,y1 and x2,y2) determine

point p (x,y)is left or right to ABFind cross product of vectors AB and AP then resulted vector has direction vector k then

point p is left to ABIf –k the point p is right to ABAP=(x-x1) *I +(y-y1) * JAB=(x2-x1) *I +(y2-y1) * JAB X AP=[(x2-x1) *(y-y1)-(y2-y1)*(y-y1)]*kd=(x2-x1) *(y-y1)-(y2-y1)*(y-y1)If d=+ then p is left to ABIf d=-Ve then p is right to AB

Page 29: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Case 1Case 1

Inside Outside

Polygonbeingclipped

Clipboundary

s

p:output

4 Cases of Polygon Clipping

Case 2Case 2

Inside Outside

s

p

i:output

Case 3Case 3

Inside Outside

s

p

(no output)

Case 4Case 4

Inside Outside

s

i:first output

p:second output

Page 30: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Algorithm Input vertex P

First Point YesNo

F=P

Does SP intersectE?

No

Yes

ComputeIntersection Point

I

Outputvertex I

S=P

Is S on leftside of E?

Exit

NO

Yes

Outputvertex S

Close Polygon entry

Does SFintersect E?

ComputeIntersection I

Yes

Outputvertex I

Exit

No

Page 31: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

3D Clipping• Both the Cohen-Sutherland and Cyrus-Beck clipping algorithm

readily extend to 3D.• For Cohen-Sutherland algorithm use two extra-bit in outcode for

incorporating z < zmin and z > zmax regions

Page 32: Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.

Thank You