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: explicit Skeleton(SkeletonNode *_root);
60 
62  public: virtual ~Skeleton();
63 
66  public: void SetRootNode(SkeletonNode* _node);
67 
70  public: SkeletonNode* GetRootNode();
71 
74  public: const SkeletonNode* GetRootNode() const;
75 
79  public: SkeletonNode* GetNodeByName(std::string _name);
80 
84  public: SkeletonNode* GetNodeById(std::string _id);
85 
89  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
90 
93  public: unsigned int GetNumNodes();
94 
97  public: unsigned int GetNumJoints();
98 
101  public: void Scale(double _scale);
102 
105  public: void SetBindShapeTransform(
106  const ignition::math::Matrix4d &_trans);
107 
110  public: ignition::math::Matrix4d BindShapeTransform();
111 
113  public: void PrintTransforms();
114 
116  public: NodeMap GetNodes();
117 
121  public: void SetNumVertAttached(unsigned int _vertices);
122 
127  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
128  double _weight);
129 
133  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
134 
139  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
140  unsigned int _i);
141 
144  public: unsigned int GetNumAnimations();
145 
149  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
150 
154  public: void AddAnimation(SkeletonAnimation *_anim);
155 
158  protected: void BuildNodeMap();
159 
161  protected: SkeletonNode *root;
162 
164  protected: NodeMap nodes;
165 
167  protected: ignition::math::Matrix4d bindShapeTransform =
168  ignition::math::Matrix4d::Identity;
169 
171  protected: RawNodeWeights rawNW;
172 
174  protected: std::vector<SkeletonAnimation*> anims;
175  };
176 
179  class GZ_COMMON_VISIBLE SkeletonNode
180  {
182  public: enum SkeletonNodeType {NODE, JOINT};
183 
186  public: explicit SkeletonNode(SkeletonNode* _parent);
187 
193  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
194  std::string _id, SkeletonNodeType _type = JOINT);
195 
197  public: virtual ~SkeletonNode();
198 
201  public: void SetName(std::string _name);
202 
207  public: std::string GetName();
208 
214  public: std::string Name() const;
215 
218  public: void SetId(std::string _id);
219 
222  public: std::string GetId();
223 
226  public: void SetType(SkeletonNodeType _type);
227 
230  public: bool IsJoint();
231 
236  public: void SetTransform(const ignition::math::Matrix4d &_trans,
237  bool _updateChildren = true);
238 
243  public: void SetModelTransform(const ignition::math::Matrix4d &_trans,
244  bool _updateChildren = true);
245 
247  public: void UpdateChildrenTransforms();
248 
251  public: void SetInitialTransform(const ignition::math::Matrix4d &_tras);
252 
256  public: void Reset(bool _resetChildren);
257 
260  public: ignition::math::Matrix4d Transform();
261 
264  public: void SetParent(SkeletonNode* _parent);
265 
268  public: SkeletonNode* GetParent();
269 
272  public: bool IsRootNode();
273 
276  public: void AddChild(SkeletonNode* _child);
277 
280  public: unsigned int GetChildCount();
281 
285  public: SkeletonNode* GetChild(unsigned int _index);
286 
290  public: SkeletonNode* GetChildByName(std::string _name);
291 
295  public: SkeletonNode* GetChildById(std::string _id);
296 
299  public: void SetHandle(unsigned int _h);
300 
303  public: unsigned int GetHandle();
304 
307  public: void SetInverseBindTransform(
308  const ignition::math::Matrix4d &_invBM);
309 
312  public: ignition::math::Matrix4d InverseBindTransform();
313 
318  public: bool HasInvBindTransform();
319 
322  public: ignition::math::Matrix4d ModelTransform() const;
323 
326  public: std::vector<NodeTransform> GetRawTransforms();
327 
330  public: unsigned int GetNumRawTrans();
331 
335  public: NodeTransform GetRawTransform(unsigned int _i);
336 
339  public: void AddRawTransform(NodeTransform _t);
340 
343  public: std::vector<NodeTransform> GetTransforms();
344 
346  protected: std::string name;
347 
349  protected: std::string id;
350 
352  protected: SkeletonNodeType type;
353 
355  protected: ignition::math::Matrix4d transform;
356 
358  protected: ignition::math::Matrix4d initialTransform;
359 
361  protected: ignition::math::Matrix4d modelTransform;
362 
364  protected: ignition::math::Matrix4d invBindTransform;
365 
367  protected: SkeletonNode *parent;
368 
370  protected: std::vector<SkeletonNode*> children;
371 
373  protected: unsigned int handle;
374 
376  protected: std::vector<NodeTransform> rawTransforms;
377  };
378 
381  class GZ_COMMON_VISIBLE NodeTransform
382  {
384  public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
385 
388  public: explicit NodeTransform(TransformType _type = MATRIX);
389 
394  public: NodeTransform(const ignition::math::Matrix4d &_mat,
395  const std::string &_sid = "_default_",
396  TransformType _type = MATRIX);
397 
399  public: ~NodeTransform();
400 
403  public: void Set(const ignition::math::Matrix4d &_mat);
404 
407  public: void SetType(TransformType _type);
408 
411  public: void SetSID(std::string _sid);
412 
415  public: ignition::math::Matrix4d GetTransform() const;
416 
419  public: TransformType GetType();
420 
423  public: std::string GetSID();
424 
428  public: void SetComponent(unsigned int _idx, double _value);
429 
432  public: void SetSourceValues(const ignition::math::Matrix4d &_mat);
433 
436  public: void SetSourceValues(const ignition::math::Vector3d &_vec);
437 
441  public: void SetSourceValues(const ignition::math::Vector3d &_axis,
442  const double _angle);
443 
445  public: void RecalculateMatrix();
446 
448  public: void PrintSource();
449 
452  public: ignition::math::Matrix4d operator()();
453 
457  public: ignition::math::Matrix4d operator*(NodeTransform _t);
458 
462  public: ignition::math::Matrix4d operator*(
463  const ignition::math::Matrix4d &_m);
464 
466  protected: std::string sid;
467 
469  protected: TransformType type;
470 
472  protected: ignition::math::Matrix4d transform;
473 
475  protected: std::vector<double> source;
476  };
478  }
479 }
480 #endif
481 
ignition::math::Matrix4d transform
transform
Definition: Skeleton.hh:472
unsigned int handle
handle index number
Definition: Skeleton.hh:373
A skeleton.
Definition: Skeleton.hh:52
Forward declarations for the common classes.
Definition: Animation.hh:26
SkeletonNodeType type
the type fo node
Definition: Skeleton.hh:352
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:182
SkeletonNode * root
the root node
Definition: Skeleton.hh:161
Skeleton animation.
Definition: SkeletonAnimation.hh:126
std::vector< NodeTransform > rawTransforms
the raw transformation
Definition: Skeleton.hh:376
std::string name
the name of the skeletal node
Definition: Skeleton.hh:346
Definition: Skeleton.hh:384
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:164
NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:381
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:475
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:384
ignition::math::Matrix4d modelTransform
the model transformation
Definition: Skeleton.hh:361
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:174
ignition::math::Matrix4d initialTransform
the initial transformation
Definition: Skeleton.hh:358
A skeleton node.
Definition: Skeleton.hh:179
ignition::math::Matrix4d transform
the transform
Definition: Skeleton.hh:355
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:364
TransformType type
transform type
Definition: Skeleton.hh:469
SkeletonNode * parent
the parent node
Definition: Skeleton.hh:367
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:171
std::vector< SkeletonNode * > children
the children nodes
Definition: Skeleton.hh:370
common
Definition: FuelModelDatabase.hh:37
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:466
std::string id
a string identifier
Definition: Skeleton.hh:349