Aviatrix3D
2.1.0

org.j3d.aviatrix3d
Class SharedNode

java.lang.Object
  extended by org.j3d.aviatrix3d.SceneGraphObject
      extended by org.j3d.aviatrix3d.Node
          extended by org.j3d.aviatrix3d.SharedNode
All Implemented Interfaces:
MultiParentNode, PickableObject, PickTarget, SinglePickTarget, Cullable, SingleCullable

public class SharedNode
extends Node
implements MultiParentNode, PickableObject, SinglePickTarget, SingleCullable

A node that can have multiple parents, thus allowing a graph structure to the scene graph.

Normal nodes cannot have more than one parent, so this class provides the ability to have more than one. In doing so, it overrides the normal methods provided by Node to provide the shared functionality. It provides a compliment to the SharedGroup for parts of the scene graph where you want to share a common piece, but really don't need the grouping functionality.

Using this node in preference to SharedGroup has several performance benefits. For example, when performing picking, the picking implementation can just ignore this node altogether as it knows the bounds are identical to it's child.

Internationalisation Resource Names

Version:
$Revision: 1.30 $
Author:
Justin Couch

Field Summary
 
Fields inherited from class org.j3d.aviatrix3d.Node
bounds, implicitBounds, INVALID_BOUNDS, parent
 
Fields inherited from class org.j3d.aviatrix3d.SceneGraphObject
alive, LISTENER_SET_TIMING_ERR_PROP, updateHandler
 
Fields inherited from interface org.j3d.aviatrix3d.picking.PickableObject
COLLIDABLE_OBJECT, GENERAL_OBJECT, PROXIMITY_OBJECT, VISIBLE_OBJECT
 
Fields inherited from interface org.j3d.aviatrix3d.picking.PickTarget
CUSTOM_PICK_TYPE, GROUP_PICK_TYPE, LEAF_PICK_TYPE, SINGLE_PICK_TYPE
 
Constructor Summary
SharedNode()
          The default constructor
 
Method Summary
protected  void checkForCyclicParent(SceneGraphObject child)
          Check to see if this node is the same reference as the passed node.
 boolean checkPickMask(int mask)
          Check the given pick mask against the node's internal pick mask representation.
 Node getChild()
          Get the currently set child of this node.
 Cullable getCullableChild()
          Get the child renderable of this object.
 Cullable getCullableParent()
          Get the parent cullable of this instance.
 Node getParent()
          Overridden to always return the current first parent in the list.
 void getParents(Node[] parents)
          Get the listing of the number of parents that this node currently has.
 BoundingVolume getPickableBounds()
          Get the bounds of this picking target so that testing can be performed on the object.
 PickTarget getPickableChild()
          Return the child that is pickable of from this target.
 int getPickMask()
          Get the current pickable state mask of this object.
 int getPickTargetType()
          Return the type constant that represents the type of pick target this is.
 boolean hasMultipleParents()
          Check to see if this cullable is mulitparented.
protected  void markBoundsDirty()
          Mark this node as having dirty bounds due to one of it's children having their bounds changed.
 int numParents()
          Request the number of parents this node currently contains
 void pickBatch(PickRequest[] reqs, int numRequests)
          Check for all intersections against this geometry and it's children to see if there is an intersection with the given set of requests.
 void pickSingle(PickRequest req)
          Check for all intersections against this geometry and it's children to see if there is an intersection with the given set of requests.
protected  void recomputeBounds()
          Internal method to recalculate the implicit bounds of this Node.
protected  void removeParent(Node p)
          Remove a parent from this shared group.
 void requestBoundsUpdate()
          Request a recomputation of the bounds of this object.
 void setChild(Node child)
          Set the child to be the new value.
protected  void setLive(boolean state)
          Notification that this object is live now.
 void setLive(Node caller, boolean state)
          Overloaded version of the notification that this object's liveness state has changed.
protected  void setParent(Node p)
          Specify this nodes parent, overridden to provide behaviour that appends the node to the list rather than replacing it.
 void setPickMask(int state)
          Set the node as being pickable currently using the given bit mask.
