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