All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Skeleton.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef SKELETON_HH
18 #define SKELETON_HH
19 
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include <utility>
24 
25 #include "math/Matrix4.hh"
26 
27 namespace gazebo
28 {
29  namespace common
30  {
31  class SkeletonNode;
32  class NodeTransform;
34 
35  typedef std::map<unsigned int, SkeletonNode*> NodeMap;
36  typedef std::map<unsigned int, SkeletonNode*>::iterator NodeMapIter;
37 
38  typedef std::map<double, std::vector<NodeTransform> > RawNodeAnim;
39  typedef std::map<std::string, RawNodeAnim> RawSkeletonAnim;
40 
41  typedef std::vector<std::vector<std::pair<std::string, double> > >
43 
46 
48  class Skeleton
49  {
51  public: Skeleton();
52 
55  public: Skeleton(SkeletonNode *_root);
56 
58  public: virtual ~Skeleton();
59 
62  public: void SetRootNode(SkeletonNode* _node);
63 
66  public: SkeletonNode* GetRootNode();
67 
71  public: SkeletonNode* GetNodeByName(std::string _name);
72 
76  public: SkeletonNode* GetNodeById(std::string _id);
77 
81  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
82 
85  public: unsigned int GetNumNodes();
86 
89  public: unsigned int GetNumJoints();
90 
93  public: void Scale(double _scale);
94 
97  public: void SetBindShapeTransform(math::Matrix4 _trans);
98 
102 
104  public: void PrintTransforms();
105 
107  public: NodeMap GetNodes();
108 
111  public: void SetNumVertAttached(unsigned int _vertices);
112 
117  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
118  double _weight);
119 
123  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
124 
129  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
130  unsigned int _i);
131 
134  public: unsigned int GetNumAnimations();
135 
139  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
140 
144  public: void AddAnimation(SkeletonAnimation *_anim);
145 
148  protected: void BuildNodeMap();
149 
151  protected: SkeletonNode *root;
152 
154  protected: NodeMap nodes;
155 
158 
160  protected: RawNodeWeights rawNW;
161 
163  protected: std::vector<SkeletonAnimation*> anims;
164  };
165 
168  {
170  public: enum SkeletonNodeType {NODE, JOINT};
171 
173  public: SkeletonNode(SkeletonNode* _parent);
174 
179  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
180  std::string _id, SkeletonNodeType _type = JOINT);
181 
183  public: virtual ~SkeletonNode();
184 
187  public: void SetName(std::string _name);
188 
191  public: std::string GetName();
192 
195  public: void SetId(std::string _id);
196 
199  public: std::string GetId();
200 
203  public: void SetType(SkeletonNodeType _type);
204 
207  public: bool IsJoint();
208 
213  public: void SetTransform(math::Matrix4 _trans,
214  bool _updateChildren = true);
215 
220  public: void SetModelTransform(math::Matrix4 _trans,
221  bool _updateChildren = true);
222 
224  public: void UpdateChildrenTransforms();
225 
228  public: void SetInitialTransform(math::Matrix4 _tras);
229 
233  public: void Reset(bool _resetChildren);
234 
236  public: math::Matrix4 GetTransform();
237 
240  public: void SetParent(SkeletonNode* _parent);
241 
244  public: SkeletonNode* GetParent();
245 
248  public: bool IsRootNode();
249 
252  public: void AddChild(SkeletonNode* _child);
253 
256  public: unsigned int GetChildCount();
257 
261  public: SkeletonNode* GetChild(unsigned int _index);
262 
266  public: SkeletonNode* GetChildByName(std::string _name);
267 
271  public: SkeletonNode* GetChildById(std::string _id);
272 
275  public: void SetHandle(unsigned int _h);
276 
279  public: unsigned int GetHandle();
280 
283  public: void SetInverseBindTransform(math::Matrix4 _invBM);
284 
288 
292 
295  public: std::vector<NodeTransform> GetRawTransforms();
296 
299  public: unsigned int GetNumRawTrans();
300 
304  public: NodeTransform GetRawTransform(unsigned int _i);
305 
308  public: void AddRawTransform(NodeTransform _t);
309 
312  public: std::vector<NodeTransform> GetTransforms();
313 
315  protected: std::string name;
316 
318  protected: std::string id;
319 
321  protected: SkeletonNodeType type;
322 
325 
328 
331 
334 
336  protected: SkeletonNode *parent;
337 
339  protected: std::vector<SkeletonNode*> children;
340 
342  protected: unsigned int handle;
343 
345  protected: std::vector<NodeTransform> rawTransforms;
346  };
347 
350  {
353 
356  public: NodeTransform(TransformType _type = MATRIX);
357 
362  public: NodeTransform(math::Matrix4 _mat, std::string _sid = "_default_",
363  TransformType _type = MATRIX);
364 
366  public: ~NodeTransform();
367 
370  public: void Set(math::Matrix4 _mat);
371 
374  public: void SetType(TransformType _type);
375 
378  public: void SetSID(std::string _sid);
379 
382  public: math::Matrix4 Get();
383 
386  public: TransformType GetType();
387 
390  public: std::string GetSID();
391 
395  public: void SetComponent(unsigned int _idx, double _value);
396 
399  public: void SetSourceValues(math::Matrix4 _mat);
400 
402  public: void SetSourceValues(math::Vector3 _vec);
403 
407  public: void SetSourceValues(math::Vector3 _axis, double _angle);
408 
410  public: void RecalculateMatrix();
411 
413  public: void PrintSource();
414 
417  public: math::Matrix4 operator() ();
418 
423 
428 
430  protected: std::string sid;
431 
433  protected: TransformType type;
434 
437 
439  protected: std::vector<double> source;
440  };
442  }
443 }
444 #endif
445