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>
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, size_t>(_name, animations_.size()) );
787 animations_.push_back(_animation);
790 names_.insert( std::pair<std::string, size_t>(_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, size_t>(_name, animations_.size()) );
821 if(animation(_hAni) != 0)
822 animations_.push_back((*animation(_hAni)).copy());
827 names_.insert( std::pair<std::string, size_t>(_name, f - animations_.begin()) );
828 if(animation(_hAni) != 0)
829 *f = (*animation(_hAni)).copy();
842 template<
typename Po
intT>
845 std::map<std::string, size_t>::iterator f = names_.find(_name);
846 if(f == names_.end())
857 template<
typename Po
intT>
860 std::map<std::string, size_t>::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, size_t>::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, size_t>::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>
986 std::map<std::string, size_t>::iterator pos = names_.begin();
988 while(pos->second != _index && pos != names_.end())
1003 template<
typename Po
intT>
1006 referencePose_.updateFromGlobal(_idJoint);
1007 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it) {
1009 (*it)->updateFromGlobal(_idJoint);
1021 template<
typename Po
intT>
1024 if (!_pChild || !_pChild->
parent() || !_pInsert)
1030 size_t childID = _pChild->
id();
1031 for(
typename std::vector<Joint*>::iterator it = joints_.begin() + childID; it != joints_.end(); ++it)
1032 (*it)->setId((*it)->id() + 1);
1035 joints_.insert(joints_.begin() + childID, _pInsert);
1036 _pInsert->setId(childID);
1043 insert_property_at(childID);
1045 referencePose_.insertJointAt(childID);
1046 for(
typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
1048 (*it)->insertJointAt(childID);
1050 referencePose_.updateFromGlobal(0,
true);
Represents a single joint in the skeleton.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
A handle used to refer to an animation or to a specific frame in an animation.
Pose * referencePose()
Returns a pointer to the reference pose.
size_t child(size_t _joint, size_t _child)
Returns the child with the given index.
Iterator()
Default constructor.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
size_t id() const
returns the joint id
ChildIter begin()
Returns an iterator on the joints children.
Stores a single animation.
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
Joint * child(size_t _index)
Returns the child joint with the given index.
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node...
Joint * root()
Returns the root joint.
std::vector< Animation * > animations_
Animations defined on the skeleton.
Joint * operator*() const
Returns a pointer to the current joint.
Iterator class for the skeleton.
void removeAnimation(std::string _name)
Removes an animation from the list.
size_t jointCount()
Returns the number of joints.
AnimationIterator(std::vector< Animation * > &_animations)
Default constructor.
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.
void clearAnimations()
Removes all animations.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
size_t frame() const
Returns the selected frame (zero based)
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
AnimationIterator animationsBegin()
Iterator over the animations.
Iterator class for the animations attached to a skeleton.
ChildIter end()
Returns the end iterator for the joints children.
AnimationHandle operator*() const
Get an animation handle for the current animation.
Iterator & operator=(const Iterator &other)
Assignment Operator.
SkeletonT()
Default constructor.
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
bool operator==(const Iterator &other) const
Compares the iterators.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
A general pose, used to store the frames of the animation.
size_t animationIndex() const
Returns the animation index (zero based)
bool operator!=(const Iterator &other) const
Compares the iterators.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
Pose referencePose_
The skeletons reference pose.
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
int parent(size_t _joint)
Returns the parents id of the given node.
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
size_t childCount(size_t _joint)
Returns the number of children of the given node.
The properties storage class.
Joint * parent()
Returns the parent joint.
size_t animationCount()
Returns the number of animations stored in this skeleton.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
AnimationIterator & operator++()
Increase the iterator.
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
std::map< std::string, size_t > names_
Binds a name to each animation.
bool isValid() const
Returns true if the handle is valid.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
void clear()
Removes all joints from the skeleton.
Iterator & operator++()
Increase the iterator.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
Joint * operator->() const
Returns a pointer to the current joint.
Joint * joint(const size_t &_index)
Returns the joint with the given index.