Skip to content
Snippets Groups Projects
Commit 83269580 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Rename concept "project" to "dataset"

parent aae091c5
No related branches found
No related tags found
1 merge request!71Object pose observer
...@@ -38,28 +38,28 @@ namespace armarx ...@@ -38,28 +38,28 @@ namespace armarx
} }
std::optional<ObjectInfo> ObjectFinder::findObject(const std::string& project, const std::string& name) const std::optional<ObjectInfo> ObjectFinder::findObject(const std::string& dataset, const std::string& name) const
{ {
init(); init();
if (!project.empty()) if (!dataset.empty())
{ {
return ObjectInfo(packageName, packageDataDir, project, name); return ObjectInfo(packageName, packageDataDir, dataset, name);
} }
// Search for object in projects. // Search for object in datasets.
const auto& projects = getProjects(); const auto& datasets = getDatasets();
for (const path& project : projects) for (const path& dataset : datasets)
{ {
if (fs::is_directory(_rootDirAbs() / project / name)) if (fs::is_directory(_rootDirAbs() / dataset / name))
{ {
return ObjectInfo(packageName, packageDataDir, project, name); return ObjectInfo(packageName, packageDataDir, dataset, name);
} }
} }
std::stringstream ss; std::stringstream ss;
ss << "Did not find object '" << name << "' in any of these projects:\n"; ss << "Did not find object '" << name << "' in any of these datasets:\n";
for (const path& project : projects) for (const path& dataset : datasets)
{ {
ss << "- " << project << "\n"; ss << "- " << dataset << "\n";
} }
ss << "Objects root directory: " << _rootDirAbs(); ss << "Objects root directory: " << _rootDirAbs();
ARMARX_WARNING << ss.str(); ARMARX_WARNING << ss.str();
...@@ -73,7 +73,7 @@ namespace armarx ...@@ -73,7 +73,7 @@ namespace armarx
if (nameOrID.find("/") != nameOrID.npos) if (nameOrID.find("/") != nameOrID.npos)
{ {
const std::vector<std::string> split = armarx::split(nameOrID, "/", true); const std::vector<std::string> split = armarx::split(nameOrID, "/", true);
ARMARX_CHECK_EQUAL(split.size(), 2) << "Expected ID of format 'Project/Name', but got: '" << nameOrID ARMARX_CHECK_EQUAL(split.size(), 2) << "Expected ID of format 'Dataset/Name', but got: '" << nameOrID
<< "' (too many '/')."; << "' (too many '/').";
return findObject(split[0], split[1]); return findObject(split[0], split[1]);
} }
...@@ -83,7 +83,7 @@ namespace armarx ...@@ -83,7 +83,7 @@ namespace armarx
} }
} }
std::vector<std::string> ObjectFinder::getProjects() const std::vector<std::string> ObjectFinder::getDatasets() const
{ {
init(); init();
const bool local = true; const bool local = true;
...@@ -91,7 +91,7 @@ namespace armarx ...@@ -91,7 +91,7 @@ namespace armarx
return std::vector<std::string>(paths.begin(), paths.end()); return std::vector<std::string>(paths.begin(), paths.end());
} }
std::vector<ObjectFinder::path> ObjectFinder::getProjectDirectories() const std::vector<ObjectFinder::path> ObjectFinder::getDatasetDirectories() const
{ {
init(); init();
const bool local = false; const bool local = false;
...@@ -103,35 +103,38 @@ namespace armarx ...@@ -103,35 +103,38 @@ namespace armarx
init(); init();
const bool local = true; const bool local = true;
std::vector<ObjectInfo> objects; std::vector<ObjectInfo> objects;
for (const path& projectDir : simox::fs::list_directory(_rootDirAbs(), local)) for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local))
{ {
if (fs::is_directory(_rootDirAbs() / projectDir)) if (fs::is_directory(_rootDirAbs() / datasetDir))
{ {
std::vector<ObjectInfo> project = findAllObjectsOfProject(projectDir, checkPaths); std::vector<ObjectInfo> dataset = findAllObjectsOfDataset(datasetDir, checkPaths);
objects.insert(objects.end(), project.begin(), project.end()); for (const auto& o : dataset)
{
objects.push_back(o);
}
} }
} }
return objects; return objects;
} }
std::vector<ObjectInfo> ObjectFinder::findAllObjectsOfProject(const std::string& project, bool checkPaths) const std::vector<ObjectInfo> ObjectFinder::findAllObjectsOfDataset(const std::string& dataset, bool checkPaths) const
{ {
init(); init();
path projectDir = _rootDirAbs() / project; path datasetDir = _rootDirAbs() / dataset;
if (!fs::is_directory(projectDir)) if (!fs::is_directory(datasetDir))
{ {
ARMARX_WARNING << "Expected project directory for project '" << project << "': \n" ARMARX_WARNING << "Expected dataset directory for dataset '" << dataset << "': \n"
<< projectDir; << datasetDir;
return {}; return {};
} }
std::vector<ObjectInfo> objects; std::vector<ObjectInfo> objects;
const bool local = true; const bool local = true;
for (const path& dir : simox::fs::list_directory(projectDir, local)) for (const path& dir : simox::fs::list_directory(datasetDir, local))
{ {
if (fs::is_directory(projectDir / dir)) if (fs::is_directory(datasetDir / dir))
{ {
ObjectInfo object(packageName, packageDataDir, project, dir.filename()); ObjectInfo object(packageName, packageDataDir, dataset, dir.filename());
if (!checkPaths || object.checkPaths()) if (!checkPaths || object.checkPaths())
{ {
objects.push_back(object); objects.push_back(object);
...@@ -153,8 +156,8 @@ namespace armarx ...@@ -153,8 +156,8 @@ namespace armarx
ObjectInfo::ObjectInfo(const std::string& packageName, const ObjectInfo::path& packageDataDir, ObjectInfo::ObjectInfo(const std::string& packageName, const ObjectInfo::path& packageDataDir,
const std::string& project, const std::string& name) : const std::string& dataset, const std::string& name) :
_packageName(packageName), _packageDataDir(packageDataDir), _project(project), _name(name) _packageName(packageName), _packageDataDir(packageDataDir), _dataset(dataset), _name(name)
{ {
} }
...@@ -163,9 +166,9 @@ namespace armarx ...@@ -163,9 +166,9 @@ namespace armarx
return _packageName; return _packageName;
} }
std::string ObjectInfo::project() const std::string ObjectInfo::dataset() const
{ {
return _project; return _dataset;
} }
std::string ObjectInfo::name() const std::string ObjectInfo::name() const
...@@ -175,12 +178,12 @@ namespace armarx ...@@ -175,12 +178,12 @@ namespace armarx
std::string ObjectInfo::id() const std::string ObjectInfo::id() const
{ {
return _project + "/" + _name; return _dataset + "/" + _name;
} }
ObjectInfo::path ObjectInfo::objectDirectory() const ObjectInfo::path ObjectInfo::objectDirectory() const
{ {
return path(_packageName) / _project / _name; return path(_packageName) / _dataset / _name;
} }
PackageFileLocation ObjectInfo::file(const std::string& _extension, const std::string& suffix) const PackageFileLocation ObjectInfo::file(const std::string& _extension, const std::string& suffix) const
......
...@@ -15,6 +15,11 @@ namespace armarx ...@@ -15,6 +15,11 @@ namespace armarx
class ObjectInfo; class ObjectInfo;
/**
* @brief Used to find objects in the ArmarX objects repository [1].
*
* @see [1] https://gitlab.com/ArmarX/ArmarXObjects
*/
class ObjectFinder : Logging class ObjectFinder : Logging
{ {
public: public:
...@@ -24,15 +29,15 @@ namespace armarx ...@@ -24,15 +29,15 @@ namespace armarx
ObjectFinder(const std::string& objectsPackageName = "ArmarXObjects"); ObjectFinder(const std::string& objectsPackageName = "ArmarXObjects");
std::optional<ObjectInfo> findObject(const std::string& project, const std::string& name) const; std::optional<ObjectInfo> findObject(const std::string& dataset, const std::string& name) const;
std::optional<ObjectInfo> findObject(const std::string& nameOrID) const; std::optional<ObjectInfo> findObject(const std::string& nameOrID) const;
std::vector<std::string> getProjects() const; std::vector<std::string> getDatasets() const;
std::vector<path> getProjectDirectories() const; std::vector<path> getDatasetDirectories() const;
std::vector<ObjectInfo> findAllObjects(bool checkPaths = true) const; std::vector<ObjectInfo> findAllObjects(bool checkPaths = true) const;
std::vector<ObjectInfo> findAllObjectsOfProject(const std::string& project, bool checkPaths = true) const; std::vector<ObjectInfo> findAllObjectsOfDataset(const std::string& dataset, bool checkPaths = true) const;
private: private:
...@@ -59,11 +64,16 @@ namespace armarx ...@@ -59,11 +64,16 @@ namespace armarx
/// Name of the ArmarX package. /// Name of the ArmarX package.
std::string package; std::string package;
/// Relative to the package's data directory.
std::string relativePath; std::string relativePath;
/// The absolute path (in the host's file system).
std::filesystem::path absolutePath; std::filesystem::path absolutePath;
}; };
/**
* @brief Accessor for the object files.
*/
class ObjectInfo class ObjectInfo
{ {
public: public:
...@@ -72,13 +82,13 @@ namespace armarx ...@@ -72,13 +82,13 @@ namespace armarx
public: public:
ObjectInfo(const std::string& packageName, const path& packageDataDir, ObjectInfo(const std::string& packageName, const path& packageDataDir,
const std::string& project, const std::string& name); const std::string& dataset, const std::string& name);
std::string package() const; std::string package() const;
std::string project() const; std::string dataset() const;
std::string name() const; std::string name() const;
/// Return "project/name". /// Return "dataset/name".
std::string id() const; std::string id() const;
PackageFileLocation file(const std::string& extension, const std::string& suffix = "") const; PackageFileLocation file(const std::string& extension, const std::string& suffix = "") const;
...@@ -109,7 +119,7 @@ namespace armarx ...@@ -109,7 +119,7 @@ namespace armarx
std::string _packageName; std::string _packageName;
path _packageDataDir; path _packageDataDir;
std::string _project; std::string _dataset;
std::string _name; std::string _name;
}; };
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
std::ostream& armarx::objpose::operator<<(std::ostream& os, const ObjectID& id) std::ostream& armarx::objpose::operator<<(std::ostream& os, const ObjectID& id)
{ {
return os << "'" << id.project << "/" << id.name << "'"; return os << "'" << id.dataset << "/" << id.name << "'";
} }
...@@ -323,9 +323,9 @@ namespace armarx ...@@ -323,9 +323,9 @@ namespace armarx
for (const objpose::ObjectPose& objectPose : objectPoses.at(providerName)) for (const objpose::ObjectPose& objectPose : objectPoses.at(providerName))
{ {
const objpose::ObjectID id = objectPose.objectID; const objpose::ObjectID id = objectPose.objectID;
std::string key = id.project + "/" + id.name; std::string key = id.dataset + "/" + id.name;
std::optional<ObjectInfo> objectInfo = objectFinder.findObject(id.project, id.name); std::optional<ObjectInfo> objectInfo = objectFinder.findObject(id.dataset, id.name);
if (!objectInfo) if (!objectInfo)
{ {
ARMARX_WARNING << "Cannot visualize object '" << key << "'."; ARMARX_WARNING << "Cannot visualize object '" << key << "'.";
...@@ -334,7 +334,7 @@ namespace armarx ...@@ -334,7 +334,7 @@ namespace armarx
PoseBasePtr pose = visu.inGlobalFrame ? objectPose.objectPoseGlobal : objectPose.objectPoseRobot; PoseBasePtr pose = visu.inGlobalFrame ? objectPose.objectPoseGlobal : objectPose.objectPoseRobot;
viz::Object object = viz::Object(id.project + "/" + id.name) viz::Object object = viz::Object(id.dataset + "/" + id.name)
.file(objectInfo->package(), objectInfo->simoxXML().relativePath) .file(objectInfo->package(), objectInfo->simoxXML().relativePath)
.pose(armarx::PosePtr::dynamicCast(pose)->toEigen()); .pose(armarx::PosePtr::dynamicCast(pose)->toEigen());
if (visu.alpha < 1) if (visu.alpha < 1)
......
...@@ -41,7 +41,7 @@ module armarx ...@@ -41,7 +41,7 @@ module armarx
struct ObjectID struct ObjectID
{ {
string project; ///< e.g. "KIT", "YCB", "SecondHands", ... string dataset; ///< e.g. "KIT", "YCB", "SecondHands", ...
string name; ///< e.g. "Amicelli", "001_chips_can", ... string name; ///< e.g. "Amicelli", "001_chips_can", ...
}; };
sequence<ObjectID> ObjectIDSeq; sequence<ObjectID> ObjectIDSeq;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment