Page 1

Graphics

2D Viewing 고려대학교 컴퓨터 그래픽스 연구실

cgvr.korea.ac.kr

1

Graphics Lab @ Korea University


Contents   

3D Rendering Pipeline 2D Rendering Pipeline Clipping  

  

CGVR

Cohen-Sutherland Line Clipping Sutherland-Hodgeman Polygon Clipping

Viewport Transformation Scan Conversion Summary of Transformation

Graphics Lab @ Korea University


3D Rendering Pipeline 3D Primitives

CGVR

3D Modeling Coordinates

Model Model Transformation Transformation 3D World Coordinates Lighting Lighting 3D World Coordinates Viewing Viewing Transformation Transformation 3D Viewing Coordinates Projection Projection Transformation Transformation 2D Projection Coordinates Clipping Clipping 2D Projection Coordinates Viewport Viewport Transformation Transformation 2D Device Coordinates Scan Scan Conversion Conversion Image

2D Device Coordinates Graphics Lab @ Korea University


3D Rendering Pipeline 3D Primitives

CGVR

3D Modeling Coordinates

Model Model Transformation Transformation 3D World Coordinates Lighting Lighting 3D World Coordinates Viewing Viewing Transformation Transformation 3D Viewing Coordinates Projection Projection Transformation Transformation 2D Projection Coordinates Clipping Clipping 2D Projection Coordinates Viewport Viewport Transformation Transformation 2D Device Coordinates Scan Scan Conversion Conversion Image

2D Device Coordinates Graphics Lab @ Korea University


2D Rendering Pipeline

CGVR

3D Primitives 2D Primitives Clipping Clipping Viewport Viewport Transformation Transformation Scan Scan Conversion Conversion

Clip portions of geometric primitives residing outside window Transform the clipped primitives from screen to image coordinates Fill pixel representing primitives in screen coordinates

Image Graphics Lab @ Korea University


2D Rendering Pipeline

CGVR

3D Primitives 2D Primitives Clipping Clipping Viewport Viewport Transformation Transformation Scan Scan Conversion Conversion

Clip portions of geometric primitives residing outside window Transform the clipped primitives from screen to image coordinates Fill pixel representing primitives in screen coordinates

Image Graphics Lab @ Korea University


Clipping 

CGVR

Avoid Drawing Parts of Primitives Outside Window  

Window defines part of scene being viewed Must draw geometric primitives only inside window

World Coordinates Graphics Lab @ Korea University


Clipping 

CGVR

Avoid Drawing Parts of Primitives Outside Window  

Window defines part of scene being viewed Must draw geometric primitives only inside window

Graphics Lab @ Korea University


Clipping 

CGVR

Avoid Drawing Parts of Primitives Outside Window     

Points Lines Polygons Circles etc.

Graphics Lab @ Korea University


Point Clipping ď Ž

CGVR

Is Point(x,y) Inside the Clip Window?

wy2

Inside Inside == (x>=wx1) (x>=wx1) && && (x<=wx2) (x<=wx2) && &&

(x, y)

(y>=wy1) (y>=wy1) && && (y<=wy2); (y<=wy2);

wy1 wx1

wx2

Graphics Lab @ Korea University


Line Clipping ď Ž

CGVR

Find the Part of a Line Inside the Clip Window P7

P1 P4 P3 P2

P6 P5

P8

P10

P9 Before Clipping Graphics Lab @ Korea University


Line Clipping 

CGVR

Find the Part of a Line Inside the Clip Window P’7

P4

P’8

P3 P6 P’5 After Clipping Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping ď Ž

CGVR

Use Simple Tests to Classify Easy Cases First P7

P1 P4 P3 P2

P6 P5

P8

P10 P9 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping ď Ž

CGVR

Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0) 1001 P7 0001 0101 Bit 4 P1 1000 P2 1010 P5 Bit 1

P3

0000

P4

P8 0100

P6 0010

P10 P9

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping ď Ž

CGVR

Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0) 1001 P7 0001 0101 Bit 4 P1 1000 P2 1010 P5 Bit 1

P3

0000

P4

P8 0100

P6 0010

P10 P9

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping ď Ž

CGVR

Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0) 1001 P7 0001 0101 Bit 4

1000

P3

0000

P4

P8 0100

P6 1010 P5 Bit 1

0010

P10 P9

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 1010 P5 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 1010 P5 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 P7 0001 0101

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

P10 P9

Bit 4

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

Bit 4

P10 P’90110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

P’8 0100

P6 P’5 1010 Bit 1

0010

Bit 4

P10 P’90110

Bit 3

Bit 2 Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping 

CGVR

Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly 1001 0001 0101 P’7

1000

P3

0000

P4

Bit 4

P’8 0100

P6 P’5 1010 Bit 1

0010

0110

Bit 3

Bit 2 Graphics Lab @ Korea University


Polygon Clipping ď Ž

CGVR

Find the Part of a Polygon Inside the Clip Window?

Before Clipping Graphics Lab @ Korea University


