icub-client
bodypart.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
3  * Authors: Tobias Fischer
4  * email: t.fischer@imperial.ac.uk
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * icub-client/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16  */
17 
19 
20 using namespace std;
21 using namespace yarp::os;
22 using namespace yarp::sig;
23 using namespace icubclient;
24 
25 Bodypart::Bodypart():Object()
26 {
28  m_joint_number = -1;
29  m_tactile_number = -1;
30  m_part = "unknown";
31  m_present = 1.0;
32  m_kinectNode = "unknown";
33 }
34 
35 
37 {
38  this->m_entity_type = b.m_entity_type;
41  this->m_part = b.m_part;
42  this->m_present = 1.0;
43  this->m_kinectNode = b.m_kinectNode;
44 }
45 
46 Bottle Bodypart::asBottle() const
47 {
48  //Get the Object bottle
49  Bottle b = this->Object::asBottle();
50 
51  Bottle bSub;
52  bSub.addString("joint_number");
53  bSub.addInt(m_joint_number);
54  b.addList() = bSub;
55  bSub.clear();
56  bSub.addString("tactile_number");
57  bSub.addInt(m_tactile_number);
58  b.addList() = bSub;
59  bSub.clear();
60  bSub.addString("part");
61  bSub.addString(m_part);
62  b.addList() = bSub;
63  bSub.clear();
64  bSub.addString("kinectNode");
65  bSub.addString(m_kinectNode);
66  b.addList() = bSub;
67  bSub.clear();
68 
69  return b;
70 }
71 
72 string Bodypart::toString() const
73 {
74  std::ostringstream oss;
75  oss<< this->Object::toString();
76  oss<< "joint number: \t\t";
77  oss<< m_joint_number << endl;
78  oss<< "tactile number: \t\t";
79  oss<< m_tactile_number << endl;
80  oss<< "part: \t\t";
81  oss<< m_part <<endl;
82  oss<< "kinectNode: \t\t";
83  oss<< m_kinectNode <<endl;
84  return oss.str();
85 }
86 
87 bool Bodypart::fromBottle(const Bottle &b)
88 {
89  if (!this->Object::fromBottle(b))
90  return false;
91 
92  if (!b.check("joint_number") ||
93  !b.check("tactile_number") ||
94  !b.check("part") ||
95  !b.check("kinectNode"))
96  {
97  return false;
98  }
99 
100  m_joint_number = b.find("joint_number").asInt();
101  m_tactile_number = b.find("tactile_number").asInt();
102  m_part = b.find("part").asString();
103  m_kinectNode = b.find("kinectNode").asString();
104 
105  return true;
106 }
double m_present
Is the object present in the scene A value of 1.0 means that the object currently is in the scene A v...
Definition: object.h:69
int m_tactile_number
Tactile number of the represented body part.
Definition: bodypart.h:43
STL namespace.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
Definition: object.h:35
#define ICUBCLIENT_OPC_ENTITY_BODYPART
Definition: tags.h:39
int m_joint_number
Joint number of the represented body part.
Definition: bodypart.h:38
virtual yarp::os::Bottle asBottle() const
Return the entity as a bottle.
Definition: bodypart.cpp:46
virtual bool fromBottle(const yarp::os::Bottle &b)
Fill entity fields from a bottle representation.
Definition: object.cpp:169
Represents a body part of the robot.
Definition: bodypart.h:29
virtual std::string toString() const
Return a human readable description of the entity.
Definition: object.cpp:213
std::string m_part
The part itself, e.g.
Definition: bodypart.h:48
virtual yarp::os::Bottle asBottle() const
Return the entity as a bottle.
Definition: object.cpp:78
virtual std::string toString() const
Return a human readable description of the entity.
Definition: bodypart.cpp:72
std::string m_kinectNode
The string labelling the kinect node (of a human kinematic structure, one of the ICUBCLIENT_OPC_BODY_...
Definition: bodypart.h:53
std::string m_entity_type
Definition: entity.h:55
virtual bool fromBottle(const yarp::os::Bottle &b)
Fill entity fields from a bottle representation.
Definition: bodypart.cpp:87