24 #include <VirtualRobot/RuntimeEnvironment.h>
35 defs->optional(properties.oldPriorKnowledge.use,
"p.oldPriorKnowledge.use");
36 defs->optional(properties.oldPriorKnowledge.name,
"p.oldPriorKnowledge.name");
49 return "SimulatorToArviz";
58 if (properties.oldPriorKnowledge.use)
67 if (properties.oldPriorKnowledge.use)
69 getProxy(priorKnowledge, properties.oldPriorKnowledge.name);
90 handleRobotLayer(scene.robots, robotLayer);
91 handleObjectLayer(scene.objects, objectLayer);
95 ARMARX_DEBUG <<
"has floor: " << scene.floor <<
" with filename: " << scene.floorTextureFile;
96 std::string
filename =
"images/Floor20x20.xml";
97 VirtualRobot::RuntimeEnvironment::getDataFileAbsolute(
filename);
101 arviz.
commit({floorLayer, robotLayer, objectLayer});
105 void SimulatorToArviz::handleRobotLayer(
const RobotVisuList& robotList,
armarx::viz::Layer& robotLayer)
107 for (
const auto& e : robotList)
109 Eigen::Vector3f position(e.pose->position->x,
111 e.pose->position->z);
113 e.pose->orientation->qx,
114 e.pose->orientation->qy,
115 e.pose->orientation->qz);
116 ARMARX_DEBUG <<
"Drawing robot " << e.name <<
" using file: " << e.robotFile <<
" and joint values " << e.jointValues;
118 .file(e.project, e.robotFile)
120 .joints(e.jointValues)
123 .pose(position, orientation);
125 robotLayer.
add(robot);
130 void SimulatorToArviz::handleObjectLayer(
const ObjectVisuList& objectList,
armarx::viz::Layer& objectLayer)
132 for (
const ObjectVisuData&
data : objectList)
134 if (
data.objectPrimitiveData)
136 handleObjectPrimitiveData(
data, objectLayer);
138 else if (not
data.filename.empty())
140 handleObjectFromFile(
data, objectLayer);
142 else if (properties.oldPriorKnowledge.use)
144 handleObjectFromObjectClass(
data, objectLayer);
150 void SimulatorToArviz::handleObjectPrimitiveData(
const ObjectVisuData& _object,
armarx::viz::Layer& objectLayer)
152 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
153 Eigen::Vector3f position(objectPose->position->x, objectPose->position->y, objectPose->position->z);
154 Eigen::Quaternionf orientation(objectPose->orientation->qw, objectPose->orientation->qx, objectPose->orientation->qy, objectPose->orientation->qz);
156 switch (_object.objectPrimitiveData->type)
158 case ObjectType::Box:
160 BoxVisuPrimitivePtr boxObject = BoxVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
163 .
size(Eigen::Vector3f{boxObject->width, boxObject->height, boxObject->depth})
164 .
color(boxObject->color.r, boxObject->color.g, boxObject->color.b)
169 case ObjectType::Sphere:
171 SphereVisuPrimitivePtr sphereObject = SphereVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
174 .
radius(sphereObject->radius)
175 .
color(sphereObject->color.r, sphereObject->color.g, sphereObject->color.b)
180 case ObjectType::Cylinder:
182 CylinderVisuPrimitivePtr cylinderObject = CylinderVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
185 .
radius(cylinderObject->radius)
186 .
height(cylinderObject->length)
187 .
color(cylinderObject->color.r, cylinderObject->color.g, cylinderObject->color.b)
195 void SimulatorToArviz::handleObjectFromFile(
const ObjectVisuData& _object,
armarx::viz::Layer& objectLayer)
197 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
199 Eigen::Vector3f position(objectPose->position->x,
200 objectPose->position->y,
201 objectPose->position->z);
203 objectPose->orientation->qx,
204 objectPose->orientation->qy,
205 objectPose->orientation->qz);
208 .
file(_object.project, _object.filename)
213 void SimulatorToArviz::handleObjectFromObjectClass(
const ObjectVisuData& _object,
armarx::viz::Layer& objectLayer)
216 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
218 Eigen::Vector3f position(objectPose->position->x,
219 objectPose->position->y,
220 objectPose->position->z);
222 objectPose->orientation->qx,
223 objectPose->orientation->qy,
224 objectPose->orientation->qz);
225 std::string
filename = getClassFilename(_object.objectClassName);
226 std::string projectname =
"";
234 std::string SimulatorToArviz::getClassFilename(
const std::string& className)
236 auto it = classFilenameCache.find(className);
237 if (it != classFilenameCache.end())
243 std::optional<memoryx::ObjectClassWrapper> objectClass = objectClassSegment.
getClass(className);
250 std::string
filename = wrapper->getManipulationObjectFileName();
252 classFilenameCache[className] =
filename;