25 const std::map<std::string,
26 std::vector<simox::control::environment::TransformedCollisionObject>>&
29 auto scene = armarx::control::common::control_law::arondto::CollisionScene();
30 for (
const auto& [fst, snd] : collisionObjects)
32 ARMARX_INFO <<
"adding " << snd.size() <<
" primitives for " << fst;
33 for (
const auto& [collisionObject, localTransformation] : snd)
35 auto globalTransform = collisionObject.getTransform();
36 const auto& rot = globalTransform.getRotation();
37 const auto& trans = globalTransform.getTranslation();
38 Eigen::Matrix4d transformation = Eigen::Matrix4d::Identity();
39 transformation.block<3, 3>(0, 0) = rot;
40 transformation.block<3, 1>(0, 3) = trans;
42 switch (collisionObject.getNodeType())
44 case hpp::fcl::NODE_TYPE::GEOM_BOX:
46 auto box = armarx::control::common::control_law::arondto::Box();
48 const hpp::fcl::CollisionGeometry* geomPtr =
49 collisionObject.collisionGeometry().get();
50 auto boxObj =
dynamic_cast<const hpp::fcl::Box*
>(geomPtr);
51 box.lengthX = boxObj->halfSide[0] * 2;
52 box.lengthZ = boxObj->halfSide[1] * 2;
53 box.lengthY = boxObj->halfSide[2] * 2;
55 box.transformation = transformation;
57 scene.boxes.push_back(box);
61 case hpp::fcl::NODE_TYPE::GEOM_SPHERE:
63 auto sphere = armarx::control::common::control_law::arondto::Sphere();
65 const hpp::fcl::CollisionGeometry* geomPtr =
66 collisionObject.collisionGeometry().get();
67 auto sphereObj =
dynamic_cast<const hpp::fcl::Sphere*
>(geomPtr);
68 sphere.radius = sphereObj->radius;
70 sphere.transformation = transformation;
72 scene.spheres.push_back(sphere);
76 case hpp::fcl::NODE_TYPE::GEOM_CYLINDER:
78 auto cylinder = armarx::control::common::control_law::arondto::Cylinder();
80 const hpp::fcl::CollisionGeometry* geomPtr =
81 collisionObject.collisionGeometry().get();
82 auto cylinderObj =
dynamic_cast<const hpp::fcl::Cylinder*
>(geomPtr);
83 cylinder.radius = cylinderObj->radius;
84 cylinder.lengthY = cylinderObj->halfLength * 2;
87 cylinder.transformation = transformation;
89 scene.cylinders.push_back(cylinder);
93 case hpp::fcl::NODE_TYPE::GEOM_CAPSULE:
95 auto capsule = armarx::control::common::control_law::arondto::Capsule();
97 const hpp::fcl::CollisionGeometry* geomPtr =
98 collisionObject.collisionGeometry().get();
99 auto capsuleObj =
dynamic_cast<const hpp::fcl::Capsule*
>(geomPtr);
100 capsule.radius = capsuleObj->radius;
101 capsule.lengthY = capsuleObj->halfLength * 2;
104 capsule.transformation = transformation;
106 scene.capsules.push_back(capsule);
110 case hpp::fcl::NODE_TYPE::GEOM_ELLIPSOID:
112 auto ellipsoid = armarx::control::common::control_law::arondto::Ellipsoid();
114 const hpp::fcl::CollisionGeometry* geomPtr =
115 collisionObject.collisionGeometry().get();
116 auto ellipsoidObj =
dynamic_cast<const hpp::fcl::Ellipsoid*
>(geomPtr);
117 ellipsoid.lengthX =
static_cast<float>(ellipsoidObj->radii[0]) * 2.0F;
118 ellipsoid.lengthZ =
static_cast<float>(ellipsoidObj->radii[1]) * 2.0F;
119 ellipsoid.lengthY =
static_cast<float>(ellipsoidObj->radii[2]) * 2.0F;
121 ellipsoid.transformation = transformation;
123 scene.ellipsoids.push_back(ellipsoid);
138 const std::vector<armarx::ObjectID>& objectIDs,
144 std::map<std::string, std::vector<simox::control::environment::TransformedCollisionObject>>
146 for (
const auto&
id : objectIDs)
148 auto classIt = classes.find(
id.getClassID());
149 if (classIt != classes.end())
151 const auto& classObj = classIt->second;
152 if (classObj.simoxXmlPath.serialize().package.empty())
154 ARMARX_INFO_S <<
"Skipping " <<
id <<
" due to empty simoxXmlPath";
157 std::filesystem::path simoxXmlPath = classObj.simoxXmlPath.toSystemPath();
160 simoxXmlPath = simox::alg::replace_all(
161 simoxXmlPath,
"PriorKnowledgeData/PriorKnowledgeData",
"PriorKnowledgeData");
162 auto manipulationObject =
163 VirtualRobot::ObjectIO::loadManipulationObject(simoxXmlPath);
166 simox::control::utils::primitive::Model primitiveModel;
168 if (!
id.instanceName().empty())
171 auto articulatedObject =
174 if (articulatedObject.has_value() and
175 not classObj.articulatedSimoxXmlPath.serialize().package.empty())
178 auto robot = VirtualRobot::RobotIO::loadRobot(
179 classObj.articulatedSimoxXmlPath.toSystemPath().string());
181 robot->setJointValues(articulatedObject.value().jointMap);
183 std::function<void(VirtualRobot::SceneObjectPtr)> processAll =
184 [&](
const VirtualRobot::SceneObjectPtr& sceneObject)
190 for (
const auto& primitive :
191 sceneObject->getPrimitiveApproximation().getModels(
192 std::vector<std::string>(),
true))
195 primitive->transform =
196 sceneObject->getGlobalPose() * primitive->transform;
197 simox::control::simox::utils::convert(*primitive, primitiveModel);
199 for (
const auto& child : sceneObject->getChildren())
204 for (
const auto& child : robot->getChildren())
212 for (
const auto& primitive :
213 manipulationObject->getPrimitiveApproximation().getModels(
214 std::vector<std::string>(),
true))
216 simox::control::simox::utils::convert(*primitive, primitiveModel);
218 if (
id.instanceName() ==
"")
222 for (
const auto& [instance,
object] :
225 Eigen::Isometry3d globalPose =
226 simox::control::simox::utils::from_simox(
object.objectPoseGlobal);
227 collisionObjects[instance] =
228 simox::control::environment::createCollisionObjects(primitiveModel,
236 if (pose.has_value())
238 Eigen::Isometry3d globalPose =
239 simox::control::simox::utils::from_simox(pose.value().objectPoseGlobal);
240 collisionObjects[
id.str()] =
241 simox::control::environment::createCollisionObjects(primitiveModel,