Commit 38129ec6 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

adjusted animation classes to new skeleton type

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11059 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0be64336
......@@ -56,7 +56,7 @@
* Both the reference pose and the skeleton hierarchy are not used by the animation class itself, but are
* passed to the poses.
*/
template<typename PointT>
template<class PointT>
class AnimationT
{
template<typename>
......
......@@ -59,7 +59,7 @@ using namespace std;
*
* @param _pose This pose will make up the only frame in this new animation
*/
template<typename PointT>
template<class PointT>
FrameAnimationT<PointT>::FrameAnimationT(const PoseT<PointT> &_pose) :
skeleton_(_pose.skeleton_)
{
......@@ -74,7 +74,7 @@ FrameAnimationT<PointT>::FrameAnimationT(const PoseT<PointT> &_pose) :
* @param _hierarchy The skeleton that will hold this animation
* @param _reference The skeletons reference pose
*/
template<typename PointT>
template<class PointT>
FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton) :
skeleton_(_skeleton)
{
......@@ -92,7 +92,7 @@ FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton) :
* @param _reference The skeletons reference pose
* @param _iNumFrames The number of frames for this animation
*/
template<typename PointT>
template<class PointT>
FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton, unsigned int _iNumFrames) :
skeleton_(_skeleton)
{
......@@ -110,7 +110,7 @@ FrameAnimationT<PointT>::FrameAnimationT(Skeleton* _skeleton, unsigned int _iNum
*
* @param _other The animation to copy from
*/
template<typename PointT>
template<class PointT>
FrameAnimationT<PointT>::FrameAnimationT(const FrameAnimationT<PointT> &_other) :
AnimationT<PointT>(),
skeleton_(_other.skeleton_)
......@@ -124,7 +124,7 @@ FrameAnimationT<PointT>::FrameAnimationT(const FrameAnimationT<PointT> &_other)
/**
* @brief Destructor
*/
template<typename PointT>
template<class PointT>
FrameAnimationT<PointT>::~FrameAnimationT()
{
for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
......@@ -137,7 +137,7 @@ FrameAnimationT<PointT>::~FrameAnimationT()
/**
* @brief Copy Function
*/
template<typename PointT>
template<class PointT>
AnimationT<PointT>* FrameAnimationT<PointT>::copy() {
return new FrameAnimationT<PointT>(*this);
}
......@@ -149,7 +149,7 @@ AnimationT<PointT>* FrameAnimationT<PointT>::copy() {
*
* @param _iFrame The poses frame number
*/
template<typename PointT>
template<class PointT>
typename FrameAnimationT<PointT>::Pose *FrameAnimationT<PointT>::pose(unsigned int _iFrame)
{
assert(_iFrame < poses_.size());
......@@ -162,7 +162,7 @@ typename FrameAnimationT<PointT>::Pose *FrameAnimationT<PointT>::pose(unsigned i
/**
* @brief Returns the number of frames stored in this pose
*/
template<typename PointT>
template<class PointT>
unsigned int FrameAnimationT<PointT>::frameCount()
{
return poses_.size();
......@@ -170,7 +170,7 @@ unsigned int FrameAnimationT<PointT>::frameCount()
//-----------------------------------------------------------------------------
template<typename PointT>
template<class PointT>
void FrameAnimationT<PointT>::setFrameCount(unsigned int _frames)
{
//delete poses
......@@ -195,7 +195,7 @@ void FrameAnimationT<PointT>::setFrameCount(unsigned int _frames)
* @param _index The new joint is inserted at this position. Insert new joints at the end by passing
* SkeletonT::joints_.size as parameter.
*/
template<typename PointT>
template<class PointT>
void FrameAnimationT<PointT>::insertJointAt(unsigned int _index)
{
for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
......@@ -211,7 +211,7 @@ void FrameAnimationT<PointT>::insertJointAt(unsigned int _index)
*
* @param _index The index of the joint that is being deleted.
*/
template<typename PointT>
template<class PointT>
void FrameAnimationT<PointT>::removeJointAt(unsigned int _index)
{
for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
......@@ -227,7 +227,7 @@ void FrameAnimationT<PointT>::removeJointAt(unsigned int _index)
*
* @param _index The joints index
*/
template<typename PointT>
template<class PointT>
void FrameAnimationT<PointT>::updateFromGlobal(unsigned int _index)
{
for(typename vector<Pose*>::iterator it = poses_.begin(); it != poses_.end(); ++it)
......
......@@ -45,7 +45,7 @@
#include "AnimationT.hh"
template<typename PointT>
template<class PointT>
class FrameAnimationT : public AnimationT<PointT>
{
template<typename>
......
......@@ -60,11 +60,10 @@ using namespace std;
*
* @param _other The animation to copy from
*/
template<typename Scalar>
InterpolationAnimationT<Scalar>::InterpolationAnimationT(const InterpolationAnimationT<Scalar> &_other) :
AnimationT<Scalar>(_other.name_),
hierarchy_(_other.hierarchy_),
reference_(_other.reference_),
template<class PointT>
InterpolationAnimationT<PointT>::InterpolationAnimationT(const InterpolationAnimationT<PointT> &_other) :
AnimationT<PointT>(_other.name_),
skeleton_(_other.skeleton_),
matrixManipulator_(_other.matrixManipulator_),
frames_(0)
{
......@@ -79,10 +78,9 @@ InterpolationAnimationT<Scalar>::InterpolationAnimationT(const InterpolationAnim
* @param _hierarchy The skeleton that will hold this animation
* @param _reference The skeletons reference pose
*/
template<typename Scalar>
InterpolationAnimationT<Scalar>::InterpolationAnimationT(SkeletonHierarchyI *_hierarchy, ReferencePose *_reference, MatrixManipulator *_matrixManipulator) :
hierarchy_(_hierarchy),
reference_(_reference),
template<class PointT>
InterpolationAnimationT<PointT>::InterpolationAnimationT(Skeleton* _skeleton, MatrixManipulator *_matrixManipulator) :
skeleton_(_skeleton),
matrixManipulator_(_matrixManipulator),
frames_(0)
{
......@@ -91,27 +89,25 @@ InterpolationAnimationT<Scalar>::InterpolationAnimationT(SkeletonHierarchyI *_hi
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
InterpolationAnimationT<Scalar>::~InterpolationAnimationT()
template<class PointT>
InterpolationAnimationT<PointT>::~InterpolationAnimationT()
{
clearPoseCache();
delete hierarchy_;
delete reference_;
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
AnimationT<Scalar>* InterpolationAnimationT<Scalar>::copy() {
return new InterpolationAnimationT<Scalar>(*this);
template<class PointT>
AnimationT<PointT>* InterpolationAnimationT<PointT>::copy() {
return new InterpolationAnimationT<PointT>(*this);
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame)
template<class PointT>
PoseT<PointT>* InterpolationAnimationT<PointT>::pose(unsigned int _iFrame)
{
return getPose(_iFrame, reference_);
return pose(_iFrame, skeleton_->referencePose());
}
//-----------------------------------------------------------------------------------------------------
......@@ -122,8 +118,8 @@ PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame)
* @param _iFrame The frame number for which the pose should be calculated.
* This is always from 0..#frames even if the animation starts with an input value other than 0.
*/
template<typename Scalar>
PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame, Pose* _reference)
template<class PointT>
PoseT<PointT>* InterpolationAnimationT<PointT>::pose(unsigned int _iFrame, Pose* _reference)
{
// std::cerr << "Frame " << _iFrame << ": ";
......@@ -135,7 +131,7 @@ PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame, P
if (_iFrame == 0) {
interpolatedPoses_.insert( make_pair(0, new Pose(*_reference)) );
// std::cerr << "Insert reference to posecache. &_reference: " << _reference << ", &cacheref: " << getPose(_iFrame, _reference) << std::endl;
return getPose(_iFrame, _reference);
return pose(_iFrame, _reference);
} else {
//Find the correct interpolator
Interpolator* interpolator = NULL;
......@@ -162,13 +158,13 @@ PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame, P
Pose *generatedPose = new Pose(*_reference);
for (uint i=0; i<influencedJoints_.size(); ++i) {
ACG::GLMatrixT<Scalar> transformation(generatedPose->getGlobal(influencedJoints_[i]).raw());
ACG::GLMatrixT<Scalar> transformation(generatedPose->globalMatrix(influencedJoints_[i]).raw());
//The frames for each interpolator are stored from 0..max, i.e. in "interpolator local time space".
// So, they have to be mapped to the global space here.
TargetType precalcVal = precalculations_[interpolator][_iFrame - min];
matrixManipulator_->doManipulation(transformation, precalcVal);
generatedPose->setGlobal(influencedJoints_[i], transformation, false);
generatedPose->setGlobalMatrix(influencedJoints_[i], transformation, false);
}
// std::cerr << std::endl;
......@@ -186,8 +182,8 @@ PoseT<Scalar>* InterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame, P
/**
* @brief Returns the number of frames stored in this pose
*/
template<typename Scalar>
unsigned long InterpolationAnimationT<Scalar>::getFrameCount()
template<class PointT>
unsigned int InterpolationAnimationT<PointT>::frameCount()
{
return frames_;
}
......@@ -202,8 +198,8 @@ unsigned long InterpolationAnimationT<Scalar>::getFrameCount()
* @param _index The new joint is inserted at this position. Insert new joints at the end by passing
* SkeletonT::joints_.size as parameter.
*/
template<typename Scalar>
void InterpolationAnimationT<Scalar>::insert_at(unsigned long _index)
template<class PointT>
void InterpolationAnimationT<PointT>::insertJointAt(unsigned int _index)
{
//NOOP
}
......@@ -217,8 +213,8 @@ void InterpolationAnimationT<Scalar>::insert_at(unsigned long _index)
*
* @param _index The index of the joint that is being deleted.
*/
template<typename Scalar>
void InterpolationAnimationT<Scalar>::remove_at(unsigned long _index)
template<class PointT>
void InterpolationAnimationT<PointT>::removeJointAt(unsigned int _index)
{
//NOOP
}
......@@ -233,16 +229,16 @@ void InterpolationAnimationT<Scalar>::remove_at(unsigned long _index)
*
* @param _index The joints index
*/
template<typename Scalar>
void InterpolationAnimationT<Scalar>::UpdateFromGlobal(unsigned long _index)
template<class PointT>
void InterpolationAnimationT<PointT>::updateFromGlobal(unsigned int _index)
{
//NOOP
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
void InterpolationAnimationT<Scalar>::addInterpolator(InterpolationT<double> *_interpolator) {
template<class PointT>
void InterpolationAnimationT<PointT>::addInterpolator(InterpolationT<double> *_interpolator) {
if (_interpolator == NULL)
return;
......@@ -271,9 +267,9 @@ void InterpolationAnimationT<Scalar>::addInterpolator(InterpolationT<double> *_i
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
InterpolationT<Scalar>*
InterpolationAnimationT<Scalar>::interpolator(unsigned int _index)
template<class PointT>
InterpolationT<typename PointT::value_type>*
InterpolationAnimationT<PointT>::interpolator(unsigned int _index)
{
if ( _index < interpolators_.size() )
return interpolators_[ _index ];
......@@ -283,8 +279,8 @@ InterpolationAnimationT<Scalar>::interpolator(unsigned int _index)
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
unsigned int InterpolationAnimationT<Scalar>::interpolatorCount()
template<class PointT>
unsigned int InterpolationAnimationT<PointT>::interpolatorCount()
{
return interpolators_.size();
}
......@@ -294,8 +290,8 @@ unsigned int InterpolationAnimationT<Scalar>::interpolatorCount()
/**
* \brief Calculates the last frame that interpolator _index is responsible for
*/
template<typename Scalar>
unsigned long InterpolationAnimationT<Scalar>::calcAbsoluteMaxForInterpolator(uint _index) {
template<class PointT>
unsigned int InterpolationAnimationT<PointT>::calcAbsoluteMaxForInterpolator(uint _index) {
assert (_index < interpolators_.size());
if (_index == 0) {
......@@ -307,8 +303,8 @@ unsigned long InterpolationAnimationT<Scalar>::calcAbsoluteMaxForInterpolator(ui
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
bool InterpolationAnimationT<Scalar>::getMinInput(Scalar& _result) {
template<class PointT>
bool InterpolationAnimationT<PointT>::getMinInput(Scalar& _result) {
if (interpolators_.size() == 0)
return false;
else
......@@ -324,8 +320,8 @@ bool InterpolationAnimationT<Scalar>::getMinInput(Scalar& _result) {
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
bool InterpolationAnimationT<Scalar>::getMaxInput(Scalar& _result) {
template<class PointT>
bool InterpolationAnimationT<PointT>::getMaxInput(Scalar& _result) {
if (interpolators_.size() == 0)
return false;
else
......@@ -341,8 +337,8 @@ bool InterpolationAnimationT<Scalar>::getMaxInput(Scalar& _result) {
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
bool InterpolationAnimationT<Scalar>::isInfluenced(int _joint) {
template<class PointT>
bool InterpolationAnimationT<PointT>::isInfluenced(int _joint) {
for (uint i=0; i<influencedJoints_.size(); ++i)
if ( influencedJoints_[i] == _joint )
return true;
......@@ -352,8 +348,8 @@ bool InterpolationAnimationT<Scalar>::isInfluenced(int _joint) {
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
std::vector<int>& InterpolationAnimationT<Scalar>::influencedJoints() {
template<class PointT>
std::vector<int>& InterpolationAnimationT<PointT>::influencedJoints() {
return influencedJoints_;
}
......
......@@ -50,7 +50,7 @@
#include "InterpolationT.hh"
#include "InterpolationMatrixManipulatorT.hh"
template<typename PointT>
template<class PointT>
class InterpolationAnimationT : public AnimationT<PointT>
{
template<typename>
......@@ -77,54 +77,53 @@ class InterpolationAnimationT : public AnimationT<PointT>
virtual bool getMaxInput(Scalar& _result);
protected:
SkeletonHierarchyI *hierarchy_; ///< Stores a pointer to the skeleton hierarchy, is passed to new poses as they are created
Pose *reference_; ///< Stores the reference pose attached to the skeleton, the poses use it for some precalculations
std::vector<int> influencedJoints_;
std::vector< Interpolator* > interpolators_;
//Hier muss es einen Mapper geben, der weiß, wie er auf die Matrix aus der Pose die Werte, die der Interpolator
//erzeugt, anwendet.
std::map < Interpolator*, std::vector < TargetType > > precalculations_;
MatrixManipulator* matrixManipulator_;
unsigned int frames_;
std::map < unsigned int, Pose* > interpolatedPoses_;
unsigned int calcAbsoluteMaxForInterpolator(uint _index);
Skeleton* skeleton_;
std::vector<int> influencedJoints_;
std::vector< Interpolator* > interpolators_;
//Hier muss es einen Mapper geben, der weiß, wie er auf die Matrix aus der Pose die Werte, die der Interpolator
//erzeugt, anwendet.
std::map < Interpolator*, std::vector < TargetType > > precalculations_;
MatrixManipulator* matrixManipulator_;
unsigned int frames_;
std::map < unsigned int, Pose* > interpolatedPoses_;
unsigned int calcAbsoluteMaxForInterpolator(uint _index);
public:
static const int FPS = 60;
static const int FPS = 60;
public:
/**
* @name Frame access
* There is one pose per frame.
*/
//@{
virtual Pose *getPose(unsigned int _iFrame);
virtual Pose *getPose(unsigned int _iFrame, Pose* _reference);
inline unsigned int getFrameCount();
//@}
/**
* @name Frame access
* There is one pose per frame.
*/
//@{
virtual Pose* pose(unsigned int _iFrame);
virtual Pose* pose(unsigned int _iFrame, Pose* _reference);
inline unsigned int frameCount();
//@}
/**
* @name Synchronization
* Use these methods to keep the poses in sync with the number (and indices) of the joints.
*/
//@{
virtual void insert_at(unsigned int _index);
virtual void remove_at(unsigned int _index);
//@}
/**
* @name Interpolators access
*/
//@{
// We use only interpolators with time as input.
void addInterpolator(InterpolationT<double> *_interpolator);
Interpolator* interpolator(unsigned int _index);
unsigned int interpolatorCount();
//@}
/**
* @name Synchronization
* Use these methods to keep the poses in sync with the number (and indices) of the joints.
*/
//@{
virtual void insertJointAt(unsigned int _index);
virtual void removeJointAt(unsigned int _index);
//@}
/**
* @name Interpolators access
*/
//@{
// We use only interpolators with time as input.
void addInterpolator(InterpolationT<double> *_interpolator);
Interpolator* interpolator(unsigned int _index);
unsigned int interpolatorCount();
//@}
/**
* @name InfluencedJoints access
......@@ -149,12 +148,10 @@ class InterpolationAnimationT : public AnimationT<PointT>
}
//@}
Pose* getReference() {
return getPose(0);
return pose(0);
}
virtual void clearPoseCache() {
if (interpolatedPoses_.size() == 1 && interpolatedPoses_.find(0) != interpolatedPoses_.end())
return;
......
......@@ -52,25 +52,24 @@
*
* @param _other The animation to copy from
*/
template<typename Scalar>
MultiInterpolationAnimationT<Scalar>::MultiInterpolationAnimationT(const MultiInterpolationAnimationT<Scalar> &_other) :
InterpolationAnimationT<Scalar>(NULL, NULL, NULL),
template<class PointT>
MultiInterpolationAnimationT<PointT>::MultiInterpolationAnimationT(const MultiInterpolationAnimationT<PointT> &_other) :
InterpolationAnimationT<PointT>(NULL, NULL),
interpolationAnimations_(_other.interpolationAnimations_)
{
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
AnimationT<Scalar>* MultiInterpolationAnimationT<Scalar>::copy() {
return new MultiInterpolationAnimationT<Scalar>(*this);
template<class PointT>
AnimationT<PointT>* MultiInterpolationAnimationT<PointT>::copy() {
return new MultiInterpolationAnimationT<PointT>(*this);
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
bool MultiInterpolationAnimationT<Scalar>::getMinInput(Scalar& _result) {
template<class PointT>
bool MultiInterpolationAnimationT<PointT>::getMinInput(Scalar& _result) {
if (interpolationAnimations_.size() == 0)
return false;
else
......@@ -89,8 +88,8 @@ bool MultiInterpolationAnimationT<Scalar>::getMinInput(Scalar& _result) {
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
bool MultiInterpolationAnimationT<Scalar>::getMaxInput(Scalar& _result) {
template<class PointT>
bool MultiInterpolationAnimationT<PointT>::getMaxInput(Scalar& _result) {
if (interpolationAnimations_.size() == 0)
return false;
else
......@@ -113,8 +112,8 @@ bool MultiInterpolationAnimationT<Scalar>::getMaxInput(Scalar& _result) {
* @brief Returns the number of frames that this animation can playback
* Note that this is not simply the sum of all animations' frame counts, as they can (and most likely will) overlap.
*/
template<typename Scalar>
unsigned long MultiInterpolationAnimationT<Scalar>::getFrameCount()
template<class PointT>
unsigned int MultiInterpolationAnimationT<PointT>::frameCount()
{
Scalar minInput=0, maxInput=0;
if (getMinInput(minInput) && getMaxInput(maxInput)) {
......@@ -126,8 +125,8 @@ unsigned long MultiInterpolationAnimationT<Scalar>::getFrameCount()
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame) {
template<class PointT>
PoseT<PointT> * MultiInterpolationAnimationT<PointT>::pose(unsigned int _iFrame) {
//Use the reference pose of the first (in terms of the input value, i.e. the time in most cases)
if (interpolationAnimations_.size() == 0)
......@@ -141,13 +140,13 @@ PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFr
minInterpolationAnimationIndex = (minValueTmp < minValue) ? i : minInterpolationAnimationIndex;
}
return getPose(_iFrame, interpolationAnimations_[minValue]->getReference());
return pose(_iFrame, interpolationAnimations_[minValue]->getReference());
}
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFrame, Pose* _reference) {
template<class PointT>
PoseT<PointT> * MultiInterpolationAnimationT<PointT>::pose(unsigned int _iFrame, Pose* _reference) {
if (_iFrame == 0)
return _reference;
......@@ -158,8 +157,8 @@ PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFr
Scalar minInput, maxInput;
interpolationAnimations_[i]->getMinInput(minInput); interpolationAnimations_[i]->getMaxInput(maxInput);
unsigned long minFrame = (minInput * FPS);
unsigned long maxFrame = (maxInput * FPS);
unsigned int minFrame = (minInput * FPS);
unsigned int maxFrame = (maxInput * FPS);
//Check, if the current animation is responsible for displaying this frame
if (_iFrame < minFrame || _iFrame > maxFrame)
......@@ -167,9 +166,9 @@ PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFr
if (interpolationAnimations_[i]) {
if (newPose == NULL)
newPose = interpolationAnimations_[i]->getPose(_iFrame - minFrame, referenceCopy);
newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, referenceCopy);
else
newPose = interpolationAnimations_[i]->getPose(_iFrame - minFrame, newPose);
newPose = interpolationAnimations_[i]->pose(_iFrame - minFrame, newPose);
}
}
......@@ -183,8 +182,8 @@ PoseT<Scalar> * MultiInterpolationAnimationT<Scalar>::getPose(unsigned long _iFr
//-----------------------------------------------------------------------------------------------------
template<typename Scalar>
InterpolationAnimationT<Scalar>* MultiInterpolationAnimationT<Scalar>::getAnimation(unsigned int _index ) {
template<class PointT>
InterpolationAnimationT<PointT>* MultiInterpolationAnimationT<PointT>::animation(unsigned int _index ) {
if ( _index < interpolationAnimations_.size() )
return interpolationAnimations_[ _index ];
else
......
......@@ -45,7 +45,7 @@
#include "InterpolationAnimationT.hh"
template<typename<