58 #include "SkeletonT.hh" 60 #include "Animation/FrameAnimationT.hh" 72 template<
typename Po
intT>
85 template<
typename Po
intT>
99 template<
typename Po
intT>
102 pCurrent_ = other.pCurrent_;
103 stJoints_ = other.stJoints_;
112 template<
typename Po
intT>
125 template<
typename Po
intT>
128 pCurrent_ = other.pCurrent_;
129 stJoints_ = other.stJoints_;
140 template<
typename Po
intT>
147 if(pCurrent_->
size() > 0)
150 stJoints_.push(pCurrent_);
151 pCurrent_ = pCurrent_->
child(0);
154 if ( pCurrent_->isRoot() ){
162 while(pSibling == 0 && !stJoints_.empty())
165 Joint *pParent = stJoints_.top();
167 if(!stJoints_.empty())
173 pCurrent_ = pSibling;
186 template<
typename Po
intT>
189 return pCurrent_ != other.pCurrent_;
199 template<
typename Po
intT>
202 return pCurrent_ == other.pCurrent_;
210 template<
typename Po
intT>
228 template<
typename Po
intT>
242 template<
typename Po
intT>
245 return pCurrent_ != 0;
257 template<
typename Po
intT>
261 typename Joint::ChildIter it;
262 for(it = _pParent->
begin(); it != _pParent->
end(); ++it)
268 if(it == _pParent->
end())
287 template<
typename Po
intT>
294 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
304 template<
typename Po
intT>
306 animations_(_animations)
308 currentIndex_ = _animationIndex;
311 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
321 template<
typename Po
intT>
326 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
337 template<
typename Po
intT>
339 currentIndex_ = other.currentIndex_;
340 animations_ = other.animations_;
349 template<
typename Po
intT>
351 return ( currentIndex_ < animations_.size() );
358 template<
typename Po
intT>
370 template<
typename Po
intT>
382 template<
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)
402 joint(pJoint->
id())->parent_ = 0;
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)
424 template<
typename Po
intT>
427 if (
this != &_other){
433 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
439 for(
typename std::vector<Joint*>::const_iterator it = _other.
joints_.begin(); it != _other.
joints_.end(); ++it){
445 joint(pJoint->
id())->parent_ = 0;
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()) );
453 for(
typename std::vector<Animation*>::const_iterator it = _other.
animations_.begin(); it != _other.
animations_.end(); ++it)
469 template<
typename Po
intT>
487 template<
typename Po
intT>
503 _pJoint->setId(
joints_.size());
506 newJointID =
joints_.size() - 1;
515 (*it)->insertJointAt(newJointID);
531 template<
typename Po
intT>
536 std::cerr <<
"Cannot delete last joint. Delete the skeleton instead." << std::endl;
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();
573 for(; it !=
joints_.end(); ++it)
574 (*it)->setId((*it)->id() - 1);
577 for (
typename std::vector<Animation*>::iterator a_it =
animations_.begin(); a_it !=
animations_.end(); ++a_it) {
579 (*a_it)->updateFromGlobal(0);
592 template<
typename Po
intT>
600 typename std::vector<Joint*>::iterator it;
617 template<
typename Po
intT>
635 template<
typename Po
intT>
651 template<
typename Po
intT>
656 return joints_[_joint]->parent()->id();
664 template<
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();
683 template<
typename Po
intT>
686 return joints_[_joint]->child(_child)->id();
694 template<
typename Po
intT>
707 template<
typename Po
intT>
718 template<
typename Po
intT>
734 template<
typename Po
intT>
754 template<
typename Po
intT>
768 template<
typename Po
intT>
772 typename std::vector<Animation*>::iterator f;
789 _animation->setName(_name);
802 template<
typename Po
intT>
806 typename std::vector<Animation*>::iterator f;
836 template<
typename Po
intT>
839 std::map<std::string, size_t>::iterator f =
names_.find(_name);
851 template<
typename Po
intT>
854 std::map<std::string, size_t>::iterator f =
names_.find(_name);
866 template<
typename Po
intT>
879 template<
typename Po
intT>
883 std::map<std::string, size_t>::iterator f =
names_.find(_name);
899 template<
typename Po
intT>
907 for(
typename std::map<std::string, size_t>::iterator it =
names_.begin(); it !=
names_.end(); ++it)
922 template<
typename Po
intT>
938 template<
typename Po
intT>
949 template<
typename Po
intT>
964 template<
typename Po
intT>
977 template<
typename Po
intT>
980 std::map<std::string, size_t>::iterator pos =
names_.begin();
982 while(pos->second != _index && pos !=
names_.end())
997 template<
typename Po
intT>
1001 for(
typename std::vector<Animation*>::iterator it =
animations_.begin(); it !=
animations_.end(); ++it) {
1003 (*it)->updateFromGlobal(_idJoint);
1015 template<
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);
1030 _pInsert->setId(childID);
1042 (*it)->insertJointAt(childID);
size_t animationIndex() const
Returns the animation index (zero based)
size_t child(size_t _joint, size_t _child)
Returns the child with the given index.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
size_t id() const
returns the joint id
size_t size() const
Returns the number of children.
SkeletonT()
Default constructor.
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
size_t jointCount()
Returns the number of joints.
Joint * joint(const size_t &_index)
Returns the joint with the given index.
AnimationIterator & operator++()
Increase the iterator.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
AnimationIterator animationsBegin()
Iterator over the animations.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Pose referencePose_
The skeletons reference pose.
Stores a single animation.
A general pose, used to store the frames of the animation.
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
size_t frame() const
Returns the selected frame (zero based)
The properties storage class.
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
bool isValid() const
Returns true if the handle is valid.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
size_t childCount(size_t _joint)
Returns the number of children of the given node.
Joint * operator*() const
Returns a pointer to the current joint.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
void remove_property_at(int _index)
Removes a property for an object that is being deleted from the derived class.
void removeAnimation(std::string _name)
Removes an animation from the list.
ChildIter end()
Returns the end iterator for the joints children.
std::map< std::string, size_t > names_
Binds a name to each animation.
Represents a single joint in the skeleton.
Pose * referencePose()
Returns a pointer to the reference pose.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
int parent(size_t _joint)
Returns the parents id of the given node.
Iterator()
Default constructor.
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
void clearAnimations()
Removes all animations.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Joint * root()
Returns the root joint.
Joint * child(size_t _index)
Returns the child joint with the given index.
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.
std::vector< Joint * > joints_
Joints of the skeleton.
Iterator class for the skeleton.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
Joint * operator->() const
Returns a pointer to the current joint.
void clear()
Removes all joints from the skeleton.
AnimationHandle operator*() const
Get an animation handle for the current animation.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
bool operator==(const Iterator &other) const
Compares the iterators.
Joint * parent()
Returns the parent joint.
AnimationIterator(std::vector< Animation *> &_animations)
Default constructor.
size_t animationCount()
Returns the number of animations stored in this skeleton.
virtual void insertJointAt(size_t _index)
Called by the skeleton/animation as a new joint is inserted.
bool operator!=(const Iterator &other) const
Compares the iterators.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
void updateFromGlobal(size_t _joint, bool _keepChildPositions=true)
This method propagates the change in the global coordinate system to the local system and all childre...
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node...
Iterator & operator++()
Increase the iterator.
std::vector< Animation * > animations_
Animations defined on the skeleton.
Iterator & operator=(const Iterator &other)
Assignment Operator.
virtual void removeJointAt(size_t _index)
Called by the skeleton/animation as a joint is removed.
void clean_properties()
While preserving the properties themself, all values in the property are deleted. ...
A handle used to refer to an animation or to a specific frame in an animation.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
ChildIter begin()
Returns an iterator on the joints children.