hmi.graphics.scenegraph
Class GNode

java.lang.Object
  extended by hmi.xml.XMLStructureAdapter
      extended by hmi.graphics.scenegraph.GNode
All Implemented Interfaces:
XMLStructure

public class GNode
extends XMLStructureAdapter

GNode represent a scenegraph node, that contains GNode typed children, references GShapes, and specifies a local 3D transformation. The latter is specified by either a 4X4 matrix, and/or by the following:

It is allowed to set either the matrix, or the rotation/translation/scaling attributes, then ask for any of them; automatic conversion between these two alternatives is performed.

Author:
Job Zwiers

Nested Class Summary
static interface GNode.Predicate
          GNode.Predicates are Objects that implement a boolean test on GNodes, in the form of their "valid" method.
 
Field Summary
private static List<GNode> EMPTYGNODELIST
           
private static List<GShape> EMPTYGSHAPELIST
           
private  List<GNode> gnodes
           
private  List<GShape> gshapes
           
private  String id
           
private  VJoint joint
           
private static int LISTSIZE
           
private  String name
           
private  GNode parent
           
private  String sid
           
private  String type
           
private  float[] vec
           
private static String XMLTAG
           
 
Fields inherited from class hmi.xml.XMLStructureAdapter
ATTRIBUTE_TOKEN_DELIMITERS, COMMA_SEPARATOR, DECODEDARRAYSIZE, DEFAULT_RECOVER_MODE, NEWLINE, SYSTEMNEWLINE, TAB, TAB_STRING
 
Constructor Summary
GNode()
          Creates a new GNode with null id.
GNode(String id)
          Creates a new GNode with specified id.
GNode(XMLTokenizer tokenizer)
           
 
Method Summary
 void addGNode(GNode sn)
          Adds some GNode as a child node.
 void addGShape(GShape gshape)
          Adds a GShape
 void addGShapes(List<GShape> gshapeList)
          Adds all elements of a List of GShapes
 void affineTransform(float[] mat4x4)
           
 void affineTransformGShapes(float[] mat4x4)
           
 StringBuilder appendAttributes(StringBuilder buf)
          appends the id, sid, name XML attributes to buf.
 StringBuilder appendContent(StringBuilder buf, XMLFormatting fmt)
          Appends a String to buf that encodes the contents for the XML encoding.
 void clearJointRotations()
           
 void clearLocalLinearTransform()
           
 void clearRotations()
           
 void decodeAttributes(HashMap<String,String> attrMap, XMLTokenizer tokenizer)
          decodes the id and sid XML attributes.
 void decodeContent(XMLTokenizer tokenizer)
          decodes the XML contents, i.e. the XML between the STag and ETag of the encoding.
 float[] getGlobalMatrix()
          Gets the global transform matrix of the associated VJoint
 List<GNode> getGNodes()
          Returns a List with GNode children of this GNode.
 List<GShape> getGShapes()
          Returns a List with the GShape children of this GNode.
 String getId()
          Returns the id attribute.
 float[] getLocalMatrix()
          Gets the local transform matrix of the associated VJoint
 String getName()
          Returns the name attribute.
 GNode getParent()
          Returns the parent GNode of this GNode, which could be null.
 GNode getPartById(String id)
          Searches for a GNode with specified id.
 GNode getPartByNamePattern(Pattern namePat)
          Searches for a GNode with a name matching the specified (java.util.regex) regular pattern.
 GNode getPartByNamePattern(String namePattern)
          Searches for a GNode with a name matching the specified regular pattern.
 GNode getPartBySid(String sid)
          Searches for a GNode with specified sid.
 String getSid()
          Returns the Collada sid attribute.
 void getTranslation(float[] result)
           
 String getType()
          Returns the Collada type attribute.
 VJoint getVJoint()
           
 String getXMLTag()
          returns the XML tag for XML encoding
 boolean hasGShapes()
          Determines whether a GNode based scene graph, with this GNode as root, includes some GShapes at all.
 void removeGNode(GNode sn)
          Removes the specified GNode from the List of child gnodes.
 void removeLinearTransforms()
          Removes the scaling and rotation transformations from this scenegraph by applying the linear part of the transformations to geometry.
 void removeLinearTransforms(float[] mat3x3)
          Removes the linear component of the transform of this GNode and its descendant.
 void renameJoints(Map<String,String> renaming)
          recursively renames the sids and names of GNodes
 List<GNode> selectGNodes()
          Selects recursively all offspring
 List<GNode> selectGNodes(GNode.Predicate select)
          Selects recursively all child GNodes that satisfy the predicate
 List<GNode> selectGNodes(GNode.Predicate select, GNode.Predicate prune)
          Selects recursively child GNodes that satisfy the predicate.
 List<GNode> selectGNodes(GNode.Predicate select, GNode.Predicate prune, ArrayList<GNode> list)
          Selects recursively child GNodes that satisfy the predicate.
 void setId(String id)
          Sets the id attribute.
 void setLocalTransform(float[] m)
          Sets the local transform matrix of the associated VJoint
 void setName(String name)
          Sets the name attribute.
 void setRotation(float[] rotation)
          Sets the rotation quaternion of the associated VJoint
 void setScale(float[] scaleVec)
          Sets the scale vector of the associated VJoint
 void setSid(String sid)
          Sets the Collada sid attribute.
 void setSkewMatrix(float[] skewMatrix)
          Sets the skewing matrix of the associated VJoint
 void setTranslation(float[] translation)
          Sets the translation of the associated VJoint
 void setType(String type)
          Sets the Collada type attribute.
 String toString()
          Returns the XML encoding of this GNode
