Developer Documentation

SkeletonT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44 //-----------------------------------------------------------------------------
45 //
46 // CLASS SkeletonT - IMPLEMENTATION
47 //
48 //-----------------------------------------------------------------------------
49
50 #define SKELETON_C
51
52 //== INCLUDES =================================================================
53
54 #include <iostream>
55 #include <algorithm>
56 #include <utility>
57
58 #include "SkeletonT.hh"
59
60 #include "Animation/FrameAnimationT.hh"
61
62
63 //-----------------------------------------------------------------------------
64 // ITERATOR - IMPLEMENTATION
65 //-----------------------------------------------------------------------------
66
72 template<typename PointT>
73 SkeletonT<PointT>::Iterator::Iterator()
74 {
75 pCurrent_ = 0;
76 }
77
78 //-----------------------------------------------------------------------------
79
85 template<typename PointT>
86 SkeletonT<PointT>::Iterator::Iterator(Joint *_root)
87 {
88 pCurrent_ = _root;
89 }
90
91 //-----------------------------------------------------------------------------
92
99 template<typename PointT>
100 SkeletonT<PointT>::Iterator::Iterator(const Iterator &other)
101 {
102 pCurrent_ = other.pCurrent_;
103 stJoints_ = other.stJoints_;
104 }
105
106 //-----------------------------------------------------------------------------
107
112 template<typename PointT>
113 SkeletonT<PointT>::Iterator::~Iterator()
114 {
115 }
116
117 //-----------------------------------------------------------------------------
118
125 template<typename PointT>
126 typename SkeletonT<PointT>::Iterator &SkeletonT<PointT>::Iterator::operator=(const Iterator &other)
127 {
128 pCurrent_ = other.pCurrent_;
129 stJoints_ = other.stJoints_;
130 return *this;
131 }
132
133 //-----------------------------------------------------------------------------
134
140 template<typename PointT>
141 typename SkeletonT<PointT>::Iterator &SkeletonT<PointT>::Iterator::operator++()
142 {
143 if(pCurrent_ == 0)
144 return *this;
145
146 // try to make this iterator point to the first child
147 if(pCurrent_->size() > 0)
148 {
149 // there are children, so add the current joint to the stack and choose the first child as new current position
150 stJoints_.push(pCurrent_);
151 pCurrent_ = pCurrent_->child(0);
152 }else{
153
154 if ( pCurrent_->isRoot() ){
155 //root without children -> return invalid iterator
156 pCurrent_ = 0;
157
158 } else {
159 // there are no children left, so try to get the next sibling
160 Joint *pSibling = nextSibling(stJoints_.top(), pCurrent_);
161
162 while(pSibling == 0 && !stJoints_.empty())
163 {
164 // there is no sibling, so try the parents sibling and so on
165 Joint *pParent = stJoints_.top();
166 stJoints_.pop();
167 if(!stJoints_.empty())
168 pSibling = nextSibling(stJoints_.top(), pParent);
169 }
170
171 // did we fail to find a next node?
172 // if so pSibling is 0 now and will invalidate the iterator
173 pCurrent_ = pSibling;
174 }
175 }
176 return *this;
177 }
178
179 //-----------------------------------------------------------------------------
180
186 template<typename PointT>
187 bool SkeletonT<PointT>::Iterator::operator!=(const Iterator &other) const
188 {
189 return pCurrent_ != other.pCurrent_;
190 }
191
192 //-----------------------------------------------------------------------------
193
199 template<typename PointT>
200 bool SkeletonT<PointT>::Iterator::operator==(const Iterator &other) const
201 {
202 return pCurrent_ == other.pCurrent_;
203 }
204
205 //-----------------------------------------------------------------------------
206
210 template<typename PointT>
211 typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::Iterator::operator*() const
212 {
213 return pCurrent_;
214 }
215
216 //-----------------------------------------------------------------------------
217
228 template<typename PointT>
229 typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::Iterator::operator->() const
230 {
231 return pCurrent_;
232 }
233
234 //-----------------------------------------------------------------------------
235
242 template<typename PointT>
243 SkeletonT<PointT>::Iterator::operator bool() const
244 {
245 return pCurrent_ != 0;
246 }
247
248 //-----------------------------------------------------------------------------
249
257 template<typename PointT>
258 typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::Iterator::nextSibling(Joint *_pParent, Joint *_pJoint)
259 {
260 // first find the current node in the parents list of children
261 typename Joint::ChildIter it;
262 for(it = _pParent->begin(); it != _pParent->end(); ++it)
263 {
264 if(*it == _pJoint)
265 {
266 // found it. If there is another child it is the wanted sibling
267 ++it;
268 if(it == _pParent->end())
269 return 0; // oh no, we ran out of siblings
270
271 return *it;
272 }
273 }
274
275 return 0;
276 }
277
278 //-----------------------------------------------------------------------------
279 // AnimationIterator - IMPLEMENTATION
280 //-----------------------------------------------------------------------------
281
287 template<typename PointT>
288 SkeletonT<PointT>::AnimationIterator::AnimationIterator(std::vector<Animation*>& _animations ) :
289 animations_(_animations)
290 {
291 currentIndex_ = 0;
292
293 // Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
294 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
295 currentIndex_++;
296 }
297
298 }
299
304 template<typename PointT>
305 SkeletonT<PointT>::AnimationIterator::AnimationIterator(std::vector<Animation*>& _animations, size_t _animationIndex ) :
306 animations_(_animations)
307 {
308 currentIndex_ = _animationIndex;
309
310 // Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
311 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
312 currentIndex_++;
313 }
314 }
315
321 template<typename PointT>
322 typename SkeletonT<PointT>::AnimationIterator& SkeletonT<PointT>::AnimationIterator::operator++() {
323 currentIndex_++;
324
325 // Increment, until we are at the end or we found a valid animation which is not deleted ( == 0 )
326 while ( currentIndex_ < animations_.size() && animations_[currentIndex_] == 0) {
327 currentIndex_++;
328 }
329
330 return *this;
331 }
332
337 template<typename PointT>
338 typename SkeletonT<PointT>::AnimationIterator& SkeletonT<PointT>::AnimationIterator::operator=(const AnimationIterator &other) {
339 currentIndex_ = other.currentIndex_;
340 animations_ = other.animations_;
341 return *this;
342 }
343
349 template<typename PointT>
350 SkeletonT<PointT>::AnimationIterator::operator bool() const {
351 return ( currentIndex_ < animations_.size() );
352 }
353
358 template<typename PointT>
359 AnimationHandle SkeletonT<PointT>::AnimationIterator::operator*() const {
360 return AnimationHandle(currentIndex_);
361 }
362
363 //-----------------------------------------------------------------------------
364 // SKELETONT - IMPLEMENTATION
365 //-----------------------------------------------------------------------------
366
370 template<typename PointT>
371 SkeletonT<PointT>::SkeletonT() : referencePose_(this)
372 {
373 }
374
375 //-----------------------------------------------------------------------------
376
382 template<typename PointT>
383 SkeletonT<PointT>::SkeletonT(const SkeletonT<PointT> &_other) :
384 Properties(),
385 referencePose_(this)
386 {
387 // create a copy of the joints, not yet linked because they refer to each other using pointers
388 for(typename std::vector<Joint*>::const_iterator it = _other.joints_.begin(); it != _other.joints_.end(); ++it)
389 {
390 joints_.push_back(new Joint(**it));
391 insert_property_at( (*it)->id() );
392 }
393
394 // construct the links
395 for(typename std::vector<Joint*>::const_iterator it = _other.joints_.begin(); it != _other.joints_.end(); ++it)
396 {
397 Joint *pJoint = *it;
398
399 if(pJoint->parent() != 0)
400 joint(pJoint->id())->parent_ = joint(pJoint->parent()->id());
401 else
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()) );
405 }
406
407 names_.insert(_other.names_.begin(), _other.names_.end());
408
409 for(typename std::vector<Animation*>::const_iterator it = _other.animations_.begin(); it != _other.animations_.end(); ++it)
410 if (*it) {
411 animations_.push_back((**it).copy());
412 }
413
414 referencePose_ = _other.referencePose_;
415 }
416
417 //-----------------------------------------------------------------------------
418
424 template<typename PointT>
425 SkeletonT<PointT>& SkeletonT<PointT>::operator= (const SkeletonT<PointT>& _other){
426
427 if (this != &_other){ // protect against invalid self-assignment
428
429 // clear the current skeleton
430 clear();
431
432 // create a copy of the joints, not yet linked because they refer to each other using pointers
433 for(typename std::vector<Joint*>::const_iterator it = _other.joints_.begin(); it != _other.joints_.end(); ++it){
434 joints_.push_back(new Joint(**it));
435 insert_property_at( (*it)->id() );
436 }
437
438 // construct the links
439 for(typename std::vector<Joint*>::const_iterator it = _other.joints_.begin(); it != _other.joints_.end(); ++it){
440 Joint *pJoint = *it;
441
442 if(pJoint->parent() != 0)
443 joint(pJoint->id())->parent_ = joint(pJoint->parent()->id());
444 else
445 joint(pJoint->id())->parent_ = 0;
446
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()) );
449 }
450
451 names_.insert(_other.names_.begin(), _other.names_.end());
452
453 for(typename std::vector<Animation*>::const_iterator it = _other.animations_.begin(); it != _other.animations_.end(); ++it)
454 if (*it)
455 animations_.push_back((**it).copy());
456
457 referencePose_ = _other.referencePose_;
458 }
459
460 return *this;
461 }
462
463 //-----------------------------------------------------------------------------
464
469 template<typename PointT>
470 SkeletonT<PointT>::~SkeletonT( )
471 {
472 // clear the joints and animations
473 clear();
474 }
475
476 //-----------------------------------------------------------------------------
477
487 template<typename PointT>
488 void SkeletonT<PointT>::addJoint(typename SkeletonT<PointT>::Joint *_pParent, typename SkeletonT<PointT>::Joint *_pJoint)
489 {
490 size_t newJointID;
491
492 if(_pParent == 0)
493 {
494 clear();
495 clean_properties();
496
497 _pJoint->setId(0);
498 joints_.push_back(_pJoint);
499
500 newJointID = 0;
501 }else{
502 _pParent->children_.push_back(_pJoint); // tell the parent about the new child
503 _pJoint->setId(joints_.size()); // set its id
504 joints_.push_back(_pJoint); // add it to the skeleton vector
505
506 newJointID = joints_.size() - 1;
507 }
508
509 //onAddJoint
510 insert_property_at(newJointID);
511
512 referencePose_.insertJointAt(newJointID);
513 for(typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
514 if (*it)
515 (*it)->insertJointAt(newJointID);
516
517 referencePose_.updateFromGlobal(0, true);
518 }
519
520 //-----------------------------------------------------------------------------
521
531 template<typename PointT>
532 void SkeletonT<PointT>::removeJoint(typename SkeletonT<PointT>::Joint *_pJoint)
533 {
534
535 if (joints_.size() == 1){
536 std::cerr << "Cannot delete last joint. Delete the skeleton instead." << std::endl;
537 return;
538 }
539
540 remove_property_at(_pJoint->id());
541 referencePose_.removeJointAt(_pJoint->id());
542
543 for(typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
544 if (*it) (*it)->removeJointAt(_pJoint->id());
545
546 // Reattach the deleted joint's children to the joint's parent
547 typename SkeletonT<PointT>::Joint::ChildIter c_it = _pJoint->begin();
548
549 if( _pJoint->parent() == 0 ){
550 //root removal
551 typename SkeletonT<PointT>::Joint* newRoot = *c_it; //first child is new root
552 newRoot->parent_ = 0;
553 ++c_it;
554
555 for ( ; c_it!=_pJoint->end(); ++c_it) {
556 (*c_it)->parent_ = newRoot;
557 newRoot->children_.push_back(*c_it);
558 }
559
560 } else {
561
562 for ( ; c_it!=_pJoint->end(); ++c_it) {
563 (*c_it)->parent_ = _pJoint->parent_;
564 _pJoint->parent_->children_.push_back(*c_it);
565 }
566
567 if(std::remove(_pJoint->parent_->children_.begin(), _pJoint->parent_->children_.end(), _pJoint) != _pJoint->parent_->children_.end()) // remove the joint from its parent
568 _pJoint->parent_->children_.resize(_pJoint->parent_->children_.size() - 1);
569 }
570
571 typename std::vector<Joint*>::iterator it = joints_.begin() + _pJoint->id(); // iterator pointing to the element that has to be erased
572 it = joints_.erase(it); // erase the element
573 for(; it != joints_.end(); ++it) // for all following elements
574 (*it)->setId((*it)->id() - 1); // reduce their index by one (since they have been moved there)
575
576 referencePose_.updateFromGlobal(0, true);
577 for (typename std::vector<Animation*>::iterator a_it = animations_.begin(); a_it != animations_.end(); ++a_it) {
578 if (*a_it)
579 (*a_it)->updateFromGlobal(0);
580 }
581 }
582
583 //-----------------------------------------------------------------------------
584
592 template<typename PointT>
593 inline void SkeletonT<PointT>::clear()
594 {
595 // no joints, so no animation either
596 clean_properties();
597 clearAnimations();
598
599 // clear the joints
600 typename std::vector<Joint*>::iterator it;
601 for(it = joints_.begin(); it != joints_.end(); ++it)
602 delete *it;
603
604 joints_.clear();
605 names_.clear();
606 }
607
608 //-----------------------------------------------------------------------------
609
617 template<typename PointT>
618 inline typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::root()
619 {
620 if(joints_.empty())
621 return 0;
622 return joints_[0];
623 }
624
625 //-----------------------------------------------------------------------------
626
635 template<typename PointT>
636 inline typename SkeletonT<PointT>::Joint *SkeletonT<PointT>::joint(const size_t& _index)
637 {
638 if(_index >= joints_.size())
639 return 0;
640 return joints_[_index];
641 }
642
643 //-----------------------------------------------------------------------------
644
651 template<typename PointT>
652 int SkeletonT<PointT>::parent(size_t _joint)
653 {
654 if(joints_[_joint]->parent() == 0)
655 return -1;
656 return joints_[_joint]->parent()->id();
657 }
658
659 //-----------------------------------------------------------------------------
660
664 template<typename PointT>
665 size_t SkeletonT<PointT>::childCount(size_t _joint)
666 {
667 if ( _joint >= joints_.size() ){
668 std::cerr << "SkeletonT : childCount() called with non-existing joint " << _joint << std::endl;
669 return 0;
670 }
671
672 return joints_[_joint]->size();
673 }
674
675 //-----------------------------------------------------------------------------
676
683 template<typename PointT>
684 size_t SkeletonT<PointT>::child(size_t _joint, size_t _child)
685 {
686 return joints_[_joint]->child(_child)->id();
687 }
688
689 //-----------------------------------------------------------------------------
690
694 template<typename PointT>
695 size_t SkeletonT<PointT>::jointCount()
696 {
697 return joints_.size();
698 }
699
700 //-----------------------------------------------------------------------------
701
707 template<typename PointT>
708 typename SkeletonT<PointT>::Iterator SkeletonT<PointT>::begin()
709 {
710 return Iterator(root());
711 }
712
713 //-----------------------------------------------------------------------------
714
718 template<typename PointT>
719 typename SkeletonT<PointT>::Iterator SkeletonT<PointT>::end()
720 {
721 // why return Iterator(0)? operator= will compare the current pointer, and 0 is used once the iterator
722 // passed the last joint
723 return Iterator(0);
724 }
725
726
727 //-----------------------------------------------------------------------------
728
734 template<typename PointT>
735 inline typename SkeletonT<PointT>::Pose* SkeletonT<PointT>::pose(const AnimationHandle &_hAni)
736 {
737 if(_hAni.isValid() && _hAni.animationIndex() < animations_.size() && animations_[_hAni.animationIndex()] != NULL)
738 return animations_[_hAni.animationIndex()]->pose(_hAni.frame());
739 else
740 return &referencePose_;
741 }
742
743 //-----------------------------------------------------------------------------
744
754 template<typename PointT>
755 inline typename SkeletonT<PointT>::Pose* SkeletonT<PointT>::referencePose()
756 {
757 return &referencePose_;
758 }
759
760 //-----------------------------------------------------------------------------
761
768 template<typename PointT>
769 AnimationHandle SkeletonT<PointT>::addAnimation(std::string _name, Animation *_animation)
770 {
771 // try to find an unused animation slot first
772 typename std::vector<Animation*>::iterator f;
773 for(f = animations_.begin(); f != animations_.end(); ++f)
774 if(*f == 0)
775 break;
776
777 if(f == animations_.end())
778 {
779 // all in use, append
780 names_.insert( std::pair<std::string, size_t>(_name, animations_.size()) );
781 animations_.push_back(_animation);
782 }else{
783 // found an empty one, use it
784 names_.insert( std::pair<std::string, size_t>(_name, f - animations_.begin()) );
785 *f = _animation;
786 }
787
788 if (_animation)
789 _animation->setName(_name);
790
791 return AnimationHandle(names_[_name]);
792 }
793
794 //-----------------------------------------------------------------------------
795
802 template<typename PointT>
803 AnimationHandle SkeletonT<PointT>::cloneAnimation(std::string _name, const AnimationHandle &_hAni)
804 {
805 // try to find an unused animation slot first
806 typename std::vector<Animation*>::iterator f;
807 for(f = animations_.begin(); f != animations_.end(); ++f)
808 if(*f == 0)
809 break;
810
811 if(f == animations_.end())
812 {
813 // all in use, append
814 names_.insert( std::pair<std::string, size_t>(_name, animations_.size()) );
815 if(animation(_hAni) != 0)
816 animations_.push_back((*animation(_hAni)).copy());
817 else
818 animations_.push_back(new FrameAnimationT<Point>(referencePose_));
819 }else{
820 // found an empty one, use it
821 names_.insert( std::pair<std::string, size_t>(_name, f - animations_.begin()) );
822 if(animation(_hAni) != 0)
823 *f = (*animation(_hAni)).copy();
824 else
825 *f = new FrameAnimationT<Point>(referencePose_);
826 }
827
828 return AnimationHandle(names_[_name]);
829 }
830
831 //-----------------------------------------------------------------------------
832
836 template<typename PointT>
837 AnimationHandle SkeletonT<PointT>::animationHandle(std::string _name)
838 {
839 std::map<std::string, size_t>::iterator f = names_.find(_name);
840 if(f == names_.end())
841 return AnimationHandle();
842
843 return AnimationHandle(f->second);
844 }
845
846 //-----------------------------------------------------------------------------
847
851 template<typename PointT>
852 typename SkeletonT<PointT>::Animation *SkeletonT<PointT>::animation(std::string _name)
853 {
854 std::map<std::string, size_t>::iterator f = names_.find(_name);
855 if(f == names_.end())
856 return 0;
857
858 return animations_[f->second];
859 }
860
861 //-----------------------------------------------------------------------------
862
866 template<typename PointT>
867 typename SkeletonT<PointT>::Animation *SkeletonT<PointT>::animation(const AnimationHandle &_hAni)
868 {
869 if(!_hAni.isValid())
870 return 0;
871 return animations_[_hAni.animationIndex()];
872 }
873
874 //-----------------------------------------------------------------------------
875
879 template<typename PointT>
880 void SkeletonT<PointT>::removeAnimation(std::string _name)
881 {
882 // get an iterator for the animation
883 std::map<std::string, size_t>::iterator f = names_.find(_name);
884 if(f == names_.end())
885 return;
886
887 // delete the animation
888 delete animations_[f->second];
889 animations_[f->second] = 0;
890 // remove the name entry
891 names_.erase(f);
892 }
893
894 //-----------------------------------------------------------------------------
895
899 template<typename PointT>
900 void SkeletonT<PointT>::removeAnimation(const AnimationHandle &_hAni)
901 {
902 // delete the animation
903 delete animations_[_hAni.animationIndex()];
904 animations_[_hAni.animationIndex()] = 0;
905
906 // remove the name entry
907 for(typename std::map<std::string, size_t>::iterator it = names_.begin(); it != names_.end(); ++it)
908 {
909 if(it->second == _hAni.animationIndex())
910 {
911 names_.erase(it);
912 break;
913 }
914 }
915 }
916
917 //-----------------------------------------------------------------------------
918
922 template<typename PointT>
923 void SkeletonT<PointT>::clearAnimations()
924 {
925 names_.clear();
926
927 for(typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
928 delete *it;
929 animations_.clear();
930 }
931
932 //-----------------------------------------------------------------------------
933
938 template<typename PointT>
939 typename SkeletonT<PointT>::AnimationIterator SkeletonT<PointT>::animationsBegin()
940 {
941 return AnimationIterator(animations_);
942 }
943
944 //-----------------------------------------------------------------------------
945
949 template<typename PointT>
950 typename SkeletonT<PointT>::AnimationIterator SkeletonT<PointT>::animationsEnd()
951 {
952
953 return AnimationIterator(animations_.size());
954 }
955
956
957 //-----------------------------------------------------------------------------
958
964 template<typename PointT>
965 size_t SkeletonT<PointT>::animationCount()
966 {
967 return names_.size();
968 }
969
970 //-----------------------------------------------------------------------------
971
977 template<typename PointT>
978 const std::string &SkeletonT<PointT>::animationName(size_t _index)
979 {
980 std::map<std::string, size_t>::iterator pos = names_.begin();
981
982 while(pos->second != _index && pos != names_.end())
983 {
984 ++pos;
985 }
986
987 return pos->first;
988 }
989
990 //-----------------------------------------------------------------------------
991
997 template<typename PointT>
998 void SkeletonT<PointT>::updateFromGlobal(size_t _idJoint)
999 {
1000 referencePose_.updateFromGlobal(_idJoint);
1001 for(typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it) {
1002 if (*it)
1003 (*it)->updateFromGlobal(_idJoint);
1004 }
1005 }
1006
1007 //-----------------------------------------------------------------------------
1008
1015 template<typename PointT>
1016 void SkeletonT<PointT>::insertJoint(typename SkeletonT<PointT>::Joint *_pChild, typename SkeletonT<PointT>::Joint *_pInsert)
1017 {
1018 if (!_pChild || !_pChild->parent() || !_pInsert)
1019 return;
1020
1021 Joint* parent = _pChild->parent();
1022
1023 //update IDs of our joints
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);
1027
1028 //insert our new joint into this skeleton
1029 joints_.insert(joints_.begin() + childID, _pInsert);
1030 _pInsert->setId(childID);
1031
1032 //update the parents
1033 //note: pChild will be automatically erased in parent->children_
1034 _pInsert->setParent(parent, *this);
1035 _pChild->setParent(_pInsert, *this);
1036
1037 insert_property_at(childID);
1038
1039 referencePose_.insertJointAt(childID);
1040 for(typename std::vector<Animation*>::iterator it = animations_.begin(); it != animations_.end(); ++it)
1041 if (*it)
1042 (*it)->insertJointAt(childID);
1043
1044 referencePose_.updateFromGlobal(0, true);
1045 }
1046
1047 //-----------------------------------------------------------------------------
1048
AnimationHandle::animationIndex
size_t animationIndex() const
Returns the animation index (zero based)
Definition: AnimationHandle.hh:57
SkeletonT::child
size_t child(size_t _joint, size_t _child)
Returns the child with the given index.
Definition: SkeletonT_impl.hh:684
SkeletonT::end
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Definition: SkeletonT_impl.hh:719
JointT::id
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97
JointT::size
size_t size() const
Returns the number of children.
Definition: JointT_impl.hh:197
SkeletonT::SkeletonT
SkeletonT()
Default constructor.
Definition: SkeletonT_impl.hh:371
SkeletonT::cloneAnimation
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
Definition: SkeletonT_impl.hh:803
SkeletonT::jointCount
size_t jointCount()
Returns the number of joints.
Definition: SkeletonT_impl.hh:695
FrameAnimationT
Definition: FrameAnimationT.hh:47
SkeletonT::joint
Joint * joint(const size_t &_index)
Returns the joint with the given index.
Definition: SkeletonT_impl.hh:636
SkeletonT::AnimationIterator::operator++
AnimationIterator & operator++()
Increase the iterator.
Definition: SkeletonT_impl.hh:322
SkeletonT::removeJoint
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
Definition: SkeletonT_impl.hh:532
SkeletonT::animationsBegin
AnimationIterator animationsBegin()
Iterator over the animations.
Definition: SkeletonT_impl.hh:939
SkeletonT::operator=
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Definition: SkeletonT_impl.hh:425
SkeletonT::referencePose_
Pose referencePose_
The skeletons reference pose.
Definition: SkeletonT.hh:223
AnimationT
Stores a single animation.
Definition: AnimationT.hh:58
PoseT
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
SkeletonT::animationsEnd
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
Definition: SkeletonT_impl.hh:950
SkeletonT::Iterator::nextSibling
Joint * nextSibling(Joint *_pParent, Joint *_pJoint)
Given a parent and one of its child nodes this method finds and returns the next sibling.
Definition: SkeletonT_impl.hh:258
AnimationHandle::frame
size_t frame() const
Returns the selected frame (zero based)
Definition: AnimationHandle.hh:60
Properties
The properties storage class.
Definition: Properties.hh:92
SkeletonT::AnimationIterator::operator=
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
Definition: SkeletonT_impl.hh:338
AnimationHandle::isValid
bool isValid() const
Returns true if the handle is valid.
Definition: AnimationHandle.hh:55
SkeletonT::begin
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Definition: SkeletonT_impl.hh:708
SkeletonT::childCount
size_t childCount(size_t _joint)
Returns the number of children of the given node.
Definition: SkeletonT_impl.hh:665
SkeletonT::Iterator::operator*
Joint * operator*() const
Returns a pointer to the current joint.
Definition: SkeletonT_impl.hh:211
JointT::setParent
void setParent(Joint *_newParent, SkeletonT< PointT > &_skeleton)
access parent of the joint
Definition: JointT_impl.hh:122
Properties::remove_property_at
void remove_property_at(int _index)
Removes a property for an object that is being deleted from the derived class.
Definition: Properties.cc:122
SkeletonT::removeAnimation
void removeAnimation(std::string _name)
Removes an animation from the list.
Definition: SkeletonT_impl.hh:880
JointT::end
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT_impl.hh:186
SkeletonT::names_
std::map< std::string, size_t > names_
Binds a name to each animation.
Definition: SkeletonT.hh:218
JointT
Represents a single joint in the skeleton.
Definition: JointT.hh:60
SkeletonT::referencePose
Pose * referencePose()
Returns a pointer to the reference pose.
Definition: SkeletonT_impl.hh:755
SkeletonT::insertJoint
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
Definition: SkeletonT_impl.hh:1016
SkeletonT::addJoint
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
Definition: SkeletonT_impl.hh:488
SkeletonT::parent
int parent(size_t _joint)
Returns the parents id of the given node.
Definition: SkeletonT_impl.hh:652
SkeletonT::Iterator::Iterator
Iterator()
Default constructor.
Definition: SkeletonT_impl.hh:73
SkeletonT::animationName
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
Definition: SkeletonT_impl.hh:978
SkeletonT::clearAnimations
void clearAnimations()
Removes all animations.
Definition: SkeletonT_impl.hh:923
SkeletonT::pose
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Definition: SkeletonT_impl.hh:735
SkeletonT::root
Joint * root()
Returns the root joint.
Definition: SkeletonT_impl.hh:618
JointT::child
Joint * child(size_t _index)
Returns the child joint with the given index.
Definition: JointT_impl.hh:211
Properties::insert_property_at
void insert_property_at(int _index)
Inserts a property for a new object at the given index.
Definition: Properties.cc:105
SkeletonT::AnimationIterator
Iterator class for the animations attached to a skeleton.
Definition: SkeletonT.hh:114
SkeletonT::joints_
std::vector< Joint * > joints_
Joints of the skeleton.
Definition: SkeletonT.hh:215
SkeletonT::Iterator
Iterator class for the skeleton.
Definition: SkeletonT.hh:82
SkeletonT::addAnimation
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
Definition: SkeletonT_impl.hh:769
SkeletonT::Iterator::operator->
Joint * operator->() const
Returns a pointer to the current joint.
Definition: SkeletonT_impl.hh:229
SkeletonT::clear
void clear()
Removes all joints from the skeleton.
Definition: SkeletonT_impl.hh:593
SkeletonT::AnimationIterator::operator*
AnimationHandle operator*() const
Get an animation handle for the current animation.
Definition: SkeletonT_impl.hh:359
SkeletonT::animation
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Definition: SkeletonT_impl.hh:852
SkeletonT::~SkeletonT
~SkeletonT()
Destructor.
Definition: SkeletonT_impl.hh:470
SkeletonT::updateFromGlobal
void updateFromGlobal(size_t _idJoint)
update the structure when parent changes for a joint
Definition: SkeletonT_impl.hh:998
SkeletonT::Iterator::operator==
bool operator==(const Iterator &other) const
Compares the iterators.
Definition: SkeletonT_impl.hh:200
JointT::parent
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
SkeletonT::Iterator::~Iterator
~Iterator()
Destructor.
Definition: SkeletonT_impl.hh:113
SkeletonT::AnimationIterator::AnimationIterator
AnimationIterator(std::vector< Animation *> &_animations)
Default constructor.
Definition: SkeletonT_impl.hh:288
SkeletonT::animationCount
size_t animationCount()
Returns the number of animations stored in this skeleton.
Definition: SkeletonT_impl.hh:965
PoseT::insertJointAt
virtual void insertJointAt(size_t _index)
Called by the skeleton/animation as a new joint is inserted.
Definition: PoseT_impl.hh:281
SkeletonT::Iterator::operator!=
bool operator!=(const Iterator &other) const
Compares the iterators.
Definition: SkeletonT_impl.hh:187
SkeletonT
Definition: JointT.hh:50
SkeletonT::animationHandle
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Definition: SkeletonT_impl.hh:837
PoseT::updateFromGlobal
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...
Definition: PoseT_impl.hh:353
JointT::parent_
Joint * parent_
The parent joint; this joint is in its parents JointT::children_ vector. It&#39;s 0 for the root node...
Definition: JointT.hh:121
SkeletonT::Iterator::operator++
Iterator & operator++()
Increase the iterator.
Definition: SkeletonT_impl.hh:141
SkeletonT::animations_
std::vector< Animation * > animations_
Animations defined on the skeleton.
Definition: SkeletonT.hh:220
SkeletonT::Iterator::operator=
Iterator & operator=(const Iterator &other)
Assignment Operator.
Definition: SkeletonT_impl.hh:126
PoseT::removeJointAt
virtual void removeJointAt(size_t _index)
Called by the skeleton/animation as a joint is removed.
Definition: PoseT_impl.hh:298
Properties::clean_properties
void clean_properties()
While preserving the properties themself, all values in the property are deleted. ...
Definition: Properties.cc:71
AnimationHandle
A handle used to refer to an animation or to a specific frame in an animation.
Definition: AnimationHandle.hh:47
JointT::children_
std::vector< Joint * > children_
The joints children, use the JointT::getChild method to access them.
Definition: JointT.hh:123
JointT::begin
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT_impl.hh:175