Skeleton.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
std::map< unsigned int, SkeletonNode * > NodeMap
Definition: Skeleton.hh:34
A skeleton.
Definition: Skeleton.hh:50
math::Matrix4 transform
the transform
Definition: Skeleton.hh:329
TransformType type
transform type
Definition: Skeleton.hh:439
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
std::string id
a string identifier
Definition: Skeleton.hh:323
Skeleton animation.
Definition: SkeletonAnimation.hh:121
std::vector< SkeletonNode * > children
the children nodes
Definition: Skeleton.hh:344
std::string sid
the sid
Definition: Skeleton.hh:436
std::string name
the name of the skeletal node
Definition: Skeleton.hh:320
A 3x3 matrix class.
Definition: Matrix4.hh:39
math::Matrix4 initialTransform
the initial transformation
Definition: Skeleton.hh:332
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:165
math::Matrix4 invBindTransform
the inverse of the bind pose skeletal transform
Definition: Skeleton.hh:338
std::vector< NodeTransform > rawTransforms
the raw transformation
Definition: Skeleton.hh:350
std::map< unsigned int, SkeletonNode * >::iterator NodeMapIter
Definition: Skeleton.hh:37
NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:355
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:358
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:173
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:156
#define SCALE
Definition: SpaceNavPrivate.hh:20
SkeletonNodeType type
the type fo node
Definition: Skeleton.hh:326
math::Matrix4 bindShapeTransform
the bind pose skeletal transform
Definition: Skeleton.hh:159
std::vector< double > source
source data values (can be a matrix, a position or rotation)
Definition: Skeleton.hh:445
Definition: Skeleton.hh:358
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:162
math::Matrix4 modelTransform
the model transformation
Definition: Skeleton.hh:335
SkeletonNode * parent
the parent node
Definition: Skeleton.hh:341
std::map< double, std::vector< NodeTransform > > RawNodeAnim
Definition: Skeleton.hh:39
unsigned int handle
handle index number
Definition: Skeleton.hh:347
A skeleton node.
Definition: Skeleton.hh:170
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
std::vector< std::vector< std::pair< std::string, double > > > RawNodeWeights
Definition: Skeleton.hh:43
SkeletonNode * root
the root node
Definition: Skeleton.hh:153
std::map< std::string, RawNodeAnim > RawSkeletonAnim
Definition: Skeleton.hh:40
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
math::Matrix4 transform
transform
Definition: Skeleton.hh:442