de.jreality.util
Class SceneGraphUtility

java.lang.Object
  extended by de.jreality.util.SceneGraphUtility

public class SceneGraphUtility
extends Object

This class holds static methods that make the parsing/traversal etc of a scene graph more comfortable.

Author:
Tim Hoffmann

Constructor Summary
SceneGraphUtility()
           
 
Method Summary
static void addChildNode(SceneGraphComponent parent, SceneGraphNode node)
          method to add a child of arbitrary type
static List<SceneGraphPath> collectClippingPlanes(SceneGraphComponent rootNode)
          Return list of paths from rootNode to an instance of ClippingPlane,
static List<SceneGraphPath> collectLights(SceneGraphComponent rootNode)
          Return list of paths from rootNode to an instance of Light.
static
<T extends SceneGraphNode>
T
copy(T template)
          Return a copy of the scene graph node template.
static SceneGraphComponent createFullSceneGraphComponent()
           
static SceneGraphComponent createFullSceneGraphComponent(String name)
          Allocate and return an instance of SceneGraphComponent fitted out with an instance of Transformation and Appearance.
static SceneGraphComponent flatten(SceneGraphComponent sgc)
           
static SceneGraphComponent flatten(SceneGraphComponent sgc, boolean rejectInvis)
          Apply transformations recursively to all instances of PointSet and produce a flat scene graph with no transformations.
static Geometry getFirstGeometry(SceneGraphComponent sgc)
           
static int getIndexOfChild(SceneGraphComponent parent, SceneGraphComponent child)
          Linear search for the index of child in childlist of parent.
static int getMetric(SceneGraphPath sgp)
          Return the metric metric at the end of the path sgp by evaluating effective appearance for the attribute CommonAttributes.METRIC.
static List<SceneGraphPath> getPathsBetween(SceneGraphComponent begin, SceneGraphNode end)
           
static List<SceneGraphPath> getPathsToNamedNodes(SceneGraphComponent root, String name)
          Find and return all paths fomr root to node with name name.
static void removeChildNode(SceneGraphComponent parent, SceneGraphNode node)
          Remove a child of arbitrary type.
static void removeChildren(SceneGraphComponent c)
          Remove all children (i.e., instances of SceneGraphComponent from this node.
static void replaceChild(SceneGraphComponent c, SceneGraphComponent ch)
          Replace the first child with the given component.
static void setMetric(SceneGraphComponent r, int metric)
          Set the metric of this sub-graph by setting the appearance attribute CommonAttributes.METRIC.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SceneGraphUtility

public SceneGraphUtility()
Method Detail

createFullSceneGraphComponent

public static SceneGraphComponent createFullSceneGraphComponent()

createFullSceneGraphComponent

public static SceneGraphComponent createFullSceneGraphComponent(String name)
Allocate and return an instance of SceneGraphComponent fitted out with an instance of Transformation and Appearance.

Parameters:
name -
Returns:

replaceChild

public static void replaceChild(SceneGraphComponent c,
                                SceneGraphComponent ch)
Replace the first child with the given component.

Parameters:
c -
ch -

removeChildren

public static void removeChildren(SceneGraphComponent c)
Remove all children (i.e., instances of SceneGraphComponent from this node.

Parameters:
component - TODO: this should be called removeChildComponents!

setMetric

public static void setMetric(SceneGraphComponent r,
                             int metric)
Set the metric of this sub-graph by setting the appearance attribute CommonAttributes.METRIC.

Parameters:
r -
metric -

getMetric

public static int getMetric(SceneGraphPath sgp)
Return the metric metric at the end of the path sgp by evaluating effective appearance for the attribute CommonAttributes.METRIC.

Parameters:
sgp -
Returns:

collectLights

public static List<SceneGraphPath> collectLights(SceneGraphComponent rootNode)
Return list of paths from rootNode to an instance of Light.

Parameters:
rootNode -
Returns:

collectClippingPlanes

public static List<SceneGraphPath> collectClippingPlanes(SceneGraphComponent rootNode)
Return list of paths from rootNode to an instance of ClippingPlane,

Parameters:
rootNode -
Returns:

getPathsBetween

public static List<SceneGraphPath> getPathsBetween(SceneGraphComponent begin,
                                                   SceneGraphNode end)

getPathsToNamedNodes

public static List<SceneGraphPath> getPathsToNamedNodes(SceneGraphComponent root,
                                                        String name)
Find and return all paths fomr root to node with name name.

Parameters:
root -
name -
Returns:

removeChildNode

public static void removeChildNode(SceneGraphComponent parent,
                                   SceneGraphNode node)
Remove a child of arbitrary type.

Parameters:
node - the child to remove
Throws:
IllegalArgumentException - if node is no child

addChildNode

public static void addChildNode(SceneGraphComponent parent,
                                SceneGraphNode node)
method to add a child of arbitrary type

Parameters:
node - the child to add

getIndexOfChild

public static int getIndexOfChild(SceneGraphComponent parent,
                                  SceneGraphComponent child)
Linear search for the index of child in childlist of parent. Can be overridden if there is a more efficient way of determining the index.

Parameters:
parent -
child -
Returns:
index, or -1 if not found.

copy

public static <T extends SceneGraphNode> T copy(T template)
Return a copy of the scene graph node template. For a SceneGraphComponent, it does not include copies of the children.

Parameters:
template -
Returns:
the copy
See Also:
CopyVisitor

getFirstGeometry

public static Geometry getFirstGeometry(SceneGraphComponent sgc)

flatten

public static SceneGraphComponent flatten(SceneGraphComponent sgc)

flatten

public static SceneGraphComponent flatten(SceneGraphComponent sgc,
                                          boolean rejectInvis)
Apply transformations recursively to all instances of PointSet and produce a flat scene graph with no transformations. It collects these instances, and transforms them into world coordinates. All these instances are put into one parent, and this parent is returned. Geometry that is not PointSet is simply ignored. Attributes are copied as much as possible, normals are also transformed. The code is not robust.

Parameters:
sgc -
rejectInvis - if true, non-visible scene graph components are skipped (default: false)
Returns: