Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 71

Graphics

CCET

2D Viewing

1 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
3D Rendering Pipeline CCET
CGVR
3D Primitives
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
2 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
3D Rendering Pipeline CCET
CGVR
3D Primitives 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
3 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2D Rendering Pipeline CCET
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
4 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping CCET
CGVR

 Avoid Drawing Parts of Primitives Outside


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

World
Coordinates
5 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2-Dimensional Views CCET
CGVR

 A 2-dimensional view is defined by two rectangles we


will refer to them as:
 A Window given in real world co-ordinates, e.g.
meters, feet etc… defining the portion of model
{scene} to be drawn
 A Viewport given in screen co-ordinates, pixels,
defining the portion of the screen which will be used to
display the contents of the window

 Note that confusingly, some textbooks sometimes


use these terms interchangeably to describe the
original rectangle (the window).

6 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Viewing Issues CCET
CGVR

 A Rasterization Issue

 How much of the data should be drawn?


 Where should it appear on the display?
 e.g: We could have a model of a whole room, full of
objects such as chairs, tables, and students.
 We may want to view the whole room in one go, or
zoom in on one single object in the room.
 We may want to display the object or scene on the
full screen, or we may only want to display it on a
portion of the screen

7 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Screen Co-ordinates CCET
CGVR

 In our final display, i.e. the frame buffer, images are


specified in terms of pixels
(screen coordinates defined with integer values) whereas
our original data is in real-number coordinates (modelling
coordinates)

 We need to apply transformations to convert from


Modelling co-ordinates to Screen Coordinates

 We can scale dimensions to change the resulting view

 We can even achieve a zooming in and out effect without


changing the model by scaling dimensions proportionally

8 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Implementation tasks CCET
CGVR

What goes on inside the graphics system

Geometric Rasterization Display


Modeling
Processing

•Transformation
•Representa- &Normalization •Scan
tion of conversion •Color
geometric •Clipping
•Antialiasing mapping
objects •Hidden surface
removal

9 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
The Viewport CCET
CGVR

 We need to associate the 2D viewport co-ordinate


system with the screen co-ordinate system in order
to determine the correct pixel associated with each
vertex.

Real-world
screen co-ordinates
co-ordinates

10 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Windows and Viewports CCET
CGVR

{wxmax,wymax}
{vxmax,vymax}

{vx,vy}
{wx,wy}

{vxmin,vymin}
{wxmin,wymin}
For any point {wx, wy} in the real-world window, what is
the corresponding pixel position?

11 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping CCET
CGVR

 Avoid Drawing Parts of Primitives Outside Window


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

12 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping CCET
CGVR

 Avoid Drawing Parts of Primitives Outside


Window
 Points
 Lines
 Polygons
 Circles

13 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Point Clipping CCET
CGVR

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

wy2
Inside
Inside ==
(x>=wx1)
(x>=wx1) &&
&&
(x, y) (x<=wx2)
(x<=wx2) &&
&&
(y>=wy1)
(y>=wy1) &&
&&
(y<=wy2);
(y<=wy2);

wy1
wx1 wx2

14 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
DIVISION OF SPACE CCET
CGVR

ymax

Clip Region

(Includes
Boundary)
ymin

x min x max
15 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
COHEN SUTHERLAND CLIPPING CCET
CGVR

Outcodes
y  ymax x  xmax

0 1 0 1

y  y min x  x min

16 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Region Outcodes CCET
CGVR

1001 1000 1010

ymax

0001 0000 0010

ymin

0101 0100 0110

x min x max

17 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Trivial Acceptance: O(P0) | O(P1) = 0 CCET
CGVR

1001 1000 1010

ymax
P1

0001 0000 0010

P0
ymin

0101 0100 0110

x min x max

18 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Trivial Rejection: O(P0) & O(P1) != 0 CCET
CGVR
P0
1001 1000 1010
P1

ymax

P0
0001 0000 0010

ymin
P0
P1 P1

0101 0100 0110

x min x max

19 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Outside vs. Inside CCET
CGVR

1001 1000 1010

ymax

0001 0000 0010

ymin

0101 0100 0110

x min x max
= “Inside”
20 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Cohen-Sutherland Clipping:
The Algorithm CCET
CGVR

 Compute the outcodes for the two vertices


 Test for trivial acceptance or rejection

 Select a vertex for which outcode is not zero


 There will always be one
 Select the first nonzero bit in the outcode to define the boundary
against which the line segment will be clipped
 This defines a fixed order for the test

 Compute the intersection and replace the vertex with the


intersection point
 Compute the outcode for the new point and iterate

21 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE1 CCET
CGVR
A
1001 1000 1010

B
ymax

0001 0000 0010

ymin

0101 0100 0110

x min x max

22 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE1 CCET
CGVR

1001 1000 1010

B
ymax

0001 0000 0010

ymin

0101 0100 0110

x min x max

23 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE2 CCET
CGVR

1001 1000 1010


E
ymax
D

