Affordance.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::Core
17 * @author Peter Kaiser <peter dot kaiser at kit dot edu>
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "Affordance.h"
24 
26 
27 namespace memoryx
28 {
29  Affordance::Affordance(const std::string& name, const std::string& id) :
30  Entity()
31  {
32  setName(name);
33  setId(id);
34  }
35 
36  void Affordance::setType(AffordanceType type, const Ice::Current& c)
37  {
38  putAttribute("type", static_cast<int>(type));
39  }
40 
41  AffordanceType Affordance::getType(const Ice::Current& c) const
42  {
43  return static_cast<AffordanceType>(getAttributeValue("type")->getInt());
44  }
45 
46  void Affordance::setPosition(const armarx::Vector3BasePtr& position, const Ice::Current& c)
47  {
48  putAttribute("position", position);
49  }
50 
51  armarx::Vector3BasePtr Affordance::getPosition(const Ice::Current& c) const
52  {
53  return getAttributeValue("position")->getClass<armarx::Vector3Base>();
54  }
55 
56  void Affordance::setPrimitiveId(const std::string& id, const Ice::Current& c)
57  {
58  putAttribute("primitiveId", id);
59  }
60 
61  std::string Affordance::getPrimitiveId(const Ice::Current& c) const
62  {
63  return getAttributeValue("primitiveId")->getString();
64  }
65 
66  void Affordance::setValidationStatus(AffordanceValidationStatus status, const Ice::Current& c)
67  {
68  putAttribute("validationStatus", static_cast<int>(status));
69  }
70 
71  AffordanceValidationStatus Affordance::getValidationStatus(const Ice::Current& c) const
72  {
73  return static_cast<AffordanceValidationStatus>(getAttributeValue("validationStatus")->getInt());
74  }
75 
76  float Affordance::getProbability(const Ice::Current& c) const
77  {
78  return getAttributeValue("probability")->getFloat();
79  }
80 
81  void Affordance::setProbability(float probability, const Ice::Current& c)
82  {
83  putAttribute("probability", probability);
84  }
85 
86  armarx::TimestampBasePtr Affordance::getTime(const Ice::Current&) const
87  {
88  return getAttributeValue("time")->getClass<armarx::TimestampBase>();
89  }
90 
91  void Affordance::setTime(const armarx::TimestampBasePtr& time, const Ice::Current&)
92  {
93  putAttribute("time", time);
94  }
95 
96  armarx::MatrixFloatBasePtr Affordance::getCertaintyFunction(const Ice::Current& c) const
97  {
98  auto entity = getAttribute("certaintyFunction");
99  if (!entity || entity->size() <= 0)
100  {
101  return armarx::MatrixFloatBasePtr(new armarx::MatrixFloat(2, 0));
102  }
103 
104  return armarx::VariantPtr::dynamicCast(entity->getValueAt(0))->getClass<armarx::MatrixFloat>();
105  }
106 
107  void Affordance::setCertaintyFunction(const armarx::MatrixFloatBasePtr& certainties, const Ice::Current& c)
108  {
109  armarx::VariantPtr variant(new armarx::Variant);
110  variant->set<armarx::MatrixFloat>(certainties);
111 
112  EntityAttributeBasePtr entity = new EntityAttribute("certaintyFunction");
113  entity->addValue(variant);
114  putAttribute(entity);
115  }
116 
117  AffordanceObservationList Affordance::getObservations(const Ice::Current& c) const
118  {
119  AffordanceObservationList result;
120 
121  auto entity = getAttribute("observations");
122  if (!entity || entity->size() <= 0)
123  {
124  return result;
125  }
126 
127  for (int i = 0; i < entity->size(); i++)
128  {
129  result.push_back(armarx::VariantPtr::dynamicCast(entity->getValueAt(i))->getClass<armarx::MatrixFloat>());
130  }
131 
132  return result;
133  }
134 
135  void Affordance::setObservations(const AffordanceObservationList& observations, const Ice::Current& c)
136  {
137  EntityAttributeBasePtr entity = new EntityAttribute("observations");
138 
139  for (auto& observation : observations)
140  {
141  armarx::VariantPtr variant(new armarx::Variant);
142  variant->set<armarx::MatrixFloat>(armarx::MatrixFloatPtr::dynamicCast(observation));
143  entity->addValue(variant);
144  }
145 
146  putAttribute(entity);
147  }
148 
149  void Affordance::addObservation(const armarx::MatrixFloatBasePtr& observation, const Ice::Current& c)
150  {
151  EntityAttributeBasePtr entity = new EntityAttribute("observations");
152 
153  armarx::VariantPtr variant(new armarx::Variant);
154  variant->set<armarx::MatrixFloat>(observation);
155  entity->addValue(variant);
156 
157  putAttribute(entity);
158  }
159 
160  std::string Affordance::getTypeName() const
161  {
162  switch (getType())
163  {
164  case memoryx::eAffordanceTypeGrasp:
165  return "G";
166 
167  case memoryx::eAffordanceTypeGraspPlatform:
168  return "G-Pl";
169 
170  case memoryx::eAffordanceTypeGraspPrismatic:
171  return "G-Pr";
172 
173  case memoryx::eAffordanceTypeSupport:
174  return "Sp";
175 
176  case memoryx::eAffordanceTypeLean:
177  return "Ln";
178 
179  case memoryx::eAffordanceTypeHold:
180  return "Hd";
181 
182  case memoryx::eAffordanceTypePush:
183  return "Ps";
184 
185  case memoryx::eAffordanceTypeLift:
186  return "Lf";
187 
188  case memoryx::eAffordanceTypeTurn:
189  return "Tn";
190 
191  case memoryx::eAffordanceTypeBimanualGraspPlatform:
192  return "Bi-G-Pl";
193 
194  case memoryx::eAffordanceTypeBimanualOpposedGraspPlatform:
195  return "Bi-OG-Pl";
196 
197  case memoryx::eAffordanceTypeBimanualGraspPrismatic:
198  return "Bi-G-Pr";
199 
200  case memoryx::eAffordanceTypeBimanualOpposedGraspPrismatic:
201  return "Bi-OG-Pr";
202 
203  case memoryx::eAffordanceTypeBimanualTurn:
204  return "Bi-Tn";
205 
206  case memoryx::eAffordanceTypeBimanualLift:
207  return "Bi-Lf";
208 
209  case memoryx::eAffordanceTypeBimanualPush:
210  return "Bi-Ps";
211 
212  default:
213  return "Unknown";
214  }
215  }
216 
218  {
219  return this->clone();
220  }
221 
222  AffordancePtr Affordance::clone(const Ice::Current& c) const
223  {
224  return new Affordance(*this);
225  }
226 }
memoryx::Affordance::getCertaintyFunction
armarx::MatrixFloatBasePtr getCertaintyFunction(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:96
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
memoryx::Affordance::getPosition
armarx::Vector3BasePtr getPosition(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:51
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::Affordance::getPrimitiveId
std::string getPrimitiveId(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:61
memoryx::Affordance::setObservations
void setObservations(const memoryx::AffordanceObservationList &observations, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:135
memoryx::Affordance::Affordance
Affordance(const std::string &name="", const std::string &id="")
Definition: Affordance.cpp:29
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
memoryx::Affordance::setValidationStatus
void setValidationStatus(AffordanceValidationStatus status, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:66
MatrixVariant.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::Affordance::setType
void setType(AffordanceType type, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:36
Affordance.h
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:308
memoryx::Affordance::getTypeName
std::string getTypeName() const
Definition: Affordance.cpp:160
IceInternal::Handle< Variant >
armarx::status
status
Definition: FiniteStateMachine.h:259
memoryx::Affordance::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: Affordance.cpp:217
armarx::MatrixFloat
The MatrixFloat class.
Definition: MatrixVariant.h:48
memoryx::Affordance::getObservations
memoryx::AffordanceObservationList getObservations(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:117
memoryx::Entity::setId
void setId(const ::std::string &id, const ::Ice::Current &=Ice::emptyCurrent) override
Set id of this entity.
Definition: Entity.cpp:167
memoryx::Affordance::setTime
void setTime(const armarx::TimestampBasePtr &time, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:91
memoryx::Affordance::setPosition
void setPosition(const armarx::Vector3BasePtr &position, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:46
memoryx::Affordance::clone
AffordancePtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: Affordance.cpp:222
memoryx::Affordance::addObservation
void addObservation(const armarx::MatrixFloatBasePtr &observation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:149
memoryx::Affordance::getProbability
float getProbability(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:76
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:48
memoryx::Affordance::setProbability
void setProbability(float probability, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:81
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::Affordance::getType
AffordanceType getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:41
memoryx::Affordance::getValidationStatus
AffordanceValidationStatus getValidationStatus(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:71
memoryx::Entity
Definition: Entity.h:246
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:179
memoryx::Affordance::getTime
armarx::TimestampBasePtr getTime(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: Affordance.cpp:86
memoryx::Affordance::setPrimitiveId
void setPrimitiveId(const std::string &id, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:56
memoryx::Affordance::setCertaintyFunction
void setCertaintyFunction(const armarx::MatrixFloatBasePtr &certainties, const Ice::Current &c=Ice::emptyCurrent) override
Definition: Affordance.cpp:107