ObjectFinder.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <unordered_map>
5
6#include <VirtualRobot/VirtualRobot.h>
7#include <VirtualRobot/XML/ObjectIO.h>
8
10
12
13#include "ObjectInfo.h"
14#include "ObjectPose.h"
15
16namespace armarx
17{
18 /**
19 * @brief Used to find objects in the ArmarX objects repository [1] (formerly [2]).
20 *
21 * @see [1] https://git.h2t.iar.kit.edu/sw/armarx/prior-knowledge-data
22 */
24 {
25 public:
26 using path = std::filesystem::path;
27 inline static const std::string DefaultObjectsPackageName = "PriorKnowledgeData";
28 inline static const std::string DefaultObjectsDirectory = "objects";
29
30
31 public:
32 ObjectFinder(const std::string& objectsPackageName = DefaultObjectsPackageName,
33 const path& relObjectsDir = DefaultObjectsDirectory);
34
36 ObjectFinder(const ObjectFinder&) = default;
39
40
41 void setPath(const std::string& path);
42
43 std::string getPackageName() const;
44
45 std::optional<ObjectInfo> findObject(const std::string& dataset,
46 const std::string& name) const;
47 std::optional<ObjectInfo> findObject(const std::string& nameOrID) const;
48 std::optional<ObjectInfo> findObject(const ObjectID& id) const;
49 std::optional<ObjectInfo> findObject(const objpose::ObjectPose& obj) const;
50
51 std::vector<std::string> getDatasets() const;
52 std::vector<path> getDatasetDirectories() const;
53
54 std::vector<ObjectInfo> findAllObjects(bool checkPaths = true) const;
55 std::map<std::string, std::vector<ObjectInfo>>
56 findAllObjectsByDataset(bool checkPaths = true) const;
57 std::vector<ObjectInfo> findAllObjectsOfDataset(const std::string& dataset,
58 bool checkPaths = true) const;
59
60 std::vector<armem::articulated_object::ArticulatedObjectDescription>
61 findAllArticulatedObjects(bool checkPaths) const;
62 std::vector<armem::articulated_object::ArticulatedObjectDescription>
63 findAllArticulatedObjectsOfDataset(const std::string& dataset, bool checkPaths) const;
64 std::unordered_map<std::string,
65 std::vector<armem::articulated_object::ArticulatedObjectDescription>>
66 findAllArticulatedObjectsByDataset(bool checkPaths = true) const;
67
68 VirtualRobot::ManipulationObjectPtr static loadManipulationObject(
69 const std::optional<ObjectInfo>& ts,
70 VirtualRobot::ObjectIO::ObjectDescription loadMode =
71 VirtualRobot::ObjectIO::ObjectDescription::eFull);
72 VirtualRobot::ManipulationObjectPtr
74 VirtualRobot::ObjectIO::ObjectDescription loadMode =
75 VirtualRobot::ObjectIO::ObjectDescription::eFull) const;
76
77 VirtualRobot::ObstaclePtr static loadObstacle(const std::optional<ObjectInfo>& ts);
78 VirtualRobot::ObstaclePtr loadObstacle(const objpose::ObjectPose& obj) const;
79
80
81 /**
82 * @brief Load names to use when matched when recognizing an object by name.
83 *
84 * If the object's names JSON file does not exist, no names will be added from a file.
85 * If you would like to detect this case, first `findObject()`, then use
86 * `ObjectInfo::loadRecognizedNames()`, which returns a `std::optional`.
87 *
88 * @param includeClassName If true, include the raw class name in the result.
89 * @see `ObjectInfo::loadRecognizedNames()`
90 */
91 std::vector<std::string> loadRecognizedNames(const ObjectID& objectID,
92 bool includeClassName = false) const;
93 /**
94 * @brief Load names to use when verbalizing an object name.
95 *
96 * If the object's names JSON file does not exist, no names will be added from a file.
97 * If you would like to detect this case, first `findObject()`, then use
98 * `ObjectInfo::loadSpokenNames()`, which returns a `std::optional`.
99 *
100 * @param includeClassName If true, include the raw class name in the result.
101 * @see `ObjectInfo::loadSpokenNames()`
102 */
103 std::vector<std::string> loadSpokenNames(const ObjectID& objectID,
104 bool includeClassName = false) const;
105
106 void setLogObjectDiscoveryError(bool logEnabled);
107
108
109 private:
110 void init() const;
111 bool isDatasetDirValid(const std::filesystem::path& path) const;
112
113 path _rootDirAbs() const;
114 path _rootDirRel() const;
115
116 bool _ready() const;
117
118
119 private:
120 /// Name of package containing the object models (ArmarXObjects by default).
121 mutable std::string packageName;
122
123 /**
124 * @brief Absolute path to data directory (e.g. "/.../repos/ArmarXObjects/data").
125 * Empty if package could not be found.
126 */
127 mutable path absPackageDataDir;
128
129 /// Path to the directory containing objects in the package's data directory.
130 path relObjectsDir;
131
132
133 // see: ObjectInfo::checkPaths()
134 bool logObjectDiscoveryError = true;
135 };
136} // namespace armarx
std::vector< path > getDatasetDirectories() const
std::vector< std::string > loadSpokenNames(const ObjectID &objectID, bool includeClassName=false) const
Load names to use when verbalizing an object name.
ObjectFinder(const std::string &objectsPackageName=DefaultObjectsPackageName, const path &relObjectsDir=DefaultObjectsDirectory)
std::vector< std::string > getDatasets() const
ObjectFinder & operator=(ObjectFinder &&)=default
static VirtualRobot::ObstaclePtr loadObstacle(const std::optional< ObjectInfo > &ts)
std::vector< std::string > loadRecognizedNames(const ObjectID &objectID, bool includeClassName=false) const
Load names to use when matched when recognizing an object by name.
std::vector< ObjectInfo > findAllObjects(bool checkPaths=true) const
std::unordered_map< std::string, std::vector< armem::articulated_object::ArticulatedObjectDescription > > findAllArticulatedObjectsByDataset(bool checkPaths=true) const
std::string getPackageName() const
ObjectFinder(ObjectFinder &&)=default
void setPath(const std::string &path)
std::filesystem::path path
static VirtualRobot::ManipulationObjectPtr loadManipulationObject(const std::optional< ObjectInfo > &ts, VirtualRobot::ObjectIO::ObjectDescription loadMode=VirtualRobot::ObjectIO::ObjectDescription::eFull)
std::vector< armem::articulated_object::ArticulatedObjectDescription > findAllArticulatedObjects(bool checkPaths) const
std::vector< armem::articulated_object::ArticulatedObjectDescription > findAllArticulatedObjectsOfDataset(const std::string &dataset, bool checkPaths) const
void setLogObjectDiscoveryError(bool logEnabled)
std::vector< ObjectInfo > findAllObjectsOfDataset(const std::string &dataset, bool checkPaths=true) const
ObjectFinder(const ObjectFinder &)=default
static const std::string DefaultObjectsPackageName
static const std::string DefaultObjectsDirectory
std::map< std::string, std::vector< ObjectInfo > > findAllObjectsByDataset(bool checkPaths=true) const
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
ObjectFinder & operator=(const ObjectFinder &)=default
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
This file offers overloads of toIce() and fromIce() functions for STL container types.
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34