org.xith3d.scenegraph
Class GroupNode

java.lang.Object
  extended by org.xith3d.scenegraph.SceneGraphObject
      extended by org.xith3d.scenegraph.Node
          extended by org.xith3d.scenegraph.GroupNode
All Implemented Interfaces:
org.jagatoo.datatypes.NamableObject, org.jagatoo.datatypes.NamedObject, org.openmali.spatial.SpatialNode
Direct Known Subclasses:
BranchGroup, DummyGroupNode, Group, TerrainTile

public abstract class GroupNode
extends Node

A Node, that can hold a list of child Nodes.


Field Summary
protected  Node[] children
          The list of children nodes in this Group.
protected  GroupNode hostGroup
           
protected  int numChildren
           
protected  long totalNumChildren
           
protected  long totalNumShapes
           
 
Fields inherited from class org.xith3d.scenegraph.Node
bounds, boundsAutoCompute, boundsDirty, globalIgnoreBounds, instanceBoundsTypeHint, transformGroup, untransformedBounds
 
Fields inherited from class org.xith3d.scenegraph.SceneGraphObject
XITH3D_USERDATAKEY_OLDUSERDATA
 
Constructor Summary
GroupNode()
          Constructs a new Group object.
GroupNode(GroupNode hostGroup)
          Constructs a new Group object.
 
Method Summary
 void absorbDetails(Node node)
          Turns the receiver into a shared copy of the node parameter.
 void addChild(Node child)
          Add a child to the group as the last child in the group.
 void addChild(Node child, int index)
          Insert a child at the specified index.
protected  void checkChild(Node child, int index)
           
 void dump()
          Dumps this Group and it's children to stdout.
protected  void dump(int indent)
          
protected  boolean ensureCapacity(int minCapacity)
           
protected  void expandBounds(Node node, boolean forceNodeUpdate)
           
<NT extends Node>
java.util.List<NT>
findAll(java.lang.Class<NT> searchedClass)
           
 java.util.List<Node> findAll(java.lang.String name)
           
<NT extends Node>
NT
findFirst(java.lang.Class<NT> searchedClass)
           
 Node findFirst(java.lang.String name)
           
 void freeOpenGLResources(CanvasPeer canvasPeer)
          This method frees OpenGL resources (names) for all Nodes in the traversal of this Node(-Group).
 Node getChild(int index)
           
 java.util.ArrayList<Node> getChildren()
          Deprecated. use numChildren() and getChild(int) instead.
<L extends java.util.List<Node>>
L
getChildren(L list)
          Fills this group's children into the given list.
 Clipper getClipper()
           
 GroupNode getPickHost()
           
 ScissorRect getScissorRect()
           
 long getTotalNumChildren()
           
 long getTotalNumShapes()
           
 int indexOf(Node child)
           
 boolean isPickHost()
           
protected  void mergeInheritedClipper(Clipper clipper, ClipperInfo clipperInfo)
           
protected  void mergeInheritedNodes(InheritedNodeAttributes in)
           
protected  void mergeInheritedScissorRect(ScissorRect scissorRect)
           
protected abstract  GroupNode newInstance()
           
 int numChildren()
          Get the number of children in this group.
 void removeAllChildren()
          Removes all the children of this group.
 Node removeChild(int index)
          Remove the child at the specified index.
 int removeChild(Node child)
          Remove a child from the group.
protected  void setBoundsDirty()
          
protected  void setBoundsDirtyUpward()
          
 Node setChild(Node child, int index)
          Set the child at the specified index.
 void setClipper(Clipper clipper)
          Sets this Group's Clipper
protected  boolean setLive(boolean live)
          Sets the live state of the object
 void setPickHost(boolean isPickHost)
          Sets this Group to be a pick-host or not.
protected  void setPickHost(GroupNode pickHost)
          Recursively searches for (grand-)children to set the pick-host property.
 void setScissorRect(ScissorRect scissorRect)
          Sets this Group's ScissorRect
 void setShowBounds(boolean show, boolean childrenToo)
           
 GroupNode sharedCopy()
          Creates a shared copy of this Node.
 GroupNode sharedCopy(CopyListener listener)
          Creates a shared copy of this Node.
 boolean traverse(TraversalCallback callback)
          Traverses the scenegraph from this node on.
protected  void unmergeInheritedFog(Fog fog)
           
protected  void unmergeInheritedLight(Light light)
           
protected  void unmergeInheritedNodes(InheritedNodeAttributes in)
           
 void updateBounds(boolean onlyDirty)
          Update bounds sets the bounds and virutal world bounds of all nodes recursively.
protected  void updateBoundsCheap(boolean onlyDirty, boolean childrenToo, boolean parentToo, boolean onlyWorld)
          Update bounds sets the bounds and virutal world bounds of all nodes recursively.
 
