hmi.animation
Class SkeletonInterpolator

java.lang.Object
  extended by hmi.xml.XMLStructureAdapter
      extended by hmi.animation.SkeletonInterpolator
All Implemented Interfaces:
ClockListener, XMLStructure

public class SkeletonInterpolator
extends XMLStructureAdapter
implements ClockListener

A SkeletonInterpolator is an interpolator for simultaneous animation of several selected parts of a VObject tree. It is assumed that the joints of this skeleton tree have rotations that are to be interpolated. Optionally, the root joint has also a translation that must be interpolated. Scaling, if any, or translation of joints other than the root are considered to be fixed.


Field Summary
private  float[] buf
           
private  ConfigList configs
           
private  int configSize
           
private  String configType
           
private static String[] empty_PartIds
           
private  boolean hasAngularVelocity
           
private  boolean hasRootTranslation
           
private  boolean hasRotation
           
private  boolean hasScale
           
private  boolean hasTranslation
           
private  boolean hasVelocity
           
private  double interval
           
private static org.slf4j.Logger logger
           
private  float[] lowerConfig
           
private  int lowerIndex
           
private  double lowerTime
           
private  String[] partIds
           
private  String rotationEncoding
           
private  int stride
           
private  VJoint target
           
private  VObject[] targetParts
           
private  float[] upperConfig
           
private  int upperIndex
           
private  double upperTime
           
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
SkeletonInterpolator()
           
SkeletonInterpolator(SkeletonInterpolator p)
           
SkeletonInterpolator(SkeletonInterpolator p, VObject[] targetParts)
           
SkeletonInterpolator(String[] partIds, ConfigList configs, String configType)
          Creates a new SkeletonInterpolator for a specified ConfigList, VParts, and Config type.
SkeletonInterpolator(XMLTokenizer tokenizer)
          Creates a new, uninitialized, SkeletonInterpolator
 
Method Summary
 StringBuilder appendAttributeString(StringBuilder buf)
          Appends a String of signature attributes to buf
 StringBuilder appendContent(StringBuilder buf, XMLFormatting fmt)
          Appends the config elements as XML content.
private  void calculateConfigSize()
           
private  void convertFromAxisAngles()
           
 void decodeAttributes(HashMap<String,String> attrMap, XMLTokenizer tokenizer)
          decodes the XML attributes
 void decodeContent(String data)
           
 void decodeContent(XMLTokenizer xmlTokenizer)
          Decodes XML content, and converts it into the double time values and float cofig data.
 void filterJoints(Set<String> joints)
          Filter out all parts that are not in joints
private  void filterTargetParts(Set<String> joints)
           
 float[] getConfig(int i)
          Returns the Config at index i
 ConfigList getConfigList()
          Gets the Config list
 int getConfigSize()
          Returns the (uniform) size of configs, in number of floats.
 String getConfigType()
          Returns the configuration type, as encoded conform VOBject types.
 double getEndTime()
           
 float[] getInterpolatedConfig(double t, float[] conf)
          Returns the interpolated config array for the specified time t, in the specified conf float array.
private  float getInterpolationConfigs(double t)
          Finds the interval [lowerIndex, upperIndex] for a specified time t, such that time[lowerIndex] <= t < time[upperIndex], where upperIndex == lowerIndex+1.
 String[] getPartIds()
          Returns the list of ids of the VObject parts that are influenced by this interpolator.
 double getStartTime()
           
 VObject[] getTargetParts()
           
 double getTime(int i)
          Returns the time for config i
private  int getWidth(int partIndex)
           
 String getXMLTag()
          The XML Stag for XML encoding -- use this method to find out the run-time xml tag of an object
 void initTime(double t)
          The time method for the ClockListener interface; equivalent to interpolateTargetParts
 void interpolateMillis(long time)
          calculates the current config for the specified time in milliseconds and copies it to the current target
 void interpolateTargetParts(double time)
          Interpolates two float array configurations lowerConfig and upperConfig, and places the result in the target VObjects.
 void mirror()
          Mirrors all joint rotations on the XY plane, switches left/right partIds
private  void mirrorParts(int i)
           
static SkeletonInterpolator read(Resources resources, String fileName)
          Creates a new SkeletonInterpolator from an XML encoded file.
static SkeletonInterpolator read(String fileName)
          Creates a new SkeletonInterpolator from an XML encoded file.
