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() ){
168 while(pSibling == 0 && !stJoints_.empty())
171 Joint *pParent = stJoints_.top();
173 if(!stJoints_.empty())
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>
312 animations_(_animations)
314 currentIndex_ = _animationIndex;
317 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
327 template<
typename Po
intT>
332 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
343 template<
typename Po
intT>
345 currentIndex_ = other.currentIndex_;
346 animations_ = other.animations_;
355 template<
typename Po
intT>
357 return ( currentIndex_ < animations_.size() );
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){
445 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
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()) );
459 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
475 template<
typename Po
intT>
493 template<
typename Po
intT>
496 unsigned int newJointID;
509 _pJoint->setId(
joints_.size());
512 newJointID =
joints_.size() - 1;
521 (*it)->insertJointAt(newJointID);
537 template<
typename Po
intT>
542 std::cerr <<
"Cannot delete last joint. Delete the skeleton instead." << std::endl;
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();
579 for(; it !=
joints_.end(); ++it)
580 (*it)->setId((*it)->id() - 1);
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;
623 template<
typename Po
intT>
641 template<
typename Po
intT>
657 template<
typename Po
intT>
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>
713 template<
typename Po
intT>
724 template<
typename Po
intT>
740 template<
typename Po
intT>
760 template<
typename Po
intT>
774 template<
typename Po
intT>
778 typename std::vector<Animation*>::iterator f;
786 names_.insert( std::pair<std::string, unsigned int>(_name,
animations_.size()) );
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;
820 names_.insert( std::pair<std::string, unsigned int>(_name,
animations_.size()) );
827 names_.insert( std::pair<std::string, unsigned int>(_name, f -
animations_.begin()) );
842 template<
typename Po
intT>
845 std::map<std::string, unsigned int>::iterator f =
names_.find(_name);
857 template<
typename Po
intT>
860 std::map<std::string, unsigned int>::iterator f =
names_.find(_name);
872 template<
typename Po
intT>
885 template<
typename Po
intT>
889 std::map<std::string, unsigned int>::iterator f =
names_.find(_name);
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>
944 template<
typename Po
intT>
955 template<
typename Po
intT>
970 template<
typename Po
intT>
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>
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);
1038 _pInsert->setId(childID);
1050 (*it)->insertJointAt(childID);
void removeAnimation(std::string _name)
Removes an animation from the list.
Iterator class for the skeleton.
Iterator & operator++()
Increase the iterator.
AnimationIterator & operator++()
Increase the iterator.
unsigned int child(unsigned int _joint, unsigned int _child)
Returns the child with the given index.
std::vector< Animation * > animations_
Animations defined on the skeleton.
virtual void removeJointAt(unsigned int _index)
Called by the skeleton/animation as a joint is removed.
bool operator!=(const Iterator &other) const
Compares the iterators.
unsigned int animationIndex() const
Returns the animation index (zero based)
Represents a single joint in the skeleton.
Joint * child(size_t _index)
Returns the child joint with the given index.
std::map< std::string, unsigned int > names_
Binds a name to each animation.
unsigned int childCount(unsigned int _joint)
Returns the number of children of the given node.
void updateFromGlobal(unsigned int _joint, bool _keepChildPositions=true)
This method propagates the change in the global coordinate system to the local system and all childre...
unsigned int jointCount()
Returns the number of joints.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
ChildIter begin()
Returns an iterator on the joints children.
void clean_properties()
While preserving the properties themself, all values in the property are deleted. ...
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
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.
bool isValid() const
Returns true if the handle is valid.
Iterator()
Default constructor.
unsigned int id()
returns the joint id
std::vector< Joint * > joints_
Joints of the skeleton.
A general pose, used to store the frames of the animation.
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
A handle used to refer to an animation or to a specific frame in an animation.
AnimationIterator animationsBegin()
Iterator over the animations.
The properties storage class.
Pose referencePose_
The skeletons reference pose.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Iterator & operator=(const Iterator &other)
Assignment Operator.
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
Joint * operator->() const
Returns a pointer to the current joint.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
AnimationHandle operator*() const
Get an animation handle for the current animation.
virtual void insertJointAt(unsigned int _index)
Called by the skeleton/animation as a new joint is inserted.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
Stores a single animation.
int parent(unsigned int _joint)
Returns the parents id of the given node.
void clearAnimations()
Removes all animations.
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node...
Joint * parent()
Returns the parent joint.
void remove_property_at(int _index)
Removes a property for an object that is being deleted from the derived class.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
AnimationIterator(std::vector< Animation * > &_animations)
Default constructor.
bool operator==(const Iterator &other) const
Compares the iterators.
ChildIter end()
Returns the end iterator for the joints children.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Iterator class for the animations attached to a skeleton.
void clear()
Removes all joints from the skeleton.
SkeletonT()
Default constructor.
Joint * joint(const unsigned int &_index)
Returns the joint with the given index.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
void updateFromGlobal(unsigned int _idJoint)
update the structure when parent changes for a joint
size_t size()
Returns the number of children.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
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.
unsigned int frame() const
Returns the selected frame (zero based)