ObjectInstanceSegmentWrapper.cpp
Go to the documentation of this file.
2 
3 // Factory shenanigans: Do not remove, these are required
4 // and runtime errors will be thrown if they are not included
7 
10 
12 
13 #include <VirtualRobot/ManipulationObject.h>
14 
15 namespace memoryx
16 {
17 
19  PriorKnowledgeInterfacePrx const& priorKnowledge,
20  WorkingMemoryInterfacePrx const& workingMemory,
21  armarx::RobotStateComponentInterfacePrx const& robotStateComponent)
22  {
23  ARMARX_CHECK_NOT_NULL(workingMemory);
24  ARMARX_CHECK_NOT_NULL(priorKnowledge);
25  ARMARX_CHECK_NOT_NULL(robotStateComponent);
26 
27  objectClassSegment.initFromProxy(priorKnowledge, {});
28 
29  this->robotStateComponent = robotStateComponent;
30  sharedRobot = robotStateComponent->getSynchronizedRobot();
31  localRobot = armarx::RemoteRobot::createLocalClone(sharedRobot);
32  objectInstancesSegment = workingMemory->getObjectInstancesSegment();
33  }
34 
35  std::vector<ObjectInstanceWrapper> ObjectInstanceSegmentWrapper::queryObjects(std::set<std::string> const& ids)
36  {
37  memoryx::EntityBaseList entities = objectInstancesSegment->getAllEntities();
38  std::vector<memoryx::ObjectInstancePtr> objectInstances;
39  for (auto& entity : entities)
40  {
41  memoryx::ObjectInstancePtr object = memoryx::ObjectInstancePtr::dynamicCast(entity);
42  if (object)
43  {
44  if (ids.empty() || ids.count(object->getId()))
45  {
46  objectInstances.push_back(object);
47  }
48  }
49  }
50 
51  std::vector<ObjectInstanceWrapper> result;
52  for (auto& objectInstance : objectInstances)
53  {
54  std::string objectName = objectInstance->getName();
55 
56  // TODO: Only synchronize if the timestamp is new
57  if (objectInstance->hasLocalizationTimestamp())
58  {
59  IceUtil::Time localizationTimestamp = objectInstance->getLocalizationTimestamp();
60  armarx::RemoteRobot::synchronizeLocalCloneToTimestamp(localRobot, robotStateComponent, localizationTimestamp.toMicroSeconds());
61  }
62  else
63  {
64  armarx::RemoteRobot::synchronizeLocalClone(localRobot, sharedRobot);
65  }
66  Eigen::Matrix4f globalPose = objectInstance->getPose()->toGlobalEigen(localRobot);
67 
68  std::string objectClass = objectInstance->getMostProbableClass();
69  auto entry = objectClassSegment.getClass(objectClass);
70  if (!entry)
71  {
72  ARMARX_WARNING << deactivateSpam(1) << "Could not find object class '" << objectClass << "'."
73  << " Skipping object '" << objectName << "'.";
74  continue;
75  }
76 
77  // This operation can be quite expensive (~ 300ms for 10 objects).
78  VirtualRobot::ManipulationObjectPtr manipulationObject = entry->manipulationObject->clone(objectName);
79  manipulationObject->setGlobalPose(globalPose);
80 
81  ObjectInstanceWrapper object;
82  object.instanceInMemory = objectInstance;
83  object.manipulationObject = manipulationObject;
84  result.push_back(object);
85  }
86 
87  return result;
88  }
89 
90 }
RemoteRobot.h
ObjectInstanceSegmentWrapper.h
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:448
memoryx::ObjectInstanceWrapper::instanceInMemory
memoryx::ObjectInstancePtr instanceInMemory
Definition: ObjectInstanceSegmentWrapper.h:18
memoryx::ObjectInstanceSegmentWrapper::queryObjects
std::vector< ObjectInstanceWrapper > queryObjects(std::set< std::string > const &ids={})
Definition: ObjectInstanceSegmentWrapper.cpp:35
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
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
ObjectClass.h
memoryx::ObjectClassSegmentWrapper::getClass
std::optional< ObjectClassWrapper > getClass(std::string const &className) const
Definition: ObjectClassSegmentWrapper.cpp:62
IceInternal::Handle< ObjectInstance >
memoryx::ObjectInstanceSegmentWrapper::initFromProxies
void initFromProxies(memoryx::PriorKnowledgeInterfacePrx const &priorKnowledge, memoryx::WorkingMemoryInterfacePrx const &workingMemory, armarx::RobotStateComponentInterfacePrx const &robotStateComponent)
Definition: ObjectInstanceSegmentWrapper.cpp:18
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
memoryx::ObjectClassSegmentWrapper::initFromProxy
void initFromProxy(memoryx::PriorKnowledgeInterfacePrx const &priorKnowledge, const std::vector< std::string > &datasets)
Definition: ObjectClassSegmentWrapper.cpp:16
memoryx::ObjectInstanceSegmentWrapper::objectClassSegment
ObjectClassSegmentWrapper objectClassSegment
Definition: ObjectInstanceSegmentWrapper.h:34
MemoryXCoreObjectFactories.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ExpressionException.h
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:328
armarx::RemoteRobot::synchronizeLocalCloneToTimestamp
static bool synchronizeLocalCloneToTimestamp(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx, Ice::Long timestamp)
Synchronizes a local robot to a robot state at timestamp.
Definition: RemoteRobot.cpp:487
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
memoryx::ObjectInstanceWrapper
Definition: ObjectInstanceSegmentWrapper.h:16
MemoryXTypesObjectFactories.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186