{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture05-Clipping

# Lecture05-Clipping - CS 455 Computer Graphics Clipping...

This preview shows pages 1–13. Sign up to view the full content.

CS 455 – Computer Graphics Clipping

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Project 2 Projection Comparison Perspective Parallel (and orthonormal)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing area? Draw just the portions of a line (or object) that fall within a given region/window/screen (usually rectangular) Drawing Area
Math Problem of the Day y=100 x=200 (x0,y0) = (10,90) (x1,y1) = (20,115) (xi,yi)=(_,_) 14 10 25 10 10 ) 0 100 ( 0 1 0 1 0 = + = - - - + = y y y x x x xi

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Line Clipping Strategies for clipping: a) Check (in inner loop) if each point is inside Works, but slow b) Clip invalid coordinate(s) to boundary Incorrect results c) Find intersection of line with boundary Correct if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) drawPoint(x,y,c); if (x < xmin) x = xmin; else if (x > xmax) x = xmax; if (y < ymin) y = ymin; else if (y > ymax) y = ymax; Input Output Clip x Clip y Clip line to intersection
Line Clipping: Possible Configurations 1. Both endpoints are inside the region (line AB ) No clipping necessary 1. One endpoint in, one out (line CD ) Clip at intersection point 3. Both endpoints outside the region: a. No intersection (lines EF , GH ) b. Line intersects the region (line IJ ) - Clip line at both intersection points A B C D F E I J G H

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Line Clipping: Cohen-Sutherland Basic algorithm: Accept (and draw) lines that have both endpoints inside the region F E Trivially reject A B Trivially accept H C D I J G Clip and retest Clip the remaining lines at a region boundary and repeat steps 1 and 2 on the clipped line segments Reject (and don’t draw) lines that have both endpoints less than x min or y min or greater than x max or y max
Cohen-Sutherland: Accept/Reject Tests Assign 4-bit code to each endpoint corresponding to its position relative to region: First bit (1000) : if y > y max Second bit (0100) : if y < y min Third bit (0010) : if x > x max Fourth bit (0001) : if x < x min Test: if code 0 OR code 1 = 0000 accept (draw) else if code 0 AND code 1 0000 reject (don’t draw) else clip and retest 0100 0101 0110 1000 1001 1010 0001 0010 0000 Why does this work?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Accept/reject/redo all based on bit-wise Boolean ops. Cohen-Sutherland Accept/Reject 0100 0101 0110 1000 1001 1010 0001 0010 0000
Cohen-Sutherland: Line Clipping Intersection algorithm: if code 0 0000 then code = code 0 else code = code 1 dx = x 1 x 0 ; dy = y 1 y 0 if code AND 1000 then begin // y max x = x 0 + dx * ( y max y 0 ) / dy ; y = y max end else if code AND 0100 then begin // y min x = x 0 + dx * ( y min y 0 ) / dy ; y = y min end else if code AND 0010 then begin // x max y = y 0 + dy * ( x max x 0 ) / dx ; x = x max end else begin // x min y = y 0 + dy * ( x min x 0 ) / dx ; x = x min end if code = code 0 then begin x 0 = x ; y 0 = y ; end else begin x 1 = x ; y 1 = y ; end ( x 1 , y 1 ) ( x 0 , y 0 ) y max y min dx dy ( x , y ) x min x max code is the code for the endpoint outside the clipping plane 0100 0100 0101 0101 0110 0110 1000 1000 1001 1001 1010 1010 0001 0001 0010 0010 0000 0000

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Cohen-Sutherland: Line Clipping Example Intersection algorithm: if code 0 0000 then code = code 0 else code = code 1 dx = x 1 x 0 ; dy = y 1 y 0 if code AND 1000 then begin // y max x = x 0 + dx * ( y max y 0 ) / dy ; y = y max end else if code AND 0100 then begin // y min x = x 0 + dx * ( y min y 0 ) / dy ; y = y
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 39

Lecture05-Clipping - CS 455 Computer Graphics Clipping...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online