protected  void setUpdateHandler(NodeUpdateHandler handler)
          Set the scenegraph update handler for this node.
protected  void updateBounds()
          Update this node's bounds and then call the parent to update it's bounds.
 
Methods inherited from class org.j3d.aviatrix3d.Node
boundsChanged, getBounds, setBounds, updateParentBounds
 
Methods inherited from class org.j3d.aviatrix3d.SceneGraphObject
checkForCyclicChild, dataChanged, getAppUpdateWriteTimingMessage, getBoundsWriteTimingMessage, getDataWriteTimingMessage, getUserData, isLive, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.j3d.aviatrix3d.rendering.SingleCullable
getBounds
 

Constructor Detail

SharedNode

public SharedNode()
The default constructor

Method Detail

getCullableChild

public Cullable getCullableChild()
Get the child renderable of this object.

Specified by:
getCullableChild in interface SingleCullable
Returns:
an array of nodes

hasMultipleParents

public boolean hasMultipleParents()
Check to see if this cullable is mulitparented. If it is, then that will cause problems for code that needs to know information like the transformation to the root of the scene graph.

Specified by:
hasMultipleParents in interface SingleCullable
Returns:
true if there are multiple parents

getCullableParent

public Cullable getCullableParent()
Get the parent cullable of this instance. If this node has multiple direct parents, then this should return null.

Specified by:
getCullableParent in interface SingleCullable
Returns:
The parent instance or null if none

setLive

public void setLive(Node caller,
                    boolean state)
Overloaded version of the notification that this object's liveness state has changed. We overload with the caller so that for shared

Specified by:
setLive in interface MultiParentNode
Parameters:
caller - The node calling us with the state changes
state - true if this should be marked as live now

markBoundsDirty

protected void markBoundsDirty()
Mark this node as having dirty bounds due to one of it's children having their bounds changed.

Overrides:
markBoundsDirty in class Node

recomputeBounds

protected void recomputeBounds()
Internal method to recalculate the implicit bounds of this Node. By default the bounds are a point sphere, so derived classes should override this method with something better.

Overrides:
recomputeBounds in class Node

requestBoundsUpdate

public void requestBoundsUpdate()
Request a recomputation of the bounds of this object. If this object is not currently live, you can request a recompute of the bounds to get the most current values. If this node is currently live, then the request is ignored.

This will recurse down the children asking all of them to recompute the bounds. If a child is found to be during this process, that branch will not update, and thus the value used will be the last updated (ie from the previous frame it was processed).

Overrides:
requestBoundsUpdate in class Node

updateBounds

protected void updateBounds()
Update this node's bounds and then call the parent to update it's bounds. Used to propogate bounds changes from the leaves of the tree to the root. A node implementation may decide when and where to tell the parent(s)s that updates are ready.

Overrides:
updateBounds in class Node

setParent

protected void setParent(Node p)
                  throws AlreadyParentedException,
                         InvalidNodeTypeException,
                         CyclicSceneGraphStructureException
Specify this nodes parent, overridden to provide behaviour that appends the node to the list rather than replacing it. The parent must be a group node in this case.

Overrides:
setParent in class Node
Parameters:
p - The new parent instance to add to the list
Throws:
AlreadyParentedException - There is a valid parent already set
InvalidNodeTypeException - Not a group node
CyclicSceneGraphStructureException - Equal parent and child causing a cycle in the scene graph structure

removeParent

protected void removeParent(Node p)
Remove a parent from this shared group. Since setParent() cannot be used to remove a parent from the graph, you'll need to use this method to remove the parent.

Overrides:
removeParent in class Node
Parameters:
p - The new parent instance to remove from the list

getParent

public Node getParent()
Overridden to always return the current first parent in the list.

Overrides:
getParent in class Node
Returns:
parent[0] if there are any

setLive

protected void setLive(boolean state)
Notification that this object is live now.

Overrides:
setLive in class SceneGraphObject
Parameters:
state - true if this should be marked as live now

setUpdateHandler

protected void setUpdateHandler(NodeUpdateHandler handler)
Set the scenegraph update handler for this node. It will notify all its children of the value. A null value will clear the current handler.

