45 #ifndef ASSISTIVE_REHAB_SKELETON_H
46 #define ASSISTIVE_REHAB_SKELETON_H
50 #include <unordered_map>
55 #include <yarp/os/Bottle.h>
56 #include <yarp/os/Property.h>
57 #include <yarp/sig/Vector.h>
58 #include <yarp/sig/Matrix.h>
60 namespace assistive_rehab
65 extern const std::string shoulder_center;
66 extern const std::string head;
67 extern const std::string shoulder_left;
68 extern const std::string elbow_left;
69 extern const std::string hand_left;
70 extern const std::string shoulder_right;
71 extern const std::string elbow_right;
72 extern const std::string hand_right;
73 extern const std::string hip_center;
74 extern const std::string hip_left;
75 extern const std::string knee_left;
76 extern const std::string ankle_left;
77 extern const std::string foot_left;
78 extern const std::string hip_right;
79 extern const std::string knee_right;
80 extern const std::string ankle_right;
81 extern const std::string foot_right;
84 namespace SkeletonType
86 extern const std::string Skeleton;
87 extern const std::string SkeletonStd;
103 yarp::sig::Vector point;
104 yarp::sig::Vector pixel;
105 std::vector<KeyPoint*> parent;
106 std::vector<KeyPoint*> child;
108 void stale() { updated=
false; }
125 KeyPoint(
const std::string &tag_,
const yarp::sig::Vector &point_=yarp::sig::Vector(3,std::numeric_limits<double>::quiet_NaN()),
126 const yarp::sig::Vector &pixel_=yarp::sig::Vector(2,std::numeric_limits<double>::quiet_NaN()),
const bool updated_=
false);
153 const std::string&
getTag()
const {
return tag; }
161 const yarp::sig::Vector &
getPoint()
const {
return point; }
178 const yarp::sig::Vector &pixel);
186 const yarp::sig::Vector &
getPixel()
const {
return pixel; }
192 unsigned int getNumParent()
const {
return (
unsigned int)parent.size(); }
205 unsigned int getNumChild()
const {
return (
unsigned int)child.size(); }
226 std::unordered_map<std::string,KeyPoint*>
tag2key;
227 std::unordered_map<KeyPoint*,unsigned int>
key2id;
234 yarp::os::Property helper_toproperty(
KeyPoint *k)
const;
235 void helper_fromproperty(yarp::os::Bottle *prop,
KeyPoint *parent);
236 void helper_updatefromproperty(yarp::os::Bottle *prop);
237 void helper_normalize(
KeyPoint* k,
const std::vector<yarp::sig::Vector> &helperpoints,
const double n);
238 void helper_scale(
KeyPoint* k,
const std::vector<yarp::sig::Vector> &helperpoints,
const double s);
239 double helper_getmaxpath(
KeyPoint* k, std::vector<bool> &visited)
const;
377 virtual void fromProperty(
const yarp::os::Property &prop);
416 virtual void update(
const std::vector<yarp::sig::Vector> &ordered);
424 virtual void update(
const std::vector<std::pair<std::string,yarp::sig::Vector>> &unordered);
433 virtual void update_withpixels(
const std::vector<std::pair<yarp::sig::Vector,yarp::sig::Vector>> &ordered);
442 virtual void update_withpixels(
const std::vector<std::pair<std::string,std::pair<yarp::sig::Vector,yarp::sig::Vector>>> &unordered);
464 virtual void update(
const yarp::os::Property &prop);
478 virtual std::vector<yarp::sig::Vector>
get_ordered()
const;
486 virtual std::vector<std::pair<std::string,yarp::sig::Vector>>
get_unordered()
const;
503 virtual std::vector<std::pair<std::string,std::pair<yarp::sig::Vector,yarp::sig::Vector>>>
get_unordered_withpixels()
const;
515 void scale(
const double s);
520 void print(std::ostream &os=std::cout)
const;
Basic class for single keypoint of a skeleton.
const KeyPoint * getParent(const unsigned int i) const
Get a pointer to the parent of the keypoint specified by index.
const yarp::sig::Vector & getPoint() const
Return a reference to the vector containing the keypoint's x,y,z camera coordinates.
virtual ~KeyPoint()
Virtual destructor.
bool setPoint(const yarp::sig::Vector &point)
Set keypoint's x,y,z camera coordinates to a desired value.
const KeyPoint * getChild(const unsigned int i) const
Get a pointer to the child of the keypoint specified by index.
KeyPoint()
Default constructor.
bool isUpdated() const
Return true if the keypoint has been updated.
const std::string & getTag() const
Return a reference to the tag of the keypoint.
unsigned int getNumParent() const
Retrieve the number of parents of the keypoint.
KeyPoint(const std::string &tag_, const yarp::sig::Vector &point_=yarp::sig::Vector(3, std::numeric_limits< double >::quiet_NaN()), const yarp::sig::Vector &pixel_=yarp::sig::Vector(2, std::numeric_limits< double >::quiet_NaN()), const bool updated_=false)
Overloaded constructor.
bool setPoint(const yarp::sig::Vector &point, const yarp::sig::Vector &pixel)
Set keypoint's x,y,z camera coordinates as well as u,v, image coordinates to a desired value.
KeyPoint(const KeyPoint &)=delete
Deleted copy constructor.
unsigned int getNumChild() const
Retrieve the number of children of the keypoint.
KeyPoint & operator=(const KeyPoint &)=delete
Deleted copy operator.
const yarp::sig::Vector & getPixel() const
Return a reference to the vector containing the keypoint's u,v image coordinates.
Basic class for skeleton standard.
bool update_planes() override
Update skeleton planes.
SkeletonStd()
Default constructor.
Abstract class for skeleton.
const std::string & getTag() const
Return a reference to the tag of the skeleton.
bool setTransverse(const yarp::sig::Vector &transverse)
Set a new transverse plane to the skeleton.
virtual void update()
Update skeleton.
virtual void update_withpixels(const std::vector< std::pair< yarp::sig::Vector, yarp::sig::Vector >> &ordered)
Update skeleton from ordered list.
void scale(const double s)
Rescale skeleton.
virtual std::vector< std::pair< yarp::sig::Vector, yarp::sig::Vector > > get_ordered_withpixels() const
Retrieve the ordered list of keypoints.
const yarp::sig::Matrix & getTransformation() const
Retrieve the transformation matrix of the skeleton.
bool setTransformation(const yarp::sig::Matrix &T)
Set a new transformation matrix of the skeleton.
yarp::sig::Matrix T
transformation matrix
yarp::sig::Vector getTransverse() const
Retrieve the transverse plane of the skeleton.
virtual void update_withpixels(const std::vector< std::pair< std::string, std::pair< yarp::sig::Vector, yarp::sig::Vector >>> &unordered)
Update skeleton from unordered list.
std::string tag
skeleton's tag
const KeyPoint * operator[](const std::string &tag) const
Keypoint access.
std::unordered_map< KeyPoint *, unsigned int > key2id
map associating a pointer to a KeyPoint to an index
const std::string & getType() const
Return a reference to the type of the skeleton.
virtual std::vector< std::pair< std::string, std::pair< yarp::sig::Vector, yarp::sig::Vector > > > get_unordered_withpixels() const
Retrieve the unordered list of keypoints.
void print(std::ostream &os=std::cout) const
Print skeleton information.
Skeleton(const Skeleton &)=delete
Deleted copy constructor.
std::vector< KeyPoint * > keypoints
vector of pointer to KeyPoint
std::string type
skeleton's type ("assistive_rehab::SkeletonStd")
yarp::sig::Vector sagittal
vector containing the normal to the sagittal plane
void normalize(const double n=1.0)
Normalize skeleton in order to have unitary/desired distance among keypoints.
virtual std::vector< std::pair< std::string, yarp::sig::Vector > > get_unordered() const
Retrieve the unordered list of keypoints.
yarp::sig::Vector getSagittal() const
Retrieve the sagittal plane of the skeleton.
int getNumFromKey(const std::string &tag) const
Retrieve the index of the keypoint from its tag.
virtual std::vector< yarp::sig::Vector > get_ordered() const
Retrieve the ordered list of keypoints.
yarp::sig::Vector getCoronal() const
Retrieve the coronal plane of the skeleton.
bool setCoronal(const yarp::sig::Vector &coronal)
Set a new coronal plane to the skeleton.
yarp::sig::Vector transverse
vector containing the normal to the transverse plane
virtual void update(const std::vector< std::pair< std::string, yarp::sig::Vector >> &unordered)
Update skeleton from unordered list.
Skeleton & operator=(const Skeleton &)=delete
Deleted copy operator.
unsigned int getNumKeyPoints() const
Retrieve the number of keypoints of the skeleton.
virtual void fromProperty(const yarp::os::Property &prop)
Import the skeleton structure from its properties.
double getMaxPath() const
Retrieve the skeleton's maximum path.
yarp::sig::Vector coronal
vector containing the normal to the coronal plane
virtual yarp::os::Property toProperty()
Export the skeleton structure as a property.
std::unordered_map< std::string, KeyPoint * > tag2key
map associating a tag to a pointer to a KeyPoint
virtual void update(const std::vector< yarp::sig::Vector > &ordered)
Update skeleton from ordered list.
void setTag(const std::string &tag)
Set the tag of the skeleton.
virtual void update(const yarp::os::Property &prop)
Update skeleton from properties.
virtual ~Skeleton()
Virtual destructor.
Skeleton()
Default constructor.
virtual bool update_planes()=0
Update skeleton planes.
bool setSagittal(const yarp::sig::Vector &sagittal)
Set a new sagittal plane to the skeleton.
Skeleton * skeleton_factory(const yarp::os::Property &prop)
Populate skeleton from a Property object.