Go to the documentation of this file.
3 #include <SimoxUtility/algorithm/string.h>
4 #include <SimoxUtility/json.h>
5 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
6 #include <SimoxUtility/shapes/OrientedBox.h>
14 namespace fs = std::filesystem;
19 _packageName(packageName), _absPackageDataDir(packageDataDir),
20 _relObjectsPath(relObjectsPath), _id(id)
25 const path& relObjectsPath,
26 const std::string& dataset,
const std::string& className) :
27 _packageName(packageName), _absPackageDataDir(packageDataDir),
28 _relObjectsPath(relObjectsPath), _id(dataset, className)
74 std::string extension = _extension;
75 if (extension.at(0) !=
'.')
77 extension =
"." + extension;
106 if (fs::is_regular_file(
simoxXML().absolutePath))
110 else if (fs::is_regular_file(
urdf().absolutePath))
114 else if (fs::is_regular_file(
sdf().absolutePath))
126 return file(
".xml",
"_articulated",
true);
131 return file(
".urdf",
"_articulated",
true);
136 return file(
".sdf",
"_articulated");
173 return file(
".json",
"_bb");
178 return file(
".json",
"_names");
188 catch (
const std::exception& e)
197 nlohmann::json jaabb = j.at(
"aabb");
198 auto center = jaabb.at(
"center").get<Eigen::Vector3f>();
199 auto extents = jaabb.at(
"extents").get<Eigen::Vector3f>();
200 auto min = jaabb.at(
"min").get<Eigen::Vector3f>();
201 auto max = jaabb.at(
"max").get<Eigen::Vector3f>();
205 static const float prec = 1e-3f;
206 ARMARX_CHECK_LESS_EQUAL((aabb.center() - center).norm(), prec) << aabb.center().transpose() <<
"\n" << center.transpose() <<
"\n" <<
id();
207 ARMARX_CHECK_LESS_EQUAL((aabb.extents() - extents).norm(), prec) << aabb.extents().transpose() <<
"\n" << extents.transpose() <<
"\n" <<
id();
221 catch (
const std::exception& e)
230 nlohmann::json joobb = j.at(
"oobb");
231 auto pos = joobb.at(
"pos").get<Eigen::Vector3f>();
233 auto extents = joobb.at(
"extents").get<Eigen::Vector3f>();
235 Eigen::Vector3f corner = pos - ori * extents / 2;
238 ori.col(0) * extents(0),
239 ori.col(1) * extents(1),
240 ori.col(2) * extents(2));
242 static const float prec = 1e-3f;
243 ARMARX_CHECK(oobb.rotation().isApprox(ori, prec)) << oobb.rotation() <<
"\n" << ori <<
"\n" <<
id();
245 if (extents.squaredNorm() < 1e5f * 1e5f)
248 <<
VAROUT(oobb.center().transpose())
249 <<
"\n" <<
VAROUT(pos.transpose())
250 <<
"\n" <<
VAROUT(extents.norm())
253 <<
VAROUT(oobb.dimensions().transpose())
254 <<
"\n" <<
VAROUT(extents.transpose())
255 <<
"\n" <<
VAROUT(extents.norm())
263 return loadNames(
"recognized_name");
268 return loadNames(
"spoken_name");
271 std::optional<std::vector<std::string> > ObjectInfo::loadNames(
const std::string& jsonKey)
const
282 catch (
const nlohmann::json::exception& e)
290 catch (
const std::exception& e)
299 return json.at(jsonKey).get<std::vector<std::string>>();
310 namespace fs = std::filesystem;
313 if (!fs::is_regular_file(
simoxXML().absolutePath))
321 if (
false and not fs::is_regular_file(
wavefrontObj().absolutePath))
338 return os << rhs.
id();
PackageFileLocation articulatedSdf() const
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
PackageFileLocation articulatedSimoxXML() const
std::string dataset() const
std::string className() const
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
ObjectInfo(const std::string &packageName, const path &absPackageDataDir, const path &relObjectsPath, const ObjectID &id)
ObjectInfo.
PackageFileLocation wavefrontObj() const
PackageFileLocation articulatedUrdf() const
std::string relativePath
Relative to the package's data directory.
virtual bool checkPaths() const
Checks the existence of expected files.
PackageFileLocation urdf() const
std::optional< std::vector< std::string > > loadRecognizedNames() const
Load names to use when matched when recognizing an object by name.
PackageFileLocation file(const std::string &extension, const std::string &suffix="", bool fixDataPath=false) const
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
PackageFileLocation boundingBoxJson() const
std::string className() const
std::filesystem::path path
PackageFileLocation sdf() const
std::string package() const
std::optional< PackageFileLocation > getModel() const
Return the Simox XML, URDF or SDF, if one exists.
std::string idStr() const
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
PackageFileLocation simoxXML() const
std::string package
Name of the ArmarX package.
std::string dataset() const
std::optional< simox::OrientedBox< float > > loadOOBB() const
Load the OOBB (object-oriented bounding box) from the bounding box JSON file.
std::optional< simox::AxisAlignedBoundingBox > loadAABB() const
Load the AABB (axis-aligned bounding-box) from the bounding box JSON file.
std::filesystem::path absolutePath
The absolute path (in the host's file system).
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
std::optional< std::vector< std::string > > loadSpokenNames() const
Load names to use when verbalizing an object name.
ObjectID id() const
Return "dataset/name".
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
PackageFileLocation meshWrl() const
void setLogError(bool enabled)
std::optional< PackageFileLocation > getArticulatedModel() const
Return the articulated Simox XML, URDF or SDF, if one exists.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
PackageFileLocation namesJson() const
File containing recognized and spoken names of objects.
Accessor for the object files.