Methods inherited from class org.xith3d.scenegraph.Node
cloneNode, detach, duplicateNode, freeOpenGLResources, getBounds, getBoundsAutoCompute, getBoundsType, getBoundsTypeHint, getDefaultPickable, getIndentString, getInheritedNodeAttributes, getModListener, getOrderedChild, getOrderedState, getParent, getRoot, getShadowAttachment, getShowBounds, getTransformGroup, getTreeCell, getWorldBounds, getWorldTransform, getWorldTransform, isBillboard, isIgnoreBounds, isOccluder, isPickable, isRenderable, isUpdatableNode, popGlobalIgnoreBounds, printBounds, pushGlobalIgnoreBounds, setBounds, setBoundsAutoCompute, setBoundsTypeHint, setDefaultPickable, setGlobalIgnoreBounds, setIgnoreBounds, setIsOccluder, setModListener, setOrderedChild, setParent, setPickable, setPickableRecursive, setPickableRecursive, setRenderable, setShadowAttachment, setShowBounds, setTransformGroup, setTreeCell, traverse, updateOrderedChild, updateTransformGroup, updateWorldTransform
 
Methods inherited from class org.xith3d.scenegraph.SceneGraphObject
getName, getUserData, getUserData, getUserDataMap, isLive, setName, setUserData, setUserData, setUserDataRecursive, setUserDataRecursive, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hostGroup

protected final GroupNode hostGroup

children

protected Node[] children
The list of children nodes in this Group.


numChildren

protected int numChildren

totalNumChildren

protected long totalNumChildren

totalNumShapes

protected long totalNumShapes
Constructor Detail

GroupNode

public GroupNode(GroupNode hostGroup)
Constructs a new Group object.

Parameters:
hostGroup - the group to be forwarded all the add/remove methods.

GroupNode

public GroupNode()
Constructs a new Group object.

Method Detail

setLive

protected boolean setLive(boolean live)
Sets the live state of the object

Overrides:
setLive in class SceneGraphObject
Returns:
true, if the state has changed

setPickHost

protected void setPickHost(GroupNode pickHost)
Recursively searches for (grand-)children to set the pick-host property. Stops the seach, if a child is a GroupNode and the pick-host flag is set.

Parameters:
pickHost - the GroupNode, which serves as the pick-host

getPickHost

public final GroupNode getPickHost()
Returns:
this GroupNode's pick-host

setPickHost

public void setPickHost(boolean isPickHost)
Sets this Group to be a pick-host or not. A Shape3D provides a method getPickHost(), which will return the (deepest) GroupNode, which is a pick-host.

Parameters:
isPickHost -
See Also:
Leaf.getPickHost()

isPickHost

public boolean isPickHost()
Returns:
the pick-host flag of this GroupNode. A Shape3D provides a method getPickHost(), which will return the (deepest) GroupNode, which is a pick-host.
See Also:
Leaf.getPickHost()

checkChild

protected final void checkChild(Node child,
                                int index)

mergeInheritedNodes

protected void mergeInheritedNodes(InheritedNodeAttributes in)
Overrides:
mergeInheritedNodes in class Node

unmergeInheritedNodes

protected void unmergeInheritedNodes(InheritedNodeAttributes in)
Overrides:
unmergeInheritedNodes in class Node

unmergeInheritedLight

protected void unmergeInheritedLight(Light light)
Overrides:
unmergeInheritedLight in class Node

unmergeInheritedFog

protected void unmergeInheritedFog(Fog fog)
Overrides:
unmergeInheritedFog in class Node

ensureCapacity

protected boolean ensureCapacity(int minCapacity)

addChild

public void addChild(Node child,
                     int index)
Insert a child at the specified index. The parent of the child is set to this object. If this object is live then the child is set live.


addChild

public final void addChild(Node child)
Add a child to the group as the last child in the group. The parent of the child is set to this object. If this object is live then the child is made live.


removeChild

public Node removeChild(int index)
Remove the child at the specified index. The parent of the child is set to null. The child is made not live.


indexOf

public final int indexOf(Node child)
Parameters:
child -
Returns:
the index of the given child Node in the list of this Group's children.

removeChild

public final int removeChild(Node child)
Remove a child from the group. The parent of the child is set to null. The child is made not live.


removeAllChildren

public void removeAllChildren()
Removes all the children of this group.


setChild

public Node setChild(Node child,
                     int index)
Set the child at the specified index. If an existing child is at that location then it is removed, its parent is set to null and it is set not live. If this object is live then the child is set live.

Parameters:
child -
index -
Returns:
the Node, that previously lived at the given position

getChild

public final Node getChild(int index)
Returns:
the child at the specified index.

numChildren

public final int numChildren()
Get the number of children in this group.


getTotalNumChildren

public final long getTotalNumChildren()
Returns:
the total number of children in this group and its subgroups.

getTotalNumShapes

public final long getTotalNumShapes()
Returns:
the total number of shapes in this group and its subgroups.

getChildren

public final <L extends java.util.List<Node>> L getChildren(L list)
Fills this group's children into the given list. Note: The list is not cleared before.

Parameters:
list -

getChildren

@Deprecated
public java.util.ArrayList<Node> getChildren()
Deprecated. use numChildren() and getChild(int) instead.

Returns:
a read-only List of all contained children

setBoundsDirtyUpward

