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