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
10namespace 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
19namespace 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 */
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
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
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
Accessor for the object files.
Definition ObjectInfo.h:37
PackageFileLocation namesJson() const
File containing recognized and spoken names of objects.
std::string name() const
Definition ObjectInfo.h:72
PackageFileLocation wavefrontObj() const
virtual bool checkPaths() const
Checks the existence of expected files.
std::string className() const
std::optional< simox::AxisAlignedBoundingBox > loadAABB() const
Load the AABB (axis-aligned bounding-box) from the bounding box JSON file.
PackageFileLocation urdf() const
std::optional< simox::OrientedBox< float > > loadOOBB() const
Load the OOBB (object-oriented bounding box) from the bounding box JSON file.
std::string idStr() const
std::optional< std::vector< std::string > > loadSpokenNames() const
Load names to use when verbalizing an object name.
PackageFileLocation articulatedSdf() const
PackageFileLocation articulatedUrdf() const
std::string package() const
void setLogError(bool enabled)
virtual ~ObjectInfo()=default
PackageFileLocation sdf() const
std::filesystem::path path
Definition ObjectInfo.h:39
PackageFileLocation file(const std::string &extension, const std::string &suffix="", bool fixDataPath=false) const
PackageFileLocation boundingBoxJson() const
PackageFileLocation meshWrl() const
std::optional< PackageFileLocation > getArticulatedModel() const
Return the articulated Simox XML, URDF or SDF, if one exists.
ObjectInfo(const std::string &packageName, const path &absPackageDataDir, const path &relObjectsPath, const ObjectID &id)
ObjectInfo.
ObjectID id() const
Return "dataset/name".
std::optional< PackageFileLocation > getModel() const
Return the Simox XML, URDF or SDF, if one exists.
std::optional< std::vector< std::string > > loadRecognizedNames() const
Load names to use when matched when recognizing an object by name.
PackageFileLocation simoxXML() const
PackageFileLocation articulatedSimoxXML() const
std::string dataset() const
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
Definition simox.h:14
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
bool operator>=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
bool operator<=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
bool operator==(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
bool operator<(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
bool operator>(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition Impl.cpp:41
std::filesystem::path absolutePath
The absolute path (in the host's file system).
Definition ObjectInfo.h:30
std::string package
Name of the ArmarX package.
Definition ObjectInfo.h:25
std::string relativePath
Relative to the package's data directory.
Definition ObjectInfo.h:28