edu.mines.jtk.sgl
Class TraversalContext

java.lang.Object
  extended by edu.mines.jtk.sgl.TraversalContext
Direct Known Subclasses:
TransformContext

public class TraversalContext
extends java.lang.Object

A context for scene graph traversal. A traversal context maintains a current node and a list of its parent nodes. Because nodes in the scene graph may have multiple parents, a node may become current at more than time during a traversal, each time with a different list of parent nodes.

Version:
2005.05.26
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
TraversalContext()
           
 
Method Summary
 int countNodes()
          Returns the number of current and parent nodes in this traversal.
 Node getNode()
          Gets the current node in this traversal.
 Node getNode(int index)
          Gets the node in this traversal with specified index.
 Node[] getNodes()
          Gets an array of nodes representing the state of this traversal.
 void popNode()
          Restores the most recently saved (pushed) node.
 void pushNode(Node node)
          Saves the current node, and then makes the specified node current.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraversalContext

public TraversalContext()
Method Detail

countNodes

public int countNodes()
Returns the number of current and parent nodes in this traversal.

Returns:
the number of nodes.

getNode

public Node getNode()
Gets the current node in this traversal.

Returns:
the current node.

getNode

public Node getNode(int index)
Gets the node in this traversal with specified index. If count is the number of nodes returned by the method countNodes(), then the current node has index count-1, and the root node has index zero.

If the specified index is negative, then count is added to the index. Therefore, the index -1 will get the current node, the index -2 will get its parent node, and so on.

Parameters:
index - the index.
Returns:
the node.

getNodes

public Node[] getNodes()
Gets an array of nodes representing the state of this traversal. Nodes in the array are ordered from parent to child. The last node in the array is the current node, the next to last node is the current node's parent, and so on.

Returns:
the array of nodes.

pushNode

public void pushNode(Node node)
Saves the current node, and then makes the specified node current.

Parameters:
node - the new current node.

popNode

public void popNode()
Restores the most recently saved (pushed) node. Discards the current node.