3 D Viewing and Clipping Ming Ouhyoung Professor

  • Slides: 36
Download presentation
3 D Viewing and Clipping Ming Ouhyoung 歐陽明 Professor Dept. of CSIE and GINM

3 D Viewing and Clipping Ming Ouhyoung 歐陽明 Professor Dept. of CSIE and GINM NTU

3 D Viewing Process Clip against view volume 3 D world-coordinate output primitives Project

3 D Viewing Process Clip against view volume 3 D world-coordinate output primitives Project onto projection plane Clipped world coordinates Transform into viewport in 2 D device coordinates for display 2 D device coordinates

Perspective Projection (Pinhole Camera, eye at origin ) x Projection plane P(x, y, z)

Perspective Projection (Pinhole Camera, eye at origin ) x Projection plane P(x, y, z) xp z d View along y axis View along x axis d z y yp Projection plane P(x, y, z)

Perspective Division However W 1, so we must divide by W to return from

Perspective Division However W 1, so we must divide by W to return from homogeneous coordinates

Specification of an Arbitrary 3 D View v VUP VRP View plane VPN n

Specification of an Arbitrary 3 D View v VUP VRP View plane VPN n • VRP: view reference point • VPN: view-plane normal • VUP: view-up vector u

Truncated View Volume for an Perspective Projection (how to do 3 D clipping? ),

Truncated View Volume for an Perspective Projection (how to do 3 D clipping? ), PRP: projection reference point, DOP: direction of projection Front Clipping plane View plane Back Clipping plane VRP VPN F B

PRP: Projection reference point

PRP: Projection reference point

Clipping: 2 D & 3 D • 2 D against clipping window • 3

Clipping: 2 D & 3 D • 2 D against clipping window • 3 D against clipping volume • Easy for line segments polygons • Hard for curves and text Convert to lines and polygons first E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 8

Clipping: wireframe E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley

Clipping: wireframe E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 9

Clipping: surface E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley

Clipping: surface E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 10

Clipping 2 D Line Segments • Brute force approach: compute intersections with all sides

Clipping 2 D Line Segments • Brute force approach: compute intersections with all sides of clipping window Inefficient: one division per intersection E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 11

Cohen-Sutherland Algorithm • Idea: eliminate as many cases as possible without computing intersections •

Cohen-Sutherland Algorithm • Idea: eliminate as many cases as possible without computing intersections • Start with four lines that determine the sides of the clipping window y = ymax x = xmin x = xmax y = ymin E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 12

The Cases • Case 1: both endpoints of line segment inside all four lines

The Cases • Case 1: both endpoints of line segment inside all four lines Draw (accept) line segment as is y = ymax x = xmin x = xmax y = ymin • Case 2: both endpoints outside all lines and on same side of a line Discard (reject) the line segment E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 13

The Cases • Case 3: One endpoint inside, one outside Must do at least

The Cases • Case 3: One endpoint inside, one outside Must do at least one intersection • Case 4: Both outside May have part inside Must do at least one intersection y = ymax x = xmin x = xmax E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 14

Defining Outcodes • For each endpoint, define an outcode b 0 b 1 b

Defining Outcodes • For each endpoint, define an outcode b 0 b 1 b 2 b 3 b 0 = 1 if y > ymax, 0 otherwise b 1 = 1 if y < ymin, 0 otherwise b 2 = 1 if x > xmax, 0 otherwise b 3 = 1 if x < xmin, 0 otherwise • Outcodes divide space into 9 regions • Computation of outcode requires at most 4 subtractions E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 15

Using Outcodes • Consider the 5 cases below • AB: outcode(A) = outcode(B) =

Using Outcodes • Consider the 5 cases below • AB: outcode(A) = outcode(B) = 0 Accept line segment E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 16

Using Outcodes • CD: outcode (C) = 0, outcode(D) 0 Compute intersection Location of

Using Outcodes • CD: outcode (C) = 0, outcode(D) 0 Compute intersection Location of 1 in outcode(D) determines which edge to intersect with Note if there were a segment from A to a point in a region with 2 ones in outcode, we might have to do two interesections E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 17

Cohen Sutherland in 3 D • Use 6 bit outcodes • When needed, clip

Cohen Sutherland in 3 D • Use 6 bit outcodes • When needed, clip line segment against planes E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 18

Clipping and Normalization • General clipping in 3 D requires intersection of line segments

