hmi.graphics.scenegraph
Class VertexAttribute

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

public class VertexAttribute
extends XMLStructureAdapter

A VertexAttribute defines the data for a single mesh vertex attribute, which can be either a predefined OpenGL attribute or a user-defined GLSL attribute. A VertexAttribute can be indexed data, in which case the index is specific for this VertexAttribute. (The alternative is to maintain a common index in GMesh, in which case the VertexData-specific index is removed, by means of the deindexify method. The plain vertex data is kept in an float array; the actual list size is are returned by the getVertexDataSize method (less then or equal to the the physical vertexData array length) A single attribute value will (usually) occupy between 1 and 4 floats. The actual number is kept as the attributeValueSize. The number of distinct attribute values is returned by getNrOfValues(). It is by definition equal to vertexDataSize/attributeValueSize; The index data is kept in an int array, where the list size is returned by getNrOfIndices(), which is less than or equal to the physical length of the int array returned by getIndices(). The vertexData and indexData arrays can be set directly, or thay can be modified via the addAttributeValuef* and addIndex methods. (These methods take care of allocating and (if necessary) resizing the data arrays.)

Author:
Job Zwiers

Field Summary
private  int attributeValueSize
           
private static int DATAITEMSPERLINE
           
private  int[] indexData
           
private  int indexDataSize
           
private static int INDICESPERLINE
           
private  String name
           
private static boolean showVertexAttributeData
           
private  float[] vertexData
           
private  int vertexDataSize
           
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
VertexAttribute()
           
VertexAttribute(String name)
          The constructor, defining the attribute name.
VertexAttribute(String name, int attributeValueSize)
          The constructor, defining the attribute name and the size of a single attribute value, in number of floats.
VertexAttribute(String name, int attributeValueSize, float[] vertexData)
          The constructor, defining the attribute name and the size of a single attribute value, in number of floats.
VertexAttribute(String name, int attributeValueSize, float[] vertexData, int[] indexData)
          The constructor, defining the attribute name and the size of a single attribute value, in number of floats.
VertexAttribute(XMLTokenizer tokenizer)
           
 
Method Summary
 void addAttributeValue1f(float x)
          Add a single float to the vertexData array;
 void addAttributeValue2f(float x, float y)
          Add a two floats to the vertexData array;
 void addAttributeValue3f(float x, float y, float z)
          Add a three floats to the vertexData array;
 void addAttributeValue4f(float x, float y, float z, float w)
          Add a four floats to the vertexData array;
 void addIndex(int idx)
          Add an index to the indexData array;
 void affineTransform(float[] mat4X4)
          Transforms the attribute values, using the specified 4x4 matrix.
 StringBuilder appendAttributeString(StringBuilder buf, XMLFormatting fmt)
          appends the attributes to buf.
 StringBuilder appendContent(StringBuilder buf, XMLFormatting fmt)
          Appends the attribute values to an XML encoding
 void decodeAttributes(HashMap<String,String> attrMap, XMLTokenizer tokenizer)
          decodes the attributes.
 void decodeContent(XMLTokenizer tokenizer)
          Decodes the attribute values from an XML encoding
private  void ensureIndexDataArraySize(int requestedSize)
           
private  void ensureVertexDataArraySize(int requestedSize)
           
 int getAttributeValueSize()
          Returns the attribute value size.
 int[] getIndexData()
          Returns the indexData array.
 String getName()
          Returns the attribute name
 int getNrOfIndices()
          Returns the number of indices, that is, size of the indexData. (<= indexData.length)
 int getNrOfValues()
          Returns the number of vertex data values, that is, vertexDataSize / attributeValueSize
 float[] getVertexData()
          Returns the vertexData array.
 int getVertexDataSize()
          Returns the size of the vertexData. (<= vertexData.length)
 String getXMLTag()
          returns the XML Stag for XML encoding
 boolean hasIndex()
          Returns true iff this VertexAttribute has (attribute-specific) index data.
 void linearTransform(float[] mat3X3)
          Transforms the attribute values, using the specified 3x3 matrix.
 void readBinary(DataInput dataIn)
           
protected  void remapData(int nrOfDistinctVertices, int[] map)
           
 void setAttributeValueSize(int attributeValueSize)
          Sets the attribute value size
 void setIndexData(int[] indexData)
          Sets the indexData array.
static void setShowVertexAttributeData(boolean show)
           
 void setVertexData(float[] vertexData)
          Sets the vertexData array.
static boolean showVertexAttributeData()
           
 String toString()
          appends the id and sid XML attributes to buf.
 void writeBinary(DataOutput dataOut)
           
static String xmlTag()
          The XML Stag 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, appendAttributes, 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

name

private String name

vertexData

private float[] vertexData

vertexDataSize

private int vertexDataSize

indexDataSize

private int indexDataSize

indexData

private int[] indexData

attributeValueSize

private int attributeValueSize

showVertexAttributeData

private static boolean showVertexAttributeData

DATAITEMSPERLINE

private static final int DATAITEMSPERLINE
See Also:
Constant Field Values

INDICESPERLINE

private static final int INDICESPERLINE
See Also:
Constant Field Values

XMLTAG

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

VertexAttribute

public VertexAttribute()

VertexAttribute

public VertexAttribute(String name)
The constructor, defining the attribute name. The atributeValueSize is not defined, and no vertexData or indexData is allocated.


VertexAttribute

public VertexAttribute(String name,
                       int attributeValueSize)
The constructor, defining the attribute name and the size of a single attribute value, in number of floats. No vertexData or indexData is allocated.


VertexAttribute

public VertexAttribute(String name,
                       int attributeValueSize,
                       float[] vertexData)
The constructor, defining the attribute name and the size of a single attribute value, in number of floats. No indexData is allocated.


VertexAttribute

public VertexAttribute(String name,
                       int attributeValueSize,
                       float[] vertexData,
                       int[] indexData)
The constructor, defining the attribute name and the size of a single attribute value, in number of floats.


VertexAttribute

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

getName

public String getName()
Returns the attribute name


getAttributeValueSize

public int getAttributeValueSize()
Returns the attribute value size. This value is usually 1, 2, or 4.


setAttributeValueSize

public void setAttributeValueSize(int attributeValueSize)
Sets the attribute value size


setVertexData

public void setVertexData(float[] vertexData)
Sets the vertexData array. Also sets vertexDataSize to vertexData.length


getVertexData

public float[] getVertexData()
Returns the vertexData array.


getVertexDataSize

public int getVertexDataSize()
Returns the size of the vertexData. (<= vertexData.length)


getNrOfValues

public int getNrOfValues()
Returns the number of vertex data values, that is, vertexDataSize / attributeValueSize


setIndexData

public void setIndexData(int[] indexData)
Sets the indexData array. Also sets indexDataSize to indexData.length


addIndex

public void addIndex(int idx)
Add an index to the indexData array;


hasIndex

public boolean hasIndex()
Returns true iff this VertexAttribute has (attribute-specific) index data.


getIndexData

public int[] getIndexData()
Returns the indexData array.


getNrOfIndices

public int getNrOfIndices()
Returns the number of indices, that is, size of the indexData. (<= indexData.length)


addAttributeValue1f

public void addAttributeValue1f(float x)
Add a single float to the vertexData array;


addAttributeValue2f

public void addAttributeValue2f(float x,
                                float y)
Add a two floats to the vertexData array;


addAttributeValue3f

public void addAttributeValue3f(float x,
                                float y,
                                float z)
Add a three floats to the vertexData array;


addAttributeValue4f

public void addAttributeValue4f(float x,
                                float y,
                                float z,
                                float w)
Add a four floats to the vertexData array;


ensureVertexDataArraySize

private void ensureVertexDataArraySize(int requestedSize)

ensureIndexDataArraySize

private void ensureIndexDataArraySize(int requestedSize)

remapData

protected void remapData(int nrOfDistinctVertices,
                         int[] map)

affineTransform

public void affineTransform(float[] mat4X4)
Transforms the attribute values, using the specified 4x4 matrix. It is assumed that the attribute size is either 3, or 4. In the latter case, the 4th value is not modified; basically we assume that it is the 1.0 value for homogeneous coordinates. The length 3 vectors are transformed by means of the rotation/scaling part of m4x4, and translated by the elements from the last column. The bottom row of m4x4 is ignored, and need not even be present. (I.e. m4x4 can be a 4x4 matrix, of length 16, or a 3x4 matrix, of length 12)


linearTransform

public void linearTransform(float[] mat3X3)
Transforms the attribute values, using the specified 3x3 matrix. It is assumed that the attribute size is 3.


toString

public String toString()
appends the id and sid XML attributes to buf.

Overrides:
toString in class XMLStructureAdapter

setShowVertexAttributeData

public static void setShowVertexAttributeData(boolean show)

showVertexAttributeData

public static boolean showVertexAttributeData()

appendAttributeString

public StringBuilder appendAttributeString(StringBuilder buf,
                                           XMLFormatting fmt)
appends the attributes to buf.

Overrides:
appendAttributeString in class XMLStructureAdapter

decodeAttributes

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

Overrides:
decodeAttributes in class XMLStructureAdapter

appendContent

public StringBuilder appendContent(StringBuilder buf,
                                   XMLFormatting fmt)
Appends the attribute values to an XML encoding

Overrides:
appendContent in class XMLStructureAdapter

decodeContent

public void decodeContent(XMLTokenizer tokenizer)
                   throws IOException
Decodes the attribute values from an XML encoding

Overrides:
decodeContent in class XMLStructureAdapter
Throws:
IOException

xmlTag

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


getXMLTag

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

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

writeBinary

public void writeBinary(DataOutput dataOut)
                 throws IOException
Throws:
IOException

readBinary

public void readBinary(DataInput dataIn)
                throws IOException
Throws:
IOException