ObjectInfo.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <optional>
5 #include <string>
6 #include <vector>
7 
8 #include "ObjectID.h"
9 
10 namespace simox
11 {
12  // #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
14  // #include <SimoxUtility/shapes/OrientedBox.h>
15  template <class FloatT>
16  class OrientedBox;
17 } // namespace simox
18 
19 namespace armarx
20 {
21 
23  {
24  /// Name of the ArmarX package.
25  std::string package;
26 
27  /// Relative to the package's data directory.
28  std::string relativePath;
29  /// The absolute path (in the host's file system).
30  std::filesystem::path absolutePath;
31  };
32 
33  /**
34  * @brief Accessor for the object files.
35  */
36  class ObjectInfo
37  {
38  public:
39  using path = std::filesystem::path;
40 
41  public:
42  /**
43  * @brief ObjectInfo
44  *
45  * @param packageName The ArmarX package.
46  * @param absPackageDataDir Absolute path to the package's data directory.
47  * @param localObjectsPath The path where objects are stored in the data directory.
48  * @param id The object class ID (with dataset and class name).
49  */
50  ObjectInfo(const std::string& packageName,
51  const path& absPackageDataDir,
52  const path& relObjectsPath,
53  const ObjectID& id);
54  ObjectInfo(const std::string& packageName,
55  const path& packageDataDir,
56  const path& relObjectsPath,
57  const std::string& dataset,
58  const std::string& className);
59 
60 
61  virtual ~ObjectInfo() = default;
62 
63 
64  void setLogError(bool enabled);
65 
66  std::string package() const;
67 
68  std::string dataset() const;
69  std::string className() const;
70 
71  [[deprecated("This function is deprecated. Use className() instead.")]] std::string
72  name() const
73  {
74  return className();
75  }
76 
77  /// Return "dataset/name".
78  ObjectID id() const;
79  std::string idStr() const;
80 
81 
82  PackageFileLocation file(const std::string& extension,
83  const std::string& suffix = "",
84  bool fixDataPath = false) const;
85 
86 
88  PackageFileLocation urdf() const;
89  PackageFileLocation sdf() const;
90  /// Return the Simox XML, URDF or SDF, if one exists.
91  std::optional<PackageFileLocation> getModel() const;
92 
96  /// Return the articulated Simox XML, URDF or SDF, if one exists.
97  std::optional<PackageFileLocation> getArticulatedModel() const;
98 
99 
102 
104 
105  /// File containing recognized and spoken names of objects.
107 
108 
109  /**
110  * @brief Load the AABB (axis-aligned bounding-box) from the bounding box JSON file.
111  * @return Return the AABB if successful, `std::nullopt` if file does not exist.
112  */
113  std::optional<simox::AxisAlignedBoundingBox> loadAABB() const;
114  /**
115  * @brief Load the OOBB (object-oriented bounding box) from the bounding box JSON file.
116  * The OOBB is defined the object's local frame.
117  * @return Return the OOBB if successful, `std::nullopt` if file does not exist.
118  */
119  std::optional<simox::OrientedBox<float>> loadOOBB() const;
120 
121  /**
122  * @brief Load names to use when matched when recognizing an object by name.
123  * @see `namesJson()`
124  */
125  std::optional<std::vector<std::string>> loadRecognizedNames() const;
126  /**
127  * @brief Load names to use when verbalizing an object name.
128  * @see `namesJson()`
129  */
130  std::optional<std::vector<std::string>> loadSpokenNames() const;
131 
132 
133  /**
134  * @brief Checks the existence of expected files.
135  * If a file is does not exist, emits a warning returns false.
136  * @return True if all existing files are found, false otherwise.
137  */
138  virtual bool checkPaths() const;
139 
140 
141  private:
142  path objectDirectory(bool fixDataPath) const;
143 
144  std::optional<std::vector<std::string>> loadNames(const std::string& jsonKey) const;
145 
146 
147  private:
148  std::string _packageName;
149  path _absPackageDataDir;
150  path _relObjectsPath;
151 
152  ObjectID _id;
153 
154  bool _logError = true;
155  };
156 
157  std::ostream& operator<<(std::ostream& os, const ObjectInfo& rhs);
158 
159  inline bool
160  operator==(const ObjectInfo& lhs, const ObjectInfo& rhs)
161  {
162  return lhs.id() == rhs.id();
163  }
164 
165  inline bool
166  operator!=(const ObjectInfo& lhs, const ObjectInfo& rhs)
167  {
168  return lhs.id() != rhs.id();
169  }
170 
171  inline bool
172  operator<(const ObjectInfo& lhs, const ObjectInfo& rhs)
173  {
174  return lhs.id() < rhs.id();
175  }
176 
177  inline bool
178  operator>(const ObjectInfo& lhs, const ObjectInfo& rhs)
179  {
180  return lhs.id() > rhs.id();
181  }
182 
183  inline bool
184  operator<=(const ObjectInfo& lhs, const ObjectInfo& rhs)
185  {
186  return lhs.id() <= rhs.id();
187  }
188 
189  inline bool
190  operator>=(const ObjectInfo& lhs, const ObjectInfo& rhs)
191  {
192  return lhs.id() >= rhs.id();
193  }
194 
195 } // namespace armarx
armarx::ObjectInfo::articulatedSdf
PackageFileLocation articulatedSdf() const
Definition: ObjectInfo.cpp:160
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
armarx::operator!=
bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:288
armarx::ObjectInfo::articulatedSimoxXML
PackageFileLocation articulatedSimoxXML() const
Definition: ObjectInfo.cpp:148
armarx::ObjectInfo::className
std::string className() const
Definition: ObjectInfo.cpp:61
armarx::ObjectInfo::ObjectInfo
ObjectInfo(const std::string &packageName, const path &absPackageDataDir, const path &relObjectsPath, const ObjectID &id)
ObjectInfo.
Definition: ObjectInfo.cpp:19
armarx::ObjectInfo::wavefrontObj
PackageFileLocation wavefrontObj() const
Definition: ObjectInfo.cpp:193
armarx::ObjectInfo::articulatedUrdf
PackageFileLocation articulatedUrdf() const
Definition: ObjectInfo.cpp:154
armarx::PackageFileLocation
Definition: ObjectInfo.h:22
armarx::PackageFileLocation::relativePath
std::string relativePath
Relative to the package's data directory.
Definition: ObjectInfo.h:28
armarx::ObjectInfo::checkPaths
virtual bool checkPaths() const
Checks the existence of expected files.
Definition: ObjectInfo.cpp:377
armarx::ObjectInfo::urdf
PackageFileLocation urdf() const
Definition: ObjectInfo.cpp:115
armarx::ObjectInfo::loadRecognizedNames
std::optional< std::vector< std::string > > loadRecognizedNames() const
Load names to use when matched when recognizing an object by name.
Definition: ObjectInfo.cpp:326
armarx::ObjectInfo::file
PackageFileLocation file(const std::string &extension, const std::string &suffix="", bool fixDataPath=false) const
Definition: ObjectInfo.cpp:90
armarx::aron::simox::arondto::AxisAlignedBoundingBox
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
Definition: simox.h:14
armarx::ObjectInfo::boundingBoxJson
PackageFileLocation boundingBoxJson() const
Definition: ObjectInfo.cpp:199
armarx::ObjectInfo::path
std::filesystem::path path
Definition: ObjectInfo.h:39
armarx::ObjectInfo::sdf
PackageFileLocation sdf() const
Definition: ObjectInfo.cpp:121
armarx::operator>=
bool operator>=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:320
armarx::ObjectInfo::package
std::string package() const
Definition: ObjectInfo.cpp:49
ObjectID.h
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::operator==
bool operator==(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:280
armarx::ObjectInfo::getModel
std::optional< PackageFileLocation > getModel() const
Return the Simox XML, URDF or SDF, if one exists.
Definition: ObjectInfo.cpp:127
armarx::ObjectInfo::idStr
std::string idStr() const
Definition: ObjectInfo.cpp:73
armarx::ObjectInfo::simoxXML
PackageFileLocation simoxXML() const
Definition: ObjectInfo.cpp:109
armarx::PackageFileLocation::package
std::string package
Name of the ArmarX package.
Definition: ObjectInfo.h:25
armarx::ObjectInfo::dataset
std::string dataset() const
Definition: ObjectInfo.cpp:55
armarx::ObjectInfo::loadOOBB
std::optional< simox::OrientedBox< float > > loadOOBB() const
Load the OOBB (object-oriented bounding box) from the bounding box JSON file.
Definition: ObjectInfo.cpp:268
armarx::ObjectInfo::loadAABB
std::optional< simox::AxisAlignedBoundingBox > loadAABB() const
Load the AABB (axis-aligned bounding-box) from the bounding box JSON file.
Definition: ObjectInfo.cpp:211
armarx::PackageFileLocation::absolutePath
std::filesystem::path absolutePath
The absolute path (in the host's file system).
Definition: ObjectInfo.h:30
armarx::operator<
bool operator<(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:296
armarx::ObjectInfo::loadSpokenNames
std::optional< std::vector< std::string > > loadSpokenNames() const
Load names to use when verbalizing an object name.
Definition: ObjectInfo.cpp:332
armarx::ObjectInfo::id
ObjectID id() const
Return "dataset/name".
Definition: ObjectInfo.cpp:67
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:285
armarx::ObjectInfo::meshWrl
PackageFileLocation meshWrl() const
Definition: ObjectInfo.cpp:187
armarx::operator<=
bool operator<=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:304
armarx::ObjectInfo::~ObjectInfo
virtual ~ObjectInfo()=default
armarx::ObjectInfo::setLogError
void setLogError(bool enabled)
Definition: ObjectInfo.cpp:43
armarx::ObjectInfo::getArticulatedModel
std::optional< PackageFileLocation > getArticulatedModel() const
Return the articulated Simox XML, URDF or SDF, if one exists.
Definition: ObjectInfo.cpp:166
simox
Definition: Impl.cpp:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::aron::simox::arondto::OrientedBox
::simox::arondto::OrientedBox OrientedBox
Definition: simox.h:15
armarx::ObjectInfo::namesJson
PackageFileLocation namesJson() const
File containing recognized and spoken names of objects.
Definition: ObjectInfo.cpp:205
armarx::ObjectInfo
Accessor for the object files.
Definition: ObjectInfo.h:36
armarx::ObjectInfo::name
std::string name() const
Definition: ObjectInfo.h:72
armarx::operator>
bool operator>(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:312