Scene Graph

Most graphics APIs are state-based. The program sets up drawing state in the display manager that defines the colour, font, translation, fill texture, etc. used by drawing operations. This reduces the amount of data that needs to be passed across the kernel boundary or network for each drawing operation.

How do you make StructuredGraphics composable?

If you are writing a graphics program that uses StructuredGraphics, you may want to define a composite shape and then draw it in different places on the display, at a different size, rotated or in a different colour.

Therefore:

Each StructuredGraphics object should encapsulate a modification to the drawing state held in the display manager, such as the SingleTransform. Composing graphical objects will cause the child to inherit the drawing state created by its tree of containers.

Define the visual objects using a DirectedAcyclicGraph (DAG) in which the leaves represent primitive shapes and intermediate nodes either encapsulate a small, reversible change to the state of the display manager that is applied to a single subgraph or compose multiple subgraphs.

Drawing is performed by walking over the graph in depth-first order, performing the following operations on the various types of nodes:

A shape can be drawn multiple times, with different transformations and other properties, by defining it once and then linking it into different parts of the graph so that different transformations are applied to it each time it is visited during the graph traversal.

However, compared to a simple StructuredGraphics framework, it is harder to map from the leaves of a SceneGraph to areas of the display, because arbitrary transformations can be applied to the shapes at the leaves of the graph. These calculations are required to calculate minimim RefreshRectangles or to implement interactivity. Such mappings must be performed by walking over the graph, keeping track of transformations by performing the matrix multiplications in the visitor. Even though this is computationally more expensive than algorithms required by a simple StructuredGraphics framework, it can still reduce the drawing time significantly when used to calculate minimum RefreshRectangles.

A SceneGraph is often used as a high-level interface for assembling CompiledGraphicCommands.

A RenderGraph? is an optimisation of the SceneGraph model.

This pattern is widely used in toolkits for 3D graphics. In particular, OpenInventor, OpenSceneGraph and Java3D all use SceneGraphs to structure scenes. It is less widely used in 2D graphics. Examples include the MorphicInterface framework in the SelfLanguage and SqueakSmalltalk, the SceneBeans and Jazz toolkits for Java, the GnomeCanvas display widget, and the SVG graphics file format defined by the W3C.


Also see GraphicsPatterns, InteractiveSceneGraph, DocumentObjectModel

CategoryPattern


EditText of this page (last edited April 2, 2009) or FindPage with title or text search