Data structures with transforms

• Representing a drawing (“scene”) • List of objects • Transform for each object Scene Graphs – can use minimal primitives: ellipse is transformed circle – transform applies to points of object CS 4620 Lecture 7

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 1 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 2

Example Groups of objects

• Can represent drawing with flat list • Treat a set of objects as one – but editing operations require updating many transforms • Introduce new object type: group – contains list of references to member objects • This makes the model into a – interior nodes = groups – leaf nodes = objects – edges = membership of object in group

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 3 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 4 Example The Scene Graph (tree)

• Add group as a new object type • A name given to various kinds of graph structures – lets the data structure reflect the drawing structure (nodes connected together) used to represent scenes – enables high-level editing by changing just one node • Simplest form: tree – just saw this – every node has one parent – leaf nodes are identified with objects in the scene

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 5 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 6

Concatenation and hierarchy Instances

• Transforms associated with nodes or edges • Simple idea: allow an object to be a member of more • Each transform applies to all geometry below it than one group at once – want group transform to transform each member – transform different in each case – members already transformed—concatenate – leads to linked copies • Frame transform for object is product of all matrices – single editing operation changes along path from root all instances – each object’s transform describes relationship between its – low memory overhead Christopher Nichols local coordinates and its group’s coordinates – hardware acceleration available – frame-to-canonical transform is the result of repeatedly changing coordinates from group to containing group

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 7 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 8 Example The Scene Graph (with instances)

• Allow multiple references to nodes • With instances, there is no more tree – reflects more of drawing structure – an object that is instanced multiple – allows editing of repeated parts in one operation times has more than one parent • Transform tree becomes DAG – directed acyclic graph – group is not allowed to contain itself, even indirectly • Transforms still accumulate along path from root – now paths from root to leaves are identified with scene objects

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 9 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 10

Implementing a hierarchy Implementing traversal

• Object-oriented language is convenient • Pass a transform down the hierarchy – define shapes and groups as derived from single class – before drawing, concatenate

abstract class Shape { abstract class Shape { void draw(); void draw(Transform t_c); } } class Group extends Shape { class Square extends Shape { class Square extends Shape { Transform t; void draw() { void draw(Transform t_c) { ShapeList members; // draw unit square // draw t_c * unit square void draw(Transform t_c) { } } for (m in members) { } } m.draw(t_c * t); } class Circle extends Shape { class Circle extends Shape { } void draw() { void draw(Transform t_c) { } // draw unit circle // draw t_c * unit circle } } } }

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 11 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 12 Basic Scene Graph operations Adding more than geometry

• Editing a transformation • Objects have properties besides shape – good to present usable UI – color, shading parameters • Getting transform of object in canonical (world) frame – approximation parameters (e.g. precision of subdividing – traverse path from root to leaf curved surfaces into triangles) • Grouping and ungrouping – behavior in response to user input – can do these operations without moving anything – … – group: insert identity node • Setting properties for entire groups is useful – ungroup: remove node, push transform to children – paint entire window green • Reparenting • Many systems include some kind of property nodes – move node from one parent to another – in traversal they are read as, e.g., “set current color” – can do without altering position

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 13 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 14

Scene Graph variations Scene Graph Implementations

• Where transforms go • Many full-featured implementations – in every node • Open Inventor (since late 80’s) – on edges – C++/Java; Built on top of OpenGL – in group nodes only – http://oss.sgi.com/projects/inventor/ • Java3D (since late 90’s) – in special Transform nodes – Built on top of OpenGL or DirectX • Tree vs. DAG – https://java3d.dev.java.net/ • Nodes for cameras and lights? • NVIDIA Scenix (since late 200x’s) – Built on top of OpenGL – Support programmable shading – Distributed GPU rendering – Support for (using OptiX) – http://developer.nvidia.com/object/scenix-details.html

Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 15 Cornell CS4620 Fall 2009 •!Lecture 7 © 2009 Doug James • 16