##

Skeleton.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_COMMON_SKELETON_HH_
#define GAZEBO_COMMON_SKELETON_HH_
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <ignition/math/Matrix4.hh>
#include "gazebo/common/CommonTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
class SkeletonNode;
class NodeTransform;
class SkeletonAnimation;
typedef std::map<unsigned int, SkeletonNode*> NodeMap;
typedef std::map<unsigned int, SkeletonNode*>::iterator NodeMapIter;
typedef std::map<double, std::vector<NodeTransform> > RawNodeAnim;
typedef std::map<std::string, RawNodeAnim> RawSkeletonAnim;
typedef std::vector<std::vector<std::pair<std::string, double> > >
RawNodeWeights;
class GZ_COMMON_VISIBLE Skeleton
{
public: Skeleton();
public: explicit Skeleton(SkeletonNode *_root);
public: virtual ~Skeleton();
public: void SetRootNode(SkeletonNode* _node);
public: SkeletonNode* GetRootNode();
public: const SkeletonNode* GetRootNode() const;
public: SkeletonNode* GetNodeByName(std::string _name);
public: SkeletonNode* GetNodeById(std::string _id);
public: SkeletonNode* GetNodeByHandle(unsigned int _handle);
public: unsigned int GetNumNodes();
public: unsigned int GetNumJoints();
public: void Scale(double _scale);
public: void SetBindShapeTransform(
const ignition::math::Matrix4d &_trans);
public: ignition::math::Matrix4d BindShapeTransform();
public: void PrintTransforms();
public: NodeMap GetNodes();
public: void SetNumVertAttached(unsigned int _vertices);
public: void AddVertNodeWeight(unsigned int _vertex, std::string _node,
double _weight);
public: unsigned int GetNumVertNodeWeights(unsigned int _vertex);
public: std::pair<std::string, double> GetVertNodeWeight(unsigned int _v,
unsigned int _i);
public: unsigned int GetNumAnimations();
public: SkeletonAnimation* GetAnimation(const unsigned int _i);
public: void AddAnimation(SkeletonAnimation *_anim);
protected: void BuildNodeMap();
protected: SkeletonNode *root;
protected: NodeMap nodes;
protected: ignition::math::Matrix4d bindShapeTransform =
ignition::math::Matrix4d::Identity;
protected: RawNodeWeights rawNW;
protected: std::vector<SkeletonAnimation*> anims;
};
class GZ_COMMON_VISIBLE SkeletonNode
{
public: enum SkeletonNodeType {NODE, JOINT};
public: explicit SkeletonNode(SkeletonNode* _parent);
public: SkeletonNode(SkeletonNode* _parent, std::string _name,
std::string _id, SkeletonNodeType _type = JOINT);
public: virtual ~SkeletonNode();
public: void SetName(std::string _name);
public: std::string GetName();
public: std::string Name() const;
public: void SetId(std::string _id);
public: std::string GetId();
public: void SetType(SkeletonNodeType _type);
public: bool IsJoint();
public: void SetTransform(const ignition::math::Matrix4d &_trans,
bool _updateChildren = true);
public: void SetModelTransform(const ignition::math::Matrix4d &_trans,
bool _updateChildren = true);
public: void UpdateChildrenTransforms();
public: void SetInitialTransform(const ignition::math::Matrix4d &_tras);
public: void Reset(bool _resetChildren);
public: ignition::math::Matrix4d Transform();
public: void SetParent(SkeletonNode* _parent);
public: SkeletonNode* GetParent();
public: bool IsRootNode();
public: void AddChild(SkeletonNode* _child);
public: unsigned int GetChildCount();
public: SkeletonNode* GetChild(unsigned int _index);
public: SkeletonNode* GetChildByName(std::string _name);
public: SkeletonNode* GetChildById(std::string _id);
public: void SetHandle(unsigned int _h);
public: unsigned int GetHandle();
public: void SetInverseBindTransform(
const ignition::math::Matrix4d &_invBM);
public: ignition::math::Matrix4d InverseBindTransform();
public: bool HasInvBindTransform();
public: ignition::math::Matrix4d ModelTransform() const;
public: std::vector<NodeTransform> GetRawTransforms();
public: unsigned int GetNumRawTrans();
public: NodeTransform GetRawTransform(unsigned int _i);
public: void AddRawTransform(NodeTransform _t);
public: std::vector<NodeTransform> GetTransforms();
protected: std::string name;
protected: std::string id;
protected: SkeletonNodeType type;
protected: ignition::math::Matrix4d transform;
protected: ignition::math::Matrix4d initialTransform;
protected: ignition::math::Matrix4d modelTransform;
protected: ignition::math::Matrix4d invBindTransform;
protected: SkeletonNode *parent;
protected: std::vector<SkeletonNode*> children;
protected: unsigned int handle;
protected: std::vector<NodeTransform> rawTransforms;
};
class GZ_COMMON_VISIBLE NodeTransform
{
public: enum TransformType {TRANSLATE, ROTATE, SCALE, MATRIX};
public: explicit NodeTransform(TransformType _type = MATRIX);
public: NodeTransform(const ignition::math::Matrix4d &_mat,
const std::string &_sid = "_default_",
TransformType _type = MATRIX);
public: ~NodeTransform();
public: void Set(const ignition::math::Matrix4d &_mat);
public: void SetType(TransformType _type);
public: void SetSID(std::string _sid);
public: ignition::math::Matrix4d GetTransform() const;
public: TransformType GetType();
public: std::string GetSID();
public: void SetComponent(unsigned int _idx, double _value);
public: void SetSourceValues(const ignition::math::Matrix4d &_mat);
public: void SetSourceValues(const ignition::math::Vector3d &_vec);
public: void SetSourceValues(const ignition::math::Vector3d &_axis,
const double _angle);
public: void RecalculateMatrix();
public: void PrintSource();
public: ignition::math::Matrix4d operator()();
public: ignition::math::Matrix4d operator*(NodeTransform _t);
public: ignition::math::Matrix4d operator*(
const ignition::math::Matrix4d &_m);
protected: std::string sid;
protected: TransformType type;
protected: ignition::math::Matrix4d transform;
protected: std::vector<double> source;
};
}
}
#endif
gazebo::common::NodeTransform::SCALE
Definition: Skeleton.hh:384
gazebo::common::SkeletonNode::SetType
void SetType(SkeletonNodeType _type)
Change the skeleton node type.
gazebo::common::Skeleton::bindShapeTransform
ignition::math::Matrix4d bindShapeTransform
the bind pose skeletal transform
Definition: Skeleton.hh:167
gazebo::common::NodeMap
std::map< unsigned int, SkeletonNode * > NodeMap
Definition: Skeleton.hh:36
gazebo::common::Skeleton::PrintTransforms
void PrintTransforms()
Outputs the transforms to std::err stream.
gazebo::common::SkeletonNode::GetId
std::string GetId()
Returns the index.
gazebo::common::SkeletonNode::type
SkeletonNodeType type
the type fo node
Definition: Skeleton.hh:352
gazebo::common::Skeleton::BuildNodeMap
void BuildNodeMap()
Initializes the hande numbers for each node in the map using breadth first traversal.
gazebo::common::Skeleton::rawNW
RawNodeWeights rawNW
the node weight table
Definition: Skeleton.hh:171
gazebo::common::SkeletonNode::rawTransforms
std::vector< NodeTransform > rawTransforms
the raw transformation
Definition: Skeleton.hh:376
gazebo::common::NodeTransform::SetComponent
void SetComponent(unsigned int _idx, double _value)
Set a transformation matrix component value.
gazebo::common::NodeTransform::Set
void Set(const ignition::math::Matrix4d &_mat)
Assign a transformation.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::SkeletonNode::GetRawTransform
NodeTransform GetRawTransform(unsigned int _i)
Find a raw transformation.
gazebo::common::RawSkeletonAnim
std::map< std::string, RawNodeAnim > RawSkeletonAnim
Definition: Skeleton.hh:42
gazebo::common::NodeTransform::GetType
TransformType GetType()
Returns the transformation type.
gazebo::common::SkeletonNode::SetTransform
void SetTransform(const ignition::math::Matrix4d &_trans, bool _updateChildren=true)
Set a transformation.
gazebo::common::RawNodeAnim
std::map< double, std::vector< NodeTransform > > RawNodeAnim
Definition: Skeleton.hh:41
gazebo::common::NodeTransform::type
TransformType type
transform type
Definition: Skeleton.hh:469
gazebo::common::NodeTransform::SetSID
void SetSID(std::string _sid)
Set the SID.
gazebo::common::Skeleton::root
SkeletonNode * root
the root node
Definition: Skeleton.hh:161
gazebo::common::SkeletonNode::SetName
void SetName(std::string _name)
Change the name.
gazebo::common::NodeTransform::MATRIX
Definition: Skeleton.hh:384
gazebo::common::NodeTransform::source
std::vector< double > source
source data values (can be a matrix, a position or rotation)
Definition: Skeleton.hh:475
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::SkeletonNode::Name
std::string Name() const
Returns the name.
gazebo::common::SkeletonNode::JOINT
Definition: Skeleton.hh:182
gazebo::common::NodeTransform::TRANSLATE
Definition: Skeleton.hh:384
gazebo::common::Skeleton::nodes
NodeMap nodes
The dictionary of nodes, indexed by name.
Definition: Skeleton.hh:164
gazebo::common::NodeTransform::GetTransform
ignition::math::Matrix4d GetTransform() const
Returns the transformation matrix.
gazebo::common::SkeletonNode::AddRawTransform
void AddRawTransform(NodeTransform _t)
Add a raw transform.
system.hh
gazebo::common::SkeletonNode::NODE
Definition: Skeleton.hh:182
gazebo::common::Skeleton::GetRootNode
SkeletonNode * GetRootNode()
Return the root.
gazebo::common::NodeTransform::~NodeTransform
~NodeTransform()
Destructor. It does nothing.
CommonTypes.hh
gazebo::common::Skeleton::SetNumVertAttached
void SetNumVertAttached(unsigned int _vertices)
Resizes the raw node weight array, this also clears all the node weights assigned.
gazebo::common::SkeletonNode::initialTransform
ignition::math::Matrix4d initialTransform
the initial transformation
Definition: Skeleton.hh:358
gazebo::common::Skeleton::GetVertNodeWeight
std::pair< std::string, double > GetVertNodeWeight(unsigned int _v, unsigned int _i)
Weight of a bone for a vertex.
gazebo::common::SkeletonNode::modelTransform
ignition::math::Matrix4d modelTransform
the model transformation
Definition: Skeleton.hh:361
gazebo::common::Skeleton::~Skeleton
virtual ~Skeleton()
Destructor.
gazebo::common::SkeletonNode::transform
ignition::math::Matrix4d transform
the transform
Definition: Skeleton.hh:355
gazebo::common::SkeletonNode::parent
SkeletonNode * parent
the parent node
Definition: Skeleton.hh:367
gazebo::common::SkeletonNode::GetName
std::string GetName()
Returns the name.
gazebo::common::NodeTransform
\clas NodeTransform Skeleton.hh common/common.hh
Definition: Skeleton.hh:381
gazebo::common::SkeletonNode::GetChild
SkeletonNode * GetChild(unsigned int _index)
Find a child by index.
gazebo::common::SkeletonNode::IsRootNode
bool IsRootNode()
Queries wether a node has no parent parent.
gazebo::common::NodeTransform::SetSourceValues
void SetSourceValues(const ignition::math::Matrix4d &_mat)
Set source data values param[in] _mat the values.
gazebo::common::SkeletonAnimation
Skeleton animation.
Definition: SkeletonAnimation.hh:126
gazebo::common::NodeTransform::transform
ignition::math::Matrix4d transform
transform
Definition: Skeleton.hh:472
gazebo::common::Skeleton::AddAnimation
void AddAnimation(SkeletonAnimation *_anim)
Add an animation.
gazebo::common::SkeletonNode::SetInverseBindTransform
void SetInverseBindTransform(const ignition::math::Matrix4d &_invBM)
Assign the inverse of the bind pose skeletal transform.
gazebo::common::Skeleton::GetAnimation
SkeletonAnimation * GetAnimation(const unsigned int _i)
Find animation.
gazebo::common::Skeleton
A skeleton.
Definition: Skeleton.hh:52
gazebo::common::NodeTransform::TransformType
TransformType
Enumeration of the transform types.
Definition: Skeleton.hh:384
gazebo::common::SkeletonNode::children
std::vector< SkeletonNode * > children
the children nodes
Definition: Skeleton.hh:370
gazebo::common::SkeletonNode::id
std::string id
a string identifier
Definition: Skeleton.hh:349
gazebo::common::SkeletonNode::SetInitialTransform
void SetInitialTransform(const ignition::math::Matrix4d &_tras)
Sets the initial transformation.
gazebo::common::SkeletonNode::HasInvBindTransform
bool HasInvBindTransform()
returns true if the node has inv bind transform.
gazebo::common::Skeleton::GetNumAnimations
unsigned int GetNumAnimations()
Returns the number of animations.
gazebo::common::SkeletonNode::InverseBindTransform
ignition::math::Matrix4d InverseBindTransform()
Retrieve the inverse of the bind pose skeletal transform.
gazebo::common::NodeTransform::operator*
ignition::math::Matrix4d operator*(NodeTransform _t)
Node transform multiplication operator.
gazebo::common::Skeleton::GetNodeByHandle
SkeletonNode * GetNodeByHandle(unsigned int _handle)
Find or create node with handle.
gazebo::common::NodeTransform::sid
std::string sid
the sid
Definition: Skeleton.hh:466
gazebo::common::SkeletonNode::GetChildByName
SkeletonNode * GetChildByName(std::string _name)
Get child by name.
gazebo::common::SkeletonNode::ModelTransform
ignition::math::Matrix4d ModelTransform() const
Retrieve the model transform.
gazebo::common::NodeTransform::NodeTransform
NodeTransform(TransformType _type=MATRIX)
Constructor.
gazebo::common::Skeleton::Scale
void Scale(double _scale)
Scale all nodes, transforms and animation data.
gazebo::common::Skeleton::BindShapeTransform
ignition::math::Matrix4d BindShapeTransform()
Return bind pose skeletal transform.
gazebo::common::Skeleton::GetNumVertNodeWeights
unsigned int GetNumVertNodeWeights(unsigned int _vertex)
Returns the number of bone weights for a vertex.
gazebo::common::NodeTransform::ROTATE
Definition: Skeleton.hh:384
gazebo::common::SkeletonNode::UpdateChildrenTransforms
void UpdateChildrenTransforms()
Apply model transformations in order for each node in the tree.
gazebo::common::Skeleton::GetNodeById
SkeletonNode * GetNodeById(std::string _id)
Find node by index.
gazebo::msgs::Set
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
gazebo::common::SkeletonNode::SetHandle
void SetHandle(unsigned int _h)
Assign a handle number.
gazebo::common::Skeleton::Skeleton
Skeleton()
Constructor.
gazebo::common::SkeletonNode::IsJoint
bool IsJoint()
Is a joint query.
gazebo::common::Skeleton::GetNumNodes
unsigned int GetNumNodes()
Returns the node count.
gazebo::common::SkeletonNode::SkeletonNodeType
SkeletonNodeType
enumeration of node types
Definition: Skeleton.hh:182
gazebo::common::SkeletonNode::GetChildById
SkeletonNode * GetChildById(std::string _id)
Get child by string id.
gazebo::common::SkeletonNode::SkeletonNode
SkeletonNode(SkeletonNode *_parent)
Constructor.
gazebo::common::SkeletonNode::GetParent
SkeletonNode * GetParent()
Returns the parent node.
gazebo::common::SkeletonNode::~SkeletonNode
virtual ~SkeletonNode()
Destructor.
gazebo::common::SkeletonNode::GetNumRawTrans
unsigned int GetNumRawTrans()
Return the raw transformations count.
gazebo::common::SkeletonNode::AddChild
void AddChild(SkeletonNode *_child)
Add a new child.
gazebo::common::SkeletonNode::GetRawTransforms
std::vector< NodeTransform > GetRawTransforms()
Retrieve the raw transformations.
gazebo::common::SkeletonNode::SetModelTransform
void SetModelTransform(const ignition::math::Matrix4d &_trans, bool _updateChildren=true)
Set the model transformation.
gazebo::common::NodeTransform::operator()
ignition::math::Matrix4d operator()()
Matrix cast operator.
gazebo::common::SkeletonNode::name
std::string name
the name of the skeletal node
Definition: Skeleton.hh:346
gazebo::common::RawNodeWeights
std::vector< std::vector< std::pair< std::string, double > > > RawNodeWeights
Definition: Skeleton.hh:45
gazebo::common::SkeletonNode::handle
unsigned int handle
handle index number
Definition: Skeleton.hh:373
gazebo::common::NodeTransform::PrintSource
void PrintSource()
Prints the transform matrix to std::err stream.
gazebo::common::SkeletonNode::Transform
ignition::math::Matrix4d Transform()
Get transform relative to parent.
gazebo::common::Skeleton::GetNodes
NodeMap GetNodes()
Get a copy or the node dictionary.
gazebo::common::SkeletonNode::SetParent
void SetParent(SkeletonNode *_parent)
Set the parent node.
gazebo::common::SkeletonNode::invBindTransform
ignition::math::Matrix4d invBindTransform
the inverse of the bind pose skeletal transform
Definition: Skeleton.hh:364
gazebo::common::SkeletonNode
A skeleton node.
Definition: Skeleton.hh:179
gazebo::common::SkeletonNode::GetHandle
unsigned int GetHandle()
Get the handle index.
gazebo::common::Skeleton::SetBindShapeTransform
void SetBindShapeTransform(const ignition::math::Matrix4d &_trans)
Set the bind pose skeletal transform.
gazebo::common::NodeTransform::RecalculateMatrix
void RecalculateMatrix()
Sets the transform matrix from the source according to the type.
gazebo::common::Skeleton::GetNumJoints
unsigned int GetNumJoints()
Returns the number of joints.
gazebo::common::SkeletonNode::GetTransforms
std::vector< NodeTransform > GetTransforms()
Returns a copy of the array of transformations.
gazebo::common::Skeleton::anims
std::vector< SkeletonAnimation * > anims
the array of animations
Definition: Skeleton.hh:174
gazebo::common::NodeTransform::SetType
void SetType(TransformType _type)
Set transform type.
gazebo::common::SkeletonNode::GetChildCount
unsigned int GetChildCount()
Returns the children count.
gazebo::common::Skeleton::AddVertNodeWeight
void AddVertNodeWeight(unsigned int _vertex, std::string _node, double _weight)
Add a new weight to a node (bone)
gazebo::common::NodeMapIter
std::map< unsigned int, SkeletonNode * >::iterator NodeMapIter
Definition: Skeleton.hh:39
gazebo::common::Skeleton::GetNodeByName
SkeletonNode * GetNodeByName(std::string _name)
Find a node.
gazebo::common::Skeleton::SetRootNode
void SetRootNode(SkeletonNode *_node)
Change the root node.
gazebo::common::NodeTransform::GetSID
std::string GetSID()
Returns thr SID.
gazebo::common::SkeletonNode::Reset
void Reset(bool _resetChildren)
Reset the transformation to the initial transformation.
gazebo::common::SkeletonNode::SetId
void SetId(std::string _id)
Change the id string.