0001 0000 0010


C

ymin
B
A
0101 0100 0110

x min x max

24 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE2 CCET
CGVR

1001 1000 1010


E
ymax
D

0001 0000 0010


C

ymin
B

0101 0100 0110

x min x max

25 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE2 CCET
CGVR

1001 1000 1010

ymax
D

0001 0000 0010


C

ymin
B

0101 0100 0110

x min x max

26 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
EXAMPLE2 CCET
CGVR

1001 1000 1010

ymax

0001 0000 0010


C

ymin
B

0101 0100 0110

x min x max

27 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Advantages / Extension CCET
CGVR

 Easily extended to 3 dimensions by adding two bits


to the outcode for the z axis.

 Calculations then reduce to intersection of line with


plane

 Algorithm most efficient when most segments can


either be trivially accepted or trivially rejected

 Disadvantages: unnecessary intersection


calculations

28 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

29 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

30 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

31 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

32 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

33 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

34 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

35 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

36 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

37 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Liang-Barsky Parametric Clipping CCET
CGVR

38 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Nicholl-Lee-Nicholl Line-cipping CCET
CGVR

39 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Nicholl-Lee-Nicholl Line-cipping CCET
CGVR

40 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Nicholl-Lee-Nicholl Line-cipping CCET
CGVR

41 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Weiler-Atherton Polygon clipping CCET
CGVR

42 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Weiler-Atherton Polygon clipping CCET
CGVR

43 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Polygon Clipping CCET
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

Before Clipping
44 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Polygon Clipping CCET
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

After Clipping
45 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

 Clip to Each Window Boundary One at a


Time

46 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

 Clip to Each Window Boundary One at a


Time

47 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

 Clip to Each Window Boundary One at a


Time

48 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

 Clip to Each Window Boundary One at a


Time

49 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

 Clip to Each Window Boundary One at a


Time

50 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR

Top Bottom Right Left

51 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR
Pipeline Clipping (x 1 , y 1 )

(x3 , y3 )

(x 4 , y 4 )
(x 5 , y 5 )

(x 2 , y 2 )

(x1 , y1 ) (x3 , y3 ) (x3 , y3 ) (x 3 , y3 ) (x 3 , y3 )


(x 2 , y 2 ) (x 2 , y 2 ) (x5 , y 5 ) (x5 , y5 ) (x 4 , y 4 )
Top Bottom Right Left

52 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
53 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
54 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
55 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
56 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
57 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
58 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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
Outside
P3 P5

P4
59 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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’ P” Inside
Outside
P3 P5

P4
60 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
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’ P” Inside
Outside

61 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2D Rendering Pipeline CCET
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
62 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Viewport Transformation CCET
CGVR

 Transform 2D Geometric Primitives from Screen


Coordinate System (Projection Coordinates) to
Image Coordinate System (Device Coordinates)

Screen Image

Viewport

63 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Window vs. Viewport CCET
CGVR

 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

64 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Viewport Transformation CCET
CGVR

 Window-to-Viewport Mapping
Window Viewport
wy2 vy2

(wx, wy) (vx, vy)


wy1 vy1
wx1 wx2 vx1 vx2
Screen Coordinates 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);

65 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Window to Viewport Mapping CCET
CGVR

Preservation of horizontal ratios implies that:


wx  wxmin wxmax  wxmin

vx  vxmin vxmax  vxmin

So, solving for vx:


vxmax - vxmin
vx  ( wx - wx min ) *  vxmin
wxmax - wxmin

vy can be solved for similarly:


vymax - vymin
vy  ( wy - wy min ) *  vymin
wy max - wy min

66 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Example CCET
CGVR

0.4
0.3

-0.4 -0.2
 Say we want to map this to a
640x480 viewport

 Where is the black point


mapped in screen coordinates? 480

640
67 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Solution CCET
CGVR
wx  -0.2 vxmax  640
wy  0.3
vxmin  0 320
wxmax  0
wxmin  -0.4
vymax  0
120
wy max  0.4 vymin  480
wy min  0
vxmax - vxmin
vx  ( wx - wx min )*  vxmin
wx max - wxmin
vymax - vymin
vy  ( wy - wy min ) *  vymin
wy max - wy min

(640-0)
vx  (-0.2 -(-0.4))   0  320
0  ( 0.4)
(0- 480)
vy  (0.3 - 0)   480  120
0.4  (0)
Repeat this for all vertices and then rasterize.
68 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2D Rendering Pipeline CCET
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
69 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Scan Conversion CCET
CGVR

 Definition
 Figure out which pixels to fill

 Example
 Filling the inside of a triangle

P1

P2
P3
70 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Triangle Scan Conversion CCET
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
 (Odd-even parity rule, Non-zero winding rule)
 Take advantage of edge linearity
 Use edge slopes to update coordinates incrementally

dx
dy

71 Prepared By : K. R. Rathod, Graphics


A. K. Ranpura, A. R. Rathod
Lab @ Korea University

You might also like