Skeleton.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 GAZEBO_COMMON_SKELETON_HH_
18 #define GAZEBO_COMMON_SKELETON_HH_
19 
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include <utility>
24 
25 #include <ignition/math/Matrix4.hh>
26 
28 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace common
33  {
34  class SkeletonNode;
35  class NodeTransform;
37 
38  typedef std::map<unsigned int, SkeletonNode*> NodeMap;
39  typedef std::map<unsigned int, SkeletonNode*>::iterator NodeMapIter;
40 
41  typedef std::map<double, std::vector<NodeTransform> > RawNodeAnim;
42  typedef std::map<std::string, RawNodeAnim> RawSkeletonAnim;
43 
44  typedef std::vector<std::vector<std::pair<std::string, double> > >
46 
49 
52  class GZ_COMMON_VISIBLE Skeleton
53  {
55  public: Skeleton();
56 
59  public: Skeleton(SkeletonNode *_root);
60 
62  public: virtual ~Skeleton();
63 
66  public: void SetRootNode(SkeletonNode* _node);
67 
70  public: SkeletonNode* GetRootNode();
71 
75  public: SkeletonNode* GetNodeByName(std::string _name);
76 
80  public: SkeletonNode* GetNodeById(std::string _id);
81 
85  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
86 
89  public: unsigned int GetNumNodes();
90 
93  public: unsigned int GetNumJoints();
94 
97  public: void Scale(double _scale);
98 
101  public: void SetBindShapeTransform(
102  const ignition::math::Matrix4d &_trans);
103 
106  public: ignition::math::Matrix4d BindShapeTransform();
107 
109  public: void PrintTransforms();
110 
112  public: NodeMap GetNodes();
113 
116  public: void SetNumVertAttached(unsigned int _vertices);
117 
122  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
123  double _weight);
124 
128  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
129 
134  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
135  unsigned int _i);
136 
139  public: unsigned int GetNumAnimations();
140 
144  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
145 
149  public: void AddAnimation(SkeletonAnimation *_anim);
150 
153  protected: void BuildNodeMap();
154 
156  protected: SkeletonNode *root;
157 
159  protected: NodeMap nodes;
160 
162  protected: ignition::math::Matrix4d bindShapeTransform;
163 
165  protected: RawNodeWeights rawNW;
166 
168  protected: std::vector<SkeletonAnimation*> anims;
169  };
170 
173  class GZ_COMMON_VISIBLE SkeletonNode
174  {
176  public: enum SkeletonNodeType {NODE, JOINT};
177 
180  public: SkeletonNode(SkeletonNode* _parent);
181 
187  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
188  std::string _id, SkeletonNodeType _type = JOINT);
189 
191  public: virtual ~SkeletonNode();
192 
195  public: void SetName(std::string _name);
196 
199  public: std::string GetName();
200 
203  public: void SetId(std::string _id);
204 
207  public: std::string GetId();
208 
211  public: void SetType(SkeletonNodeType _type);
212 
215  public: bool IsJoint();
216 
221  public: void SetTransform(const ignition::math::Matrix4d &_trans,
222  bool _updateChildren = true);
223 
228  public: void SetModelTransform(const ignition::math::Matrix4d &_trans,
229  bool _updateChildren = true);
230 
232  public: void UpdateChildrenTransforms();
233 
236  public: void SetInitialTransform(const ignition::math::Matrix4d &_tras);
237 
241  public: void Reset(bool _resetChildren);
242 
245  public: ignition::math::Matrix4d Transform();
246 
249  public: void SetParent(SkeletonNode* _parent);
250 
253  public: SkeletonNode* GetParent();
254 
257  public: bool IsRootNode();
258 
261  public: void AddChild(SkeletonNode* _child);
262 
265  public: unsigned int GetChildCount();
266 
270  public: SkeletonNode* GetChild(unsigned int _index);
271 
275  public: SkeletonNode* GetChildByName(std::string _name);
276 
280  public: SkeletonNode* GetChildById(std::string _id);
281 
284  public: void SetHandle(unsigned int _h);
285 
288  public: unsigned int GetHandle();
289 
292  public: void SetInverseBindTransform(
293  const ignition::math::Matrix4d &_invBM);
294 
297  public: ignition::math::Matrix4d InverseBindTransform();
298 
301  public: ignition::math::Matrix4d ModelTransform() const;
302 
305  public: std::vector<NodeTransform> GetRawTransforms();
306 
309  public: unsigned int GetNumRawTrans();
310 
314  public: NodeTransform GetRawTransform(unsigned int _i);
315 
318  public: void AddRawTransform(NodeTransform _t);
319 
322  public: std::vector<NodeTransform> GetTransforms();
323 
325  protected: std::string name;
326 
328  protected: std::string id;
329 
331  protected: SkeletonNodeType type;
332 
334  protected: ignition::math::Matrix4d transform;
335 
337  protected: ignition::math::Matrix4d initialTransform;
338 
340  protected: ignition::math::Matrix4d modelTransform;
341 
343  protected: ignition::math::Matrix4d invBindTransform;
344 
346  protected: SkeletonNode *parent;
347 
349  protected: std::vector<SkeletonNode*> children;
350 
352  protected: unsigned int handle;
353 
355  protected: std::vector<NodeTransform> rawTransforms;
356  };
357 
360  class GZ_COMMON_VISIBLE NodeTransform
361  {
363  public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
364 
367  public: NodeTransform(TransformType _type = MATRIX);
368 
373  public: NodeTransform(const ignition::math::Matrix4d &_mat,
374  const std::string &_sid = "_default_",
375  TransformType _type = MATRIX);
376 
378  public: ~NodeTransform();
379 
382  public: void Set(const ignition::math::Matrix4d &_mat);
383 
386  public: void SetType(TransformType _type);
387 
390  public: void SetSID(std::string _sid);
391 
394  public: ignition::math::Matrix4d GetTransform() const;
395 
398  public: TransformType GetType();
399 
402  public: std::string GetSID();
403 
407  public: void SetComponent(unsigned int _idx, double _value);
408 
411  public: void SetSourceValues(const ignition::math::Matrix4d &_mat);
412 
415  public: void SetSourceValues(const ignition::math::Vector3d &_vec);
416 
420  public: void SetSourceValues(const ignition::math::Vector3d &_axis,
421  const double _angle);
422 
424  public: void RecalculateMatrix();
425 
427  public: void PrintSource();
428 
431  public: ignition::math::Matrix4d operator()();
432 
436  public: ignition::math::Matrix4d operator*(NodeTransform _t);
437 
441  public: ignition::math::Matrix4d operator*(
442  const ignition::math::Matrix4d &_m);
443 
445  protected: std::string sid;
446 
448  protected: TransformType type;
449 
451  protected: ignition::math::Matrix4d transform;
452 
454  protected: std::vector<double> source;
455  };
457  }
458 }
459 #endif
460 
ignition::math::Matrix4d transform
transform
Definition: Skeleton.hh:451
ignition::math::Matrix4d bindShapeTransform
the bind pose skeletal transform
Definition: Skeleton.hh:162
unsigned int handle
handle index number
Definition: Skeleton.hh:352
A skeleton.
Definition: Skeleton.hh:52
SkeletonNodeType type
the type fo node
Definition: Skeleton.hh:331
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:176
SkeletonNode * root
the root node
Definition: Skeleton.hh:156
Skeleton animation.
Definition: SkeletonAnimation.hh:126
std::vector< NodeTransform > rawTransforms
the raw transformation
Definition: Skeleton.hh:355
std::string name
the name of the skeletal node
Definition: Skeleton.hh:325
Definition: Skeleton.hh:363
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:159
NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:360
std::map< double, std::vector< NodeTransform > > RawNodeAnim
Definition: Skeleton.hh:41
std::map< unsigned int, SkeletonNode * > NodeMap
Definition: Skeleton.hh:36
std::vector< double > source
source data values (can be a matrix, a position or rotation)
Definition: Skeleton.hh:454
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:363
ignition::math::Matrix4d modelTransform
the model transformation
Definition: Skeleton.hh:340
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:168
ignition::math::Matrix4d initialTransform
the initial transformation
Definition: Skeleton.hh:337
A skeleton node.
Definition: Skeleton.hh:173
ignition::math::Matrix4d transform
the transform
Definition: Skeleton.hh:334
std::map< unsigned int, SkeletonNode * >::iterator NodeMapIter
Definition: Skeleton.hh:39
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
ignition::math::Matrix4d invBindTransform
the inverse of the bind pose skeletal transform
Definition: Skeleton.hh:343
TransformType type
transform type
Definition: Skeleton.hh:448
SkeletonNode * parent
the parent node
Definition: Skeleton.hh:346
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:165
std::vector< SkeletonNode * > children
the children nodes
Definition: Skeleton.hh:349
std::vector< std::vector< std::pair< std::string, double > > > RawNodeWeights
Definition: Skeleton.hh:45
std::map< std::string, RawNodeAnim > RawSkeletonAnim
Definition: Skeleton.hh:42
std::string sid
the sid
Definition: Skeleton.hh:445
std::string id
a string identifier
Definition: Skeleton.hh:328