Ignition Common

API Reference

3.14.0
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 <ignition/math/Matrix4.hh>
27 #include <ignition/common/graphics/Export.hh>
28 
29 namespace ignition
30 {
31  namespace common
32  {
34  class SkeletonPrivate;
35  class SkeletonAnimation;
36 
39  class IGNITION_COMMON_GRAPHICS_VISIBLE Skeleton
40  {
42  public: Skeleton();
43 
46  public: explicit Skeleton(SkeletonNode *_root);
47 
49  public: virtual ~Skeleton();
50 
53  public: void RootNode(SkeletonNode *_node);
54 
57  public: SkeletonNode *RootNode() const;
58 
62  public: SkeletonNode *NodeByName(const std::string &_name) const;
63 
67  public: SkeletonNode *NodeById(const std::string &_id) const;
68 
72  public: SkeletonNode *NodeByHandle(const unsigned int _handle) const;
73 
76  public: unsigned int NodeCount() const;
77 
80  public: unsigned int JointCount() const;
81 
84  public: void Scale(const double _scale);
85 
88  public: void SetBindShapeTransform(const math::Matrix4d &_trans);
89 
93 
95  public: void PrintTransforms() const;
96 
99  public: const SkeletonNodeMap &Nodes() const;
100 
103  public: void SetNumVertAttached(const unsigned int _vertices);
104 
109  public: void AddVertNodeWeight(const unsigned int _vertex,
110  const std::string &_node, const double _weight);
111 
115  public: unsigned int VertNodeWeightCount(
116  const unsigned int _vertex) const;
117 
123  const unsigned int _v, const unsigned int _i) const;
124 
127  public: unsigned int AnimationCount() const;
128 
132  public: SkeletonAnimation *Animation(const unsigned int _i) const;
133 
137  public: void AddAnimation(SkeletonAnimation *_anim);
138 
143  public: bool AddBvhAnimation(const std::string &_bvhFile, double _scale);
144 
150  public: std::string NodeNameAnimToSkin(unsigned int _index,
151  const std::string &_animNodeName);
152 
158  public: math::Matrix4d AlignTranslation(unsigned int _index,
159  const std::string &_animNodeName);
160 
166  public: math::Matrix4d AlignRotation(unsigned int _index,
167  const std::string &_animNodeName);
168 
171  private: void BuildNodeMap();
172 
174  private: SkeletonPrivate *data;
175  };
176  }
177 }
178 #endif
Skeleton animation.
Definition: SkeletonAnimation.hh:41
A skeleton node.
Definition: SkeletonNode.hh:37
A skeleton, usually used for animation purposes.
Definition: Skeleton.hh:40
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.