Skeleton.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
53  class GZ_COMMON_VISIBLE Skeleton
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 
102  public: void SetBindShapeTransform(
103  const ignition::math::Matrix4d &_trans);
104 
107  public: ignition::math::Matrix4d BindShapeTransform();
108 
110  public: void PrintTransforms();
111 
113  public: NodeMap GetNodes();
114 
117  public: void SetNumVertAttached(unsigned int _vertices);
118 
123  public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
124  double _weight);
125 
129  public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
130 
135  public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
136  unsigned int _i);
137 
140  public: unsigned int GetNumAnimations();
141 
145  public: SkeletonAnimation* GetAnimation(const unsigned int _i);
146 
150  public: void AddAnimation(SkeletonAnimation *_anim);
151 
154  protected: void BuildNodeMap();
155 
157  protected: SkeletonNode *root;
158 
160  protected: NodeMap nodes;
161 
163  protected: ignition::math::Matrix4d bindShapeTransform;
164 
166  protected: RawNodeWeights rawNW;
167 
169  protected: std::vector<SkeletonAnimation*> anims;
170  };
171 
174  class GZ_COMMON_VISIBLE SkeletonNode
175  {
177  public: enum SkeletonNodeType {NODE, JOINT};
178 
181  public: SkeletonNode(SkeletonNode* _parent);
182 
188  public: SkeletonNode(SkeletonNode* _parent, std::string _name,
189  std::string _id, SkeletonNodeType _type = JOINT);
190 
192  public: virtual ~SkeletonNode();
193 
196  public: void SetName(std::string _name);
197 
200  public: std::string GetName();
201 
204  public: void SetId(std::string _id);
205 
208  public: std::string GetId();
209 
212  public: void SetType(SkeletonNodeType _type);
213 
216  public: bool IsJoint();
217 
222  public: void SetTransform(const ignition::math::Matrix4d &_trans,
223  bool _updateChildren = true);
224 
229  public: void SetModelTransform(const ignition::math::Matrix4d &_trans,
230  bool _updateChildren = true);
231 
233  public: void UpdateChildrenTransforms();
234 
237  public: void SetInitialTransform(const ignition::math::Matrix4d &_tras);
238 
242  public: void Reset(bool _resetChildren);
243 
246  public: ignition::math::Matrix4d Transform();
247 
250  public: void SetParent(SkeletonNode* _parent);
251 
254  public: SkeletonNode* GetParent();
255 
258  public: bool IsRootNode();
259 
262  public: void AddChild(SkeletonNode* _child);
263 
266  public: unsigned int GetChildCount();
267 
271  public: SkeletonNode* GetChild(unsigned int _index);
272 
276  public: SkeletonNode* GetChildByName(std::string _name);
277 
281  public: SkeletonNode* GetChildById(std::string _id);
282 
285  public: void SetHandle(unsigned int _h);
286 
289  public: unsigned int GetHandle();
290 
293  public: void SetInverseBindTransform(
294  const ignition::math::Matrix4d &_invBM);
295 
298  public: ignition::math::Matrix4d InverseBindTransform();
299 
302  public: ignition::math::Matrix4d ModelTransform() const;
303 
306  public: std::vector<NodeTransform> GetRawTransforms();
307 
310  public: unsigned int GetNumRawTrans();
311 
315  public: NodeTransform GetRawTransform(unsigned int _i);
316 
319  public: void AddRawTransform(NodeTransform _t);
320 
323  public: std::vector<NodeTransform> GetTransforms();
324 
326  protected: std::string name;
327 
329  protected: std::string id;
330 
332  protected: SkeletonNodeType type;
333 
335  protected: ignition::math::Matrix4d transform;
336 
338  protected: ignition::math::Matrix4d initialTransform;
339 
341  protected: ignition::math::Matrix4d modelTransform;
342 
344  protected: ignition::math::Matrix4d invBindTransform;
345 
347  protected: SkeletonNode *parent;
348 
350  protected: std::vector<SkeletonNode*> children;
351 
353  protected: unsigned int handle;
354 
356  protected: std::vector<NodeTransform> rawTransforms;
357  };
358 
361  class GZ_COMMON_VISIBLE NodeTransform
362  {
364  public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
365 
368  public: NodeTransform(TransformType _type = MATRIX);
369 
374  public: NodeTransform(const ignition::math::Matrix4d &_mat,
375  const std::string &_sid = "_default_",
376  TransformType _type = MATRIX);
377 
379  public: ~NodeTransform();
380 
383  public: void Set(const ignition::math::Matrix4d &_mat);
384 
387  public: void SetType(TransformType _type);
388 
391  public: void SetSID(std::string _sid);
392 
395  public: ignition::math::Matrix4d GetTransform() const;
396 
399  public: TransformType GetType();
400 
403  public: std::string GetSID();
404 
408  public: void SetComponent(unsigned int _idx, double _value);
409 
412  public: void SetSourceValues(const ignition::math::Matrix4d &_mat);
413 
416  public: void SetSourceValues(const ignition::math::Vector3d &_vec);
417 
421  public: void SetSourceValues(const ignition::math::Vector3d &_axis,
422  const double _angle);
423 
425  public: void RecalculateMatrix();
426 
428  public: void PrintSource();
429 
432  public: ignition::math::Matrix4d operator()();
433 
437  public: ignition::math::Matrix4d operator*(NodeTransform _t);
438 
442  public: ignition::math::Matrix4d operator*(
443  const ignition::math::Matrix4d &_m);
444 
446  protected: std::string sid;
447 
449  protected: TransformType type;
450 
452  protected: ignition::math::Matrix4d transform;
453 
455  protected: std::vector<double> source;
456  };
458  }
459 }
460 #endif
461 
ignition::math::Matrix4d transform
transform
Definition: Skeleton.hh:452
ignition::math::Matrix4d bindShapeTransform
the bind pose skeletal transform
Definition: Skeleton.hh:163
unsigned int handle
handle index number
Definition: Skeleton.hh:353
A skeleton.
Definition: Skeleton.hh:53
SkeletonNodeType type
the type fo node
Definition: Skeleton.hh:332
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:177
SkeletonNode * root
the root node
Definition: Skeleton.hh:157
Skeleton animation.
Definition: SkeletonAnimation.hh:128
std::vector< NodeTransform > rawTransforms
the raw transformation
Definition: Skeleton.hh:356
std::string name
the name of the skeletal node
Definition: Skeleton.hh:326
Definition: Skeleton.hh:364
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:160
NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:361
std::map< double, std::vector< NodeTransform > > RawNodeAnim
Definition: Skeleton.hh:42
std::map< unsigned int, SkeletonNode * > NodeMap
Definition: Skeleton.hh:37
std::vector< double > source
source data values (can be a matrix, a position or rotation)
Definition: Skeleton.hh:455
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:364
ignition::math::Matrix4d modelTransform
the model transformation
Definition: Skeleton.hh:341
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:169
ignition::math::Matrix4d initialTransform
the initial transformation
Definition: Skeleton.hh:338
A skeleton node.
Definition: Skeleton.hh:174
ignition::math::Matrix4d transform
the transform
Definition: Skeleton.hh:335
std::map< unsigned int, SkeletonNode * >::iterator NodeMapIter
Definition: Skeleton.hh:40
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:344
TransformType type
transform type
Definition: Skeleton.hh:449
SkeletonNode * parent
the parent node
Definition: Skeleton.hh:347
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:166
std::vector< SkeletonNode * > children
the children nodes
Definition: Skeleton.hh:350
std::vector< std::vector< std::pair< std::string, double > > > RawNodeWeights
Definition: Skeleton.hh:46
std::map< std::string, RawNodeAnim > RawSkeletonAnim
Definition: Skeleton.hh:43
std::string sid
the sid
Definition: Skeleton.hh:446
std::string id
a string identifier
Definition: Skeleton.hh:329