Title: 2D Viewing
12D Viewing
2Contents
- 3D Rendering Pipeline
- 2D Rendering Pipeline
- Clipping
- Cohen-Sutherland Line Clipping
- Sutherland-Hodgeman Polygon Clipping
- Viewport Transformation
- Scan Conversion
- Summary of Transformation
33D Rendering Pipeline
3D Primitives
3D Modeling Coordinates
Model Transformation
3D World Coordinates
Lighting
3D World Coordinates
Viewing Transformation
3D Viewing Coordinates
Projection Transformation
2D Projection Coordinates
Clipping
2D Projection Coordinates
Viewport Transformation
2D Device Coordinates
Scan Conversion
2D Device Coordinates
Image
43D Rendering Pipeline
3D Primitives
3D Modeling Coordinates
Model Transformation
3D World Coordinates
Lighting
3D World Coordinates
Viewing Transformation
3D Viewing Coordinates
Projection Transformation
2D Projection Coordinates
Clipping
2D Projection Coordinates
Viewport Transformation
2D Device Coordinates
Scan Conversion
2D Device Coordinates
Image
52D Rendering Pipeline
3D Primitives
2D Primitives
Clipping
Clip portions of geometric primitives residing
outside window
Viewport Transformation
Transform the clipped primitives from screen to
image coordinates
Scan Conversion
Fill pixel representing primitives in screen
coordinates
Image
62D Rendering Pipeline
3D Primitives
2D Primitives
Clipping
Clip portions of geometric primitives residing
outside window
Viewport Transformation
Transform the clipped primitives from screen to
image coordinates
Scan Conversion
Fill pixel representing primitives in screen
coordinates
Image
7Clipping
- Avoid Drawing Parts of Primitives Outside Window
- Window defines part of scene being viewed
- Must draw geometric primitives only inside window
World Coordinates
8Clipping
- Avoid Drawing Parts of Primitives Outside Window
- Window defines part of scene being viewed
- Must draw geometric primitives only inside window
9Clipping
- Avoid Drawing Parts of Primitives Outside Window
- Points
- Lines
- Polygons
- Circles
- etc.
10Point Clipping
- Is Point(x,y) Inside the Clip Window?
wy2
Inside (xgtwx1) (xltwx2)
(ygtwy1) (yltwy2)
(x, y)
wy1
wx2
wx1
11Line Clipping
- Find the Part of a Line Inside the Clip Window
P7
P1
P4
P8
P3
P2
P6
P10
P9
P5
Before Clipping
12Line Clipping
- Find the Part of a Line Inside the Clip Window
P7
P8
P4
P3
P6
P5
After Clipping
13Cohen-Sutherland Line Clipping
- Use Simple Tests to Classify Easy Cases First
P7
P1
P4
P8
P3
P2
P6
P10
P9
P5
14Cohen-Sutherland Line Clipping
- Classify Some Lines Quickly by AND of Bit Codes
Representing Regions of Two Endpoints (Must Be 0)
P7
1001
0001
0101
Bit 4
P1
P4
P8
0100
0000
1000
P3
P2
P6
P10
Bit 3
0110
0010
1010
P5
P9
Bit 2
Bit 1
15Cohen-Sutherland Line Clipping
- Classify Some Lines Quickly by AND of Bit Codes
Representing Regions of Two Endpoints (Must Be 0)
P7
1001
0001
0101
Bit 4
P1
P4
P8
0100
0000
1000
P3
P2
P6
P10
Bit 3
0110
0010
1010
P5
P9
Bit 2
Bit 1
16Cohen-Sutherland Line Clipping
- Classify Some Lines Quickly by AND of Bit Codes
Representing Regions of Two Endpoints (Must Be 0)
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
0110
0010
1010
P5
P9
Bit 2
Bit 1
17Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
0110
0010
1010
P5
P9
Bit 2
Bit 1
18Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
0110
0010
1010
P5
P9
Bit 2
Bit 1
19Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
20Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
21Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
22Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
P7
1001
0001
0101
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
23Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
24Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P4
P8
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
25Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
26Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
27Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
28Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
0110
0010
1010
P9
Bit 2
Bit 1
29Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
P9
0110
0010
1010
Bit 2
Bit 1
30Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
P10
Bit 3
P5
P9
0110
0010
1010
Bit 2
Bit 1
31Cohen-Sutherland Line Clipping
- Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001
0001
0101
P7
Bit 4
P8
P4
0100
0000
1000
P3
P6
Bit 3
P5
0110
0010
1010
Bit 2
Bit 1
32Polygon Clipping
- Find the Part of a Polygon Inside the Clip Window?
Before Clipping
33Polygon Clipping
- Find the Part of a Polygon Inside the Clip Window?
After Clipping
34Sutherland-Hodgeman Polygon Clipping
- Clip to Each Window Boundary One at a Time
35Sutherland-Hodgeman Polygon Clipping
- Clip to Each Window Boundary One at a Time
36Sutherland-Hodgeman Polygon Clipping
- Clip to Each Window Boundary One at a Time
37Sutherland-Hodgeman Polygon Clipping
- Clip to Each Window Boundary One at a Time
38Sutherland-Hodgeman Polygon Clipping
- Clip to Each Window Boundary One at a Time
39Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
Outside
P5
P3
P4
40Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
Outside
P5
P3
P4
41Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
Outside
P5
P3
P4
42Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
Outside
P5
P3
P4
43Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
P
Outside
P5
P3
P4
44Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
P
Outside
P5
P3
P4
45Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
P
Outside
P5
P3
P4
46Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
P
P
Outside
P5
P3
P4
47Clipping to a Boundary
- Do Inside Test for Each Point in Sequence,
- Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P1
P2
Window Boundary
Inside
P
P
Outside
482D Rendering Pipeline
3D Primitives
2D Primitives
Clipping
Clip portions of geometric primitives residing
outside window
Viewport Transformation
Transform the clipped primitives from screen to
image coordinates
Scan Conversion
Fill pixel representing primitives in screen
coordinates
Image
49Viewport Transformation
- Transform 2D Geometric Primitives from Screen
Coordinate System (Projection Coordinates) to
Image Coordinate System (Device Coordinates)
Screen
Image
Viewport
50Window vs. Viewport
- Window
- World-coordinate area selected for display
- What is to be viewed
- Viewport
- Area on the display device to which a window is
mapped - Where it is to be displayed
51Viewport Transformation
- Window-to-Viewport Mapping
Window
Viewport
wy2
vy2
(wx, wy)
(vx, vy)
wy1
vy1
wx2
wx1
vx2
vx1
Screen Coordinates
Image Coordinates
vx vx1 (wx wx1) (vx2 vx1) / (wx2
wx1) vy vy1 (wy wy1) (vy2 vy1) / (wy2
wy1)
522D Rendering Pipeline
3D Primitives
2D Primitives
Clipping
Clip portions of geometric primitives residing
outside window
Viewport Transformation
Transform the clipped primitives from screen to
image coordinates
Scan Conversion
Fill pixel representing primitives in screen
coordinates
Image
53Scan Conversion
- Definition
- Figure out which pixels to fill
- Example
- Filling the inside of a triangle
P1
P2
P3
54Triangle Scan Conversion
- Simple Algorithm
- Color all pixels inside a triangle
- Inside triangle test
- A point is inside a triangle if it is in the
positive halfspace of all three boundary lines
L1
L3
P
L2
55Triangle Scan Conversion
- Triangle Sweep-Line Algorithm
- Take advantage of spatial coherence
- Compute which pixels are inside using horizontal
spans - Process horizontal spans in scan-line order
- Take advantage of edge linearity
- Use edge slopes to update coordinates
incrementally
dx
dy
56Polygon Scan Conversion
- Fill Pixels Inside a Polygon
- Triangle
- Quadrilateral
- Convex
- Star-Shaped
- Concave
- Self-Intersecting
- Holes
57Inside Polygon Rule
- Need Better Test for Points Inside a Polygon
- Inside triangle test works only for convex
polygon
Convex Polygon
Concave Polygon
58Inside Polygon Rule
- Odd-Parity Rule
- Any ray from P to infinity crosses odd number of
edges
Concave
Self-Intersecting
With Holes
59Polygon Scan Conversion
- Polygon Line-Sweep Algorithm
- Incremental algorithm to find spans, and
determine insideness with odd-parity rule
Triangle
Polygon
60Polygon Scan Conversion
- Hardware Scan Conversion
- Convert everything into Triangles
61Summary of Transformation
P(x, y, z)
3D Object Coordinates
Modeling Transformation
3D World Coordinates
Viewing Transformation
3D Viewing Coordinates
Projection Transformation
2D Projection Coordinates
Window-to-Viewport Transformation
2D Device Coordinates
P(x, y)