Polygon Clipping ď Ž

CGVR

Find the Part of a Polygon Inside the Clip Window?

After Clipping Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon Clipping ď Ž

CGVR

Clip to Each Window Boundary One at a Time

Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon Clipping ď Ž

CGVR

Clip to Each Window Boundary One at a Time

Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon Clipping ď Ž

CGVR

Clip to Each Window Boundary One at a Time

Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon Clipping ď Ž

CGVR

Clip to Each Window Boundary One at a Time

Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon Clipping ď Ž

CGVR

Clip to Each Window Boundary One at a Time

Graphics Lab @ Korea University


Clipping to a Boundary ď Ž

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary ď Ž

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary ď Ž

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary ď Ž

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary 

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary P’

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary 

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary P’

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary 

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary P’

Inside P5

P3

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary 

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2

P1

Window Boundary P’ P3

P”

Inside

P5

Outside

P4 Graphics Lab @ Korea University


Clipping to a Boundary 

CGVR

Do Inside Test for Each Point in Sequence, Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary P2 Window Boundary P’

P1 P”

Inside Outside

Graphics Lab @ Korea University


2D Rendering Pipeline

CGVR

3D Primitives 2D Primitives Clipping Clipping Viewport Viewport Transformation Transformation Scan Scan Conversion Conversion

Clip portions of geometric primitives residing outside window Transform the clipped primitives from screen to image coordinates Fill pixel representing primitives in screen coordinates

Image Graphics Lab @ Korea University


Viewport Transformation ď Ž

CGVR

Transform 2D Geometric Primitives from Screen Coordinate System (Projection Coordinates) to Image Coordinate System (Device Coordinates) Screen

Image

Viewport

Graphics Lab @ Korea University


Window vs. Viewport 

Window  

CGVR

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

Graphics Lab @ Korea University


Viewport Transformation 

CGVR

Window-to-Viewport Mapping

wy2

Window

(wx, wy) wy1 wx1 wx2 Screen Coordinates

vy2

Viewport

(vx, vy) vy1 vx1 vx2 Image Coordinates

vx vx == vx1 vx1 ++ (wx (wx –– wx1) wx1) ** (vx2 (vx2 –– vx1) vx1) // (wx2 (wx2 –– wx1); wx1); vy vy == vy1 vy1 ++ (wy (wy –– wy1) wy1) ** (vy2 (vy2 –– vy1) vy1) // (wy2 (wy2 –– wy1); wy1); Graphics Lab @ Korea University


2D Rendering Pipeline

CGVR

3D Primitives 2D Primitives Clipping Clipping Viewport Viewport Transformation Transformation Scan Scan Conversion Conversion

Clip portions of geometric primitives residing outside window Transform the clipped primitives from screen to image coordinates Fill pixel representing primitives in screen coordinates

Image Graphics Lab @ Korea University


Scan Conversion 

Definition 

CGVR

Figure out which pixels to fill

Example 

Filling the inside of a triangle P1

P2

P3 Graphics Lab @ Korea University


Triangle Scan Conversion 

CGVR

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

P

L3

L2 Graphics Lab @ Korea University


Triangle Scan Conversion 

CGVR

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

dy

dx

Graphics Lab @ Korea University


Polygon Scan Conversion 

CGVR

Fill Pixels Inside a Polygon       

Triangle Quadrilateral Convex Star-Shaped Concave Self-Intersecting Holes

Graphics Lab @ Korea University


Inside Polygon Rule 

CGVR

Need Better Test for Points Inside a Polygon 

“Inside triangle test” works only for convex polygon

L2

L

L

1

1

L5

L2

L5B L5A

L3

L3 L4

Convex Polygon

L4

Concave Polygon Graphics Lab @ Korea University


Inside Polygon Rule 

CGVR

Odd-Parity Rule 

Any ray from P to infinity crosses odd number of edges

Concave

Self-Intersecting

With Holes Graphics Lab @ Korea University


Polygon Scan Conversion ď Ž

CGVR

Polygon Line-Sweep Algorithm ď Ž

Incremental algorithm to find spans, and determine insideness with odd-parity rule

Triangle

Polygon Graphics Lab @ Korea University


Polygon Scan Conversion 

CGVR

Hardware Scan Conversion 

Convert everything into Triangles

Graphics Lab @ Korea University


Summary of Transformation

CGVR

P(x, y, z) 3D Object Coordinates

Modeling Modeling Transformation Transformation 3D World Coordinates

Viewing Viewing Transformation Transformation 3D Viewing Coordinates

Projection Projection Transformation Transformation 2D Projection Coordinates

Window-to-Viewport Window-to-Viewport Transformation Transformation P(x, y)

2D Device Coordinates Graphics Lab @ Korea University

05viewing2d  

2D Viewing Graphics Lab @ Korea University cgvr.korea.ac.kr 1 Contents  Cohen-Sutherland Line Clipping  Sutherland-Hodgeman Polygon Clippi...