Gazebo Common

API Reference

4.8.1
gz/common/Skeleton.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 IGNITION_COMMON_SKELETON_HH_
18 #define IGNITION_COMMON_SKELETON_HH_
19 
20 #include <vector>
21 #include <string>
22 #include <map>
23 #include <utility>
24 
25 #include <gz/math/Matrix4.hh>
26 
27 #include <ignition/utils/ImplPtr.hh>
28 
29 #include <gz/common/config.hh>
31 #include <gz/common/graphics/Export.hh>
32 
33 namespace ignition
34 {
35  namespace common
36  {
37  class SkeletonAnimation;
38 
41  class IGNITION_COMMON_GRAPHICS_VISIBLE Skeleton
42  {
44  public: Skeleton();
45 
48  public: explicit Skeleton(SkeletonNode *_root);
49 
51  public: virtual ~Skeleton();
52 
55  public: void RootNode(SkeletonNode *_node);
56 
59  public: SkeletonNode *RootNode() const;
60 
64  public: SkeletonNode *NodeByName(const std::string &_name) const;
65 
69  public: SkeletonNode *NodeById(const std::string &_id) const;
70 
74  public: SkeletonNode *NodeByHandle(const unsigned int _handle) const;
75 
78  public: unsigned int NodeCount() const;
79 
82  public: unsigned int JointCount() const;
83 
86  public: void Scale(const double _scale);
87 
90  public: void SetBindShapeTransform(const math::Matrix4d &_trans);
91 
95 
97  public: void PrintTransforms() const;
98 
101  public: const SkeletonNodeMap &Nodes() const;
102 
105  public: void SetNumVertAttached(const unsigned int _vertices);
106 
111  public: void AddVertNodeWeight(const unsigned int _vertex,
112  const std::string &_node, const double _weight);
113 
117  public: unsigned int VertNodeWeightCount(
118  const unsigned int _vertex) const;
119 
125  const unsigned int _v, const unsigned int _i) const;
126 
129  public: unsigned int AnimationCount() const;
130 
134  public: SkeletonAnimation *Animation(const unsigned int _i) const;
135 
139  public: void AddAnimation(SkeletonAnimation *_anim);
140 
145  public: bool AddBvhAnimation(const std::string &_bvhFile, double _scale);
146 
152  public: std::string NodeNameAnimToSkin(unsigned int _index,
153  const std::string &_animNodeName);
154 
160  public: math::Matrix4d AlignTranslation(unsigned int _index,
161  const std::string &_animNodeName);
162 
168  public: math::Matrix4d AlignRotation(unsigned int _index,
169  const std::string &_animNodeName);
170 
173  private: void BuildNodeMap();
174 
176  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
177  };
178  }
179 }
180 #endif
Skeleton animation.
Definition: gz/common/SkeletonAnimation.hh:41
A skeleton node.
Definition: gz/common/SkeletonNode.hh:37
A skeleton, usually used for animation purposes.
Definition: gz/common/Skeleton.hh:42
void AddVertNodeWeight(const unsigned int _vertex, const std::string &_node, const double _weight)
Add a new weight to a node (bone)
void SetNumVertAttached(const unsigned int _vertices)
Resizes the raw node weight array.
SkeletonNode * RootNode() const
Return the root.
std::string NodeNameAnimToSkin(unsigned int _index, const std::string &_animNodeName)
Finding the skin node name that corresponds to the given animation node name.
bool AddBvhAnimation(const std::string &_bvhFile, double _scale)
Add an animation from BVH file.
void AddAnimation(SkeletonAnimation *_anim)
Add an animation. The skeleton does not take ownership of the animation.
math::Matrix4d AlignTranslation(unsigned int _index, const std::string &_animNodeName)
Get the transformation to align translation from the animation skeleton to skin skeleton.
virtual ~Skeleton()
Destructor.
SkeletonNode * NodeByHandle(const unsigned int _handle) const
Find or create node with handle.
void PrintTransforms() const
Outputs the transforms to standard out.
Skeleton(SkeletonNode *_root)
Constructor.
math::Matrix4d AlignRotation(unsigned int _index, const std::string &_animNodeName)
Get the transformation to align rotation from the animation skeleton to skin skeleton.
unsigned int VertNodeWeightCount(const unsigned int _vertex) const
Returns the number of bone weights for a vertex.
void Scale(const double _scale)
Scale all nodes, transforms and animation data.
unsigned int AnimationCount() const
Returns the number of animations.
unsigned int NodeCount() const
Returns the node count.
const SkeletonNodeMap & Nodes() const
Get a copy or the node dictionary.
SkeletonAnimation * Animation(const unsigned int _i) const
Find animation.
void SetBindShapeTransform(const math::Matrix4d &_trans)
Set the bind pose skeletal transform.
SkeletonNode * NodeById(const std::string &_id) const
Find node by index.
void RootNode(SkeletonNode *_node)
Change the root node.
math::Matrix4d BindShapeTransform() const
Return bind pose skeletal transform.
unsigned int JointCount() const
Returns the number of joints.
std::pair< std::string, double > VertNodeWeight(const unsigned int _v, const unsigned int _i) const
Weight of a bone for a vertex.
SkeletonNode * NodeByName(const std::string &_name) const
Find a node.
Forward declarations for the common classes.