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