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 (C) 2012-2014 Open Source Robotics Foundation
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 "gazebo/math/Matrix4.hh"
26 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace common
31  {
32  class SkeletonNode;
33  class NodeTransform;
35 
36  typedef std::map<unsigned int, SkeletonNode*> NodeMap;
37  typedef std::map<unsigned int, SkeletonNode*>::iterator NodeMapIter;
38 
39  typedef std::map<double, std::vector<NodeTransform> > RawNodeAnim;
40  typedef std::map<std::string, RawNodeAnim> RawSkeletonAnim;
41 
42  typedef std::vector<std::vector<std::pair<std::string, double> > >
44 
47 
51  {
53  public: Skeleton();
54 
57  public: Skeleton(SkeletonNode *_root);
58 
60  public: virtual ~Skeleton();
61 
64  public: void SetRootNode(SkeletonNode* _node);
65 
68  public: SkeletonNode* GetRootNode();
69 
73  public: SkeletonNode* GetNodeByName(std::string _name);
74 
78  public: SkeletonNode* GetNodeById(std::string _id);
79 
83  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
84 
87  public: unsigned int GetNumNodes();
88 
91  public: unsigned int GetNumJoints();
92 
95  public: void Scale(double _scale);
96 
99  public: void SetBindShapeTransform(math::Matrix4 _trans);
100 
103  public: math::Matrix4 GetBindShapeTransform();
104 
106  public: void PrintTransforms();
107 
109  public: NodeMap GetNodes();
110 
113  public: void SetNumVertAttached(unsigned int _vertices);
114 
119  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
120  double _weight);
121 
125  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
126 
131  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
132  unsigned int _i);
133 
136  public: unsigned int GetNumAnimations();
137 
141  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
142 
146  public: void AddAnimation(SkeletonAnimation *_anim);
147 
150  protected: void BuildNodeMap();
151 
153  protected: SkeletonNode *root;
154 
156  protected: NodeMap nodes;
157 
160 
162  protected: RawNodeWeights rawNW;
163 
165  protected: std::vector<SkeletonAnimation*> anims;
166  };
167 
171  {
173  public: enum SkeletonNodeType {NODE, JOINT};
174 
177  public: SkeletonNode(SkeletonNode* _parent);
178 
184  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
185  std::string _id, SkeletonNodeType _type = JOINT);
186 
188  public: virtual ~SkeletonNode();
189 
192  public: void SetName(std::string _name);
193 
196  public: std::string GetName();
197 
200  public: void SetId(std::string _id);
201 
204  public: std::string GetId();
205 
208  public: void SetType(SkeletonNodeType _type);
209 
212  public: bool IsJoint();
213 
218  public: void SetTransform(math::Matrix4 _trans,
219  bool _updateChildren = true);
220 
225  public: void SetModelTransform(math::Matrix4 _trans,
226  bool _updateChildren = true);
227 
229  public: void UpdateChildrenTransforms();
230 
233  public: void SetInitialTransform(math::Matrix4 _tras);
234 
238  public: void Reset(bool _resetChildren);
239 
241  public: math::Matrix4 GetTransform();
242 
245  public: void SetParent(SkeletonNode* _parent);
246 
249  public: SkeletonNode* GetParent();
250 
253  public: bool IsRootNode();
254 
257  public: void AddChild(SkeletonNode* _child);
258 
261  public: unsigned int GetChildCount();
262 
266  public: SkeletonNode* GetChild(unsigned int _index);
267 
271  public: SkeletonNode* GetChildByName(std::string _name);
272 
276  public: SkeletonNode* GetChildById(std::string _id);
277 
280  public: void SetHandle(unsigned int _h);
281 
284  public: unsigned int GetHandle();
285 
288  public: void SetInverseBindTransform(math::Matrix4 _invBM);
289 
292  public: math::Matrix4 GetInverseBindTransform();
293 
296  public: math::Matrix4 GetModelTransform();
297 
300  public: std::vector<NodeTransform> GetRawTransforms();
301 
304  public: unsigned int GetNumRawTrans();
305 
309  public: NodeTransform GetRawTransform(unsigned int _i);
310 
313  public: void AddRawTransform(NodeTransform _t);
314 
317  public: std::vector<NodeTransform> GetTransforms();
318 
320  protected: std::string name;
321 
323  protected: std::string id;
324 
326  protected: SkeletonNodeType type;
327 
330 
333 
336 
339 
341  protected: SkeletonNode *parent;
342 
344  protected: std::vector<SkeletonNode*> children;
345 
347  protected: unsigned int handle;
348 
350  protected: std::vector<NodeTransform> rawTransforms;
351  };
352 
356  {
358  public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
359 
362  public: NodeTransform(TransformType _type = MATRIX);
363 
368  public: NodeTransform(math::Matrix4 _mat, std::string _sid = "_default_",
369  TransformType _type = MATRIX);
370 
372  public: ~NodeTransform();
373 
376  public: void Set(math::Matrix4 _mat);
377 
380  public: void SetType(TransformType _type);
381 
384  public: void SetSID(std::string _sid);
385 
388  public: math::Matrix4 Get();
389 
392  public: TransformType GetType();
393 
396  public: std::string GetSID();
397 
401  public: void SetComponent(unsigned int _idx, double _value);
402 
405  public: void SetSourceValues(math::Matrix4 _mat);
406 
408  public: void SetSourceValues(math::Vector3 _vec);
409 
413  public: void SetSourceValues(math::Vector3 _axis, double _angle);
414 
416  public: void RecalculateMatrix();
417 
419  public: void PrintSource();
420 
423  public: math::Matrix4 operator() ();
424 
428  public: math::Matrix4 operator* (NodeTransform _t);
429 
433  public: math::Matrix4 operator* (math::Matrix4 _m);
434 
436  protected: std::string sid;
437 
439  protected: TransformType type;
440 
443 
445  protected: std::vector<double> source;
446  };
448  }
449 }
450 #endif
451