25#include <VirtualRobot/RuntimeEnvironment.h>
39 defs->optional(properties.oldPriorKnowledge.use,
"p.oldPriorKnowledge.use");
40 defs->optional(properties.oldPriorKnowledge.name,
"p.oldPriorKnowledge.name");
58 return "SimulatorToArviz";
67 if (properties.oldPriorKnowledge.use)
76 if (properties.oldPriorKnowledge.use)
78 getProxy(priorKnowledge, properties.oldPriorKnowledge.name);
79 objectClassSegment.initFromProxy(priorKnowledge, {});
99 handleRobotLayer(scene.robots, robotLayer);
100 handleObjectLayer(scene.objects, objectLayer);
105 <<
" with filename: " << scene.floorTextureFile;
106 std::string filename =
"images/Floor20x20.xml";
107 VirtualRobot::RuntimeEnvironment::getDataFileAbsolute(filename);
111 arviz.commit({floorLayer, robotLayer, objectLayer});
115 SimulatorToArviz::handleRobotLayer(
const RobotVisuList& robotList,
118 for (
const auto& e : robotList)
120 Eigen::Vector3f position(e.pose->position->x, e.pose->position->y, e.pose->position->z);
122 e.pose->orientation->qx,
123 e.pose->orientation->qy,
124 e.pose->orientation->qz);
125 ARMARX_DEBUG <<
"Drawing robot " << e.name <<
" using file: " << e.robotFile
126 <<
" and joint values " << e.jointValues;
128 .
file(e.project, e.robotFile)
133 .
pose(position, orientation);
135 robotLayer.
add(robot);
140 SimulatorToArviz::handleObjectLayer(
const ObjectVisuList& objectList,
141 armarx::viz::Layer& objectLayer)
143 for (
const ObjectVisuData& data : objectList)
145 if (
data.objectPrimitiveData)
147 handleObjectPrimitiveData(data, objectLayer);
149 else if (not
data.filename.empty())
151 handleObjectFromFile(data, objectLayer);
153 else if (properties.oldPriorKnowledge.use)
155 handleObjectFromObjectClass(data, objectLayer);
161 SimulatorToArviz::handleObjectPrimitiveData(
const ObjectVisuData& _object,
162 armarx::viz::Layer& objectLayer)
164 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
165 Eigen::Vector3f position(
166 objectPose->position->x, objectPose->position->y, objectPose->position->z);
168 objectPose->orientation->qx,
169 objectPose->orientation->qy,
170 objectPose->orientation->qz);
172 switch (_object.objectPrimitiveData->type)
174 case ObjectType::Box:
176 BoxVisuPrimitivePtr boxObject =
177 BoxVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
180 armarx::viz::Box(_object.name)
182 Eigen::Vector3f{boxObject->width, boxObject->height, boxObject->depth})
183 .color(boxObject->color.r, boxObject->color.g, boxObject->color.b)
185 .orientation(orientation));
188 case ObjectType::Sphere:
190 SphereVisuPrimitivePtr sphereObject =
191 SphereVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
194 armarx::viz::Sphere(_object.name)
195 .radius(sphereObject->radius)
196 .color(sphereObject->color.r, sphereObject->color.g, sphereObject->color.b)
198 .orientation(orientation));
201 case ObjectType::Cylinder:
203 CylinderVisuPrimitivePtr cylinderObject =
204 CylinderVisuPrimitivePtr::dynamicCast(_object.objectPrimitiveData);
206 objectLayer.
add(armarx::viz::Cylinder(_object.name)
207 .radius(cylinderObject->radius)
208 .height(cylinderObject->length)
209 .color(cylinderObject->color.r,
210 cylinderObject->color.g,
211 cylinderObject->color.b)
213 .orientation(orientation));
220 SimulatorToArviz::handleObjectFromFile(
const ObjectVisuData& _object,
221 armarx::viz::Layer& objectLayer)
223 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
225 Eigen::Vector3f position(
226 objectPose->position->x, objectPose->position->y, objectPose->position->z);
228 objectPose->orientation->qx,
229 objectPose->orientation->qy,
230 objectPose->orientation->qz);
232 objectLayer.
add(armarx::viz::Object(_object.name)
233 .file(_object.project, _object.filename)
235 .orientation(orientation));
239 SimulatorToArviz::handleObjectFromObjectClass(
const ObjectVisuData& _object,
240 armarx::viz::Layer& objectLayer)
243 const PoseBasePtr& objectPose = _object.objectPoses.at(_object.name);
245 Eigen::Vector3f position(
246 objectPose->position->x, objectPose->position->y, objectPose->position->z);
248 objectPose->orientation->qx,
249 objectPose->orientation->qy,
250 objectPose->orientation->qz);
251 std::string filename = getClassFilename(_object.objectClassName);
252 std::string projectname =
"";
253 objectLayer.
add(armarx::viz::Object(_object.name)
254 .file(projectname, filename)
256 .orientation(orientation));
260 SimulatorToArviz::getClassFilename(
const std::string& className)
262 auto it = classFilenameCache.find(className);
263 if (it != classFilenameCache.end())
269 std::optional<memoryx::ObjectClassWrapper> objectClass =
270 objectClassSegment.getClass(className);
276 objectClass->classInMemory
277 ->getWrapper<memoryx::EntityWrappers::SimoxObjectWrapper>();
278 std::string filename = wrapper->getManipulationObjectFileName();
280 classFilenameCache[className] = filename;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
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)
Brief description of class SimulatorToArviz.
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportSceneUpdated(const SceneVisuData &scene, const ::Ice::Current &=::Ice::emptyCurrent) override
void onConnectComponent() override
static std::string GetDefaultName()
void onExitComponent() override
std::string getDefaultName() const override
Retrieve default name of component.
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)