58#include "SkeletonT.hh"
60#include "Animation/FrameAnimationT.hh"
72template<
typename Po
intT>
85template<
typename Po
intT>
99template<
typename Po
intT>
102 pCurrent_ = other.pCurrent_;
103 stJoints_ = other.stJoints_;
112template<
typename Po
intT>
125template<
typename Po
intT>
128 pCurrent_ = other.pCurrent_;
129 stJoints_ = other.stJoints_;
140template<
typename Po
intT>
147 if(pCurrent_->size() > 0)
150 stJoints_.push(pCurrent_);
151 pCurrent_ = pCurrent_->
child(0);
154 if ( pCurrent_->isRoot() ){
160 Joint *pSibling = nextSibling(stJoints_.top(), pCurrent_);
162 while(pSibling == 0 && !stJoints_.empty())
165 Joint *pParent = stJoints_.top();
167 if(!stJoints_.empty())
168 pSibling = nextSibling(stJoints_.top(), pParent);
173 pCurrent_ = pSibling;
186template<
typename Po
intT>
189 return pCurrent_ != other.pCurrent_;
199template<
typename Po
intT>
202 return pCurrent_ == other.pCurrent_;
210template<
typename Po
intT>
228template<
typename Po
intT>
242template<
typename Po
intT>
245 return pCurrent_ != 0;
257template<
typename Po
intT>
261 typename Joint::ChildIter it;
262 for(it = _pParent->
begin(); it != _pParent->
end(); ++it)
268 if(it == _pParent->
end())
287template<
typename Po
intT>
294 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
304template<
typename Po
intT>
308 currentIndex_ = _animationIndex;
311 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
321template<
typename Po
intT>
337template<
typename Po
intT>
339 currentIndex_ = other.currentIndex_;
349template<
typename Po
intT>
358template<
typename Po
intT>
370template<
typename Po
intT>
382template<
typename Po
intT>
388 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it)
395 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it)
403 for(
typename Joint::ChildIter it_ch = pJoint->
begin(); it_ch != pJoint->
end(); ++it_ch)
404 joint(pJoint->
id())->children_.push_back(
joint((*it_ch)->id()) );
409 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
424template<
typename Po
intT>
427 if (
this != &_other){
433 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
434 joints_.push_back(
new Joint(**it));
435 insert_property_at( (*it)->id() );
439 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
443 joint(pJoint->
id())->parent_ = joint(pJoint->
parent()->
id());
447 for(
typename Joint::ChildIter it_ch = pJoint->
begin(); it_ch != pJoint->
end(); ++it_ch)
448 joint(pJoint->
id())->children_.push_back( joint((*it_ch)->id()) );
451 names_.insert(_other.
names_.begin(), _other.
names_.end());
453 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
455 animations_.push_back((**it).copy());
469template<
typename Po
intT>
487template<
typename Po
intT>
498 joints_.push_back(_pJoint);
503 _pJoint->
setId(joints_.size());
504 joints_.push_back(_pJoint);
506 newJointID = joints_.size() - 1;
510 insert_property_at(newJointID);
512 referencePose_.insertJointAt(newJointID);
513 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
515 (*it)->insertJointAt(newJointID);
517 referencePose_.updateFromGlobal(0,
true);
531template<
typename Po
intT>
535 if (joints_.size() == 1){
536 std::cerr <<
"Cannot delete last joint. Delete the skeleton instead." << std::endl;
540 remove_property_at(_pJoint->
id());
541 referencePose_.removeJointAt(_pJoint->
id());
543 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
544 if (*it) (*it)->removeJointAt(_pJoint->
id());
547 typename SkeletonT<PointT>::Joint::ChildIter c_it = _pJoint->
begin();
549 if( _pJoint->
parent() == 0 ){
555 for ( ; c_it!=_pJoint->
end(); ++c_it) {
556 (*c_it)->parent_ = newRoot;
562 for ( ; c_it!=_pJoint->
end(); ++c_it) {
563 (*c_it)->parent_ = _pJoint->
parent_;
571 typename std::vector<Joint*>::iterator it = joints_.begin() + _pJoint->
id();
572 it = joints_.erase(it);
573 for(; it != joints_.end(); ++it)
574 (*it)->setId((*it)->id() - 1);
576 referencePose_.updateFromGlobal(0,
true);
577 for (
typename std::vector<Animation*>::iterator a_it = animations_.begin(); a_it != animations_.end(); ++a_it) {
579 (*a_it)->updateFromGlobal(0);
592template<
typename Po
intT>
600 typename std::vector<Joint*>::iterator it;
601 for(it = joints_.begin(); it != joints_.end(); ++it)
617template<
typename Po
intT>
635template<
typename Po
intT>
638 if(_index >= joints_.size())
640 return joints_[_index];
651template<
typename Po
intT>
654 if(joints_[_joint]->parent() == 0)
656 return joints_[_joint]->
parent()->
id();
664template<
typename Po
intT>
667 if ( _joint >= joints_.size() ){
668 std::cerr <<
"SkeletonT : childCount() called with non-existing joint " << _joint << std::endl;
672 return joints_[_joint]->size();
683template<
typename Po
intT>
686 return joints_[_joint]->child(_child)->id();
694template<
typename Po
intT>
697 return joints_.size();
707template<
typename Po
intT>
718template<
typename Po
intT>
734template<
typename Po
intT>
740 return &referencePose_;
754template<
typename Po
intT>
757 return &referencePose_;
768template<
typename Po
intT>
772 typename std::vector<Animation*>::iterator f;
773 for(f = animations_.begin(); f != animations_.end(); ++f)
777 if(f == animations_.end())
780 names_.insert( std::pair<std::string, size_t>(_name, animations_.size()) );
781 animations_.push_back(_animation);
784 names_.insert( std::pair<std::string, size_t>(_name, f - animations_.begin()) );
789 _animation->setName(_name);
802template<
typename Po
intT>
806 typename std::vector<Animation*>::iterator f;
807 for(f = animations_.begin(); f != animations_.end(); ++f)
811 if(f == animations_.end())
814 names_.insert( std::pair<std::string, size_t>(_name, animations_.size()) );
815 if(animation(_hAni) != 0)
816 animations_.push_back((*animation(_hAni)).copy());
821 names_.insert( std::pair<std::string, size_t>(_name, f - animations_.begin()) );
822 if(animation(_hAni) != 0)
823 *f = (*animation(_hAni)).copy();
836template<
typename Po
intT>
839 std::map<std::string, size_t>::iterator f = names_.find(_name);
840 if(f == names_.end())
851template<
typename Po
intT>
854 std::map<std::string, size_t>::iterator f = names_.find(_name);
855 if(f == names_.end())
858 return animations_[f->second];
866template<
typename Po
intT>
879template<
typename Po
intT>
883 std::map<std::string, size_t>::iterator f = names_.find(_name);
884 if(f == names_.end())
888 delete animations_[f->second];
889 animations_[f->second] = 0;
899template<
typename Po
intT>
907 for(
typename std::map<std::string, size_t>::iterator it = names_.begin(); it != names_.end(); ++it)
922template<
typename Po
intT>
927 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
938template<
typename Po
intT>
949template<
typename Po
intT>
964template<
typename Po
intT>
967 return names_.size();
977template<
typename Po
intT>
980 std::map<std::string, size_t>::iterator pos = names_.begin();
982 while(pos->second != _index && pos != names_.end())
997template<
typename Po
intT>
1000 referencePose_.updateFromGlobal(_idJoint);
1001 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it) {
1003 (*it)->updateFromGlobal(_idJoint);
1015template<
typename Po
intT>
1018 if (!_pChild || !_pChild->
parent() || !_pInsert)
1024 size_t childID = _pChild->
id();
1025 for(
typename std::vector<Joint*>::iterator it = joints_.begin() + childID; it != joints_.end(); ++it)
1026 (*it)->setId((*it)->id() + 1);
1029 joints_.insert(joints_.begin() + childID, _pInsert);
1030 _pInsert->
setId(childID);
1037 insert_property_at(childID);
1039 referencePose_.insertJointAt(childID);
1040 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
1042 (*it)->insertJointAt(childID);
1044 referencePose_.updateFromGlobal(0,
true);
A handle used to refer to an animation or to a specific frame in an animation.
bool isValid() const
Returns true if the handle is valid.
size_t frame() const
Returns the selected frame (zero based)
size_t animationIndex() const
Returns the animation index (zero based)
Stores a single animation.
Represents a single joint in the skeleton.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
ChildIter end()
Returns the end iterator for the joints children.
size_t id() const
returns the joint id
Joint * child(size_t _index)
Returns the child joint with the given index.
void setId(const size_t _id)
An unique identifier, guaranteed to be part of a continuous sequence starting from 0.
ChildIter begin()
Returns an iterator on the joints children.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Joint * parent()
Returns the parent joint.
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node.
A general pose, used to store the frames of the animation.
The properties storage class.
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
Iterator class for the animations attached to a skeleton.
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
AnimationIterator & operator++()
Increase the iterator.
AnimationIterator(std::vector< Animation * > &_animations)
Default constructor.
AnimationHandle operator*() const
Get an animation handle for the current animation.
Iterator class for the skeleton.
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
Joint * operator*() const
Returns a pointer to the current joint.
Iterator & operator=(const Iterator &other)
Assignment Operator.
Iterator & operator++()
Increase the iterator.
bool operator!=(const Iterator &other) const
Compares the iterators.
bool operator==(const Iterator &other) const
Compares the iterators.
Iterator()
Default constructor.
Joint * operator->() const
Returns a pointer to the current joint.
std::map< std::string, size_t > names_
Binds a name to each animation.
Pose * referencePose()
Returns a pointer to the reference pose.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
size_t jointCount()
Returns the number of joints.
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
size_t animationCount()
Returns the number of animations stored in this skeleton.
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void clearAnimations()
Removes all animations.
void removeAnimation(std::string _name)
Removes an animation from the list.
SkeletonT()
Default constructor.
void clear()
Removes all joints from the skeleton.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
size_t child(size_t _joint, size_t _child)
Returns the child with the given index.
Joint * joint(const size_t &_index)
Returns the joint with the given index.
Pose referencePose_
The skeletons reference pose.
size_t childCount(size_t _joint)
Returns the number of children of the given node.
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
std::vector< Animation * > animations_
Animations defined on the skeleton.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
std::vector< Joint * > joints_
Joints of the skeleton.
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
AnimationIterator animationsBegin()
Iterator over the animations.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
int parent(size_t _joint)
Returns the parents id of the given node.
Joint * root()
Returns the root joint.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.