1 L Feb-15-04 SMD159, Object-Oriented Modeling Overview - - PDF document

1 l
SMART_READER_LITE
LIVE PREVIEW

1 L Feb-15-04 SMD159, Object-Oriented Modeling Overview - - PDF document

INSTITUTIONEN FR SYSTEMTEKNIK LULE TEKNISKA UNIVERSITET Object-Oriented Modeling David Carr Fundamentals of Computer Graphics Spring 2004 1 L Feb-15-04 SMD159, Object-Oriented Modeling Overview Motivation Hierarchical models,


slide-1
SLIDE 1

1

Feb-15-04 SMD159, Object-Oriented Modeling 1 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Object-Oriented Modeling

David Carr Fundamentals of Computer Graphics Spring 2004

Feb-15-04 SMD159, Object-Oriented Modeling 2 L

Overview

  • Motivation
  • Hierarchical models, trees, and DAGs
  • Scene graphs
  • Jazz, an example scene graph system
  • Other graphical trees

Feb-15-04 SMD159, Object-Oriented Modeling 3 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Motivation

slide-2
SLIDE 2

2

Feb-15-04 SMD159, Object-Oriented Modeling 4 L

Why Object Oriented?

  • Strong tie between object-oriented design and graphics
  • Often hand-in-hand
  • Concentration on drawing has drawbacks
  • Interactivity is awkward
  • Independent movement (animation) is awkward
  • Pruning the display list is difficult
  • Reuse is difficult

Feb-15-04 SMD159, Object-Oriented Modeling 5 L

Advantages of Object-Oriented Models

  • Can define objects and create many instances
  • E.g. a car has 4 wheels

+ Define the wheels once + Create 4 instances in different locations

  • Separates location from structure
  • Simplifies Animation

Wheels rotate independently of the car

Feb-15-04 SMD159, Object-Oriented Modeling 6 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Hierarchical Models, Trees, and DAGs

slide-3
SLIDE 3

3

Feb-15-04 SMD159, Object-Oriented Modeling 7 L

Object Models

  • Consider the car example
  • We would want:
  • Wheels made of tires, rims, and hub caps
  • Windows made of glass
  • Body panels made of metal and painted
  • Lens for lights made of different colors of plastic
  • Lights with different intensities
  • Note there are many common components

Feb-15-04 SMD159, Object-Oriented Modeling 8 L

Simplified Car Object

  • Easily represented as a

tree

  • But, requires 4 copies of

the wheel

  • Better structure, DAG
  • Directed Acyclic Graph

Feb-15-04 SMD159, Object-Oriented Modeling 9 L

Trees versus DAGs

  • Logically the same
  • Tree requires unique nodes, DAG can share
  • DAG representations of trees are loop free
  • For object models:
  • DAGs require separation of common properties from specific

properties

  • I.E., the values of parameters must be separated from

parameter existence.

slide-4
SLIDE 4

4

Feb-15-04 SMD159, Object-Oriented Modeling 10 L

Storing Trees

  • Binary trees are simple
  • Left and right children
  • But, arbitrary trees don’t

easily fit

  • Left child, Right sibling
  • List representation
  • Natural for pre-order traversal

using recursive traversal

Feb-15-04 SMD159, Object-Oriented Modeling 11 L

Traversal and OpenGL

  • Consider a hierarchical model
  • Each level is defined relative to the one above (its container)
  • We need a uniform way to handle changes
  • If we use recursive traversal
  • Associated with each left-child there is:

+ A new sub-model + A new graphical context

  • Associated with each right-sibling

+ The sub-model context is unchanged + But, the sibling may have its own graphical context

  • So:
  • A push-draw node/draw sub-model-pop applies to the graphics
  • The program can’t do this for us, we must do it explicitly

Feb-15-04 SMD159, Object-Oriented Modeling 12 L

Pseudo Code

  • Method DrawTree
  • glPushMatrix, glPushParameters, …
  • Modify to create map local coordinates, parameters
  • DrawTree on left child
  • Draw self
  • DrawTree on right sibling
  • glPopMatrix, glPopParameters, …
  • Return
slide-5
SLIDE 5

5

Feb-15-04 SMD159, Object-Oriented Modeling 13 L

Example, a Humanoid Figure

  • Head and limbs attached to

torso as children.

  • Top figure shows block

diagram

  • Bottom figure is tree
  • Matrix traversal if M is

transform for torso

  • M fi MMh head fi M torso fi
  • MMlua fi MMluaMlla left-lower

arm fi

  • MMlua Left-upper arm fi M …

Feb-15-04 SMD159, Object-Oriented Modeling 14 L