protected void setBoundsDirtyUpward()

Overrides:
setBoundsDirtyUpward in class Node

setBoundsDirty

protected void setBoundsDirty()

Overrides:
setBoundsDirty in class Node

expandBounds

protected final void expandBounds(Node node,
                                  boolean forceNodeUpdate)
Parameters:
node -
forceNodeUpdate -

updateBoundsCheap

protected void updateBoundsCheap(boolean onlyDirty,
                                 boolean childrenToo,
                                 boolean parentToo,
                                 boolean onlyWorld)
Update bounds sets the bounds and virutal world bounds of all nodes recursively.

Overrides:
updateBoundsCheap in class Node
Parameters:
onlyDirty - Only update those nodes which have been marked as dirty.
childrenToo - if false, the children bounds are not updated
parentToo - if false, the parent Node will not be updated
onlyWorld - if true, only the vworld bounds are updated

updateBounds

public void updateBounds(boolean onlyDirty)
Update bounds sets the bounds and virutal world bounds of all nodes recursively.

Overrides:
updateBounds in class Node
Parameters:
onlyDirty - Only update those nodes which have been marked as dirty.

setShowBounds

public void setShowBounds(boolean show,
                          boolean childrenToo)

mergeInheritedScissorRect

protected void mergeInheritedScissorRect(ScissorRect scissorRect)
Overrides:
mergeInheritedScissorRect in class Node

setScissorRect

public void setScissorRect(ScissorRect scissorRect)
Sets this Group's ScissorRect

Parameters:
scissorRect - the new ScissorRect

getScissorRect

public final ScissorRect getScissorRect()
Returns:
this Group's ScissorBox

mergeInheritedClipper

protected void mergeInheritedClipper(Clipper clipper,
                                     ClipperInfo clipperInfo)
Overrides:
mergeInheritedClipper in class Node

setClipper

public void setClipper(Clipper clipper)
Sets this Group's Clipper

Parameters:
clipper - the new Clipper

getClipper

public final Clipper getClipper()
Returns:
this Group's Clipper

newInstance

protected abstract GroupNode newInstance()
Returns:
a new instance of this class. This is invoked by the sharedCopy() method.
See Also:
sharedCopy(CopyListener)

sharedCopy

public GroupNode sharedCopy(CopyListener listener)
Creates a shared copy of this Node. A shared copy is one where the geometry and appearance is shared, but everything else is copied. This is a replacement for shared groups because of performance considerations. If you are loading the same model many times then this can save on memory and load times. The only allowable within the subtree are groups and shapes. This also copies a shapes bounds and turns autocomute off so that it is fast to insert the model into the scene.

Overrides:
sharedCopy in class Node
Returns:
a shared copy of this Node
See Also:
Node.absorbDetails(Node)

sharedCopy

public GroupNode sharedCopy()
Creates a shared copy of this Node. A shared copy is one where the geometry and appearance is shared, but everything else is copied. This is a replacement for shared groups because of performance considerations. If you are loading the same model many times then this can save on memory and load times. The only allowable within the subtree are groups and shapes. This also copies a shapes bounds and turns autocomute off so that it is fast to insert the model into the scene.

Overrides:
sharedCopy in class Node
Returns:
a shared copy of this Node
See Also:
Node.absorbDetails(Node)

absorbDetails

public void absorbDetails(Node node)
Turns the receiver into a shared copy of the node parameter. This is precisely the inverse operation of sharedCopy; i.e., shared copy creates a new node, but absorbDetails turns the current node into a copy exactly equivalent to what would be returned, if you created a new copy via the sharedCopy() method.

Overrides:
absorbDetails in class Node
Parameters:
node - the node to copy.
See Also:
Node.sharedCopy()

dump

protected void dump(int indent)

Specified by:
dump in class Node

dump

public void dump()
Dumps this Group and it's children to stdout.


freeOpenGLResources

public void freeOpenGLResources(CanvasPeer canvasPeer)
This method frees OpenGL resources (names) for all Nodes in the traversal of this Node(-Group).

Specified by:
freeOpenGLResources in class Node

traverse

public boolean traverse(TraversalCallback callback)
Traverses the scenegraph from this node on. If this Node is a Group it will recusively run through each child.

Overrides:
traverse in class Node
Parameters:
callback - the listener is notified of any traversed Node on the way
Returns:
if false, the whole traversal will stop

findFirst

public Node findFirst(java.lang.String name)
Parameters:
name - the name to be searched for
Returns:
the first child named "name", or null if not foud

findAll

public java.util.List<Node> findAll(java.lang.String name)
Parameters:
name - the name to be searched for
Returns:
all the found children named "name", or null if none foud

findFirst

public <NT extends Node> NT findFirst(java.lang.Class<NT> searchedClass)
Parameters:
searchedClass - the class to search for
Returns:
a list of the first node of the specified class in this group, or null if not found

findAll

public <NT extends Node> java.util.List<NT> findAll(java.lang.Class<NT> searchedClass)
Parameters:
searchedClass - the class to search for
Returns:
a list of all nodes of the specified class found in this group or null if none found