scene graphs & modeling transformations · 2011. 2. 28. · basic 2d transformations matrix...

52
Scene Graphs & Modeling Transformations COS 426

Upload: others

Post on 12-Sep-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs &Modeling Transformations

COS 426

Page 2: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

3D Object Representations• Points

Range image Point cloud

• Surfaces Polygonal mesh Subdivision Parametric Implicit

• Solids Voxels BSP tree CSG Sweep

• High-level structures Scene graph Application specific

Page 3: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

3D Object Representations• What object representation is best for this?

Page 4: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

3D Object Representations• Desirable properties of an object representation

Easy to acquire Accurate Concise Intuitive editing Efficient editing Efficient display Efficient intersections Guaranteed validity Guaranteed smoothness etc.

(CS Building, Princeton University)

Page 5: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Overview• Scene graphs

Geometry & attributes Transformations Bounding volumes

• Transformations Basic 2D transformations Matrix representation Matrix composition 3D transformations

Page 6: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs

Building

Floor 4 Floor5Floor 3Floor 2Floor 1

Chair KBookshelf 1

Desk ChairBookshelf

Desk 1 Desk 2 Chair 1

Floor Furniture

Office NOffice 1

Office Furniture

Definitions

Instances

Page 7: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs• Hierarchy of nodes, where each node may have:

Geometry representation Modeling transformation Parents and/or children Bounding volume

Base[M1]

Upper Arm[M2]

Lower Arm[M3]

Robot Arm Angel Figures 8.8 & 8.9

Page 8: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs• Advantages

Allows definitions of objects in own coordinate systems Allows use of object definition multiple times in a scene

y

xz

Page 9: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs• Advantages

Allows definitions of objects in own coordinate systems Allows use of object definition multiple times in a scene

H&B Figure 109

IcosahedronTetrahedronCube Octahedron Dodecahedron

Level B

Instance 4Instance 1

Level A

Instances

Definitions

Instance 4Instance 1

Scene

Instance 4Instance 1

Page 10: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs• Advantages

Allows definitions of objects in own coordinate systems Allows use of object definition multiple times in a scene Allows hierarchical processing (e.g., intersections)

Haverkort

Page 11: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graphs• Advantages

Allows definitions of objects in own coordinate systems Allows use of object definition multiple times in a scene Allows hierarchical processing (e.g., intersections) Allows articulated animation Base

[M1]

Upper Arm[M2]

Lower Arm[M3]

Robot Arm Angel Figures 8.8 & 8.9

Page 12: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Scene Graph Example

Pixar

Page 13: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Overview• Scene graphs

Geometry & attributes Transformations Bounding volumes

• Transformations Basic 2D transformations Matrix representation Matrix composition 3D transformations

Page 14: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

ScaleRotate

Translate

ScaleTranslate

x

y

World Coordinates

ModelingCoordinates

Page 15: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

x

y

World Coordinates

ModelingCoordinates

Let’s lookat this indetail…

Page 16: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

x

y

ModelingCoordinates

Page 17: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

Page 18: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

Page 19: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

World Coordinates

Page 20: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

Transformations can be combined

(with simple algebra)

Page 21: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

Page 22: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

x’ = x*sxy’ = y*sy

(x,y)(x’,y’)

Page 23: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

x’ = (x*sx)*cosΘ − (y*sy)*sinΘy’ = (x*sx)*sinΘ + (y*sy)*cosΘ

(x’,y’)

Page 24: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

x’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty

(x’,y’)

Page 25: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Translation:

x’ = x + tx y’ = y + ty

• Scale: x’ = x * sx y’ = y * sy

• Shear: x’ = x + hx*y y’ = y + hy*x

• Rotation: x’ = x*cosΘ - y*sinΘ y’ = x*sinΘ + y*cosΘ

x’ = ((x*sx)*cosΘ − (y*sy)*sinΘ) + txy’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty

Page 26: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Overview• Scene graphs

Geometry & attributes Transformations Bounding volumes

• Transformations Basic 2D transformations Matrix representation Matrix composition 3D transformations

Page 27: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Representation• Represent 2D transformation by a matrix

• Multiply matrix by column vector⇔ apply transformation to point

=

yx

dcba

yx

''

dcba

dycxybyaxx

+=+=

''

Page 28: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Representation• Transformations combined by multiplication

=

yx

lkji

hgfe

dcba

yx''

Matrices are a convenient and efficient way to represent a sequence of transformations!

Page 29: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

=

yx

dcba

yx''

2x2 Matrices• What types of transformations can be

represented with a 2x2 matrix?

2D Identity?

yyxx

==''

=

yx

yx

1001

''

2D Scale around (0,0)?

ysyyxsxx

*'*'

==

=

yx

dcba

yx''

=

yx

sysx

yx

00

''

Page 30: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2x2 Matrices• What types of transformations can be

represented with a 2x2 matrix?

2D Rotate around (0,0)?

yxyyxx

*cos*sin'*sin*cos'

Θ+Θ=Θ−Θ=

=

yx

dcba

yx

''

ΘΘΘ−Θ=

yx

yx

cossinsincos

''

2D Shear?

yxshyyyshxxx

+=+=

*'*'

=

yx

dcba

yx''

=

yx

shyshx

yx

11

''

Page 31: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2x2 Matrices• What types of transformations can be

represented with a 2x2 matrix?

2D Mirror over Y axis?

yyxx

=−=

''

=

yx

dcba

yx''

−=

yx

yx

1001

''

2D Mirror over (0,0)?

yyxx

−=−=

''

=

yx

dcba

yx''

−−=

yx

yx

1001

''

Page 32: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

=

yx

dcba

yx''

