cz.cuni.jagrlib
Class DefaultSceneNode

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultSceneNode
All Implemented Interfaces:
IntersectionAttributes, SceneNode
Direct Known Subclasses:
CSGCommonNode

public abstract class DefaultSceneNode
extends java.lang.Object
implements SceneNode

Default implementation of scene node. Doesn't implement hierarchy-related methods.

Since:
0.25
See Also:
DefaultSceneNode.java

Field Summary
protected  int serial
          Serial number used in intersection testing.
 
Fields inherited from interface cz.cuni.jagrlib.SceneNode
ATTR_BSSRDF, ATTR_COLOR, ATTR_TEXTURE
 
Constructor Summary
DefaultSceneNode()
           
 
Method Summary
 int assertAttributes(MicroFacet mf, java.lang.Object tmp, int attributes)
          Asserts validity of the given intersection-attributes.
 java.lang.Object getAttribute(java.lang.String key)
          Returns the given attribute (defined in this SceneNode or inherited from some parent node).
 java.util.List<java.lang.Object> getAttributes(java.lang.String key)
          Returns the whole inherence-sequence for the given attribute.
 SceneNode getChild(int i)
          Returns the given child node.
 TrMatrix getChildMatrix(int i)
          Returns transformation matrix for the given child node.
 TrMatrix getChildMatrixInv(int i)
          Returns inverse transformation matrix for the given child node.
 int getOrder()
          Returns order of this SceneNode in its parent.
 SceneNode getParent()
          Returns the parent of this node.
 int getSerial()
          Sets serial number of the current test.
 int children()
          Returns number of child nodes.
 int insertChild(SceneNode child, TrMatrix m, TrMatrix mInv)
          Inserts a new child node.
 java.util.List<MicroFacet> intersection(double[] P0, double[] P1)
          Computes all intersections of the given ray with the sub-scene.
 boolean isObjectRoot()
          Returns true if this node is root of object (component) hierarchy.
 int removeChild(int i)
          Removes the given child node.
 boolean selfAttribute(java.lang.String key)
          Is the given attribute defined in the node itself or is it inherited?
 java.lang.Object setAttribute(java.lang.String key, java.lang.Object value)
          Defines the given attribute (key-value pair) in the node.
 void setObjectRoot(boolean root)
          Sets this node as root for the object (component).
 void setOrder(int ord)
          Sets order of this SceneNode in its parent.
 void setParent(SceneNode par)
          Sets handle to the parent node.
 void setSerial(int serial)
          Returns serial number assigned to the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serial

protected int serial
Serial number used in intersection testing.

Constructor Detail

DefaultSceneNode

public DefaultSceneNode()
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Returns the given attribute (defined in this SceneNode or inherited from some parent node).

Returned object can be an original data object and must not be altered outside this SceneNode instance.

Specified by:
getAttribute in interface SceneNode
Parameters:
key - Key-string.
Returns:
Attribute object or null. Must not be altered!
See Also:
getAttributes(java.lang.String), setAttribute(java.lang.String, java.lang.Object), selfAttribute(java.lang.String)

selfAttribute

public boolean selfAttribute(java.lang.String key)
Is the given attribute defined in the node itself or is it inherited?

Specified by:
selfAttribute in interface SceneNode
Parameters:
key - Key-string.
Returns:
true if the node defines the given attribute.
See Also:
getAttribute(java.lang.String), setAttribute(java.lang.String, java.lang.Object), getAttributes(java.lang.String)

setAttribute

public java.lang.Object setAttribute(java.lang.String key,
                                     java.lang.Object value)
Defines the given attribute (key-value pair) in the node.

Specified by:
setAttribute in interface SceneNode
Parameters:
key - Key-string.
value - Attribute value (arbitrary type).
Returns:
The old attribute value (defined in the node itself!) or null.
See Also:
getAttribute(java.lang.String), selfAttribute(java.lang.String), getAttributes(java.lang.String)

getAttributes

public java.util.List<java.lang.Object> getAttributes(java.lang.String key)
Returns the whole inherence-sequence for the given attribute.

Specified by:
getAttributes in interface SceneNode
Parameters:
key - Key-string.
Returns:
List of attribute values: result[0] .. definition in the node itself, result[1] .. definition in parent node, result[2] .. definition in "grand-parent" node, etc.
See Also:
getAttribute(java.lang.String), setAttribute(java.lang.String, java.lang.Object), selfAttribute(java.lang.String)

children

public int children()
Returns number of child nodes.

