25#include <VirtualRobot/RuntimeEnvironment.h>
37 defs->optional(properties.oldPriorKnowledge.use,
"p.oldPriorKnowledge.use");
38 defs->optional(properties.oldPriorKnowledge.name,
"p.oldPriorKnowledge.name");
50 return "SimulatorToArviz";
59 if (properties.oldPriorKnowledge.use)
68 if (properties.oldPriorKnowledge.use)
70 getProxy(priorKnowledge, properties.oldPriorKnowledge.name);
71 objectClassSegment.initFromProxy(priorKnowledge, {});
91 handleRobotLayer(scene.robots, robotLayer);
92 handleObjectLayer(scene.objects, objectLayer);
97 <<
" with filename: " << scene.floorTextureFile;
98 std::string filename =
"images/Floor20x20.xml";
99 VirtualRobot::RuntimeEnvironment::getDataFileAbsolute(filename);
103 arviz.commit({floorLayer, robotLayer, objectLayer});
107 SimulatorToArviz::handleRobotLayer(
const RobotVisuList& robotList,
110 for (
const auto& e : robotList)
112 Eigen::Vector3f position(e.pose->position->x, e.pose->position->y, e.pose->position->z);
114 e.pose->orientation->qx,
115 e.pose->orientation->qy,
116 e.pose->orientation->qz);
117 ARMARX_DEBUG <<
"Drawing robot " << e.name <<
" using file: " << e.robotFile
118 <<
" and joint values " << e.jointValues;
120 .
file(e.project, e.robotFile)
125 .
pose(position, orientation);
127 robotLayer.
add(robot);
132 SimulatorToArviz::handleObjectLayer(
const ObjectVisuList& objectList,
133 armarx::viz::Layer& objectLayer)
135 for (
const ObjectVisuData& data : objectList)
137 if (
data.objectPrimitiveData)
139 handleObjectPrimitiveData(data, objectLayer);
141 else if (not
data.filename.empty())
143 handleObjectFromFile(data, objectLayer);
145 else if (properties.oldPriorKnowledge.use)
147 handleObjectFromObjectClass(data, objectLayer);
153 SimulatorToArviz::handleObjectPrimitiveData(
const ObjectVisuData& _object,
154 armarx::viz::Layer& objectLayer)
156 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
157 Eigen::Vector3f position(
158 objectPose->position->x, objectPose->position->y, objectPose->position->z);
160 objectPose->orientation->qx,
161 objectPose->orientation->qy,
162 objectPose->orientation->qz);
164 switch (_object.objectPrimitiveData->type)
166 case ObjectType::Box:
168 BoxVisuPrimitivePtr boxObject =
169 BoxVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
172 armarx::viz::Box(_object.name)
174 Eigen::Vector3f{boxObject->width, boxObject->height, boxObject->depth})
175 .color(boxObject->color.r, boxObject->color.g, boxObject->color.b)
177 .orientation(orientation));
180 case ObjectType::Sphere:
182 SphereVisuPrimitivePtr sphereObject =
183 SphereVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
186 armarx::viz::Sphere(_object.name)
187 .radius(sphereObject->radius)
188 .color(sphereObject->color.r, sphereObject->color.g, sphereObject->color.b)
190 .orientation(orientation));
193 case ObjectType::Cylinder:
195 CylinderVisuPrimitivePtr cylinderObject =
196 CylinderVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
198 objectLayer.
add(armarx::viz::Cylinder(_object.name)
199 .radius(cylinderObject->radius)
200 .height(cylinderObject->length)
201 .color(cylinderObject->color.r,
202 cylinderObject->color.g,
203 cylinderObject->color.b)
205 .orientation(orientation));
212 SimulatorToArviz::handleObjectFromFile(
const ObjectVisuData& _object,
213 armarx::viz::Layer& objectLayer)
215 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
217 Eigen::Vector3f position(
218 objectPose->position->x, objectPose->position->y, objectPose->position->z);
220 objectPose->orientation->qx,
221 objectPose->orientation->qy,
222 objectPose->orientation->qz);
224 objectLayer.
add(armarx::viz::Object(_object.name)
225 .file(_object.project, _object.filename)
227 .orientation(orientation));
231 SimulatorToArviz::handleObjectFromObjectClass(
const ObjectVisuData& _object,
232 armarx::viz::Layer& objectLayer)
235 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
237 Eigen::Vector3f position(
238 objectPose->position->x, objectPose->position->y, objectPose->position->z);
240 objectPose->orientation->qx,
241 objectPose->orientation->qy,
242 objectPose->orientation->qz);
243 std::string filename = getClassFilename(_object.objectClassName);
244 std::string projectname =
"";
245 objectLayer.
add(armarx::viz::Object(_object.name)
246 .file(projectname, filename)
248 .orientation(orientation));
252 SimulatorToArviz::getClassFilename(
const std::string& className)
254 auto it = classFilenameCache.find(className);
255 if (it != classFilenameCache.end())
261 std::optional<memoryx::ObjectClassWrapper> objectClass =
262 objectClassSegment.getClass(className);
268 objectClass->classInMemory
269 ->getWrapper<memoryx::EntityWrappers::SimoxObjectWrapper>();
270 std::string filename = wrapper->getManipulationObjectFileName();
272 classFilenameCache[className] = filename;
armarx::viz::Client arviz
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportSceneUpdated(const SceneVisuData &scene, const ::Ice::Current &=::Ice::emptyCurrent) override
void onConnectComponent() override
void onExitComponent() override
std::string getDefaultName() const override
DerivedT & pose(Eigen::Matrix4f const &pose)
DerivedT & scale(Eigen::Vector3f scale)
Robot & useOriginalColor()
Robot & joints(std::map< std::string, float > const &values)
Robot & file(std::string const &project, std::string const &filename)
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Quaternion< float, 0 > Quaternionf
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
void add(ElementT const &element)