2x2 Matrices• What types of transformations can be

represented with a 2x2 matrix?

2D Translation?

tyyytxxx

+=+=

''

Only linear 2D transformations can be represented with a 2x2 matrix

NO!

Page 33: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Linear Transformations• Linear transformations are combinations of …

Scale, Rotation, Shear, and Mirror

• Properties of linear transformations: Satisfies: Origin maps to origin Points at infinity stay at infinity Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition

)()()( 22112211 pppp TsTsssT +=+

=

yx

dcba

yx''

Page 34: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

2D Translation• 2D translation represented by a 3x3 matrix

Point represented with homogeneous coordinates

tyyytxxx

+=+=

''

=

11001001

1''

yx

tytx

yx

Page 35: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Homogeneous Coordinates• Add a 3rd coordinate to every 2D point

(x, y, w) represents a point at location (x/w, y/w) (x, y, 0) represents a point at infinity (0, 0, 0) is not allowed

1 2

1

2 (2,1,1) or (4,2,2) or (6,3,3)

Convenient coordinate system to represent many useful transformations

x

y

Page 36: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 2D Transformations• Basic 2D transformations as 3x3 matrices

ΘΘΘ−Θ

=

11000cossin0sincos

1''

yx

yx

=

11001001

1''

yx

tytx

yx

=

11000101

1''

yx

shyshx

yx

Translate

Rotate Shear

=

11000000

1''

yx

sysx

yx

Scale

Page 37: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Affine Transformations• Affine transformations are combinations of …

Linear transformations, and Translations

• Properties of affine transformations: Origin does not necessarily map to origin Points at infinity remain at infinity Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition

=

wyx

fedcba

wyx

100''

Page 38: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Projective Transformations• Projective transformations (homographies):

Affine transformations, and Projective warps

• Properties of projective transformations: Origin does not necessarily map to origin Point at infinity may map to finite point Lines map to lines Parallel lines do not necessarily remain parallel Ratios are not preserved (but “cross-ratios” are) Closed under composition

=

wyx

ihgfedcba

wyx

'''

Page 39: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Projective Transformations• Will be useful to model (pinhole) cameras:

can represent camera projection in same framework as modeling transformations

Page 40: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Cross-Ratio• Definition: for 4 collinear points A, B, C, D

• Projective Invariant: (A,B;C,D) = (A’,B’;C’,D’)

BCADBDAC

DCBA =),;,(

Wikipedia

Page 41: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Overview• Scene graphs

Geometry & attributes Transformations Bounding volumes

• Transformations Basic 2D transformations Matrix representation Matrix composition 3D transformations

Page 42: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Composition• Transformations can be combined by

matrix multiplication

ΘΘΘ−Θ

=

wyx

sysx

tytx

wyx

1000000

1000cossin0sincos

1001001

'''

p’ = T(tx,ty) R(Θ) S(sx,sy) p

Page 43: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Composition• Matrices are a convenient and efficient way to

represent a sequence of transformations General purpose representation Hardware matrix multiply Efficiency with premultiplication

» Matrix multiplication is associative

p’ = (T * (R * (S*p) ) )p’ = (T*R*S) * p

Page 44: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Composition• Be aware: order of transformations matters

» Matrix multiplication is not commutative

p’ = T * R * S * p

“Global” “Local”

Page 45: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Matrix Composition• Rotate by Θ around arbitrary point (a,b)

M=T(a,b) * R(Θ) * T(-a,-b)

• Scale by sx,sy around arbitrary point (a,b) M=T(a,b) * S(sx,sy) * T(-a,-b)

(a,b)

(a,b)

The trick:First, translate (a,b) to the origin.Next, do the rotation about origin.Finally, translate back.

(Use the same trick.)

Page 46: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Overview• Scene graphs

Geometry & attributes Transformations Bounding volumes

• Transformations Basic 2D transformations Matrix representation Matrix composition 3D transformations

Page 47: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

3D Transformations• Same idea as 2D transformations

Homogeneous coordinates: (x,y,z,w) 4x4 transformation matrices

=

wzyx

ponmlkjihgfedcba

wzyx

''''

Page 48: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 3D Transformations

=

wzyx

wzyx

1000010000100001

'''

=

wzyx

tztytx

wzyx

1000100010001

'''

=

wzyx

szsy

sx

wzyx

1000000000000

'''

−=

wzyx

wzyx

1000010000100001

'''

Identity Scale

Translation Mirror over X axis

Page 49: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Basic 3D Transformations

ΘΘΘ−Θ

=

wzyx

wzyx

1000010000cossin00sincos

'''

Rotate around Z axis:

ΘΘ

Θ−Θ=

wzyx

wzyx

10000cos0sin00100sin0cos

'''

Rotate around Y axis:

ΘΘΘ−Θ=

wzyx

wzyx

10000cossin00sincos00001

'''

Rotate around X axis:

Page 50: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Transformations in Scene Graphs

Rose et al. `96

Root

LHip

LKnee

LAnkle

RHip

RKnee

RAnkle

Chest

LCollar

LShld

LElbow

LWrist

LCollar

LShld

LElbow

LWrist

Neck

Head

Page 51: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Transformations in Scene Graphs

Mihai Parparita, COS 426

Page 52: Scene Graphs & Modeling Transformations · 2011. 2. 28. · Basic 2D transformations Matrix representation Matrix composition 3D transformations. Scene Graphs Building Floor 1. Floor

Summary• Scene graphs

Hierarchical Modeling transformations Bounding volumes

• Coordinate systems World coordinates Modeling coordinates

• 3D modeling transformations Represent most transformations by 4x4 matrices Composite with matrix multiplication (order matters)