29 #include <SimoxUtility/color/interpolation.h>
30 #include <SimoxUtility/math/pose/pose.h>
33 #define FUNCTION_NOT_IMPLEMENTED_MESSAGE \
34 "Function DebugDrawerToArViz::" << __FUNCTION__ << "(): Not implemented."
36 #define LOG_FUNCTION_NOT_IMPLEMENTED_MESSAGE() \
37 ARMARX_VERBOSE << FUNCTION_NOT_IMPLEMENTED_MESSAGE
45 Eigen::Vector3f
toEigen(Vector3BasePtr
v)
48 return {
v->x,
v->y,
v->z };
51 Eigen::Vector3f
toEigen(DebugDrawerPointCloudElement e)
53 return { e.x, e.y, e.z };
65 return simox::math::pose(
toEigen(pose->position),
toEigen(pose->orientation));
89 std::scoped_lock lock(mutex);
95 std::vector<viz::Layer> cleared;
96 for (
const auto& [name, layer] : layers)
100 cleared.push_back(arviz.
layer(name));
103 if (!cleared.empty())
122 std::scoped_lock lock(mutex);
132 std::scoped_lock lock(mutex);
137 setAndCommit(layer,
viz::Pose(name).pose(
toEigen(globalPose)).scale(scale));
140 void DebugDrawerToArViz::setLineVisu(
const std::string& layer,
const std::string& name,
const Vector3BasePtr& globalPosition1,
const Vector3BasePtr& globalPosition2,
Ice::Float lineWidth,
const DrawColor& color,
const Ice::Current&)
142 std::scoped_lock lock(mutex);
148 .color(toViz(color)).width(lineWidth).color(simox::Color::black(0)));
153 std::scoped_lock lock(mutex);
163 if (lineSet.useHeatMap)
165 ARMARX_VERBOSE <<
"DebugDrawerToArViz::" << __FUNCTION__ <<
"(): " <<
"'useHeatMap' not supported.";
168 simox::Color color0 = toSimox(lineSet.colorNoIntensity);
169 simox::Color color1 = toSimox(lineSet.colorFullIntensity);
171 for (
size_t i = 0; i + 1 < lineSet.points.size(); i += 2)
173 const auto& p1 = lineSet.points[i];
174 const auto& p2 = lineSet.points[i + 1];
175 float intensity = lineSet.intensities[i / 2];
178 std::stringstream ss;
179 ss << name <<
"/" << i <<
"_" << i + 1;
181 .lineColor(color).lineWidth(lineSet.lineWidth).
color(simox::Color::black(0)));
186 void DebugDrawerToArViz::setBoxVisu(
const std::string& layer,
const std::string& name,
const PoseBasePtr& globalPose,
const Vector3BasePtr& dimensions,
const DrawColor& color,
const Ice::Current&)
188 std::scoped_lock lock(mutex);
193 setAndCommit(layer,
viz::Box(name).pose(
toEigen(globalPose)).size(
toEigen(dimensions)).color(toViz(color)));
196 void DebugDrawerToArViz::setTextVisu(
const std::string& layer,
const std::string& name,
const std::string& text,
const Vector3BasePtr& globalPosition,
const DrawColor& color,
Ice::Int size,
const Ice::Current&)
198 std::scoped_lock lock(mutex);
203 setAndCommit(layer,
viz::Text(name).text(text).position(
toEigen(globalPosition))
204 .scale(size).color(toViz(color)));
209 std::scoped_lock lock(mutex);
214 setAndCommit(layer,
viz::Sphere(name).position(
toEigen(globalPosition)).radius(radius).color(toViz(color)));
219 std::scoped_lock lock(mutex);
226 for (
const auto& p : pointCloud.points)
235 std::scoped_lock lock(mutex);
242 for (
const auto& p : pointCloud.points)
244 viz::ColoredPoint cp;
248 cp.color = toViz(p.color);
256 std::scoped_lock lock(mutex);
263 for (
const auto& p : pointCloud.points)
265 viz::ColoredPoint cp;
275 void DebugDrawerToArViz::setPolygonVisu(
const std::string& layer,
const std::string& name,
const PolygonPointList& polygonPoints,
const DrawColor& colorInner,
const DrawColor& colorBorder,
Ice::Float lineWidth,
const Ice::Current&)
277 std::scoped_lock lock(mutex);
284 for (
const auto& p : polygonPoints)
288 setAndCommit(layer, poly.
color(toViz(colorInner)).lineColor(toViz(colorBorder)).lineWidth(lineWidth));
293 std::scoped_lock lock(mutex);
299 std::vector<Eigen::Vector3f> vertices;
300 std::vector<viz::data::Color> colors;
301 std::vector<viz::data::Face> faces;
302 for (
const auto&
v : triMesh.vertices)
304 vertices.emplace_back(
v.x,
v.y,
v.z);
306 for (
const auto&
c : triMesh.colors)
308 colors.emplace_back(toViz(
c));
310 for (
const auto& f : triMesh.faces)
312 viz::data::Face& face = faces.emplace_back();
313 face.v0 = f.vertex1.vertexID;
314 face.v1 = f.vertex2.vertexID;
315 face.v2 = f.vertex3.vertexID;
316 face.c0 = f.vertex1.colorID;
317 face.c1 = f.vertex2.colorID;
318 face.c2 = f.vertex3.colorID;
320 setAndCommit(layer,
viz::Mesh(name).vertices(vertices).colors(colors).faces(faces));
325 std::scoped_lock lock(mutex);
331 .color(toViz(color)).width(width).length(length));
336 std::scoped_lock lock(mutex);
343 .color(toViz(color)).radius(radius));
348 std::scoped_lock lock(mutex);
354 .radius(radius).completion(circleCompletion).color(toViz(color)).width(width));
358 void DebugDrawerToArViz::setRobotVisu(
const std::string& layer,
const std::string& name,
const std::string& robotFile,
const std::string& armarxProject, DrawStyle drawStyleType,
const Ice::Current&)
360 std::scoped_lock lock(mutex);
367 switch (drawStyleType)
369 case DrawStyle::CollisionModel:
372 case DrawStyle::FullModel:
377 robots.emplace(std::make_pair(layer, name), robot);
378 setAndCommit(layer, robot);
383 std::scoped_lock lock(mutex);
388 if (
auto it = robots.find(std::make_pair(layer, name)); it != robots.end())
393 arviz.
commit({getLayer(layer)});
398 std::scoped_lock lock(mutex);
403 if (
auto it = robots.find(std::make_pair(layer, name)); it != robots.end())
406 robot.
joints(configuration);
408 arviz.
commit({getLayer(layer)});
413 std::scoped_lock lock(mutex);
418 if (
auto it = robots.find(std::make_pair(layer, name)); it != robots.end())
423 arviz.
commit({getLayer(layer)});
428 (void) layer, (
void) name, (void) robotNodeName, (
void) color;
434 std::scoped_lock lock(mutex);
439 robots.erase(std::make_pair(layer, name));
440 removeAndCommit(layer, name);
454 setLineVisu(DEBUG_LAYER_NAME, name, globalPosition1, globalPosition2, lineWidth, color,
c);
462 setBoxVisu(DEBUG_LAYER_NAME, name, globalPose, dimensions, color,
c);
466 setTextVisu(DEBUG_LAYER_NAME, name, text, globalPosition, color, size,
c);
470 setSphereVisu(DEBUG_LAYER_NAME, name, globalPosition, color, radius,
c);
482 setPolygonVisu(DEBUG_LAYER_NAME, name, polygonPoints, colorInner, colorBorder, lineWidth,
c);
490 setArrowVisu(DEBUG_LAYER_NAME, name, position, direction, color, length, width,
c);
494 setCylinderVisu(DEBUG_LAYER_NAME, name, globalPosition, direction, length, radius, color,
c);
498 (void) name, (
void) globalPosition, (void) directionVec, (
void) radius, (void) circleCompletion, (
void) width, (void) color;
505 std::scoped_lock lock(mutex);
508 removeAndCommit(layer, name);
513 std::scoped_lock lock(mutex);
516 removeAndCommit(layer, name);
521 std::scoped_lock lock(mutex);
524 removeAndCommit(layer, name);
529 std::scoped_lock lock(mutex);
532 removeAndCommit(layer, name);
537 std::scoped_lock lock(mutex);
540 removeAndCommit(layer, name);
545 std::scoped_lock lock(mutex);
548 removeAndCommit(layer, name);
553 std::scoped_lock lock(mutex);
556 removeAndCommit(layer, name);
561 std::scoped_lock lock(mutex);
564 removeAndCommit(layer, name);
569 std::scoped_lock lock(mutex);
572 removeAndCommit(layer, name);
577 std::scoped_lock lock(mutex);
580 removeAndCommit(layer, name);
585 std::scoped_lock lock(mutex);
588 removeAndCommit(layer, name);
593 std::scoped_lock lock(mutex);
596 removeAndCommit(layer, name);
601 std::scoped_lock lock(mutex);
604 removeAndCommit(layer, name);
609 std::scoped_lock lock(mutex);
612 removeAndCommit(layer, name);
676 std::scoped_lock lock(mutex);
678 std::vector<viz::Layer> commit;
679 commit.reserve(layers.size());
680 for (
auto& [name, layer] : layers)
683 commit.push_back(layer);
689 std::scoped_lock lock(mutex);
702 (void) layer, (
void) visible;
755 (void) layer, (
void) elementName;
760 (void) layer, (
void) elementName;
771 viz::Layer& DebugDrawerToArViz::getLayer(
const std::string& layerName)
773 if (
auto it = layers.find(layerName); it != layers.end())
779 return layers.emplace(layerName, arviz.
layer(layerName)).first->second;
783 viz::data::ElementSeq::iterator DebugDrawerToArViz::findLayerElement(
viz::Layer& layer,
const std::string& elementName)
785 return std::find_if(layer.
data_.elements.begin(), layer.
data_.elements.end(),
786 [&elementName](
const viz::data::ElementPtr & e)
788 return e->id == elementName;
792 void DebugDrawerToArViz::removeLayerElement(
viz::Layer& layer,
const std::string& name)
794 auto it = findLayerElement(layer, name);
795 if (it != layer.
data_.elements.end())
797 layer.
data_.elements.erase(it);
801 void DebugDrawerToArViz::removeAndCommit(
const std::string& layerName,
const std::string& name)
804 removeLayerElement(layer, name);