ObjectClassSegmentWrapper.cpp
Go to the documentation of this file.
2 
3 #include <SimoxUtility/algorithm/string.h>
4 #include <VirtualRobot/ManipulationObject.h>
5 
7 
11 
12 namespace memoryx
13 {
14 
15  void
16  ObjectClassSegmentWrapper::initFromProxy(PriorKnowledgeInterfacePrx const& priorKnowledge,
17  const std::vector<std::string>& datasets)
18  {
20  ARMARX_CHECK_NOT_NULL(priorKnowledge);
21 
22  memoryx::PersistentObjectClassSegmentBasePrx objectClassesSegment =
23  priorKnowledge->getObjectClassesSegment();
24  memoryx::GridFileManagerPtr fileManager(
25  new memoryx::GridFileManager(priorKnowledge->getCommonStorage()));
26 
27  memoryx::EntityBaseList classEntities = objectClassesSegment->getAllEntities();
28  for (auto& classEntity : classEntities)
29  {
31  ARMARX_CHECK_NOT_NULL(classEntity);
32  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(classEntity);
33  if (objectClass)
34  {
35  std::string objectClassName = objectClass->getName();
36  bool load = datasets.empty();
37  for (const auto& d : datasets)
38  {
39  if (simox::alg::count(objectClassName, "/") ==
40  0) // we always load the legacy stuff
41  {
42  load = true;
43  break;
44  }
45  if (simox::alg::starts_with(objectClassName, d + "/"))
46  {
47  load = true;
48  break;
49  }
50  }
51 
52  if (load)
53  {
54  ARMARX_INFO << "Getting files for object class '" << objectClassName << "'";
55  memoryx::EntityWrappers::SimoxObjectWrapperPtr sw = objectClass->addWrapper(
57  VirtualRobot::ManipulationObjectPtr manipulationObject =
58  sw->getManipulationObject();
59 
60  ObjectClassWrapper classData = {objectClass, manipulationObject};
61  classToWrapper.emplace(objectClassName, classData);
62  }
63  }
64  }
65  }
66 
67  std::optional<ObjectClassWrapper>
68  ObjectClassSegmentWrapper::getClass(std::string const& className) const
69  {
70  auto found = classToWrapper.find(className);
71  if (found == classToWrapper.end())
72  {
73  return std::nullopt;
74  }
75  else
76  {
77  return found->second;
78  }
79  }
80 
81 } // namespace memoryx
ObjectClassSegmentWrapper.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
GridFileManager.h
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
memoryx::ObjectClassWrapper
Definition: ObjectClassSegmentWrapper.h:16
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
IceInternal::Handle< ObjectClass >
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
memoryx::ObjectClassSegmentWrapper::initFromProxy
void initFromProxy(memoryx::PriorKnowledgeInterfacePrx const &priorKnowledge, const std::vector< std::string > &datasets)
Definition: ObjectClassSegmentWrapper.cpp:16
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
ExpressionException.h
SimoxObjectWrapper.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:41
armarx::armem::server::ltm::mongodb::util::load
void load(const mongocxx::database &db, armem::wm::Memory &m)
Definition: operations.cpp:48