Clipping
3D Rendering Pipeline (for direct illumination) 3D Primitives 3D Modeling Coordinates Modeling Transformation Lighting 3D Camera Coordinates Projection Transformation Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 3D World Coordinates 3D World Coordinates Viewing Transformation 2D Screen Coordinates 2D Image Coordinates
3D Rendering Pipeline (for direct illumination) 3D Primitives 3D Modeling Coordinates Modeling Transformation Lighting 3D Camera Coordinates Projection Transformation Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 3D World Coordinates 3D World Coordinates Viewing Transformation 2D Screen Coordinates 2D Image Coordinates
2D Rendering Pipeline 3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Clip portions of geometric primitives residing outside the window Transform the clipped primitives from screen to image coordinates Fill pixels representing primitives in screen coordinates Image
2D Rendering Pipeline 3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Clip portions of geometric primitives residing outside the window Transform the clipped primitives from screen to image coordinates Fill pixels representing primitives in screen coordinates Image
Clipping Avoid drawing parts of primitives outside window o Window defines part of scene being viewed o Must draw geometric primitives only inside window Window Screen Coordinates
Clipping Avoid drawing parts of primitives outside window o Window defines part of scene being viewed o Must draw geometric primitives only inside window Viewing Window
Clipping Avoid drawing parts of primitives outside window o Points o Lines o Polygons o Circles o etc. Viewing Window
Point Clipping Is point (x,y) inside the clip window? wy2 (x,y) inside = (x >= wx1) && (x <= wx2) && (y >= wy1) && (y <= wy2); wy1 wx1 Window wx2
Line Clipping Find the part of a line inside the clip window P 7 P 1 P 3 P 4 P 8 P 2 P 6 P 10 P 5 P 9 Before Clipping
Line Clipping Find the part of a line inside the clip window P 7 P 3 P 4 P 8 P 6 P 5 After Clipping
Cohen Sutherland Line Clipping Use simple tests to classify easy cases first P 7 P 1 P 3 P 4 P 8 P 2 P 6 P 10 P 5 P 9
Cohen Sutherland Line Clipping Unique 4-bit binary number: b 0 b 1 b 2 b 3 (outcode) b 0 = 1 if x<x min, 0 otherwise b 1 = 1 if x>x max, 0 otherwise b 2 = 1 if y<y min, 0 otherwise b 3 = 1 if y>y max, 0 otherwise 1001 0001 0101 y max 1000 0000 0100 1010 0010 0110 y min x min x max
Cohen Sutherland Line Clipping 1001 P 7 0001 0101 Bit 4 P 1 1000 P 3 P 4 P 8 0000 0100 1010 P 2 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen Sutherland Line Clipping Classify some lines quickly by AND of bit codes representing regions of two endpoints (must be 0) 1001 P 7 0001 0101 Bit 4 P 1 1000 P 3 P 4 P 8 0000 0100 1010 P 2 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen Sutherland Line Clipping Classify some lines quickly by AND of bit codes representing regions of two endpoints (must be 0) 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen Sutherland Line Clipping Classify some lines quickly by AND of bit codes representing regions of two endpoints (must be 0) 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly: y=mx+h 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 P 7 0001 0101 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 0010 P 9 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 P 9 0010 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 P 10 P 9 0010 0110 Bit 1 Bit 2 Bit 3
Cohen-Sutherland Line Clipping Compute interesections with window boundary for lines that can t be classified quickly 1001 0001 0101 P 7 Bit 4 1000 P 3 P 4 P 8 0000 0100 1010 P 5 P 6 0010 0110 Bit 1 Bit 2 Bit 3
Liang-Barsky Clipping Use parametric form for lines More efficient Line segment, p 1 and p 2 Matrix form p(α)=(1-α)p 1 + αp 2 Scalar form x(α)=(1- α)x 1 + αx 2 y(α)=(1- α)y 1 + αy 2
Liang-Barksy Clipping α varies from 0 1 moving along line from p 1 to p 2 -α yields points on other side of p 1 from p 2 α>1 yields points past on one past p 2 going off to infinity Intersection at 4 points of extended window
Liang-Barksy Clipping α α α α α α α α
Liang-Barksy Order the points 1>α 4 > α 3 > α 2 > α 1 >0 accept, α 3 and α 2 define clipped line 1>α 4 > α 2 > α 3 > α 1 >0 trivially reject entire line ymax y1 α = y2 y1 y(α)=(1- α)y 1 + αy 2 intersection at top of window similar for other sides, ymin, Xmax, and Xmin
Liang-Barksy Rewrite the equation as: α(y 2 -y 1 )=α y=y max -y 1 = y max All tests can be rewritten in the form of y max, y, x max, x No floating point division for any testing Only required if line must be shortened Many lines can be rejected before all computations are done
Clipping Avoid drawing parts of primitives outside window o Points o Lines o Polygons o Circles o etc. Window 2D Screen Coordinates
Polygon Clipping
Polygon Clipping Find the part of a polygon inside the clip window? Before Clipping
Polygon Clipping Find the part of a polygon inside the clip window? After Clipping
Sutherland Hodgeman Clipping Clip to each window boundary one at a time
Sutherland Hodgeman Clipping Clip to each window boundary one at a time
Sutherland Hodgeman Clipping Clip to each window boundary one at a time
Sutherland Hodgeman Clipping Clip to each window boundary one at a time
Sutherland Hodgeman Clipping Clip to each window boundary one at a time
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary P Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary P Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary P Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary P P Inside Outside P 3 P 5 P 4
Clipping to a Boundary Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary P 2 P 1 Window Boundary P P Inside Outside
Polygon Clipping Single polygon with edges that overlap along the sides of the window Causes implementation difficulties
Polygon Clipping Divide (tessellate) a given polygon into a set of convex polygons
Problems With Clipping Polygons Forbid concave polygons Convex polygons result in at most one convex polygon Unpredictable results o Multiple Polygons o How to handle? Tesselate concave polygons Clip each line in a polygon
Sutherland-Hodgeman Clipping Fits well with pipeline architectures Black Box Input: pair of vertices from segment Output: pair of vertices of clipped line segment or nothing.
Sutherland-Hodgeman Clipping Instead of clipping window with four line segments, think of an object created by the intersection of four infinite lines for the top, bottom, right and left sides of the window Subdivide clipper into a pipeline of simpler clippers Each clipper works against a single line that is an extension of an edge of the window
Sutherland-Hodgeman Clipping Clipping against the top Black Box Input: pair of vertices from segment Output: one of three pairs {(x 1,y 1 ),(x 2,y 2 )}, {(x 1,y 1 ),(x i,y max )}, {(x i,y max ),(x 2,y 2 )} Parameter: y max
Sutherland-Hodgeman Clipping Arrange the four clippers in a pipeline
Sutherland-Hodgeman Clipping Build into hardware and clipper works on four vertices concurrently
Bounding Boxes Entire polygon lies outside the clipping window Bounding Box of the polygon is the smallest rectangle, aligned with the window, that contains the polygon. Go through the vertices of the polygon and find the min and max of both the x and y values
Bounding Boxes Detailed clipping only if bounding box straddles the window Powerful technique for 2D and 3D Modeling systems automatically compute and store the bounding box with the object
Curves, Surfaces and Text Approximate curves with line segments; surfaces with planar polygons Use bounding boxes Extremes: bitmapped vs stroke characters
Clipping in the Frame Buffer Scissoring is a technique for clipping in the frame buffer Generally used only on raster objects or blocks of pixels OpenGL allows both techniques: bitmapped in frame buffer, or clip geometric objects (stroke char)
Clipping in Three Dimensions Cohen-Sutherland o Extend 4 bit outcode to 6 bits o Set if in front or behind clipping volume Liang-Barsky o Add equation: z(α)=(1-α)z 1 +αz 2 o Six Intersections Clipping against surfaces instead of lines o p(α)=(1-α)p 1 +αp 2 o n (p(α)-p 0 )=0 o α=(n p 0 -p 1 ))/ (n p 2 -p 1 ))
Cohen-Sutherland
Clipping Against Surfaces
2D Rendering Pipeline 3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Clip portions of geometric primitives residing outside the window Transform the clipped primitives from screen to image coordinates Fill pixels representing primitives in screen coordinates Image
Viewport Transformation Transform 2D geometric primitives from screen coordinate system (normalized device coordinates) to image coordinate system (pixels) Screen Image Viewport Window
Viewport Transformation Window-to-viewport mapping wy2 Window vy2 Viewport (wx,wy) wy1 wx1 wx2 Screen Coordinates (vx,vy) vy1 vx1 vx2 Image Coordinates vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1); vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);
Summary of Transformations p(x,y,z) 3D Object Coordinates Modeling Transformation 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation 2D Screen Coordinates Window-to-Viewport Transformation p (x,y ) 2D Image Coordinates } Modeling } Viewport transformation Viewing transformations transformation
Summary 3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Clip portions of geometric primitives residing outside the window Transform the clipped primitives from screen to image coordinates Fill pixels representing primitives in screen coordinates Image
Summary 3D Primitives 3D Modeling Coordinates Modeling Transformation Lighting 3D World Coordinates 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 2D Screen Coordinates 2D Image Coordinates Viewing Window
Next Time 3D Primitives 3D Modeling Coordinates Modeling Transformation Lighting 3D Camera Coordinates Projection Transformation Clipping 3D World Coordinates 3D World Coordinates Viewing Transformation 2D Screen Coordinates P 2 P 1 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion 2D Image Coordinates Image Scan Conversion! P 3