Graphical Objects

  • How should we implement an object-oriented graphics

system?

  • What are the characteristics of objects?
  • Topology
  • Geometry
  • Surface material
  • What other things do we need?
  • Lights
  • Viewers (more than one per scene?)
  • Operations on objects such as rendering

Feb-15-04 SMD159, Object-Oriented Modeling 15 L

Simple Example, a Cube (Topology)

  • 6 faces, with 8 vertices
  • Same length sides
  • Right angles in each corner
  • Canonical cube
  • Front, lower-left corner at (0,0,0)
  • Unit sides
  • Vertices (0,0,0), (1,0,0), (1,1,0), (0,1,0), repeat z=1
  • Faces (0,1,2,3), (1,5,6,2), …
  • Note, could define based on center!
slide-6
SLIDE 6

6

Feb-15-04 SMD159, Object-Oriented Modeling 16 L

Cube (Other attributes)

  • Geometry
  • Location in world or relative

to parent

  • Front, lower-left corner (center)
  • Size
  • Length of side
  • Orientation
  • Direction of front, bottom edge
  • Direction from center to a

vertex

  • Materials and/or Color
  • By face
  • By entire cube
  • Only light properties
  • Methods
  • Render

Feb-15-04 SMD159, Object-Oriented Modeling 17 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Scene Graphs

Feb-15-04 SMD159, Object-Oriented Modeling 18 L

Motivation

  • Need a structure to construct hierarchical

representations of a scene

  • Would like to describe the scene and then modify only

small parts

  • Would like to avoid (re)writing the code to display the

hierarchical representation

  • Reuse
  • Reduced chance of error
  • Would like to save the scene in a file for reuse
slide-7
SLIDE 7

7

Feb-15-04 SMD159, Object-Oriented Modeling 19 L

Scene Graphs

  • We’ve see how trees (DAGs) can represent objects
  • Nodes are the objects
  • Links are their relationship
  • What if we extend the idea? We could
  • Have nodes for transformations
  • Represent cameras as nodes

fiScene Graphs

Feb-15-04 SMD159, Object-Oriented Modeling 20 L

Scene Graph Basics

  • Different types of nodes for:
  • Transformations
  • Object aggregation
  • Material properties
  • Cameras

+ Limited parts of the hierarchy + Different views + Special properties

  • Types are application dependent
  • Links for relationships
  • Graph compiler
  • API or language
  • Rendering engine

Feb-15-04 SMD159, Object-Oriented Modeling 21 L

Scene Graph Systems

  • Open Inventor
  • SGI, API
  • Based on GL (now OpenGL)
  • VRML
  • Text description language
  • Based on Open Inventor
  • X3D
  • Extension of VRML adding XML syntax, semantics
  • Java 3D
  • Java-based API
  • Based on OpenGL
  • Jazz
  • Java-based, 2D API for Zooming User Interfaces (ZUIs)
  • Piccolo
  • Simplified version of Jazz
slide-8
SLIDE 8

8

Feb-15-04 SMD159, Object-Oriented Modeling 22 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Jazz, an Example Scene Graph System

Feb-15-04 SMD159, Object-Oriented Modeling 23 L

Zooming User Interfaces

  • Problems with Overlapping

Windows

  • Significant time managing

windows.

  • Replacement causes a disruptive

context switch

  • Even a “rooms” metaphor causes

the context switch

  • Scrolling is not an appropriate

browsing method + For many applications + But, it’s all you usually get.

  • ZUI an Alternate Paradigm
  • Infinite canvas, infinitely

stretchable

  • No icons, overlapping windows
  • Navigation by zoom and pan
  • Smooth context switch maintains

spatial continuity

  • Small windows effectively icons
  • Rooms are groups of windows
  • Semantic zooming
  • Navigation aids and shortcuts
  • Windows may be views of the

canvas

  • Windows may be pasted to the

display instead of the canvas

Feb-15-04 SMD159, Object-Oriented Modeling 24 L

Why a Special Scene Graph System?

  • ZUIs have unique requirements. They must support:
  • Custom non-rectangular or transparent graphics
  • Large numbers of objects
  • Arbitrary transforms and hierarchical grouping
  • Continuous and smooth zooms and pans
  • Rendering objects differently in different (simultaneous)

contexts

  • Multiple views
  • Event handlers for individual elements and groups of objects
  • Standard tool kits don’t met these requirements
slide-9
SLIDE 9

9

Feb-15-04 SMD159, Object-Oriented Modeling 25 L

