Professional Documents
Culture Documents
09 Clip
09 Clip
09 Clip
3D Primitives 3D Modeling Coordinates Modeling Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation 2D Screen Coordinates Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 2D Image Coordinates
Clipping
Greg Humphreys CS445: Intro Graphics University of Virginia, Fall 2004
2D Rendering Pipeline
3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Image 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
2D Rendering Pipeline
3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Image 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
Clipping
Avoid drawing parts of primitives outside window
Window defines part of scene being viewed Must draw geometric primitives only inside window
Clipping
Avoid drawing parts of primitives outside window
Window defines part of scene being viewed Must draw geometric primitives only inside window
Clipping
Avoid drawing parts of primitives outside window
Points Lines Polygons Circles etc.
Viewing Window
Viewing Window
Point Clipping
Is point (x,y) inside the clip window?
wy2 (x,y)
inside = (x >= wx1) && (x <= wx2) && (y >= wy1) && (y <= wy2);
Line Clipping
Find the part of a line inside the clip window
P7 P1 P3 P2 P5 P6 P9
P4
P8 P10
wx2
Before Clipping
Line Clipping
Find the part of a line inside the clip window
P7 P4 P6 P5 P8
P7 P1 P3 P2 P5 P6 P9
P3
P4
P8 P10
After Clipping
0001 P7
0101
0001 P7
0101
Bit 4
1000
P2
P3
0000
P6
P4
P8
0100
P10 Bit 3
1000
P2
P3
0000
P6
P4
P8
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1000
P3
0000
P6
P4
P8
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
P7 P4
P7 P4
1000
P3
0000
P6
0100
P10 Bit 3
1000
P3
0000
P6
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
P7 P4
P7 P4
1000
P3
0000
P6
0100
P10 Bit 3
1000
P3
0000
P6
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
P7 P4
P7 P4
1000
P3
0000
P6
0100
P10 Bit 3
1000
P3
0000
P6
0100
P10 Bit 3
1010
Bit 1
P5
0010 P9
Bit 2
0110
1010
Bit 1
P5
0010 P9
Bit 2
0110
P7 P4
P7 P4
1000
P3
0000
P6
0100
P10 P9 Bit 2 Bit 3
1000
P3
0000
P6
0100
P10 P9 Bit 2 Bit 3
1010
Bit 1
P5
0010
0110
1010
Bit 1
P5
0010
0110
Clipping
Avoid drawing parts of primitives outside window
Points Lines Polygons Circles etc.
P7 P4
1000
P3
0000
P6
0100
Window Bit 3
1010
Bit 1
P5
0010
Bit 2
0110
2D Screen Coordinates
Polygon Clipping
Find the part of a polygon inside the clip window?
Polygon Clipping
Find the part of a polygon inside the clip window?
Before Clipping
After Clipping
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P3 P4 P1 Inside Outside P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P3 P4 P1 Inside Outside P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P3 P4 P1 Inside Outside P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P3 P4 P1 Inside Outside P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P1 Inside Outside P3 P4 P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P1 Inside Outside P3 P4 P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P1 Inside Outside P3 P4 P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P1 P Inside Outside P3 P4 P5
Clipping to a Boundary
Do inside test for each point in sequence, Insert new points when cross window boundary, Remove points outside window boundary
P2 Window Boundary P1 P Inside Outside
2D Rendering Pipeline
3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Image 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
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
Window
wy2 vy2
Summary of Transformations
p(x,y,z) Viewport
3D Object Coordinates Modeling Transformation 3D World Coordinates Viewing Transformation
} }
3D Camera Coordinates
Screen Coordinates
Image Coordinates
vx2
Modeling transformation
Viewing transformations
Viewport transformation
vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1); vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);
Summary
3D Primitives 2D Primitives Clipping Viewport Transformation Scan Conversion Image 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
Summary
3D Primitives 3D Modeling Coordinates Modeling Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation 2D Screen Coordinates Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 2D Image Coordinates
Viewing Window
Next Time
3D Primitives 3D Modeling Coordinates Modeling Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation 2D Screen Coordinates Clipping 2D Screen Coordinates Viewport Transformation 2D Image Coordinates Scan Conversion Image 2D Image Coordinates
P1 P2 P3
Scan Conversion!
10