ObjectPose.cpp
Go to the documentation of this file.
1 #include "ObjectPose.h"
2 
3 #include <SimoxUtility/math/pose/invert.h>
4 #include <SimoxUtility/math/pose/pose.h>
5 
6 #include <VirtualRobot/Robot.h>
7 #include <VirtualRobot/RobotConfig.h>
8 
11 
16 
17 #include "ice_conversions.h"
18 
19 
20 namespace armarx::objpose
21 {
23  {
24  }
25 
26  ObjectPose::ObjectPose(const data::ObjectPose& ice)
27  {
28  fromIce(ice);
29  }
30 
31  void ObjectPose::fromIce(const data::ObjectPose& ice)
32  {
33  armarx::fromIce(ice.objectID, objectID);
34 
35  providerName = ice.providerName;
36  objectType = ice.objectType;
37  isStatic = ice.isStatic;
38 
39  armarx::fromIce(ice.objectPoseRobot, objectPoseRobot);
40  objpose::fromIce(ice.objectPoseRobotGaussian, objectPoseRobotGaussian);
41 
42  armarx::fromIce(ice.objectPoseGlobal, objectPoseGlobal);
43  objpose::fromIce(ice.objectPoseGlobalGaussian, objectPoseGlobalGaussian);
44 
45  armarx::fromIce(ice.objectPoseOriginal, objectPoseOriginal);
46  objectPoseOriginalFrame = ice.objectPoseOriginalFrame;
47  objpose::fromIce(ice.objectPoseOriginalGaussian, objectPoseOriginalGaussian);
48 
49  objectJointValues = ice.objectJointValues;
50 
51  robotConfig = ice.robotConfig;
52  armarx::fromIce(ice.robotPose, robotPose);
53  robotName = ice.robotName;
54 
55  objpose::fromIce(ice.attachment, this->attachment);
56 
57  confidence = ice.confidence;
58  armarx::core::time::fromIce(ice.timestamp, timestamp);
59 
60  objpose::fromIce(ice.localOOBB, localOOBB);
61  }
62 
63  data::ObjectPose ObjectPose::toIce() const
64  {
65  data::ObjectPose ice;
66  toIce(ice);
67  return ice;
68  }
69 
70  void ObjectPose::toIce(data::ObjectPose& ice) const
71  {
72  armarx::toIce(ice.objectID, objectID);
73 
74  ice.providerName = providerName;
75  ice.objectType = objectType;
76  ice.isStatic = isStatic;
77 
78  armarx::toIce(ice.objectPoseRobot, objectPoseRobot);
79  objpose::toIce(ice.objectPoseRobotGaussian, objectPoseRobotGaussian);
80 
81  armarx::toIce(ice.objectPoseGlobal, objectPoseGlobal);
82  objpose::toIce(ice.objectPoseGlobalGaussian, objectPoseGlobalGaussian);
83 
84  armarx::toIce(ice.objectPoseOriginal, objectPoseOriginal);
85  ice.objectPoseOriginalFrame = objectPoseOriginalFrame;
86  objpose::toIce(ice.objectPoseOriginalGaussian, objectPoseOriginalGaussian);
87 
88  ice.objectJointValues = objectJointValues;
89 
90  ice.robotConfig = robotConfig;
91  ice.robotPose = new Pose(robotPose);
92  ice.robotName = robotName;
93 
94  objpose::toIce(ice.attachment, this->attachment);
95 
96  ice.confidence = confidence;
97  armarx::core::time::toIce(ice.timestamp, timestamp);
98 
99  objpose::toIce(ice.localOOBB, localOOBB);
100  }
101 
103  const data::ProvidedObjectPose& provided, VirtualRobot::RobotPtr robot)
104  {
105  armarx::fromIce(provided.objectID, objectID);
106 
107  providerName = provided.providerName;
108  objectType = provided.objectType;
109  isStatic = provided.isStatic;
110 
111  armarx::fromIce(provided.objectPose, objectPoseOriginal);
112  objpose::fromIce(provided.objectPoseGaussian, objectPoseOriginalGaussian);
113  objectPoseOriginalFrame = provided.objectPoseFrame;
114 
115  objectJointValues = provided.objectJointValues;
116 
117  if (robot)
118  {
120  framed.changeFrame(robot, robot->getRootNode()->getName());
121  objectPoseRobot = framed.toEigen();
122  objectPoseRobotGaussian = std::nullopt;
123 
125  if (objectPoseOriginalGaussian.has_value() and objectPoseOriginalFrame != robot->getRootNode()->getName())
126  {
128  }
129 
130  framed.changeToGlobal(robot);
131  objectPoseGlobal = framed.toEigen();
132 
135  {
137  }
138 
139  robotConfig = robot->getConfig()->getRobotNodeJointValueMap();
140  robotPose = robot->getGlobalPose();
141  robotName = robot->getName();
142  }
143  else
144  {
145  // Try to get what we can.
147  {
150  }
151  else
152  {
153  // Nothing we can do about it ... Let's not lie about it at least.
154  objectPoseGlobal.setIdentity();
156  }
157 
158  robotConfig.clear();
159  robotPose.setIdentity();
160  robotName = provided.robotName;
161 
162  // Keep original and robot consistent.
165  }
166 
167  attachment = std::nullopt;
168 
169  confidence = provided.confidence;
170  armarx::core::time::fromIce(provided.timestamp, timestamp);
171 
172  objpose::fromIce(provided.localOOBB, localOOBB);
173  }
174 
175  // ToDo: We can provide ...Robot() and ...Original() versions as well.
177  {
178  objpose::ProvidedObjectPose providedObjectPose;
179 
180  providedObjectPose.objectID = this->objectID;
181  providedObjectPose.providerName = this->providerName;
182  providedObjectPose.objectType = this->objectType;
183 
184  providedObjectPose.isStatic = this->isStatic;
185 
186  providedObjectPose.objectPoseFrame = GlobalFrame;
187  providedObjectPose.objectPose = this->objectPoseGlobal;
188  providedObjectPose.objectPoseGaussian = this->objectPoseGlobalGaussian;
189 
190  providedObjectPose.objectJointValues = this->objectJointValues;
191 
192  providedObjectPose.confidence = this->confidence;
193  providedObjectPose.timestamp = this->timestamp;
194 
195  providedObjectPose.localOOBB = this->localOOBB;
196 
197  return providedObjectPose;
198  }
199 
201  const Eigen::Matrix4f& objectPoseRobot, bool updateObjectPoseGlobal)
202  {
203  this->objectPoseRobot = objectPoseRobot;
204  if (updateObjectPoseGlobal)
205  {
207  }
208  }
209 
211  const Eigen::Matrix4f& objectPoseGlobal, bool updateObjectPoseRobot)
212  {
213  this->objectPoseGlobal = objectPoseGlobal;
214  if (updateObjectPoseRobot)
215  {
216  this->objectPoseRobot = simox::math::inverted_pose(robotPose) * objectPoseGlobal;
217  }
218  }
219 
220 
221  std::optional<simox::OrientedBoxf> ObjectPose::oobbRobot() const
222  {
223  if (localOOBB)
224  {
225  return localOOBB->transformed(objectPoseRobot);
226  }
227  return std::nullopt;
228  }
229 
230  std::optional<simox::OrientedBoxf> ObjectPose::oobbGlobal() const
231  {
232  if (localOOBB)
233  {
234  return localOOBB->transformed(objectPoseGlobal);
235  }
236  return std::nullopt;
237  }
238 
240  {
242 
243  objpose::ObjectPose updated = *this;
244  updated.updateAttached(agent);
245  return updated;
246  }
247 
249  {
251  ARMARX_CHECK_NOT_NULL(agent);
252 
253  ARMARX_CHECK_EQUAL(attachment->agentName, agent->getName());
254 
255  VirtualRobot::RobotNodePtr robotNode = agent->getRobotNode(attachment->frameName);
256  ARMARX_CHECK_NOT_NULL(robotNode);
257 
258  // Overwrite object pose
259  objectPoseRobot = robotNode->getPoseInRootFrame() * attachment->poseInFrame;
260  objectPoseGlobal = agent->getGlobalPose() * objectPoseRobot;
261 
262  // Overwrite robot config.
263  robotPose = agent->getGlobalPose();
264  robotConfig = agent->getConfig()->getRobotNodeJointValueMap();
265  }
266 
267 }
268 
269 
270 namespace armarx
271 {
272 
273  void objpose::fromIce(const data::ObjectAttachmentInfo& ice, ObjectAttachmentInfo& attachment)
274  {
275  attachment.agentName = ice.agentName;
276  attachment.frameName = ice.frameName;
277  attachment.poseInFrame = ::armarx::fromIce(ice.poseInFrame);
278  }
279 
280  void objpose::fromIce(const data::ObjectAttachmentInfoPtr& ice, std::optional<ObjectAttachmentInfo>& attachment)
281  {
282  if (ice)
283  {
284  attachment = ObjectAttachmentInfo();
285  fromIce(*ice, *attachment);
286  }
287  else
288  {
289  attachment = std::nullopt;
290  }
291  }
292 
293  std::optional<objpose::ObjectAttachmentInfo> objpose::fromIce(const data::ObjectAttachmentInfoPtr& ice)
294  {
295  if (!ice)
296  {
297  return std::nullopt;
298  }
300  fromIce(*ice, info);
301  return info;
302  }
303 
304  void objpose::toIce(data::ObjectAttachmentInfo& ice, const ObjectAttachmentInfo& attachment)
305  {
306  ice.agentName = attachment.agentName;
307  ice.frameName = attachment.frameName;
308  ice.poseInFrame = new Pose(attachment.poseInFrame);
309  }
310 
311  void objpose::toIce(data::ObjectAttachmentInfoPtr& ice, const std::optional<ObjectAttachmentInfo>& attachment)
312  {
313  if (attachment)
314  {
315  ice = new objpose::data::ObjectAttachmentInfo();
316  toIce(*ice, *attachment);
317  }
318  else
319  {
320  ice = nullptr;
321  }
322  }
323 
324  objpose::data::ObjectAttachmentInfoPtr objpose::toIce(const std::optional<ObjectAttachmentInfo>& attachment)
325  {
326  if (!attachment)
327  {
328  return nullptr;
329  }
330  objpose::data::ObjectAttachmentInfoPtr ice = new objpose::data::ObjectAttachmentInfo();
331  toIce(*ice, *attachment);
332  return ice;
333  }
334 
335 
336  void objpose::fromIce(const data::ObjectPose& ice, ObjectPose& pose)
337  {
338  pose.fromIce(ice);
339  }
340  objpose::ObjectPose objpose::fromIce(const data::ObjectPose& ice)
341  {
342  return ObjectPose(ice);
343  }
344 
346  {
347  poses.clear();
348  poses.reserve(ice.size());
349  for (const auto& i : ice)
350  {
351  poses.emplace_back(i);
352  }
353  }
355  {
356  ObjectPoseSeq poses;
357  fromIce(ice, poses);
358  return poses;
359  }
360 
361 
362  void objpose::toIce(data::ObjectPose& ice, const ObjectPose& pose)
363  {
364  pose.toIce(ice);
365  }
366  objpose::data::ObjectPose objpose::toIce(const ObjectPose& pose)
367  {
368  return pose.toIce();
369  }
370 
372  {
373  ice.clear();
374  ice.reserve(poses.size());
375  for (const auto& p : poses)
376  {
377  ice.emplace_back(p.toIce());
378  }
379  }
381  {
383  toIce(ice, poses);
384  return ice;
385  }
386 
387 
389  {
390  for (objpose::ObjectPose& pose : objectPoses)
391  {
392  if (pose.objectID == id)
393  {
394  return &pose;
395  }
396  }
397  return nullptr;
398  }
399 
401  {
402  for (const objpose::ObjectPose& pose : objectPoses)
403  {
404  if (pose.objectID == id)
405  {
406  return &pose;
407  }
408  }
409  return nullptr;
410  }
411 
412  objpose::data::ObjectPose* objpose::findObjectPoseByID(data::ObjectPoseSeq& objectPoses, const armarx::data::ObjectID& id)
413  {
414  for (objpose::data::ObjectPose& pose : objectPoses)
415  {
416  if (pose.objectID == id)
417  {
418  return &pose;
419  }
420  }
421  return nullptr;
422  }
423 
424  const objpose::data::ObjectPose* objpose::findObjectPoseByID(const data::ObjectPoseSeq& objectPoses, const armarx::data::ObjectID& id)
425  {
426  for (const objpose::data::ObjectPose& pose : objectPoses)
427  {
428  if (pose.objectID == id)
429  {
430  return &pose;
431  }
432  }
433  return nullptr;
434  }
435 
436 }
armarx::objpose::ObjectPose::getAttached
objpose::ObjectPose getAttached(VirtualRobot::RobotPtr agent) const
Get a copy of *this with updated attachment.
Definition: ObjectPose.cpp:239
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
armarx::objpose::ProvidedObjectPose::objectID
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition: ProvidedObjectPose.h:47
armarx::core::time::fromIce
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
Definition: ice_conversions.cpp:12
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::objpose::ObjectPose::objectType
ObjectType objectType
Known or unknown object.
Definition: ObjectPose.h:63
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::objpose::ObjectPose::fromIce
void fromIce(const data::ObjectPose &ice)
Definition: ObjectPose.cpp:31
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::armem::attachment::ObjectID
armem::MemoryID ObjectID
Definition: types.h:79
Pose.h
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::objpose::ObjectPose::robotName
std::string robotName
The name of the robot.
Definition: ObjectPose.h:92
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:33
armarx::objpose::ObjectPose::localOOBB
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
Definition: ObjectPose.h:104
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:62
armarx::objpose::fromIce
void fromIce(const Box &box, simox::OrientedBox< float > &oobb)
armarx::objpose::ObjectPose::oobbRobot
std::optional< simox::OrientedBoxf > oobbRobot() const
Get the OOBB in the robot frame (according to objectPoseRobot).
Definition: ObjectPose.cpp:221
armarx::objpose::ObjectPose::providerName
std::string providerName
Name of the providing component.
Definition: ObjectPose.h:61
armarx::objpose::ObjectAttachmentInfo::agentName
std::string agentName
Definition: ObjectPose.h:28
ice_conversions.h
armarx::objpose::findObjectPoseByID
ObjectPose * findObjectPoseByID(ObjectPoseSeq &objectPoses, const ObjectID &id)
Find an object pose by the object ID.
Definition: ObjectPose.cpp:388
armarx::objpose::ProvidedObjectPose::objectPoseFrame
std::string objectPoseFrame
Definition: ProvidedObjectPose.h:50
armarx::objpose::ObjectAttachmentInfo::frameName
std::string frameName
Definition: ObjectPose.h:27
armarx::objpose::ObjectPose::fromProvidedPose
void fromProvidedPose(const data::ProvidedObjectPose &provided, VirtualRobot::RobotPtr robot=nullptr)
Definition: ObjectPose.cpp:102
armarx::objpose::ObjectPose::objectPoseOriginalGaussian
std::optional< PoseManifoldGaussian > objectPoseOriginalGaussian
... and with uncertainty.
Definition: ObjectPose.h:82
armarx::objpose::ObjectPose::ObjectPose
ObjectPose()
Definition: ObjectPose.cpp:22
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::objpose::ObjectPose::setObjectPoseGlobal
void setObjectPoseGlobal(const Eigen::Matrix4f &objectPoseGlobal, bool updateObjectPoseRobot=true)
Definition: ObjectPose.cpp:210
armarx::objpose::ObjectPose::toIce
data::ObjectPose toIce() const
Definition: ObjectPose.cpp:63
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::objpose::ObjectPose::oobbGlobal
std::optional< simox::OrientedBoxf > oobbGlobal() const
Get the OOBB in the global frame (according to objectPoseGlobal).
Definition: ObjectPose.cpp:230
armarx::objpose::ObjectPose::isStatic
bool isStatic
Whether object is static. Static objects don't decay.
Definition: ObjectPose.h:65
armarx::objpose::ObjectPose::objectPoseRobotGaussian
std::optional< PoseManifoldGaussian > objectPoseRobotGaussian
... and with uncertainty.
Definition: ObjectPose.h:70
armarx::objpose::ObjectPose::objectPoseOriginalFrame
std::string objectPoseOriginalFrame
The frame the object was originally localized in.
Definition: ObjectPose.h:80
armarx::objpose::ObjectPose::robotPose
Eigen::Matrix4f robotPose
The robot pose when the object was observed.
Definition: ObjectPose.h:90
armarx::objpose::ObjectAttachmentInfo::poseInFrame
Eigen::Matrix4f poseInFrame
Definition: ObjectPose.h:29
FramedPose.h
armarx::core::eigen::fromIce
void fromIce(Eigen::Vector2f &e, const Ice::FloatSeq &ice)
Definition: ice_conversions.cpp:10
armarx::objpose::ProvidedObjectPose::objectPoseGaussian
std::optional< PoseManifoldGaussian > objectPoseGaussian
Definition: ProvidedObjectPose.h:51
armarx::objpose
This file is part of ArmarX.
Definition: objpose.h:7
armarx::Pose::toEigen
virtual Eigen::Matrix4f toEigen() const
Definition: Pose.cpp:334
armarx::objpose::ObjectPose::toProvidedObjectPoseGlobal
objpose::ProvidedObjectPose toProvidedObjectPoseGlobal() const
Definition: ObjectPose.cpp:176
ObjectPose.h
armarx::objpose::ProvidedObjectPose::providerName
std::string providerName
Name of the providing component.
Definition: ProvidedObjectPose.h:40
armarx::objpose::ObjectPose::robotConfig
std::map< std::string, float > robotConfig
The robot config when the object was observed.
Definition: ObjectPose.h:88
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
armarx::objpose::ObjectPose::setObjectPoseRobot
void setObjectPoseRobot(const Eigen::Matrix4f &objectPoseRobot, bool updateObjectPoseGlobal=true)
Definition: ObjectPose.cpp:200
ExpressionException.h
armarx::objpose::ProvidedObjectPose
An object pose provided by an ObjectPoseProvider.
Definition: ProvidedObjectPose.h:25
armarx::objpose::ObjectPose::updateAttached
void updateAttached(VirtualRobot::RobotPtr agent)
Update an the object pose and robot state of an attached object pose according to the given agent sta...
Definition: ObjectPose.cpp:248
armarx::objpose::toIce
objpose::AABB toIce(const simox::AxisAlignedBoundingBox &aabb)
Definition: ice_conversions.cpp:94
armarx::objpose::ObjectPose::objectID
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition: ObjectPose.h:58
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::objpose::ProvidedObjectPose::objectType
ObjectType objectType
Known or unknown object.
Definition: ProvidedObjectPose.h:42
ProvidedObjectPose.h
armarx::objpose::ProvidedObjectPose::isStatic
bool isStatic
Whether object is static. Static objects don't decay.
Definition: ProvidedObjectPose.h:44
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:73
armarx::objpose::ObjectPose::attachment
std::optional< ObjectAttachmentInfo > attachment
Attachment information.
Definition: ObjectPose.h:95
armarx::objpose::ProvidedObjectPose::objectJointValues
std::map< std::string, float > objectJointValues
The object's joint values if it is articulated.
Definition: ProvidedObjectPose.h:54
armarx::objpose::ObjectPose::objectPoseOriginal
Eigen::Matrix4f objectPoseOriginal
The object pose in the frame it was originally localized in.
Definition: ObjectPose.h:78
armarx::objpose::ProvidedObjectPose::localOOBB
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
Definition: ProvidedObjectPose.h:64
armarx::objpose::ProvidedObjectPose::confidence
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
Definition: ProvidedObjectPose.h:58
armarx::objpose::ObjectPose::objectPoseRobot
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
Definition: ObjectPose.h:68
armarx::FramedPose::changeToGlobal
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
Definition: FramedPose.cpp:467
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::objpose::ProvidedObjectPose::timestamp
DateTime timestamp
Source timestamp.
Definition: ProvidedObjectPose.h:60
armarx::objpose::ObjectAttachmentInfo
Definition: ObjectPose.h:25
armarx::objpose::ObjectPose::objectJointValues
std::map< std::string, float > objectJointValues
The object's joint values if it is articulated.
Definition: ObjectPose.h:85
armarx::objpose::ObjectPose::confidence
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
Definition: ObjectPose.h:98
armarx::objpose::ProvidedObjectPose::objectPose
Eigen::Matrix4f objectPose
Definition: ProvidedObjectPose.h:49
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:36
armarx::FramedPose::changeFrame
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
Definition: FramedPose.cpp:406
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::objpose::ObjectPose::timestamp
DateTime timestamp
Source timestamp.
Definition: ObjectPose.h:100
armarx::objpose::ObjectPose::objectPoseGlobalGaussian
std::optional< PoseManifoldGaussian > objectPoseGlobalGaussian
... and with uncertainty.
Definition: ObjectPose.h:75