27#include <unordered_set>
45 def->component(proxies.commonStorage);
46 def->component(proxies.priorKnowledge);
47 def->component(proxies.workingMemory);
48 def->component(proxies.longtermMemory);
50 def->optional(properties.mongoDbName,
52 "Name of snapshot Mongo database to load files into");
53 def->optional(properties.dryRun,
"p.dryRun",
"If true, don't actually change anything.");
56 def->optional(properties.importObjects,
"p.obj.00_DoImport",
"Whether to import objects.");
58 def->optional(properties.objectsRepository,
59 "p.obj.10_Repository",
60 "Repository such as ArmarXObjects containing the object classes.");
62 def->optional(properties.datasetName,
63 "p.obj.20_DatasetName",
64 "If set, only the given dataset in ArmarXObjects is imported.\n"
65 "Otherwise (default), all objects are imported.");
66 def->optional(properties.className,
68 "If set, only the given dataset in ArmarXObjects is imported.\n"
69 "Otherwise (default), all objects are imported.");
72 def->optional(properties.importScenes,
"p.scenes.00_DoImport",
"Whether to import scenes.");
73 def->optional(properties.scenesDirectory,
74 "p.scenes.10_Directory",
75 "Directory containing the scene files (Scene_*.json).");
76 def->optional(properties.sceneNames,
78 "Scenes to load by name. Comma separated. ({scene_name}.json).");
93 memoryx::PersistentObjectClassSegmentBasePrx objectClassesSegment =
94 proxies.priorKnowledge->getObjectClassesSegment();
98 importer.
dryRun = properties.dryRun;
100 if (properties.dryRun)
105 if (properties.importObjects)
108 std::vector<armarx::ObjectInfo> objectInfos;
109 if (properties.datasetName.size() > 0)
111 if (properties.className.size() > 0)
113 ARMARX_INFO <<
"Finding " << properties.datasetName << properties.className
115 if (
auto info = finder.
findObject(properties.datasetName, properties.className))
117 objectInfos.push_back(info.value());
122 ARMARX_INFO <<
"Finding objects in dataset " << properties.datasetName
132 ARMARX_INFO <<
"Found " << objectInfos.size() <<
" object classes in "
133 << properties.objectsRepository <<
".";
135 ARMARX_INFO <<
"Importing " << objectInfos.size() <<
" object classes ...";
137 objectInfos, gridFileManager, objectClassesSegment, properties.mongoDbName);
140 if (properties.importScenes)
142 const std::filesystem::path scenesDir =
144 std::unordered_set<std::string> scenes;
145 if (not properties.sceneNames.empty())
147 bool trim =
true, removeEmpty =
true;
148 const auto scenesTmp =
armarx::split(properties.sceneNames,
",", trim, removeEmpty);
150 scenes = std::unordered_set<std::string>(scenesTmp.begin(), scenesTmp.end());
153 if (not scenes.empty())
155 ARMARX_INFO <<
"The following scenes will be loaded (if available): "
156 << std::vector<std::string>(scenes.begin(), scenes.end());
159 ARMARX_INFO <<
"Importing scenes in " << scenesDir;
161 proxies.longtermMemory,
162 proxies.workingMemory,
163 objectClassesSegment,
181 return "ArmarXObjectsImporter";
187 return "ArmarXObjectsImporter";
190 ArmarXObjectsImporter::Properties::Properties() :
191 objectsRepository(
armarx::ObjectFinder::DefaultObjectsPackageName),
192 scenesDirectory(
armarx::ObjectFinder::DefaultObjectsPackageName +
"/scenes")
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
static std::string resolvePath(const std::string &path, bool verbose=true)
Resolves environment variables and home paths and tries to make path absolute.
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
std::vector< ObjectInfo > findAllObjects(bool checkPaths=true) const
std::vector< ObjectInfo > findAllObjectsOfDataset(const std::string &dataset, bool checkPaths=true) const
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
Brief description of class ArmarXObjectsImporter.
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
static std::string GetDefaultName()
void onExitComponent() override
std::string getDefaultName() const override
void importObjectsToPriorKnowledge(std::vector< armarx::ObjectInfo > const &objectInfos, memoryx::GridFileManagerPtr const &gridFileManager, memoryx::PersistentObjectClassSegmentBasePrx const &objectClassesSegment, std::string const &mongoDbName) const
bool dryRun
If true, don't actually change anything.
void importScenesAsSnapshots(std::filesystem::path const &scenesDirectory, memoryx::LongtermMemoryInterfacePrx const &longtermMemory, memoryx::WorkingMemoryInterfacePrx const &workingMemory, memoryx::PersistentObjectClassSegmentBasePrx const &objectClassesSegment, const std::unordered_set< std::string > &scenes) const
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.