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 _GAZEBO_SKELETON_HH_
18 #define _GAZEBO_SKELETON_HH_
19 
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include <utility>
24 
25 #include <ignition/math/Matrix4.hh>
26 
27 #include "gazebo/math/Matrix4.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class SkeletonNode;
36  class NodeTransform;
38 
39  typedef std::map<unsigned int, SkeletonNode*> NodeMap;
40  typedef std::map<unsigned int, SkeletonNode*>::iterator NodeMapIter;
41 
42  typedef std::map<double, std::vector<NodeTransform> > RawNodeAnim;
43  typedef std::map<std::string, RawNodeAnim> RawSkeletonAnim;
44 
45  typedef std::vector<std::vector<std::pair<std::string, double> > >
47 
50 
54  {
56  public: Skeleton();
57 
60  public: Skeleton(SkeletonNode *_root);
61 
63  public: virtual ~Skeleton();
64 
67  public: void SetRootNode(SkeletonNode* _node);
68 
71  public: SkeletonNode* GetRootNode();
72 
76  public: SkeletonNode* GetNodeByName(std::string _name);
77 
81  public: SkeletonNode* GetNodeById(std::string _id);
82 
86  public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
87 
90  public: unsigned int GetNumNodes();
91 
94  public: unsigned int GetNumJoints();
95 
98  public: void Scale(double _scale);
99 
104  public: void SetBindShapeTransform(math::Matrix4 _trans)
105  GAZEBO_DEPRECATED(6.0);
106 
109  public: void SetBindShapeTransform(
110  const ignition::math::Matrix4d &_trans);
111 
116  public: math::Matrix4 GetBindShapeTransform() GAZEBO_DEPRECATED(6.0);
117 
120  public: ignition::math::Matrix4d BindShapeTransform();
121 
123  public: void PrintTransforms();
124 
126  public: NodeMap GetNodes();
127 
130  public: void SetNumVertAttached(unsigned int _vertices);
131 
136  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
137  double _weight);
138 
142  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
143 
148  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
149  unsigned int _i);
150 
153  public: unsigned int GetNumAnimations();
154 
158  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
159 
163  public: void AddAnimation(SkeletonAnimation *_anim);
164 
167  protected: void BuildNodeMap();
168 
170  protected: SkeletonNode *root;
171 
173  protected: NodeMap nodes;
174 
176  protected: ignition::math::Matrix4d bindShapeTransform;
177 
179  protected: RawNodeWeights rawNW;
180 
182  protected: std::vector<SkeletonAnimation*> anims;
183  };
184 
188  {
190  public: enum SkeletonNodeType {NODE, JOINT};
191 
194  public: SkeletonNode(SkeletonNode* _parent);
195 
201  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
202  std::string _id, SkeletonNodeType _type = JOINT);
203 
205  public: virtual ~SkeletonNode();
206 
209  public: void SetName(std::string _name);
210 
213  public: std::string GetName();
214 
217  public: void SetId(std::string _id);
218 
221  public: std::string GetId();
222 
225  public: void SetType(SkeletonNodeType _type);
226 
229  public: bool IsJoint();
230 
237  public: void SetTransform(math::Matrix4 _trans,
238  bool _updateChildren = true) GAZEBO_DEPRECATED(6.0);
239 
244  public: void SetTransform(const ignition::math::Matrix4d &_trans,
245  bool _updateChildren = true);
246 
253  public: void SetModelTransform(math::Matrix4 _trans,
254  bool _updateChildren = true) GAZEBO_DEPRECATED(6.0);
255 
260  public: void SetModelTransform(const ignition::math::Matrix4d &_trans,
261  bool _updateChildren = true);
262 
264  public: void UpdateChildrenTransforms();
265 
270  public: void SetInitialTransform(math::Matrix4 _tras)
271  GAZEBO_DEPRECATED(6.0);
272 
275  public: void SetInitialTransform(const ignition::math::Matrix4d &_tras);
276 
280  public: void Reset(bool _resetChildren);
281 
286  public: math::Matrix4 GetTransform() GAZEBO_DEPRECATED(6.0);
287 
290  public: ignition::math::Matrix4d Transform();
291 
294  public: void SetParent(SkeletonNode* _parent);
295 
298  public: SkeletonNode* GetParent();
299 
302  public: bool IsRootNode();
303 
306  public: void AddChild(SkeletonNode* _child);
307 
310  public: unsigned int GetChildCount();
311 
315  public: SkeletonNode* GetChild(unsigned int _index);
316 
320  public: SkeletonNode* GetChildByName(std::string _name);
321 
325  public: SkeletonNode* GetChildById(std::string _id);
326 
329  public: void SetHandle(unsigned int _h);
330 
333  public: unsigned int GetHandle();
334 
339  public: void SetInverseBindTransform(math::Matrix4 _invBM)
340  GAZEBO_DEPRECATED(6.0);
341 
344  public: void SetInverseBindTransform(
345  const ignition::math::Matrix4d &_invBM);
346 
351  public: math::Matrix4 GetInverseBindTransform() GAZEBO_DEPRECATED(6.0);
352 
355  public: ignition::math::Matrix4d InverseBindTransform();
356 
361  public: math::Matrix4 GetModelTransform() GAZEBO_DEPRECATED(6.0);
362 
365  public: ignition::math::Matrix4d ModelTransform() const;
366 
369  public: std::vector<NodeTransform> GetRawTransforms();
370 
373  public: unsigned int GetNumRawTrans();
374 
378  public: NodeTransform GetRawTransform(unsigned int _i);
379 
382  public: void AddRawTransform(NodeTransform _t);
383 
386  public: std::vector<NodeTransform> GetTransforms();
387 
389  protected: std::string name;
390 
392  protected: std::string id;
393 
395  protected: SkeletonNodeType type;
396 
398  protected: ignition::math::Matrix4d transform;
399 
401  protected: ignition::math::Matrix4d initialTransform;
402 
404  protected: ignition::math::Matrix4d modelTransform;
405 
407  protected: ignition::math::Matrix4d invBindTransform;
408 
410  protected: SkeletonNode *parent;
411 
413  protected: std::vector<SkeletonNode*> children;
414 
416  protected: unsigned int handle;
417 
419  protected: std::vector<NodeTransform> rawTransforms;
420  };
421 
425  {
427  public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
428 
431  public: NodeTransform(TransformType _type = MATRIX);
432 
439  public: NodeTransform(math::Matrix4 _mat, std::string _sid = "_default_",
440  TransformType _type = MATRIX) GAZEBO_DEPRECATED(6.0);
441 
446  public: NodeTransform(const ignition::math::Matrix4d &_mat,
447  const std::string &_sid = "_default_",
448  TransformType _type = MATRIX);
449 
451  public: ~NodeTransform();
452 
457  public: void Set(math::Matrix4 _mat) GAZEBO_DEPRECATED(6.0);
458 
461  public: void Set(const ignition::math::Matrix4d &_mat);
462 
465  public: void SetType(TransformType _type);
466 
469  public: void SetSID(std::string _sid);
470 
475  public: math::Matrix4 Get() GAZEBO_DEPRECATED(6.0);
476 
479  public: ignition::math::Matrix4d GetTransform() const;
480 
483  public: TransformType GetType();
484 
487  public: std::string GetSID();
488 
492  public: void SetComponent(unsigned int _idx, double _value);
493 
498  public: void SetSourceValues(math::Matrix4 _mat) GAZEBO_DEPRECATED(6.0);
499 
502  public: void SetSourceValues(const ignition::math::Matrix4d &_mat);
503 
508  public: void SetSourceValues(math::Vector3 _vec) GAZEBO_DEPRECATED(6.0);
509 
512  public: void SetSourceValues(const ignition::math::Vector3d &_vec);
513 
519  public: void SetSourceValues(math::Vector3 _axis, double _angle)
520  GAZEBO_DEPRECATED(6.0);
521 
525  public: void SetSourceValues(const ignition::math::Vector3d &_axis,
526  const double _angle);
527 
529  public: void RecalculateMatrix();
530 
532  public: void PrintSource();
533 
536  public: ignition::math::Matrix4d operator()();
537 
541  public: ignition::math::Matrix4d operator*(NodeTransform _t);
542 
547  public: math::Matrix4 operator* (math::Matrix4 _m) GAZEBO_DEPRECATED(6.0);
548 
552  public: ignition::math::Matrix4d operator*(
553  const ignition::math::Matrix4d &_m);
554 
556  protected: std::string sid;
557 
559  protected: TransformType type;
560 
562  protected: ignition::math::Matrix4d transform;
563 
565  protected: std::vector<double> source;
566  };
568  }
569 }
570 #endif
571 
std::map< unsigned int, SkeletonNode * > NodeMap
Definition: Skeleton.hh:37
A skeleton.
Definition: Skeleton.hh:53
Skeleton animation.
Definition: SkeletonAnimation.hh:176
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
A 3x3 matrix class.
Definition: Matrix4.hh:40
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:182
std::map< unsigned int, SkeletonNode * >::iterator NodeMapIter
Definition: Skeleton.hh:40
NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:424
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:427
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:190
ignition::math::Matrix4d bindShapeTransform
the bind pose skeletal transform
Definition: Skeleton.hh:176
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:173
#define SCALE
Definition: SpaceNavPrivate.hh:20
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
Definition: Skeleton.hh:427
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:179
std::map< double, std::vector< NodeTransform > > RawNodeAnim
Definition: Skeleton.hh:42
A skeleton node.
Definition: Skeleton.hh:187
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:46
SkeletonNode * root
the root node
Definition: Skeleton.hh:170
std::map< std::string, RawNodeAnim > RawSkeletonAnim
Definition: Skeleton.hh:43