static SkeletonInterpolator read(String resourceDir, String fileName)
          Creates a new SkeletonInterpolator from an XML encoded file.
 void sampleTargetParts(double time)
          Samples the transformations from the target VObjects, and stores these as configuration, sor the specified time.
 void setConfigList(ConfigList configs)
          Sets the ConfigList, defining the VPartsConfigs to be interpolated.
 void setConfigType(String configType)
           
 void setPartIds(String[] partIds)
          Sets the list of VObject ids/sids
 void setRotationEncoding(String rotationEncoding)
           
 void setTarget(VJoint target)
          Sets a specified VJoint as target for interpolation A lookup is performed for parts of the target with Id/Sid/Name as defined by the partIds for this interpolator.
 void setTargetParts(int c)
          Set targetparts to the configlist at frame c
 int size()
          returns the size of the list
 void time(double t)
          The time method for the ClockListener interface; equivalent to interpolateTargetParts
static String xmlTag()
          The XML Stag for XML encoding -- use this static method when you want to see if a given String equals the xml tag for this class
 
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, toString, 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

logger

private static org.slf4j.Logger logger

empty_PartIds

private static final String[] empty_PartIds

partIds

private String[] partIds

configs

private ConfigList configs

configType

private String configType

configSize

private int configSize

stride

private int stride

hasRootTranslation

private boolean hasRootTranslation

hasTranslation

private boolean hasTranslation

hasRotation

private boolean hasRotation

hasScale

private boolean hasScale

hasVelocity

private boolean hasVelocity

hasAngularVelocity

private boolean hasAngularVelocity

rotationEncoding

private String rotationEncoding

targetParts

private VObject[] targetParts

target

private VJoint target

lowerIndex

private int lowerIndex

upperIndex

private int upperIndex

lowerTime

private double lowerTime

upperTime

private double upperTime

interval

private double interval

lowerConfig

private float[] lowerConfig

upperConfig

private float[] upperConfig

buf

private float[] buf

XMLTAG

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

SkeletonInterpolator

public SkeletonInterpolator(XMLTokenizer tokenizer)
                     throws IOException
Creates a new, uninitialized, SkeletonInterpolator

Throws:
IOException

SkeletonInterpolator

public SkeletonInterpolator(String[] partIds,
                            ConfigList configs,
                            String configType)
Creates a new SkeletonInterpolator for a specified ConfigList, VParts, and Config type. The Config type should be a String like "T1R" or "R", or "TRSVW".


SkeletonInterpolator

public SkeletonInterpolator(SkeletonInterpolator p,
                            VObject[] targetParts)

SkeletonInterpolator

public SkeletonInterpolator(SkeletonInterpolator p)

SkeletonInterpolator

public SkeletonInterpolator()
Method Detail

setConfigList

public void setConfigList(ConfigList configs)
Sets the ConfigList, defining the VPartsConfigs to be interpolated.


getConfigList

public ConfigList getConfigList()
Gets the Config list


setPartIds

public void setPartIds(String[] partIds)
Sets the list of VObject ids/sids


getPartIds

public String[] getPartIds()
Returns the list of ids of the VObject parts that are influenced by this interpolator.


getConfigType

public String getConfigType()
Returns the configuration type, as encoded conform VOBject types.


setConfigType

public void setConfigType(String configType)

calculateConfigSize

private void calculateConfigSize()

setRotationEncoding

public void setRotationEncoding(String rotationEncoding)

getConfigSize

public int getConfigSize()
Returns the (uniform) size of configs, in number of floats.


size

public int size()
returns the size of the list


getTime

public double getTime(int i)
Returns the time for config i


getConfig

public float[] getConfig(int i)
Returns the Config at index i


getStartTime

public double getStartTime()

getEndTime

public double getEndTime()

setTarget

public void setTarget(VJoint target)
Sets a specified VJoint as target for interpolation A lookup is performed for parts of the target with Id/Sid/Name as defined by the partIds for this interpolator.


getWidth

private int getWidth(int partIndex)

filterTargetParts

private void filterTargetParts(Set<String> joints)

filterJoints

public void filterJoints(Set<String> joints)
Filter out all parts that are not in joints


interpolateMillis

public void interpolateMillis(long time)
calculates the current config for the specified time in milliseconds and copies it to the current target


getInterpolatedConfig

public float[] getInterpolatedConfig(double t,
                                     float[] conf)
Returns the interpolated config array for the specified time t, in the specified conf float array. If the latter is null, a new float array is allocated.


initTime

public void initTime(double t)
The time method for the ClockListener interface; equivalent to interpolateTargetParts

Specified by:
initTime in interface ClockListener

