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 
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 
49  class Skeleton
50  {
52  public: Skeleton();
53 
56  public: Skeleton(SkeletonNode *_root);
57 
59  public: virtual ~Skeleton();
60 
63  public: void SetRootNode(SkeletonNode* _node);
64 
67  public: SkeletonNode* GetRootNode();
68 
72  public: SkeletonNode* GetNodeByName(std::string _name);
73 
77  public: SkeletonNode* GetNodeById(std::string _id);
78 
82  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
83 
86  public: unsigned int GetNumNodes();
87 
90  public: unsigned int GetNumJoints();
91 
94  public: void Scale(double _scale);
95 
98  public: void SetBindShapeTransform(math::Matrix4 _trans);
99 
103 
105  public: void PrintTransforms();
106 
108  public: NodeMap GetNodes();
109 
112  public: void SetNumVertAttached(unsigned int _vertices);
113 
118  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
119  double _weight);
120 
124  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
125 
130  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
131  unsigned int _i);
132 
135  public: unsigned int GetNumAnimations();
136 
140  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
141 
145  public: void AddAnimation(SkeletonAnimation *_anim);
146 
149  protected: void BuildNodeMap();
150 
152  protected: SkeletonNode *root;
153 
155  protected: NodeMap nodes;
156 
159 
161  protected: RawNodeWeights rawNW;
162 
164  protected: std::vector<SkeletonAnimation*> anims;
165  };
166 
170  {
172  public: enum SkeletonNodeType {NODE, JOINT};
173 
176  public: SkeletonNode(SkeletonNode* _parent);
177 
183  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
184  std::string _id, SkeletonNodeType _type = JOINT);
185 
187  public: virtual ~SkeletonNode();
188 
191  public: void SetName(std::string _name);
192 
195  public: std::string GetName();
196 
199  public: void SetId(std::string _id);
200 
203  public: std::string GetId();
204 
207  public: void SetType(SkeletonNodeType _type);
208 
211  public: bool IsJoint();
212 
217  public: void SetTransform(math::Matrix4 _trans,
218  bool _updateChildren = true);
219 
224  public: void SetModelTransform(math::Matrix4 _trans,
225  bool _updateChildren = true);
226 
228  public: void UpdateChildrenTransforms();
229 
232  public: void SetInitialTransform(math::Matrix4 _tras);
233 
237  public: void Reset(bool _resetChildren);
238 
240  public: math::Matrix4 GetTransform();
241 
244  public: void SetParent(SkeletonNode* _parent);
245 
248  public: SkeletonNode* GetParent();
249 
252  public: bool IsRootNode();
253 
256  public: void AddChild(SkeletonNode* _child);
257 
260  public: unsigned int GetChildCount();
261 
265  public: SkeletonNode* GetChild(unsigned int _index);
266 
270  public: SkeletonNode* GetChildByName(std::string _name);
271 
275  public: SkeletonNode* GetChildById(std::string _id);
276 
279  public: void SetHandle(unsigned int _h);
280 
283  public: unsigned int GetHandle();
284 
287  public: void SetInverseBindTransform(math::Matrix4 _invBM);
288 
292 
296 
299  public: std::vector<NodeTransform> GetRawTransforms();
300 
303  public: unsigned int GetNumRawTrans();
304 
308  public: NodeTransform GetRawTransform(unsigned int _i);
309 
312  public: void AddRawTransform(NodeTransform _t);
313 
316  public: std::vector<NodeTransform> GetTransforms();
317 
319  protected: std::string name;
320 
322  protected: std::string id;
323 
325  protected: SkeletonNodeType type;
326 
329 
332 
335 
338 
340  protected: SkeletonNode *parent;
341 
343  protected: std::vector<SkeletonNode*> children;
344 
346  protected: unsigned int handle;
347 
349  protected: std::vector<NodeTransform> rawTransforms;
350  };
351 
355  {
358 
361  public: NodeTransform(TransformType _type = MATRIX);
362 
367  public: NodeTransform(math::Matrix4 _mat, std::string _sid = "_default_",
368  TransformType _type = MATRIX);
369 
371  public: ~NodeTransform();
372 
375  public: void Set(math::Matrix4 _mat);
376 
379  public: void SetType(TransformType _type);
380 
383  public: void SetSID(std::string _sid);
384 
387  public: math::Matrix4 Get();
388 
391  public: TransformType GetType();
392 
395  public: std::string GetSID();
396 
400  public: void SetComponent(unsigned int _idx, double _value);
401 
404  public: void SetSourceValues(math::Matrix4 _mat);
405 
407  public: void SetSourceValues(math::Vector3 _vec);
408 
412  public: void SetSourceValues(math::Vector3 _axis, double _angle);
413 
415  public: void RecalculateMatrix();
416 
418  public: void PrintSource();
419 
422  public: math::Matrix4 operator() ();
423 
428 
433 
435  protected: std::string sid;
436 
438  protected: TransformType type;
439 
442 
444  protected: std::vector<double> source;
445  };
447  }
448 }
449 #endif
450