diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp index 8e86d96dc398d707ab4e8629e4b971519db8dc65..2e026dd211cf6906d8b54b468ad6eebfff12141b 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp @@ -55,6 +55,12 @@ namespace armarx } + bool ObjectFinder::isDatasetDirValid(const path& path) const + { + return path.filename() != "Scenes" and std::filesystem::is_directory(path); + } + + std::optional<ObjectInfo> ObjectFinder::findObject(const std::string& dataset, const std::string& name) const { init(); @@ -67,8 +73,8 @@ namespace armarx return ObjectInfo(packageName, packageDataDir, dataset, name); } // Search for object in datasets. - const auto& datasets = getDatasets(); - for (const path& dataset : datasets) + const std::vector<std::string>& datasets = getDatasets(); + for (const std::string& dataset : datasets) { if (fs::is_directory(_rootDirAbs() / dataset / name)) { @@ -106,7 +112,7 @@ namespace armarx { // init(); // Done by called methods. std::vector<std::string> datasets; - for (const auto& dir : getDatasetDirectories()) + for (const path& dir : getDatasetDirectories()) { datasets.push_back(dir.filename()); } @@ -123,9 +129,9 @@ namespace armarx const bool local = false; std::vector<path> dirs = simox::fs::list_directory(_rootDirAbs(), local); std::vector<path> datasetDirs; - for (const auto& p : dirs) + for (const path& p : dirs) { - if (std::filesystem::is_directory(p)) + if (isDatasetDirValid(p)) { datasetDirs.push_back(p); } @@ -144,7 +150,7 @@ namespace armarx std::vector<ObjectInfo> objects; for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local)) { - if (fs::is_directory(_rootDirAbs() / datasetDir)) + if (isDatasetDirValid(_rootDirAbs() / datasetDir)) { std::vector<ObjectInfo> dataset = findAllObjectsOfDataset(datasetDir, checkPaths); for (const auto& o : dataset) @@ -169,7 +175,7 @@ namespace armarx std::vector<armem::articulated_object::ArticulatedObjectDescription> objects; for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local)) { - if (fs::is_directory(_rootDirAbs() / datasetDir)) + if (isDatasetDirValid(_rootDirAbs() / datasetDir)) { const auto dataset = findAllArticulatedObjectsOfDataset(datasetDir, checkPaths); objects.insert(objects.end(), dataset.begin(), dataset.end()); @@ -221,7 +227,9 @@ namespace armarx return objects; } - std::unordered_map<std::string, std::vector<armem::articulated_object::ArticulatedObjectDescription>> ObjectFinder::findAllArticulatedObjectsByDataset(bool checkPaths) const + + std::unordered_map<std::string, std::vector<armem::articulated_object::ArticulatedObjectDescription>> + ObjectFinder::findAllArticulatedObjectsByDataset(bool checkPaths) const { init(); if (!_ready()) @@ -234,7 +242,7 @@ namespace armarx std::unordered_map<std::string, std::vector<armem::articulated_object::ArticulatedObjectDescription>> datasets; for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local)) { - if (fs::is_directory(_rootDirAbs() / datasetDir)) + if (isDatasetDirValid(_rootDirAbs() / datasetDir)) { const auto dataset = findAllArticulatedObjectsOfDataset(datasetDir, checkPaths); datasets[datasetDir] = dataset; @@ -244,7 +252,8 @@ namespace armarx } - std::vector<armem::articulated_object::ArticulatedObjectDescription> ObjectFinder::findAllArticulatedObjectsOfDataset(const std::string& dataset, bool checkPaths) const + std::vector<armem::articulated_object::ArticulatedObjectDescription> + ObjectFinder::findAllArticulatedObjectsOfDataset(const std::string& dataset, bool checkPaths) const { init(); if (!_ready()) @@ -252,7 +261,7 @@ namespace armarx return {}; } path datasetDir = _rootDirAbs() / dataset; - if (!fs::is_directory(datasetDir)) + if (!isDatasetDirValid(datasetDir)) { ARMARX_WARNING << "Expected dataset directory for dataset '" << dataset << "': \n" << datasetDir; diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h index 2b342f3ac1151d0589bbc4b0212c3aed2fde798d..0bef0667120ee99e7d65f575f1c9b61b446ffe6f 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h @@ -89,14 +89,18 @@ namespace armarx private: + void init() const; + bool isDatasetDirValid(const std::filesystem::path& path) const; path _rootDirAbs() const; path _rootDirRel() const; bool _ready() const; + private: + /// Name of package containing the object models (ArmarXObjects by default). mutable std::string packageName; @@ -105,5 +109,6 @@ namespace armarx * Empty if package could not be found. */ mutable path packageDataDir; + }; }