6 #include <SimoxUtility/algorithm/string.h>
7 #include <SimoxUtility/json.h>
8 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
9 #include <SimoxUtility/shapes/OrientedBox.h>
17 namespace fs = std::filesystem;
21 const path& relObjectsPath,
23 _packageName(packageName),
24 _absPackageDataDir(packageDataDir),
25 _relObjectsPath(relObjectsPath),
32 const path& relObjectsPath,
33 const std::string& dataset,
34 const std::string& className) :
35 _packageName(packageName),
36 _absPackageDataDir(packageDataDir),
37 _relObjectsPath(relObjectsPath),
38 _id(dataset, className)
79 ObjectInfo::objectDirectory(
const bool fixDataPath)
const
91 const std::string& suffix,
92 const bool fixDataPath)
const
94 std::string extension = _extension;
95 if (extension.at(0) !=
'.')
97 extension =
"." + extension;
117 return file(
".urdf");
126 std::optional<PackageFileLocation>
129 if (fs::is_regular_file(
simoxXML().absolutePath))
133 else if (fs::is_regular_file(
urdf().absolutePath))
137 else if (fs::is_regular_file(
sdf().absolutePath))
150 return file(
".xml",
"_articulated",
true);
156 return file(
".urdf",
"_articulated",
true);
162 return file(
".sdf",
"_articulated");
165 std::optional<PackageFileLocation>
201 return file(
".json",
"_bb");
207 return file(
".json",
"_names");
210 std::optional<simox::AxisAlignedBoundingBox>
219 catch (
const std::exception& e)
231 nlohmann::json jaabb = j.at(
"aabb");
232 auto center = jaabb.at(
"center").get<Eigen::Vector3f>();
233 auto extents = jaabb.at(
"extents").get<Eigen::Vector3f>();
234 auto min = jaabb.at(
"min").get<Eigen::Vector3f>();
235 auto max = jaabb.at(
"max").get<Eigen::Vector3f>();
239 static const float prec = 1e-3f;
241 << aabb.center().transpose() <<
"\n"
242 << center.transpose() <<
"\n"
245 << aabb.extents().transpose() <<
"\n"
246 << extents.transpose() <<
"\n"
249 << aabb.min().transpose() <<
"\n"
250 <<
min.transpose() <<
"\n"
253 << aabb.max().transpose() <<
"\n"
254 <<
max.transpose() <<
"\n"
267 std::optional<simox::OrientedBox<float>>
276 catch (
const std::exception& e)
287 nlohmann::json joobb = j.at(
"oobb");
288 auto pos = joobb.at(
"pos").get<Eigen::Vector3f>();
290 auto extents = joobb.at(
"extents").get<Eigen::Vector3f>();
292 Eigen::Vector3f corner = pos - ori * extents / 2;
295 corner, ori.col(0) * extents(0), ori.col(1) * extents(1), ori.col(2) * extents(2));
297 static const float prec = 1e-3f;
298 ARMARX_CHECK(oobb.rotation().isApprox(ori, prec)) << oobb.rotation() <<
"\n"
302 if (extents.squaredNorm() < 1e5f * 1e5f)
305 <<
VAROUT(oobb.center().transpose()) <<
"\n"
306 <<
VAROUT(pos.transpose()) <<
"\n"
307 <<
VAROUT(extents.norm()) <<
"\n"
310 <<
VAROUT(oobb.dimensions().transpose()) <<
"\n"
311 <<
VAROUT(extents.transpose()) <<
"\n"
312 <<
VAROUT(extents.norm()) <<
"\n"
325 std::optional<std::vector<std::string>>
328 return loadNames(
"recognized_name");
331 std::optional<std::vector<std::string>>
334 return loadNames(
"spoken_name");
337 std::optional<std::vector<std::string>>
338 ObjectInfo::loadNames(
const std::string& jsonKey)
const
349 catch (
const nlohmann::json::exception& e)
358 catch (
const std::exception& e)
368 return json.at(jsonKey).get<std::vector<std::string>>();
379 namespace fs = std::filesystem;
382 if (!fs::is_regular_file(
simoxXML().absolutePath))
386 ARMARX_WARNING <<
"Expected simox object file for object " << *
this <<
": "
391 if (
false and not fs::is_regular_file(
wavefrontObj().absolutePath))
395 ARMARX_WARNING <<
"Expected wavefront object file (.obj) for object " << *
this
409 return os << rhs.
id();