static String xmlTag()
          The XML tag for XML encoding
 
Methods inherited from class hmi.xml.XMLStructureAdapter
appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttributes, appendAttributeString, appendAttributeString, appendBooleans, appendCloseEmptyTag, appendCloseSTag, appendComment, appendContent, appendDoubleElement, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendETag, appendETag, appendFloatArrayElement, appendFloatElement, appendFloats, appendIntArrayElement, appendIntElement, appendInts, appendLongElement, appendNewLine, appendNewLine, appendNewLine, appendOpenSTag, appendOptionalDoubleElement, appendOptionalFloatElement, appendOptionalIntElement, appendOptionalLongElement, appendSpaces, appendSpaces, appendSTag, appendSTag, appendSTag, appendStringArrayElement, appendStrings, appendSystemNewLine, appendTab, appendTextElement, appendXML, appendXML, appendXML, appendXML, appendXML, appendXMLStructure, appendXMLStructureList, appendXMLTextElementList, countTokens, countTokens, decodeAttribute, decodeAttribute, decodeBoolean, decodeBooleanArray, decodeBooleanArray, decodeBooleanArray, decodeBooleanArray, decodeDouble, decodeDoubleArray, decodeDoubleArray, decodeDoubleArray, decodeDoubleArray, decodeFloat, decodeFloatArray, decodeFloatArray, decodeFloatArray, decodeFloatArray, decodeInt, decodeIntArray, decodeIntArray, decodeIntArray, decodeIntArray, decodeLong, decodeStringArray, decodeStringArray, decodeStringArray, decodeStringArray, decodeXMLStructureList, decodeXMLValueElement, getNamespace, getOptionalAttribute, getOptionalAttribute, getOptionalBooleanAttribute, getOptionalDoubleAttribute, getOptionalFloatAttribute, getOptionalIntAttribute, getOptionalLongAttribute, getRequiredAttribute, getRequiredBooleanAttribute, getRequiredDoubleAttribute, getRequiredFloatAttribute, getRequiredIntAttribute, getRequiredLongAttribute, getTagLine, hasContent, parseXMLElement, postProcess, preProcess, readXML, readXML, readXML, setConsoleAttributeEnabled, setDefaultRecoverMode, setRecoverMode, spaces, toXMLString, toXMLString, toXMLString, toXMLString, toXMLString, toXMLString, writeXML, writeXML, writeXML, writeXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

private String id

sid

private String sid

name

private String name

type

private String type

parent

private GNode parent

gnodes

private List<GNode> gnodes

gshapes

private List<GShape> gshapes

joint

private VJoint joint

EMPTYGNODELIST

private static final List<GNode> EMPTYGNODELIST

EMPTYGSHAPELIST

private static final List<GShape> EMPTYGSHAPELIST

vec

private float[] vec

LISTSIZE

private static final int LISTSIZE
See Also:
Constant Field Values

XMLTAG

private static final String XMLTAG
See Also:
Constant Field Values
Constructor Detail

GNode

public GNode()
Creates a new GNode with null id.


GNode

public GNode(String id)
Creates a new GNode with specified id.


GNode

public GNode(XMLTokenizer tokenizer)
      throws IOException
Throws:
IOException
Method Detail

setId

public void setId(String id)
Sets the id attribute.


getId

public String getId()
Returns the id attribute.


setSid

public void setSid(String sid)
Sets the Collada sid attribute.


getSid

public String getSid()
Returns the Collada sid attribute.


setName

public void setName(String name)
Sets the name attribute.


getName

public String getName()
Returns the name attribute.


setType

public void setType(String type)
Sets the Collada type attribute.


getType

public String getType()
Returns the Collada type attribute.


selectGNodes

public List<GNode> selectGNodes()
Selects recursively all offspring


selectGNodes

public List<GNode> selectGNodes(GNode.Predicate select)
Selects recursively all child GNodes that satisfy the predicate


selectGNodes

public List<GNode> selectGNodes(GNode.Predicate select,
                                GNode.Predicate prune)
Selects recursively child GNodes that satisfy the predicate. The recursive search is pruned for GNodes that satisfy the prune predicate


selectGNodes

public List<GNode> selectGNodes(GNode.Predicate select,
                                GNode.Predicate prune,
                                ArrayList<GNode> list)
Selects recursively child GNodes that satisfy the predicate. The recursive search is pruned for GNodes that satisfy the prune predicate. The results are added to the specified List.


