6 #ifdef PINOCCHIO_WITH_HPP_FCL
11 #endif // PINOCCHIO_WITH_HPP_FCL
21 double pi = boost::math::constants::pi<double>();
22 if (geomType ==
"box")
26 else if (geomType ==
"cylinder")
28 return 2 * pi * std::pow(
size(0), 2) *
size(1);
30 else if (geomType ==
"sphere")
32 return 4.0 / 3 * pi * std::pow(
size(0), 3);
34 else if (geomType ==
"capsule")
36 return 4.0 / 3 * pi * std::pow(
size(0), 3) + 2 * pi * std::pow(
size(0), 2) *
size(1);
38 else if (geomType ==
"ellipsoid")
40 return 4.0 / 3 * pi *
size.prod();
44 throw std::invalid_argument(
"geometry type does not exist");
67 #ifdef PINOCCHIO_WITH_HPP_FCL
70 const MjcfGeom & geom,
71 const MjcfGraph & currentGraph,
72 std::string & meshPath,
73 Eigen::Vector3d & meshScale)
75 if (geom.geomType ==
"mesh")
77 MjcfMesh currentMesh = currentGraph.mapOfMeshes.at(geom.meshName);
78 if (currentMesh.vertices.size() > 0)
80 auto vertices = currentMesh.vertices;
82 for (std::size_t
i = 0;
i < vertices.rows(); ++
i)
83 vertices.row(
i) = vertices.row(
i).cwiseProduct(currentMesh.scale.transpose());
84 auto model = std::make_shared<hpp::fcl::BVHModel<fcl::OBBRSS>>();
86 model->addVertices(vertices);
88 model->buildConvexHull(
true,
"Qt");
91 meshPath = currentMesh.filePath;
92 meshScale = currentMesh.scale;
96 else if (geom.geomType ==
"cylinder")
98 meshPath =
"CYLINDER";
100 double radius = geom.size(0);
101 double height = geom.size(1) * 2;
104 else if (geom.geomType ==
"box")
107 meshScale << 1, 1, 1;
108 double x = geom.size(0);
109 double y = geom.size(1);
110 double z = geom.size(2);
111 return std::make_shared<fcl::Box>(x, y, z);
113 else if (geom.geomType ==
"sphere")
116 meshScale << 1, 1, 1;
117 double radius = geom.size(0);
118 return std::make_shared<fcl::Sphere>(
radius);
120 else if (geom.geomType ==
"ellipsoid")
122 meshPath =
"ELLIPSOID";
123 meshScale << 1, 1, 1;
124 double rx = geom.size(0);
125 double ry = geom.size(1);
126 double rz = geom.size(2);
127 return std::make_shared<fcl::Ellipsoid>(rx, ry, rz);
129 else if (geom.geomType ==
"capsule")
131 meshPath =
"CAPSULE";
132 meshScale << 1, 1, 1;
133 double radius = geom.size(0);
134 double height = geom.size(1) * 2;
138 throw std::invalid_argument(
"Unknown geometry type :");
148 return std::make_shared<fcl::CollisionGeometry>();
164 const std::string & bodyName = currentBody.
bodyName;
168 const SE3 & bodyPlacement =
frame.placement;
170 std::size_t objectId = 0;
173 std::string meshPath =
"";
174 Eigen::Vector3d meshScale(Eigen::Vector3d::Ones());
182 std::string texturePath;
183 if (!geom.materialName.empty())
188 if (!
mat.texture.empty())
194 const SE3 geomPlacement = bodyPlacement * geom.geomPlacement;
195 std::ostringstream geometry_object_suffix;
196 geometry_object_suffix <<
"_" << objectId;
197 std::string geometry_object_name = std::string(bodyName + geometry_object_suffix.str());
211 auto text_s = el.get_optional<std::string>(
"<xmlattr>.texture");
216 auto single_v = el.get_optional<
float>(
"<xmlattr>.emission");
221 if ((single_v = el.get_optional<
float>(
"<xmlattr>.specular")))
225 if ((single_v = el.get_optional<
float>(
"<xmlattr>.shininess")))
228 if ((single_v = el.get_optional<
float>(
"<xmlattr>.reflectance")))
231 auto rgba_ = el.get_optional<std::string>(
"<xmlattr>.rgba");
233 rgba = internal::getVectorFromStream<4>(*rgba_);
238 if (el.get_child_optional(
"<xmlattr>.pos") && el.get_child_optional(
"<xmlattr>.fromto"))
239 throw std::invalid_argument(
"Both pos and fromto are defined in geom object");
245 auto value_v = el.get_optional<
double>(
"<xmlattr>.density");
250 auto val_v = el.get_optional<
int>(
"<xmlattr>.contype");
254 if ((val_v = el.get_optional<
int>(
"<xmlattr>.conaffinity")))
257 if ((val_v = el.get_optional<
int>(
"<xmlattr>.group")))
261 massGeom = el.get_optional<
double>(
"<xmlattr>.mass");
264 auto value_s = el.get_optional<std::string>(
"<xmlattr>.shellinertia");
266 throw std::invalid_argument(
"Shell inertia computation is not supported yet.");
269 if ((value_s = el.get_optional<std::string>(
"<xmlattr>.type")))
273 if ((value_s = el.get_optional<std::string>(
"<xmlattr>.material")))
278 value_s = el.get_optional<std::string>(
"<xmlattr>.mesh");
284 if ((value_s = el.get_optional<std::string>(
"<xmlattr>.rgba")))
285 rgba = internal::getVectorFromStream<4>(*value_s);
288 if ((value_s = el.get_optional<std::string>(
"<xmlattr>.size")))
292 fromtoS = el.get_optional<std::string>(
"<xmlattr>.fromto");
295 Eigen::VectorXd poses = internal::getVectorFromStream<6>(*
fromtoS);
298 Eigen::Vector3d zaxis = poses.tail(3) - poses.head(3);
301 Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d::UnitZ(), zaxis).toRotationMatrix();
318 std::vector<std::string> forbiddenListFromTo = {
"plane",
"hfield",
"mesh",
"sphere"};
321 && std::find(forbiddenListFromTo.begin(), forbiddenListFromTo.end(),
geomType)
322 != forbiddenListFromTo.end())
323 throw std::invalid_argument(
324 "fromto tag can only be used with capsules, boxes, cylinders and ellipsoids");
328 size = internal::getVectorFromStream<1>(
sizeS);
330 size = internal::getVectorFromStream<3>(
sizeS);
334 size = internal::getVectorFromStream<3>(
sizeS) * 2;
337 size = Eigen::Vector3d::Zero();
338 size(0) = internal::getVectorFromStream<1>(
sizeS)(0) * 2;
340 Eigen::VectorXd poses = internal::getVectorFromStream<6>(*
fromtoS);
341 Eigen::Vector3d zaxis = poses.tail(3) - poses.head(3);
342 size(2) = zaxis.norm();
348 size = internal::getVectorFromStream<3>(
sizeS);
351 size = Eigen::Vector3d::Zero();
352 size(0) = internal::getVectorFromStream<1>(
sizeS)(0);
354 Eigen::VectorXd poses = internal::getVectorFromStream<6>(*
fromtoS);
355 Eigen::Vector3d zaxis = poses.tail(3) - poses.head(3);
356 size(2) = zaxis.norm() / 2;
362 size = internal::getVectorFromStream<2>(
sizeS);
365 size = Eigen::Vector2d::Zero();
366 size(0) = internal::getVectorFromStream<1>(
sizeS)(0);
367 Eigen::VectorXd poses = internal::getVectorFromStream<6>(*
fromtoS);
368 Eigen::Vector3d zaxis = poses.tail(3) - poses.head(3);
369 size(1) = zaxis.norm() / 2;
375 throw std::invalid_argument(
"geomType does not exist");
411 throw std::invalid_argument(
"Unsupported geometry type");
419 auto name_s = el.get_optional<std::string>(
"<xmlattr>.name");
430 if (
auto geom_p = classD.
classElement.get_child_optional(
"geom"))
437 if (
auto geom_p = classE.
classElement.get_child_optional(
"geom"))
442 auto cl_s = el.get_optional<std::string>(
"<xmlattr>.class");
445 std::string className = *cl_s;
447 if (
auto geom_p = classE.
classElement.get_child_optional(
"geom"))
454 throw std::invalid_argument(
"Type is mesh but no mesh file were provided");
466 if (el.get_child_optional(
"<xmlattr>.pos") && el.get_child_optional(
"<xmlattr>.fromto"))
467 throw std::invalid_argument(
"Both pos and fromto are defined in site object");
472 auto fromtoS = el.get_optional<std::string>(
"<xmlattr>.fromto");
475 Eigen::VectorXd poses = internal::getVectorFromStream<6>(*fromtoS);
478 Eigen::Vector3d zaxis = poses.tail(3) - poses.head(3);
481 Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d::UnitZ(), zaxis).toRotationMatrix();
489 auto name_s = el.get_optional<std::string>(
"<xmlattr>.name");
500 if (
auto site_p = classD.
classElement.get_child_optional(
"site"))
507 if (
auto site_p = classE.
classElement.get_child_optional(
"site"))
512 auto cl_s = el.get_optional<std::string>(
"<xmlattr>.class");
515 std::string className = *cl_s;
517 if (
auto site_p = classE.
classElement.get_child_optional(
"site"))
530 #ifdef PINOCCHIO_WITH_HPP_FCL
532 meshLoader = std::make_shared<fcl::MeshLoader>(fcl::MeshLoader());
533 #endif // ifdef PINOCCHIO_WITH_HPP_FCL