ObjectClassSegmentWrapper.cpp
Go to the documentation of this file.
2
3#include <SimoxUtility/algorithm/string.h>
4#include <VirtualRobot/ManipulationObject.h>
5
7
11
12namespace 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();
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
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
std::optional< ObjectClassWrapper > getClass(std::string const &className) const
void initFromProxy(memoryx::PriorKnowledgeInterfacePrx const &priorKnowledge, const std::vector< std::string > &datasets)
#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_INFO
The normal logging level.
Definition Logging.h:181
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
VirtualRobot headers.
IceInternal::Handle< ObjectClass > ObjectClassPtr
Definition ObjectClass.h:35
std::shared_ptr< GridFileManager > GridFileManagerPtr
#define ARMARX_TRACE
Definition trace.h:77