Overrides:
setUpdateHandler in class SceneGraphObject
Parameters:
handler - The instance to use as a handler

checkForCyclicParent

protected void checkForCyclicParent(SceneGraphObject child)
                             throws CyclicSceneGraphStructureException
Check to see if this node is the same reference as the passed node. This is the upwards check to ensure that there is no cyclic scene graph structures at the point where someone adds a node to the scenegraph. When the reference and this are the same, an exception is generated. If not, then the code will find the parent of this class and invoke this same method on the parent.

Overrides:
checkForCyclicParent in class Node
Parameters:
child - The reference to check against this class
Throws:
CyclicSceneGraphStructureException - Equal parent and child

setPickMask

public void setPickMask(int state)
Set the node as being pickable currently using the given bit mask. A mask of 0 will completely disable picking.

Specified by:
setPickMask in interface PickableObject
Parameters:
state - A bit mask of available options to pick for

getPickMask

public int getPickMask()
Get the current pickable state mask of this object. A value of zero means it is completely unpickable.

Specified by:
getPickMask in interface PickableObject
Returns:
A bit mask of available options to pick for

pickBatch

public void pickBatch(PickRequest[] reqs,
                      int numRequests)
               throws NotPickableException,
                      InvalidPickTimingException
Check for all intersections against this geometry and it's children to see if there is an intersection with the given set of requests.

Specified by:
pickBatch in interface PickableObject
Parameters:
reqs - The list of picks to be made, starting at this object
numRequests - The number of valid pick requests to process
Throws:
NotPickableException - This object has been marked as non pickable, but you decided to try to call the method anyway
InvalidPickTimingException - An attempt was made to pick outside of the ApplicationUpdateObserver callback method

pickSingle

public void pickSingle(PickRequest req)
                throws NotPickableException,
                       InvalidPickTimingException
Check for all intersections against this geometry and it's children to see if there is an intersection with the given set of requests.

Specified by:
pickSingle in interface PickableObject
Parameters:
req - The details of the pick to be made
Throws:
NotPickableException - This object has been marked as non pickable, but you decided to try to call the method anyway
InvalidPickTimingException - An attempt was made to pick outside of the ApplicationUpdateObserver callback method

getPickableChild

public PickTarget getPickableChild()
Return the child that is pickable of from this target. If there is none then return null.

Specified by:
getPickableChild in interface SinglePickTarget
Returns:
The child pickable object or null

getPickTargetType

public final int getPickTargetType()
Return the type constant that represents the type of pick target this is. Used to provided optimised picking implementations.

Specified by:
getPickTargetType in interface PickTarget
Returns:
One of the _PICK_TYPE constants

checkPickMask

public boolean checkPickMask(int mask)
Check the given pick mask against the node's internal pick mask representation. If there is a match in one or more bitfields then this will return true, allowing picking to continue to process for this target.

Specified by:
checkPickMask in interface PickTarget
Parameters:
mask - The bit mask to check against
Returns:
true if the mask has an overlapping set of bitfields

getPickableBounds

public BoundingVolume getPickableBounds()
Get the bounds of this picking target so that testing can be performed on the object.

Specified by:
getPickableBounds in interface PickTarget
Returns:
A representation of the volume representing the pickable objects

numParents

public int numParents()
Request the number of parents this node currently contains

Returns:
a positive number

getParents

public void getParents(Node[] parents)
Get the listing of the number of parents that this node currently has. The provided array must be at least big enough to copy all the values into it.

Parameters:
parents - An array to copy the parent listing into

setChild

public void setChild(Node child)
              throws CyclicSceneGraphStructureException
Set the child to be the new value. If the existing child is set, it is replaced by this current child. Setting a value of null will remove the old one.

Parameters:
child - The new instance to set or null
Throws:
CyclicSceneGraphStructureException - Equal parent and child causing a cycle in the scene graph structure
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener bounds callback method

getChild

public Node getChild()
Get the currently set child of this node. If there is none set, the return null.

Returns:
The current child or null

Aviatrix3D
2.1.0

Latest Info from http://aviatrix3d.j3d.org/
Copyright © 2003 - 2009 j3d.org