Jazz Architecture

  • Nodes, visual components, and cameras
  • Nodes
  • Hierarchy, which represents relationships between objects
  • No visual appearance
  • Based on light-weight ZNode object
  • Specify where something is in the visual hierarchy (structure)
  • Visual Components
  • Provide appearance
  • Attached to visual leaf nodes and visual group nodes
  • Specify what something looks like (content)

Feb-15-04 SMD159, Object-Oriented Modeling 26 L

Jazz Architecture

  • Cameras
  • Views of the scene graph
  • Implement a drawing surface that is a Swing

component

  • Can also be interior to a scene graph, provide an

embedded view of the graph (portals)

  • Contains a list of layers

Feb-15-04 SMD159, Object-Oriented Modeling 27 L

Jazz Events

  • Follow the Java model
  • Listeners attached to scene graph nodes
  • Multiple listeners allowed
  • May be associated with any scene graph node
  • Two kinds
  • Input, mouse events, etc.
  • Object, result from modifications of the scene graph
  • Events are passed up the tree to ancestors by default
  • Are dispatched in the “event thread”
  • Jazz is not thread safe
  • Same restrictions as Swing and AWT apply
slide-10
SLIDE 10

10

Feb-15-04 SMD159, Object-Oriented Modeling 28 L

Relation Between Jazz and Swing

  • Jazz’s ZCanvas is a Swing object
  • A Jazz scene graph can be displayed in a Swing frame

(JFrame)

  • Jazz provides ZSwing to embed Swing widgets
  • N.B.! JMenu and JComboBox don’t work

+ Use ZMenu and ZComboBox instead

  • JPopupMenu is always potentially heavyweight

+ Can extend outside its parent window + Manage at the level of ZCanvas

Feb-15-04 SMD159, Object-Oriented Modeling 29 L

Overview of Classes

Feb-15-04 SMD159, Object-Oriented Modeling 30 L

Visual Components

  • ZShape
  • Abstract class
  • Meant to be extended by visual

components that wrap the standard java.awt.Shapes.

  • ZShape sub classes and their

underlying shape model

  • Zarc, uses Arc2D
  • ZCubicCurve, uses CubicCurve2D
  • ZQuadCurve, uses QuadCurve2D
  • ZLine, uses Line2D
  • ZRectangle, used for rectangles and

squares

  • ZRoundedRectangle, uses

RoundedRectangle2D

  • ZShape sub classes, continuted
  • ZPolyline, set of line segments that

connect a set of points.

  • ZPolygon, fills in the polygon between

a set of points.

  • ZEllipse, hard-cornered or rounded

ellipse.

  • ZImage, an image.
  • ZLabel, lightweight visual component

to support a label containing one line of text.

  • ZText, paints a text string.
  • ZCamera, view onto a portion of the

scenegraph.

  • ZSwing wraps a standard Java Swing

widget.

slide-11
SLIDE 11

11

Feb-15-04 SMD159, Object-Oriented Modeling 31 L

Transforms

  • Standard 2D affine transforms
  • Affine transforms preserve straightness and parallelism of

lines

  • Based on ZTransformGroup
  • All nodes contained in a ZTransformGroup are transformed
  • Implements: scale, rotate, and translate

Feb-15-04 SMD159, Object-Oriented Modeling 32 L

INSTITUTIONEN FÖR SYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Other Graphical Trees

Feb-15-04 SMD159, Object-Oriented Modeling 33 L

Constructive Solid Geometry

  • Problem:
  • Polygons represent surfaces
  • Difficult to compute properties of solids (volume, center-of-

mass)

  • Ambiguous representations
  • Solution:
  • Use solid primitives
  • With set operations », «, & -
  • Construct expression trees
  • Use post-order traversal to render
slide-12
SLIDE 12

12

Feb-15-04 SMD159, Object-Oriented Modeling 34 L

CSG Tree, Example

Feb-15-04 SMD159, Object-Oriented Modeling 35 L

Shade Trees

  • Remember Phong shading
  • Simple shading equation
  • Computation of the reflection
  • Renderman uses a similar

structure to express custom renderers r = 2 (l · n ) n - l I =kd Id l · n + ks Is (v · r )a + ka Ia

Feb-15-04 SMD159, Object-Oriented Modeling 36 L

BSP Trees

  • Binary Spatial Partition trees
  • Insert polygons front to back
  • Backward in order transversal

+ Right branch first

  • Avoids resorting by depth
  • If the user moves
  • Change order of traversal
  • Prune
slide-13
SLIDE 13

13

Feb-15-04 SMD159, Object-Oriented Modeling 37 L

Quadtrees and Octrees

  • Recursive division of a plane into 4 parts
  • Stops when a subdivision is 1 color
  • Octrees extend to volume

Feb-15-04 SMD159, Object-Oriented Modeling 38 L

Questions?