Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Actorics/JointDataSequencer.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file JointDataSequencer.cpp
    00003 *
    00004 * Implementation of JointDataSequencer class.
    00005 *
    00006 * @author Max Risler
    00007 */
    00008
    00009 #include "JointDataSequencer.h"
    00010
    00011 JointDataSequencer::JointDataSequencer()
    00012 {
    00013   running = false;
    00014 }
    00015
    00016 JointDataSequencer& JointDataSequencer::operator=(const JointDataSequence& other)
    00017 {
    00018   numOfEntries = other.numOfEntries;
    00019   loop = other.loop;
    00020   for (int i = 0; i < numOfEntries; i++)
    00021   {
    00022     entry[i] = other.entry[i];
    00023     interpolate[i] = other.interpolate[i];
    00024     repeats[i] = other.repeats[i];
    00025   }
    00026
    00027   running = false;
    00028
    00029   return *this;
    00030 }
    00031
    00032 bool JointDataSequencer::isRunning()
    00033 {
    00034   return running;
    00035 }
    00036
    00037 void JointDataSequencer::start()
    00038 {
    00039   running = (numOfEntries>0);
    00040   sequencePos = 0;
    00041   repetitionCounter = 0;
    00042 }
    00043
    00044 void JointDataSequencer::stop()
    00045 {
    00046   running = false;
    00047 }
    00048
    00049 void JointDataSequencer::nextSequenceData(JointData& jointData)
    00050 {
    00051   if (!running) return;
    00052
    00053   //set next data
    00054   if (interpolate[sequencePos] && sequencePos > 0)
    00055     interpolateJointData(jointData,entry[sequencePos-1],entry[sequencePos],repetitionCounter,repeats[sequencePos]);
    00056   else if (interpolate[sequencePos] && sequencePos == 0 && loop)
    00057   interpolateJointData(jointData,entry[numOfEntries - 1],entry[0],repetitionCounter,repeats[sequencePos]);
    00058   else
    00059     jointData = entry[sequencePos];
    00060
    00061   //increase position in sequence
    00062   repetitionCounter++;
    00063   if (repetitionCounter >= repeats[sequencePos])
    00064   {
    00065     //finished repeating current line
    00066     repetitionCounter = 0;
    00067     sequencePos++;
    00068     if (sequencePos >= numOfEntries)
    00069     {
    00070       //finished sequence
    00071       if (loop)
    00072         //repeat
    00073         sequencePos = 0;
    00074       else
    00075         //finished
    00076         running = false;
    00077     }
    00078   }
    00079 }
    00080
    00081 void JointDataSequencer::interpolateJointData(
    00082     JointData& jointData,
    00083     const JointData& from, const JointData& to, int step, int len
    00084     )
    00085 {
    00086   for (int i = 0; i < JointData::numOfJoint; i++)
    00087     if (from.data[i] == jointDataInvalidValue || to.data[i] == jointDataInvalidValue)
    00088       jointData.data[i] = jointDataInvalidValue;
    00089     else
    00090       jointData.data[i] =
    00091         from.data[i] +
    00092         (to.data[i] - from.data[i]) * step / len;
    00093 }