time

public void time(double t)
The time method for the ClockListener interface; equivalent to interpolateTargetParts

Specified by:
time in interface ClockListener

setTargetParts

public void setTargetParts(int c)
Set targetparts to the configlist at frame c


interpolateTargetParts

public void interpolateTargetParts(double time)
Interpolates two float array configurations lowerConfig and upperConfig, and places the result in the target VObjects. Only translation, rotation, and scale can be interpolated. The type parameter determines the types of the configuration, and how to interpolate individual elements of the configurations, like lerp, quaternion slerp. It is assumed that all arrays are allocated, i.e. non-null, and have the appropriate length.


getInterpolationConfigs

private final float getInterpolationConfigs(double t)
Finds the interval [lowerIndex, upperIndex] for a specified time t, such that time[lowerIndex] <= t < time[upperIndex], where upperIndex == lowerIndex+1. This assumes that 1) the list is non-empty, 2) time[0] <= t < time[listSize-1] 3) previous values of lowerIndex and upperIndex are such that lowerIndex==upperIndex or lowerIndex+1==upperIndex. In this case, true is returned. Special case 1: when size() == 0, false is returned and lowerIndex == upperIndex ==0. Special case 2): when t < time[0], false is returned and lowerIndex == upperIndex ==0 Special case 3) : when t>= time[listSize-1], false is returned and lowerIndex == upperIndex == listSize-1 or when t < time[0], then the interval is [0, 0], i.e lowerIndex==upperIndex==0 On the other hand, when time[listSize-1] <= t then the interval is defined to be [listSize-1, listSize-1] The two indices are always legal indices, i.e. inside the list range, except when the list is empty. Upon return the following fields are set: lowerIndex, upperIndex lowerTime, upperTime lowerConfig, UpperConfig The interpolation weight factor alpha is returned. Example: for a list with listSize==5, and with time stamps as follows: [100, 200, 200, 200, 300], we have: findInterpolateInterval(0) = findInterpolateInterval(99) = [0, 0] findInterpolateInterval(100) = findInterpolateInterval(150) = [0, 1] findInterpolateInterval(200) = findInterpolateInterval(250) = [3, 4] findInterpolateInterval(300) = findInterpolateInterval(500) = [4, 4]


sampleTargetParts

public void sampleTargetParts(double time)
Samples the transformations from the target VObjects, and stores these as configuration, sor the specified time.


mirrorParts

private void mirrorParts(int i)

mirror

public void mirror()
Mirrors all joint rotations on the XY plane, switches left/right partIds


appendAttributeString

public StringBuilder appendAttributeString(StringBuilder buf)
Appends a String of signature attributes to buf

Overrides:
appendAttributeString in class XMLStructureAdapter

decodeAttributes

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

Overrides:
decodeAttributes in class XMLStructureAdapter

appendContent

public StringBuilder appendContent(StringBuilder buf,
                                   XMLFormatting fmt)
Appends the config elements as XML content.

Overrides:
appendContent in class XMLStructureAdapter

decodeContent

public void decodeContent(XMLTokenizer xmlTokenizer)
                   throws IOException
Decodes XML content, and converts it into the double time values and float cofig data.

Overrides:
decodeContent in class XMLStructureAdapter
Throws:
IOException

decodeContent

public void decodeContent(String data)

convertFromAxisAngles

private void convertFromAxisAngles()

read

public static SkeletonInterpolator read(Resources resources,
                                        String fileName)
                                 throws IOException
Creates a new SkeletonInterpolator from an XML encoded file. The first argument must be a Resources object that determines the resource directory, whereas the seond argument must be the filename relative to the resource directory.

Throws:
IOException

read

public static SkeletonInterpolator read(String resourceDir,
                                        String fileName)
                                 throws IOException
Creates a new SkeletonInterpolator from an XML encoded file. The first argument must be a the resource directory, relative to the project's resource directory. The seond argument must be the filename relative to the specified resource directory.

Throws:
IOException

read

public static SkeletonInterpolator read(String fileName)
                                 throws IOException
Creates a new SkeletonInterpolator from an XML encoded file. The specified file name must be relative to the project's resource directory.

Throws:
IOException

xmlTag

public static String xmlTag()
The XML Stag for XML encoding -- use this static method when you want to see if a given String equals the xml tag for this class


getXMLTag

public String getXMLTag()
The XML Stag for XML encoding -- use this method to find out the run-time xml tag of an object

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

getTargetParts

public VObject[] getTargetParts()
Returns:
the targetParts