64 #include "SkeletonT.hh"
66 #include "Animation/FrameAnimationT.hh"
78 template<
typename Po
intT>
91 template<
typename Po
intT>
105 template<
typename Po
intT>
108 pCurrent_ = other.pCurrent_;
109 stJoints_ = other.stJoints_;
118 template<
typename Po
intT>
131 template<
typename Po
intT>
134 pCurrent_ = other.pCurrent_;
135 stJoints_ = other.stJoints_;
146 template<
typename Po
intT>
153 if(pCurrent_->size() > 0)
156 stJoints_.push(pCurrent_);
157 pCurrent_ = pCurrent_->
child(0);
160 if ( pCurrent_->isRoot() ){
166 Joint *pSibling = nextSibling(stJoints_.top(), pCurrent_);
168 while(pSibling == 0 && !stJoints_.empty())
171 Joint *pParent = stJoints_.top();
173 if(!stJoints_.empty())
174 pSibling = nextSibling(stJoints_.top(), pParent);
179 pCurrent_ = pSibling;
192 template<
typename Po
intT>
195 return pCurrent_ != other.pCurrent_;
205 template<
typename Po
intT>
208 return pCurrent_ == other.pCurrent_;
216 template<
typename Po
intT>
234 template<
typename Po
intT>
248 template<
typename Po
intT>
251 return pCurrent_ != 0;
263 template<
typename Po
intT>
267 typename Joint::ChildIter it;
268 for(it = _pParent->
begin(); it != _pParent->
end(); ++it)
274 if(it == _pParent->
end())
293 template<
typename Po
intT>
300 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
310 template<
typename Po
intT>
314 currentIndex_ = _animationIndex;
317 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
327 template<
typename Po
intT>
343 template<
typename Po
intT>
345 currentIndex_ = other.currentIndex_;
355 template<
typename Po
intT>
364 template<
typename Po
intT>
376 template<
typename Po
intT>
388 template<
typename Po
intT>
394 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it)
401 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it)
408 joint(pJoint->
id())->parent_ = 0;
409 for(
typename Joint::ChildIter it_ch = pJoint->
begin(); it_ch != pJoint->
end(); ++it_ch)
410 joint(pJoint->
id())->children_.push_back(
joint((*it_ch)->id()) );
415 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
430 template<
typename Po
intT>
433 if (
this != &_other){
439 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
440 joints_.push_back(
new Joint(**it));
441 insert_property_at( (*it)->id() );
445 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
449 joint(pJoint->
id())->parent_ = joint(pJoint->
parent()->
id());
451 joint(pJoint->
id())->parent_ = 0;
453 for(
typename Joint::ChildIter it_ch = pJoint->
begin(); it_ch != pJoint->
end(); ++it_ch)
454 joint(pJoint->
id())->children_.push_back( joint((*it_ch)->id()) );
457 names_.insert(_other.
names_.begin(), _other.
names_.end());
459 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
461 animations_.push_back((**it).copy());
475 template<
typename Po
intT>
493 template<
typename Po
intT>
496 unsigned int newJointID;
504 joints_.push_back(_pJoint);
509 _pJoint->setId(joints_.size());
510 joints_.push_back(_pJoint);
512 newJointID = joints_.size() - 1;
516 insert_property_at(newJointID);
518 referencePose_.insertJointAt(newJointID);
519 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
521 (*it)->insertJointAt(newJointID);
523 referencePose_.updateFromGlobal(0,
true);
537 template<
typename Po
intT>
541 if (joints_.size() == 1){
542 std::cerr <<
"Cannot delete last joint. Delete the skeleton instead." << std::endl;
546 remove_property_at(_pJoint->
id());
547 referencePose_.removeJointAt(_pJoint->
id());
549 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
550 if (*it) (*it)->removeJointAt(_pJoint->
id());
553 typename SkeletonT<PointT>::Joint::ChildIter c_it = _pJoint->
begin();
555 if( _pJoint->
parent() == 0 ){
561 for ( ; c_it!=_pJoint->
end(); ++c_it) {
562 (*c_it)->parent_ = newRoot;
568 for ( ; c_it!=_pJoint->
end(); ++c_it) {
569 (*c_it)->parent_ = _pJoint->
parent_;
577 typename std::vector<Joint*>::iterator it = joints_.begin() + _pJoint->
id();
578 it = joints_.erase(it);
579 for(; it != joints_.end(); ++it)
580 (*it)->setId((*it)->id() - 1);
582 referencePose_.updateFromGlobal(0,
true);
583 for (
typename std::vector<Animation*>::iterator a_it = animations_.begin(); a_it != animations_.end(); ++a_it) {
585 (*a_it)->updateFromGlobal(0);
598 template<
typename Po
intT>
606 typename std::vector<Joint*>::iterator it;
607 for(it = joints_.begin(); it != joints_.end(); ++it)
623 template<
typename Po
intT>
641 template<
typename Po
intT>
644 if(_index >= joints_.size())
646 return joints_[_index];
657 template<
typename Po
intT>
660 if(joints_[_joint]->parent() == 0)
662 return joints_[_joint]->parent()->id();
670 template<
typename Po
intT>
673 if ( _joint >= joints_.size() ){
674 std::cerr <<
"SkeletonT : childCount() called with non-existing joint " << _joint << std::endl;
678 return joints_[_joint]->size();
689 template<
typename Po
intT>
692 return joints_[_joint]->child(_child)->id();
700 template<
typename Po
intT>
703 return joints_.size();
713 template<
typename Po
intT>
724 template<
typename Po
intT>
740 template<
typename Po
intT>
746 return &referencePose_;
760 template<
typename Po
intT>
763 return &referencePose_;
774 template<
typename Po
intT>
778 typename std::vector<Animation*>::iterator f;
779 for(f = animations_.begin(); f != animations_.end(); ++f)
783 if(f == animations_.end())
786 names_.insert( std::pair<std::string, unsigned int>(_name, animations_.size()) );
787 animations_.push_back(_animation);
790 names_.insert( std::pair<std::string, unsigned int>(_name, f - animations_.begin()) );
795 _animation->setName(_name);
808 template<
typename Po
intT>
812 typename std::vector<Animation*>::iterator f;
813 for(f = animations_.begin(); f != animations_.end(); ++f)
817 if(f == animations_.end())
820 names_.insert( std::pair<std::string, unsigned int>(_name, animations_.size()) );
821 if(animation(_hAni) != 0)
822 animations_.push_back((*animation(_hAni)).copy());
827 names_.insert( std::pair<std::string, unsigned int>(_name, f - animations_.begin()) );
828 if(animation(_hAni) != 0)
829 *f = (*animation(_hAni)).copy();
842 template<
typename Po
intT>
845 std::map<std::string, unsigned int>::iterator f = names_.find(_name);
846 if(f == names_.end())
857 template<
typename Po
intT>
860 std::map<std::string, unsigned int>::iterator f = names_.find(_name);
861 if(f == names_.end())
864 return animations_[f->second];
872 template<
typename Po
intT>
885 template<
typename Po
intT>
889 std::map<std::string, unsigned int>::iterator f = names_.find(_name);
890 if(f == names_.end())
894 delete animations_[f->second];
895 animations_[f->second] = 0;
905 template<
typename Po
intT>
913 for(
typename std::map<std::string, unsigned int>::iterator it = names_.begin(); it != names_.end(); ++it)
928 template<
typename Po
intT>
933 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
944 template<
typename Po
intT>
955 template<
typename Po
intT>
970 template<
typename Po
intT>
973 return names_.size();
983 template<
typename Po
intT>
987 std::map<std::string, unsigned int>::iterator pos = names_.begin();
989 while(pos->second != _index && pos != names_.end())
1005 template<
typename Po
intT>
1008 referencePose_.updateFromGlobal(_idJoint);
1009 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it) {
1011 (*it)->updateFromGlobal(_idJoint);
1023 template<
typename Po
intT>
1026 if (!_pChild || !_pChild->
parent() || !_pInsert)
1032 unsigned int childID = _pChild->
id();
1033 for(
typename std::vector<Joint*>::iterator it = joints_.begin() + childID; it != joints_.end(); ++it)
1034 (*it)->setId((*it)->id() + 1);
1037 joints_.insert(joints_.begin() + childID, _pInsert);
1038 _pInsert->setId(childID);
1045 insert_property_at(childID);
1047 referencePose_.insertJointAt(childID);
1048 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
1050 (*it)->insertJointAt(childID);
1052 referencePose_.updateFromGlobal(0,
true);
unsigned int child(unsigned int _joint, unsigned int _child)
Returns the child with the given index.
bool isValid() const
Returns true if the handle is valid.
unsigned int childCount(unsigned int _joint)
Returns the number of children of the given node.
AnimationIterator(std::vector< Animation * > &_animations)
Default constructor.
ChildIter begin()
Returns an iterator on the joints children.
std::vector< Joint * > joints_
Joints of the skeleton.
int parent(unsigned int _joint)
Returns the parents id of the given node.
Iterator class for the animations attached to a skeleton.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
void clearAnimations()
Removes all animations.
bool operator==(const Iterator &other) const
Compares the iterators.
Pose referencePose_
The skeletons reference pose.
The properties storage class.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Joint * root()
Returns the root joint.
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
Pose * referencePose()
Returns a pointer to the reference pose.
Joint * child(size_t _index)
Returns the child joint with the given index.
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
Iterator & operator=(const Iterator &other)
Assignment Operator.
ChildIter end()
Returns the end iterator for the joints children.
void removeAnimation(std::string _name)
Removes an animation from the list.
A general pose, used to store the frames of the animation.
unsigned int jointCount()
Returns the number of joints.
unsigned int animationIndex() const
Returns the animation index (zero based)
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Iterator class for the skeleton.
Iterator()
Default constructor.
Joint * joint(const unsigned int &_index)
Returns the joint with the given index.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
AnimationIterator & operator++()
Increase the iterator.
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node...
std::map< std::string, unsigned int > names_
Binds a name to each animation.
Joint * parent()
Returns the parent joint.
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
Joint * operator->() const
Returns a pointer to the current joint.
void updateFromGlobal(unsigned int _idJoint)
update the structure when parent changes for a joint
unsigned int frame() const
Returns the selected frame (zero based)
bool operator!=(const Iterator &other) const
Compares the iterators.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
Iterator & operator++()
Increase the iterator.
AnimationHandle operator*() const
Get an animation handle for the current animation.
unsigned int id()
returns the joint id
A handle used to refer to an animation or to a specific frame in an animation.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Stores a single animation.
Joint * operator*() const
Returns a pointer to the current joint.
const std::string & animationName(unsigned int _index)
Returns the name of the animation with the given index.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
Represents a single joint in the skeleton.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
std::vector< Animation * > animations_
Animations defined on the skeleton.
AnimationIterator animationsBegin()
Iterator over the animations.
void clear()
Removes all joints from the skeleton.
SkeletonT()
Default constructor.