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);
Joint * child(size_t _index)
Returns the child joint with the given index.
size_t animationIndex() const
Returns the animation index (zero based)
std::map< std::string, size_t > names_
Binds a name to each animation.
virtual void insertJointAt(size_t _index)
Called by the skeleton/animation as a new joint is inserted.
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
AnimationIterator animationsBegin()
Iterator over the animations.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
bool operator==(const Iterator &other) const
Compares the iterators.
size_t childCount(size_t _joint)
Returns the number of children of the given node.
void clear()
Removes all joints from the skeleton.
ChildIter end()
Returns the end iterator for the joints children.
void clean_properties()
While preserving the properties themself, all values in the property are deleted. ...
size_t frame() const
Returns the selected frame (zero based)
Pose referencePose_
The skeletons reference pose.
A general pose, used to store the frames of the animation.
bool operator!=(const Iterator &other) const
Compares the iterators.
size_t animationCount()
Returns the number of animations stored in this skeleton.
Iterator class for the skeleton.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
void remove_property_at(int _index)
Removes a property for an object that is being deleted from the derived class.
Joint * root()
Returns the root joint.
int parent(size_t _joint)
Returns the parents id of the given node.
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
Joint * operator->() const
Returns a pointer to the current joint.
A handle used to refer to an animation or to a specific frame in an animation.
Joint * parent()
Returns the parent joint.
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)
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
The properties storage class.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Represents a single joint in the skeleton.
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
ChildIter begin()
Returns an iterator on the joints children.
AnimationIterator & operator++()
Increase the iterator.
SkeletonT()
Default constructor.
void removeAnimation(std::string _name)
Removes an animation from the list.
std::vector< Animation * > animations_
Animations defined on the skeleton.
void clearAnimations()
Removes all animations.
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...
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
size_t jointCount()
Returns the number of joints.
Stores a single animation.
size_t child(size_t _joint, size_t _child)
Returns the child with the given index.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
virtual void removeJointAt(size_t _index)
Called by the skeleton/animation as a joint is removed.
Iterator class for the animations attached to a 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 * joint(const size_t &_index)
Returns the joint with the given index.
Iterator & operator=(const Iterator &other)
Assignment Operator.
bool isValid() const
Returns true if the handle is valid.
Iterator & operator++()
Increase the iterator.
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
Iterator()
Default constructor.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
size_t size() const
Returns the number of children.
AnimationIterator(std::vector< Animation *> &_animations)
Default constructor.
size_t id() const
returns the joint id
Joint * operator*() const
Returns a pointer to the current joint.
AnimationHandle operator*() const
Get an animation handle for the current animation.
std::vector< Joint * > joints_
Joints of the skeleton.
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It's 0 for the root node...