Clipping and Normalization • General clipping in 3 D requires intersection of line segments against arbitrary plane • Example: oblique view E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 19

Two cameras: (b) back not parallel to the front E. Angel and D. Shreiner:

Two cameras: (b) back not parallel to the front E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 20

Plane-Line Intersections Line p 1 p 2 = p 1 + t*(p 2 p

Plane-Line Intersections Line p 1 p 2 = p 1 + t*(p 2 p 1) where 0<= t<=1 when t = a The intersection point E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 21

Plane-Line Intersections: II E. Angel and D. Shreiner: Interactive Computer Graphics 6 E ©

Plane-Line Intersections: II E. Angel and D. Shreiner: Interactive Computer Graphics 6 E © Addison-Wesley 2012 22

Canonical View Volume for Perspective Projection: 3 D clipping is easier this way! x

Canonical View Volume for Perspective Projection: 3 D clipping is easier this way! x or y Back plane -z 1 Front plane -1 -1 • x = z, y = z, z = -zmin • x = -z, y = -z, z = -1

The Extension of the Cohen-Sutherland Algorithm • • • bit 1 – point is

The Extension of the Cohen-Sutherland Algorithm • • • bit 1 – point is above view volume bit 2 – point is below view volume bit 3 – point is right of view volume bit 4 – point is left of view volume bit 5 – point is behind view volume bit 6 – point is in front of view volume y > -z y<z x > -z x<z z < -1 z > -zmin

Why simplified clipping? (by space transformation)

Why simplified clipping? (by space transformation)

The Steps of Implementation of Perspective Projection • • • Translate the VRP to

The Steps of Implementation of Perspective Projection • • • Translate the VRP to the origin Rotate VRC such that the VPN becomes the z axis Translate such that the PRP is at the origin Shear such that the DOP becomes parallel to the z axis Scale such that the view volume becomes the canonical perspective view volume

 • Nper = Sper * SHper * T(-PRP) * R * T(-VRP) =T(0,

• Nper = Sper * SHper * T(-PRP) * R * T(-VRP) =T(0, 0, 0) where no oblique proj. T(-PRP) = T((0, 0, d)) • SHper=1, R=Ry(180 o)= [ -1 [ 0 [ 0 0 0 1 0 0 -1 0 0 0] 0] 0] 1]

 • Sper(scaling)= • Assuming back clipping plane = (Umax, Vmax, B ) •

• Sper(scaling)= • Assuming back clipping plane = (Umax, Vmax, B ) • Front clipping plane = (Umin, Vmin, Zmin = F) • For example, let Umax = 5 = Vmax, B=10, F=-d+2 Umin = -5 = Vmin, vrpz‘ = d, where d=8

Detailed derivation: step by step

Detailed derivation: step by step

Vanishing Points • Parallel lines (not parallel to the projection plan) on the object

Vanishing Points • Parallel lines (not parallel to the projection plan) on the object converge at a single point in the projection (the vanishing point) • Drawing simple perspectives by hand uses these vanishing point(s) vanishing point

Advantages and Disadvantages • Objects further from viewer are projected smaller than the same

Advantages and Disadvantages • Objects further from viewer are projected smaller than the same sized objects closer to the viewer (diminuition) – Looks realistic • Equal distances along a line are not projected into equal distances (nonuniform foreshortening) • Angles preserved only in planes parallel to the projection plane • More difficult to construct by hand than parallel projections (but not more difficult by computer)

Canonical View Volume for Orthographic Parallel Projection x or y Back plane -z 1

Canonical View Volume for Orthographic Parallel Projection x or y Back plane -z 1 Front plane -1 -1 • x = -1, y = -1, z = 0 • x = 1, y = 1, z = -1

The Extension of the Cohen-Sutherland Algorithm • • • bit 1 – point is

The Extension of the Cohen-Sutherland Algorithm • • • bit 1 – point is above view volume bit 2 – point is below view volume bit 3 – point is right of view volume bit 4 – point is left of view volume bit 5 – point is behind view volume bit 6 – point is in front of view volume y>1 y < -1 x>1 x < -1 z>0

Intersection of a 3 D Line • A line from represented as • So

Intersection of a 3 D Line • A line from represented as • So when y = 1 to can be

Intersection of a 3 D Line • So when y = z

Intersection of a 3 D Line • So when y = z

Standard Graphics Pipeline

Standard Graphics Pipeline