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
19namespace armarx::objpose
20{
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;
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;
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(
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 {
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
283namespace 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
369 objpose::fromIce(const data::ObjectPoseSeq& ice, ObjectPoseSeq& poses)
370 {
371 poses.clear();
372 poses.reserve(ice.size());
373 for (const auto& i : ice)
374 {
375 poses.emplace_back(i);
376 }
377 }
378
380 objpose::fromIce(const data::ObjectPoseSeq& ice)
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
400 objpose::toIce(data::ObjectPoseSeq& ice, const ObjectPoseSeq& poses)
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
410 objpose::data::ObjectPoseSeq
412 {
413 data::ObjectPoseSeq ice;
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
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*
445 objpose::findObjectPoseByID(data::ObjectPoseSeq& objectPoses, const armarx::data::ObjectID& id)
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*
458 objpose::findObjectPoseByID(const data::ObjectPoseSeq& objectPoses,
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
The FramedPose class.
Definition FramedPose.h:281
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
The Pose class.
Definition Pose.h:243
virtual Eigen::Matrix4f toEigen() const
Definition Pose.cpp:334
An object pose provided by an ObjectPoseProvider.
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
std::string providerName
Name of the providing component.
bool isStatic
Whether object is static. Static objects don't decay.
DateTime timestamp
Source timestamp.
ObjectType objectType
Known or unknown object.
std::map< std::string, float > objectJointValues
The object's joint values if it is articulated.
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
std::optional< PoseManifoldGaussian > objectPoseGaussian
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#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...
#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...
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
ObjectPose * findObjectPoseByID(ObjectPoseSeq &objectPoses, const ObjectID &id)
Find an object pose by the object ID.
std::vector< ObjectPose > ObjectPoseSeq
void fromIce(const Box &box, simox::OrientedBox< float > &oobb)
objpose::AABB toIce(const simox::AxisAlignedBoundingBox &aabb)
This file offers overloads of toIce() and fromIce() functions for STL container types.
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34
float confidence
Confidence in [0, 1] (1 = full, 0 = none).
Definition ObjectPose.h:96
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition ObjectPose.h:56
objpose::ObjectPose getAttached(VirtualRobot::RobotPtr agent) const
Get a copy of *this with updated attachment.
std::optional< ObjectAttachmentInfo > attachment
Attachment information.
Definition ObjectPose.h:93
std::map< std::string, float > robotConfig
The robot config when the object was observed.
Definition ObjectPose.h:86
std::string providerName
Name of the providing component.
Definition ObjectPose.h:59
void fromProvidedPose(const data::ProvidedObjectPose &provided, VirtualRobot::RobotPtr robot=nullptr)
data::ObjectPose toIce() const
void setObjectPoseGlobal(const Eigen::Matrix4f &objectPoseGlobal, bool updateObjectPoseRobot=true)
bool isStatic
Whether object is static. Static objects don't decay.
Definition ObjectPose.h:63
void updateAttached(VirtualRobot::RobotPtr agent)
Update an the object pose and robot state of an attached object pose according to the given agent sta...
std::optional< simox::OrientedBoxf > oobbRobot() const
Get the OOBB in the robot frame (according to objectPoseRobot).
DateTime timestamp
Source timestamp.
Definition ObjectPose.h:98
Eigen::Matrix4f objectPoseRobot
The object pose in the robot root frame.
Definition ObjectPose.h:66
Eigen::Matrix4f robotPose
The robot pose when the object was observed.
Definition ObjectPose.h:88
Eigen::Matrix4f objectPoseOriginal
The object pose in the frame it was originally localized in.
Definition ObjectPose.h:76
ObjectType objectType
Known or unknown object.
Definition ObjectPose.h:61
std::optional< PoseManifoldGaussian > objectPoseGlobalGaussian
... and with uncertainty.
Definition ObjectPose.h:73
void setObjectPoseRobot(const Eigen::Matrix4f &objectPoseRobot, bool updateObjectPoseGlobal=true)
std::map< std::string, float > objectJointValues
The object's joint values if it is articulated.
Definition ObjectPose.h:83
std::optional< simox::OrientedBoxf > localOOBB
Object bounding box in object's local coordinate frame.
Definition ObjectPose.h:102
void fromIce(const data::ObjectPose &ice)
std::optional< simox::OrientedBoxf > oobbGlobal() const
Get the OOBB in the global frame (according to objectPoseGlobal).
std::optional< PoseManifoldGaussian > objectPoseOriginalGaussian
... and with uncertainty.
Definition ObjectPose.h:80
objpose::ProvidedObjectPose toProvidedObjectPoseGlobal() const
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition ObjectPose.h:71
std::string robotName
The name of the robot.
Definition ObjectPose.h:90
std::optional< PoseManifoldGaussian > objectPoseRobotGaussian
... and with uncertainty.
Definition ObjectPose.h:68
std::string objectPoseOriginalFrame
The frame the object was originally localized in.
Definition ObjectPose.h:78