Specified by:
children in interface SceneNode
Returns:
Number of child nodes (= 0 for this node).
See Also:
getChild(int), getChildMatrix(int), getChildMatrixInv(int)

getChild

public SceneNode getChild(int i)
Returns the given child node.

Specified by:
getChild in interface SceneNode
Parameters:
i - Order of the requested node (from 0 to children()-1).
Returns:
The requested node or null.
See Also:
children(), getChildMatrix(int), getChildMatrixInv(int)

getChildMatrix

public TrMatrix getChildMatrix(int i)
Returns transformation matrix for the given child node.

Specified by:
getChildMatrix in interface SceneNode
Parameters:
i - Order of the child node.
Returns:
Transformation matrix from the child's coordinate system to this node's one. null stands for identity.
See Also:
children(), getChild(int), getChildMatrixInv(int)

getChildMatrixInv

public TrMatrix getChildMatrixInv(int i)
Returns inverse transformation matrix for the given child node.

Specified by:
getChildMatrixInv in interface SceneNode
Parameters:
i - Order of the child node.
Returns:
Transformation matrix from this node's coordinate system to child's one. null stands for identity.
See Also:
children(), getChild(int), getChildMatrix(int)

insertChild

public int insertChild(SceneNode child,
                       TrMatrix m,
                       TrMatrix mInv)
Inserts a new child node.

Specified by:
insertChild in interface SceneNode
Parameters:
child - The new child node.
m - Transformation matrix for the new child node (transformation from child's coordinate system to this node's one). Can be null, even for non-trivial mInv.
mInv - Inverse transformation matrix for the new child node (transformation from this node's coordinate system to child's one). Can be null, even for non-trivial m.
Returns:
Order of the inserted child node (or -1 in case of failure).
See Also:
removeChild(int), children()

removeChild

public int removeChild(int i)
Removes the given child node.

Specified by:
removeChild in interface SceneNode
Parameters:
i - Order of the child node to be removed.
Returns:
Number of child nodes after the remove-operation.
See Also:
insertChild(cz.cuni.jagrlib.SceneNode, cz.cuni.jagrlib.TrMatrix, cz.cuni.jagrlib.TrMatrix), children()

getParent

public SceneNode getParent()
Returns the parent of this node.

Specified by:
getParent in interface SceneNode
Returns:
The parend node or null for scene-root.
See Also:
setParent(cz.cuni.jagrlib.SceneNode), getOrder(), children(), getChild(int)

setParent

public void setParent(SceneNode par)
Sets handle to the parent node.

Specified by:
setParent in interface SceneNode
Parameters:
par - Parent node (or null).
See Also:
getParent()

getOrder

public int getOrder()
Returns order of this SceneNode in its parent.

Specified by:
getOrder in interface SceneNode
Returns:
Order of this node as a child (or -1 for scene-root).
See Also:
setOrder(int), getParent()

setOrder

public void setOrder(int ord)
Sets order of this SceneNode in its parent.

Specified by:
setOrder in interface SceneNode
Parameters:
ord - The new order.
See Also:
getOrder()

isObjectRoot

public boolean isObjectRoot()
Returns true if this node is root of object (component) hierarchy.

Specified by:
isObjectRoot in interface SceneNode
See Also:
setObjectRoot(boolean)

setObjectRoot

public void setObjectRoot(boolean root)
Sets this node as root for the object (component).

Specified by:
setObjectRoot in interface SceneNode
Parameters:
root - Should this node be treated as root?
See Also:
isObjectRoot()

getSerial

public int getSerial()
Sets serial number of the current test. Used in intersection testing.

Specified by:
getSerial in interface SceneNode

setSerial

public void setSerial(int serial)
Returns serial number assigned to the node.

Specified by:
setSerial in interface SceneNode

intersection

public java.util.List<MicroFacet> intersection(double[] P0,
                                               double[] P1)
Computes all intersections of the given ray with the sub-scene.

Specified by:
intersection in interface SceneNode
Parameters:
P0 - Ray origin (double[3] or double[4]).
P1 - Direction vector of the ray (double[3] or double[4]).
Returns:
List of all ray vs. sub-scene intersections.

assertAttributes

public int assertAttributes(MicroFacet mf,
                            java.lang.Object tmp,
                            int attributes)
Asserts validity of the given intersection-attributes. Doesn't resolve anything.

Specified by:
assertAttributes in interface IntersectionAttributes
Parameters:
mf - The checked intersection.
tmp - Non-mandatory object holding state-information for deferred computations.
attributes - Attribute mask (required attributes - see MicroFacet.VALID_*).
Returns:
Attributes which were not computed.