getVJoint

public VJoint getVJoint()

addGNode

public void addGNode(GNode sn)
Adds some GNode as a child node. Also updates the parent-child relationship for the VJoints within thisGNode and the child GNode.


removeGNode

public void removeGNode(GNode sn)
Removes the specified GNode from the List of child gnodes.


getGNodes

public List<GNode> getGNodes()
Returns a List with GNode children of this GNode.


getParent

public GNode getParent()
Returns the parent GNode of this GNode, which could be null.


addGShape

public void addGShape(GShape gshape)
Adds a GShape


addGShapes

public void addGShapes(List<GShape> gshapeList)
Adds all elements of a List of GShapes


getGShapes

public List<GShape> getGShapes()
Returns a List with the GShape children of this GNode.


hasGShapes

public boolean hasGShapes()
Determines whether a GNode based scene graph, with this GNode as root, includes some GShapes at all.


getPartBySid

public GNode getPartBySid(String sid)
Searches for a GNode with specified sid. The search is recursive, among the child nodes of this GNode, and include this GNode as well.


getPartById

public GNode getPartById(String id)
Searches for a GNode with specified id. The search is recursive, among the child nodes of this GNode, and include this GNode as well.


getPartByNamePattern

public GNode getPartByNamePattern(String namePattern)
Searches for a GNode with a name matching the specified regular pattern. For example getPartByNamePattern(".*L.*Clavicle$") would find GNodes with names like "CWom0023-L_Clavicle" See the Javadoc for java.util.regex.Pattern for the synatx of allowed regular expressions.


getPartByNamePattern

public GNode getPartByNamePattern(Pattern namePat)
Searches for a GNode with a name matching the specified (java.util.regex) regular pattern.


renameJoints

public void renameJoints(Map<String,String> renaming)
recursively renames the sids and names of GNodes


setTranslation

public void setTranslation(float[] translation)
Sets the translation of the associated VJoint


getTranslation

public void getTranslation(float[] result)

setRotation

public void setRotation(float[] rotation)
Sets the rotation quaternion of the associated VJoint


setScale

public void setScale(float[] scaleVec)
Sets the scale vector of the associated VJoint


setSkewMatrix

public void setSkewMatrix(float[] skewMatrix)
Sets the skewing matrix of the associated VJoint


setLocalTransform

public void setLocalTransform(float[] m)
Sets the local transform matrix of the associated VJoint


getLocalMatrix

public float[] getLocalMatrix()
Gets the local transform matrix of the associated VJoint


getGlobalMatrix

public float[] getGlobalMatrix()
Gets the global transform matrix of the associated VJoint


clearLocalLinearTransform

public void clearLocalLinearTransform()

clearRotations

public void clearRotations()

clearJointRotations

public void clearJointRotations()

affineTransform

public void affineTransform(float[] mat4x4)

affineTransformGShapes

public void affineTransformGShapes(float[] mat4x4)

removeLinearTransforms

public void removeLinearTransforms()
Removes the scaling and rotation transformations from this scenegraph by applying the linear part of the transformations to geometry. Translation is modified accordingly, but not eliminated.


removeLinearTransforms

public void removeLinearTransforms(float[] mat3x3)
Removes the linear component of the transform of this GNode and its descendant. That, the upper left 3X3 part, specifying the linear transform part, will be set to identity, but a translation part will remain.


toString

public String toString()
Returns the XML encoding of this GNode

Overrides:
toString in class XMLStructureAdapter

appendAttributes

public StringBuilder appendAttributes(StringBuilder buf)
appends the id, sid, name XML attributes to buf.

Overrides:
appendAttributes in class XMLStructureAdapter

decodeAttributes

public void decodeAttributes(HashMap<String,String> attrMap,
                             XMLTokenizer tokenizer)
decodes the id and sid XML attributes.

Overrides:
decodeAttributes in class XMLStructureAdapter

appendContent

public StringBuilder appendContent(StringBuilder buf,
                                   XMLFormatting fmt)
Description copied from class: XMLStructureAdapter
Appends a String to buf that encodes the contents for the XML encoding. MUST BE OVERWRITTEN BY IMPLEMENTATIONS. (The default implementation appends nothing). The encoding should start on a new line, using indentation equal to tab. There should be no newline after the encoding.

Overrides:
appendContent in class XMLStructureAdapter

decodeContent

public void decodeContent(XMLTokenizer tokenizer)
                   throws IOException
Description copied from class: XMLStructureAdapter
decodes the XML contents, i.e. the XML between the STag and ETag of the encoding. MUST BE OVERWRITTEN BY IMPLEMENTATIONS.

Overrides:
decodeContent in class XMLStructureAdapter
Throws:
IOException

xmlTag

public static String xmlTag()
The XML tag for XML encoding


getXMLTag

public String getXMLTag()
returns the XML tag for XML encoding

Specified by:
getXMLTag in interface XMLStructure
Overrides:
getXMLTag in class XMLStructureAdapter