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 
11 namespace simox
12 {
13  // #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
15  // #include <SimoxUtility/shapes/OrientedBox.h>
16  template<class FloatT> class OrientedBox;
17 }
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  /**
35  * @brief Accessor for the object files.
36  */
37  class ObjectInfo
38  {
39  public:
40  using path = std::filesystem::path;
41 
42  public:
43 
44  /**
45  * @brief ObjectInfo
46  *
47  * @param packageName The ArmarX package.
48  * @param absPackageDataDir Absolute path to the package's data directory.
49  * @param localObjectsPath The path where objects are stored in the data directory.
50  * @param id The object class ID (with dataset and class name).
51  */
52  ObjectInfo(const std::string& packageName, const path& absPackageDataDir,
53  const path& relObjectsPath, const ObjectID& id);
54  ObjectInfo(const std::string& packageName, const path& packageDataDir,
55  const path& relObjectsPath,
56  const std::string& dataset, const std::string& className);
57 
58 
59  virtual ~ObjectInfo() = default;
60 
61 
62  void setLogError(bool enabled);
63 
64  std::string package() const;
65 
66  std::string dataset() const;
67  std::string className() const;
68  [[deprecated("This function is deprecated. Use className() instead.")]]
69  std::string name() const
70  {
71  return className();
72  }
73 
74  /// Return "dataset/name".
75  ObjectID id() const;
76  std::string idStr() const;
77 
78 
79  PackageFileLocation file(const std::string& extension, const std::string& suffix = "", bool fixDataPath = false) const;
80 
81 
83  PackageFileLocation urdf() const;
84  PackageFileLocation sdf() const;
85  /// Return the Simox XML, URDF or SDF, if one exists.
86  std::optional<PackageFileLocation> getModel() const;
87 
91  /// Return the articulated Simox XML, URDF or SDF, if one exists.
92  std::optional<PackageFileLocation> getArticulatedModel() const;
93 
94 
97 
99 
100  /// File containing recognized and spoken names of objects.
102 
103 
104  /**
105  * @brief Load the AABB (axis-aligned bounding-box) from the bounding box JSON file.
106  * @return Return the AABB if successful, `std::nullopt` if file does not exist.
107  */
108  std::optional<simox::AxisAlignedBoundingBox> loadAABB() const;
109  /**
110  * @brief Load the OOBB (object-oriented bounding box) from the bounding box JSON file.
111  * The OOBB is defined the object's local frame.
112  * @return Return the OOBB if successful, `std::nullopt` if file does not exist.
113  */
114  std::optional<simox::OrientedBox<float>> loadOOBB() const;
115 
116  /**
117  * @brief Load names to use when matched when recognizing an object by name.
118  * @see `namesJson()`
119  */
120  std::optional<std::vector<std::string>> loadRecognizedNames() const;
121  /**
122  * @brief Load names to use when verbalizing an object name.
123  * @see `namesJson()`
124  */
125  std::optional<std::vector<std::string>> loadSpokenNames() const;
126 
127 
128  /**
129  * @brief Checks the existence of expected files.
130  * If a file is does not exist, emits a warning returns false.
131  * @return True if all existing files are found, false otherwise.
132  */
133  virtual bool checkPaths() const;
134 
135 
136 
137  private:
138 
139  path objectDirectory(bool fixDataPath) const;
140 
141  std::optional<std::vector<std::string>> loadNames(const std::string& jsonKey) const;
142 
143 
144  private:
145 
146  std::string _packageName;
147  path _absPackageDataDir;
148  path _relObjectsPath;
149 
150  ObjectID _id;
151 
152  bool _logError = true;
153 
154  };
155 
156  std::ostream& operator<<(std::ostream& os, const ObjectInfo& rhs);
157 
158 
159  inline bool operator==(const ObjectInfo& lhs, const ObjectInfo& rhs)
160  {
161  return lhs.id() == rhs.id();
162  }
163  inline bool operator!=(const ObjectInfo& lhs, const ObjectInfo& rhs)
164  {
165  return lhs.id() != rhs.id();
166  }
167  inline bool operator< (const ObjectInfo& lhs, const ObjectInfo& rhs)
168  {
169  return lhs.id() < rhs.id();
170  }
171  inline bool operator> (const ObjectInfo& lhs, const ObjectInfo& rhs)
172  {
173  return lhs.id() > rhs.id();
174  }
175  inline bool operator<=(const ObjectInfo& lhs, const ObjectInfo& rhs)
176  {
177  return lhs.id() <= rhs.id();
178  }
179  inline bool operator>=(const ObjectInfo& lhs, const ObjectInfo& rhs)
180  {
181  return lhs.id() >= rhs.id();
182  }
183 
184 }
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:11
armarx::operator!=
bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:220
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:40
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:236
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:216
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:224
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:221
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:228
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:28
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:37
armarx::ObjectInfo::name
std::string name() const
Definition: ObjectInfo.h:69
armarx::operator>
bool operator>(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:232