Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SkeletonT.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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #ifndef SKELETONT_HH
51 #define SKELETONT_HH
52
53
54 //== INCLUDES =================================================================
55 #include <map>
56 #include <vector>
57 #include <iostream>
58 #include "JointT.hh"
59 #include "Properties.hh"
60 #include "Animation/AnimationT.hh"
61 #include "PoseT.hh"
62
63 #include <stack>
64
65 template <class PointT>
66 class SkeletonT : public Properties
67 {
68 template<typename>
69 friend class JointT;
70
71 public:
72 typedef PointT Point;
73 typedef typename Point::value_type Scalar;
74 typedef JointT<Point> Joint;
75 typedef PoseT<PointT> Pose;
76 typedef AnimationT<PointT> Animation;
77 typedef typename ACG::Matrix4x4T<Scalar> Matrix;
78
79 public:
80
88 class Iterator
89 {
90 public:
91 Iterator();
92 Iterator(Joint *_root);
93 Iterator(const Iterator &other);
94 ~Iterator();
95 Iterator &operator=(const Iterator &other);
96
97 public:
98 Iterator &operator++();
99 bool operator!=(const Iterator &other) const;
100 bool operator==(const Iterator &other) const;
101 Joint *operator*() const;
102 Joint *operator->() const;
103 operator bool() const;
104
105 private:
106 Joint *nextSibling(Joint *_pParent, Joint *_pJoint);
107
108 private:
109 // Holds the current position in the tree
110 Joint *pCurrent_;
111 // The stack of joints, marking a path back to the root joint
112 std::stack<Joint*> stJoints_;
113 };
114
120 class AnimationIterator {
121 public:
122 AnimationIterator(std::vector<Animation*>& _animations );
123 AnimationIterator(std::vector<Animation*>& _animations, unsigned int _animationIndex );
124
125 public:
126 AnimationIterator &operator++();
127 AnimationHandle operator*() const;
128 AnimationIterator &operator=(const AnimationIterator &other);
129 operator bool() const;
130
131 private:
132 unsigned int currentIndex_;
133
134 std::vector<Animation*>& animations_;
135 };
136
137 public:
139 SkeletonT();
141 SkeletonT(const SkeletonT<PointT>& _other);
143 SkeletonT& operator= (const SkeletonT<PointT>& _other);
144
146 ~SkeletonT();
147
148 public:
153 void addJoint(typename SkeletonT<PointT>::Joint *_pParent, typename SkeletonT<PointT>::Joint *_pJoint);
155 void insertJoint(typename SkeletonT<PointT>::Joint *_pChild, typename SkeletonT<PointT>::Joint *_pInsert);
156 void removeJoint(typename SkeletonT<PointT>::Joint *_pJoint);
157 inline void clear();
159
165 inline Joint *root();
167 inline Joint *joint(const unsigned int &_index);
168 int parent(unsigned int _joint);
169 unsigned int childCount(unsigned int _joint);
170 unsigned int child(unsigned int _joint, unsigned int _child);
171 unsigned int jointCount();
172
174 Iterator begin();
175 Iterator end();
177
182
184 inline Pose *pose(const AnimationHandle &_hAni);
185 inline Pose *referencePose();
186
187 AnimationHandle addAnimation(std::string _name, Animation* _animation);
188 AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni);
189 AnimationHandle animationHandle(std::string _name);
190 Animation *animation(std::string _name);
191 Animation *animation(const AnimationHandle &_hAni);
192 void removeAnimation(std::string _name);
193 void removeAnimation(const AnimationHandle &_hAni);
194 void clearAnimations();
195
196 void replaceAnimationName(const std::string& _strOld, const std::string& _strNew) {
197 std::map<std::string,unsigned int>::iterator f = names_.find(_strOld);
198 if(f != names_.end()) {
199 unsigned int c = f->second;
200 names_.erase(f);
201 names_[_strNew] = c;
202 }
203 }
204
206 AnimationIterator animationsBegin();
207 AnimationIterator animationsEnd();
208
209 unsigned int animationCount();
210 const std::string &animationName(unsigned int _index);
212
213
214 protected:
216 void updateFromGlobal(unsigned int _idJoint);
217
218 protected:
219
221 std::vector<Joint*> joints_;
222
224 std::map<std::string, unsigned int> names_;
226 std::vector<Animation*> animations_;
227
229 Pose referencePose_;
230 };
231
232 //=============================================================================
233 //=============================================================================
234 #if defined(INCLUDE_TEMPLATES) && !defined(SKELETON_C)
235 #define SKELETONT_TEMPLATES
236 #include "SkeletonT.cc"
237 #endif
238 //=============================================================================
239 #endif // SKELETONT_HH defined
240 //=============================================================================
241
SkeletonT::child
unsigned int child(unsigned int _joint, unsigned int _child)
Returns the child with the given index.
Definition: SkeletonT.cc:690
SkeletonT::childCount
unsigned int childCount(unsigned int _joint)
Returns the number of children of the given node.
Definition: SkeletonT.cc:671
SkeletonT::AnimationIterator::AnimationIterator
AnimationIterator(std::vector< Animation * > &_animations)
Default constructor.
Definition: SkeletonT.cc:294
SkeletonT::joints_
std::vector< Joint * > joints_
Joints of the skeleton.
Definition: SkeletonT.hh:221
SkeletonT::parent
int parent(unsigned int _joint)
Returns the parents id of the given node.
Definition: SkeletonT.cc:658
SkeletonT::AnimationIterator
Iterator class for the animations attached to a skeleton.
Definition: SkeletonT.hh:120
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.cc:494
SkeletonT::clearAnimations
void clearAnimations()
Removes all animations.
Definition: SkeletonT.cc:929
SkeletonT::Iterator::operator==
bool operator==(const Iterator &other) const
Compares the iterators.
Definition: SkeletonT.cc:206
SkeletonT::referencePose_
Pose referencePose_
The skeletons reference pose.
Definition: SkeletonT.hh:229
SkeletonT::Iterator::~Iterator
~Iterator()
Destructor.
Definition: SkeletonT.cc:119
Properties
The properties storage class.
Definition: Properties.hh:100
SkeletonT::pose
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Definition: SkeletonT.cc:741
SkeletonT::root
Joint * root()
Returns the root joint.
Definition: SkeletonT.cc:624
SkeletonT::animationsEnd
AnimationIterator animationsEnd()
Returns an iterator pointing behind the last animation.
Definition: SkeletonT.cc:956
SkeletonT::referencePose
Pose * referencePose()
Returns a pointer to the reference pose.
Definition: SkeletonT.cc:761
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.cc:264
SkeletonT::animation
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Definition: SkeletonT.cc:858
SkeletonT::Iterator::operator=
Iterator & operator=(const Iterator &other)
Assignment Operator.
Definition: SkeletonT.cc:132
SkeletonT::removeAnimation
void removeAnimation(std::string _name)
Removes an animation from the list.
Definition: SkeletonT.cc:886
SkeletonT::~SkeletonT
~SkeletonT()
Destructor.
Definition: SkeletonT.cc:476
PoseT
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
SkeletonT::jointCount
unsigned int jointCount()
Returns the number of joints.
Definition: SkeletonT.cc:701
SkeletonT::end
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Definition: SkeletonT.cc:725
SkeletonT::Iterator
Iterator class for the skeleton.
Definition: SkeletonT.hh:88
SkeletonT::Iterator::Iterator
Iterator()
Default constructor.
Definition: SkeletonT.cc:79
SkeletonT::joint
Joint * joint(const unsigned int &_index)
Returns the joint with the given index.
Definition: SkeletonT.cc:642
SkeletonT::removeJoint
void removeJoint(typename SkeletonT< PointT >::Joint *_pJoint)
Remove the given joint from the tree.
Definition: SkeletonT.cc:538
SkeletonT::animationHandle
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Definition: SkeletonT.cc:843
SkeletonT::cloneAnimation
AnimationHandle cloneAnimation(std::string _name, const AnimationHandle &_hAni)
Creates a new animation by cloning an existing one.
Definition: SkeletonT.cc:809
SkeletonT::AnimationIterator::operator=
AnimationIterator & operator=(const AnimationIterator &other)
Operator =.
Definition: SkeletonT.cc:344
SkeletonT::begin
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Definition: SkeletonT.cc:714
Properties.hh
The header for the properties, one file for all objects.
SkeletonT::AnimationIterator::operator++
AnimationIterator & operator++()
Increase the iterator.
Definition: SkeletonT.cc:328
SkeletonT::replaceAnimationName
void replaceAnimationName(const std::string &_strOld, const std::string &_strNew)
Returns a pointer to the pose with the given animation handle.
Definition: SkeletonT.hh:196
SkeletonT::names_
std::map< std::string, unsigned int > names_
Binds a name to each animation.
Definition: SkeletonT.hh:224
SkeletonT::animationCount
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
Definition: SkeletonT.cc:971
SkeletonT
Definition: JointT.hh:56
SkeletonT::Iterator::operator->
Joint * operator->() const
Returns a pointer to the current joint.
Definition: SkeletonT.cc:235
SkeletonT::updateFromGlobal
void updateFromGlobal(unsigned int _idJoint)
update the structure when parent changes for a joint
Definition: SkeletonT.cc:1006
SkeletonT::Iterator::operator!=
bool operator!=(const Iterator &other) const
Compares the iterators.
Definition: SkeletonT.cc:193
SkeletonT::insertJoint
void insertJoint(typename SkeletonT< PointT >::Joint *_pChild, typename SkeletonT< PointT >::Joint *_pInsert)
insert a Joint given its future child joint
Definition: SkeletonT.cc:1024
SkeletonT::Iterator::operator++
Iterator & operator++()
Increase the iterator.
Definition: SkeletonT.cc:147
SkeletonT::AnimationIterator::operator*
AnimationHandle operator*() const
Get an animation handle for the current animation.
Definition: SkeletonT.cc:365
AnimationHandle
A handle used to refer to an animation or to a specific frame in an animation.
Definition: AnimationHandle.hh:56
SkeletonT::operator=
SkeletonT & operator=(const SkeletonT< PointT > &_other)
Assignment operator.
Definition: SkeletonT.cc:431
AnimationT
Stores a single animation.
Definition: AnimationT.hh:67
SkeletonT::Iterator::operator*
Joint * operator*() const
Returns a pointer to the current joint.
Definition: SkeletonT.cc:217
SkeletonT::animationName
const std::string & animationName(unsigned int _index)
Returns the name of the animation with the given index.
Definition: SkeletonT.cc:984
SkeletonT::addAnimation
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
Definition: SkeletonT.cc:775
JointT
Represents a single joint in the skeleton.
Definition: JointT.hh:66
ACG::Matrix4x4T
Definition: Matrix4x4T.hh:98
SkeletonT::animations_
std::vector< Animation * > animations_
Animations defined on the skeleton.
Definition: SkeletonT.hh:226
SkeletonT::animationsBegin
AnimationIterator animationsBegin()
Iterator over the animations.
Definition: SkeletonT.cc:945
SkeletonT::clear
void clear()
Removes all joints from the skeleton.
Definition: SkeletonT.cc:599
SkeletonT::SkeletonT
SkeletonT()
Default constructor.
Definition: SkeletonT.cc:377