28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 #include <VirtualRobot/Robot.h>
30 #include <VirtualRobot/VirtualRobot.h>
31 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
32 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
33 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
34 #include <VirtualRobot/Visualization/TriMeshModel.h>
35 #include <VirtualRobot/Visualization/VisualizationFactory.h>
36 #include <VirtualRobot/XML/RobotIO.h>
43 #include <Inventor/SbVec3f.h>
44 #include <Inventor/actions/SoWriteAction.h>
45 #include <Inventor/fields/SoMFColor.h>
46 #include <Inventor/fields/SoMFVec3f.h>
47 #include <Inventor/nodes/SoAnnotation.h>
48 #include <Inventor/nodes/SoComplexity.h>
49 #include <Inventor/nodes/SoCoordinate3.h>
50 #include <Inventor/nodes/SoCube.h>
51 #include <Inventor/nodes/SoCylinder.h>
52 #include <Inventor/nodes/SoDrawStyle.h>
53 #include <Inventor/nodes/SoFont.h>
54 #include <Inventor/nodes/SoLineSet.h>
55 #include <Inventor/nodes/SoMaterial.h>
56 #include <Inventor/nodes/SoMaterialBinding.h>
57 #include <Inventor/nodes/SoMatrixTransform.h>
58 #include <Inventor/nodes/SoPointSet.h>
59 #include <Inventor/nodes/SoShapeHints.h>
60 #include <Inventor/nodes/SoSphere.h>
61 #include <Inventor/nodes/SoText2.h>
62 #include <Inventor/nodes/SoTransform.h>
63 #include <Inventor/nodes/SoTranslation.h>
64 #include <Inventor/nodes/SoUnits.h>
68 #define SELECTION_NAME_PREFIX \
69 ("selection_" + std::to_string(reinterpret_cast<std::uintptr_t>(this)))
70 #define SELECTION_NAME_SPLITTER "____"
71 #define SELECTION_NAME(layerName, elementName) \
72 simox::alg::replace_all(std::string(SELECTION_NAME_PREFIX + "_" + layerName + \
73 SELECTION_NAME_SPLITTER + elementName), \
80 std::recursive_mutex DebugDrawerComponent::selectionMutex;
100 static const std::string DEBUG_LAYER_NAME{
"debug"};
102 DebugDrawerComponent::DebugDrawerComponent() :
106 defaultLayerVisibility(true)
123 SoUnits* u =
new SoUnits();
124 u->units = SoUnits::MILLIMETERS;
134 ARMARX_INFO <<
"Enabling selections for layer " << layerName;
143 ARMARX_INFO <<
"Disabling selections for layer " << layerName;
162 ARMARX_INFO <<
"Clearing selections on layer " << layerName;
172 if (path->containsNode(
layers.at(layerName).mainNode))
184 const std::string& elementName,
192 ARMARX_DEBUG <<
"Selecting element '" << elementName <<
"' on layer '" << layerName
193 <<
"' (internal name: " <<
SELECTION_NAME(layerName, elementName) <<
")";
195 SoNode* n = SoSelection::getByName(
SELECTION_NAME(layerName, elementName));
213 const std::string& elementName,
221 ARMARX_DEBUG <<
"Deselecting element '" << elementName <<
"' on layer '" << layerName
222 <<
"' (internal name: " <<
SELECTION_NAME(layerName, elementName) <<
")";
224 SoNode* n = SoSelection::getByName(
SELECTION_NAME(layerName, elementName));
280 for (
auto& e : selectedElements)
282 SoNode* n = SoSelection::getByName(
SELECTION_NAME(e.layerName, e.elementName));
295 DebugDrawerSelectionList
300 DebugDrawerSelectionList selectedElements;
306 for (
int j = 0; j < path->getLength(); j++)
308 SoNode* node = path->getNodeFromTail(j);
314 std::string name = node->getName().getString();
323 std::string layer = l.first;
324 if (
layers[layer].addedBoxVisualizations.find(name) !=
325 layers[layer].addedBoxVisualizations.end() ||
326 layers[layer].addedTextVisualizations.find(name) !=
327 layers[layer].addedTextVisualizations.end() ||
328 layers[layer].addedSphereVisualizations.find(name) !=
329 layers[layer].addedSphereVisualizations.end() ||
330 layers[layer].addedCylinderVisualizations.find(name) !=
331 layers[layer].addedCylinderVisualizations.end() ||
332 layers[layer].addedPolygonVisualizations.find(name) !=
333 layers[layer].addedPolygonVisualizations.end())
335 DebugDrawerSelectionElement e;
337 e.elementName = name;
339 selectedElements.push_back(e);
350 return selectedElements;
358 ARMARX_ERROR <<
"Cannot change the cycle time, once the thread has been started...";
362 if (visuUpdatesPerSec <= 0)
384 usingTopic(getProperty<std::string>(
"DebugDrawerTopic").getValue());
385 bool enabled = getProperty<bool>(
"ShowDebugDrawing").getValue();
394 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
404 offeringTopic(getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
405 usingTopic(getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
430 getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
436 std::cout <<
"onDisconnectComponent debug drawer" << std::endl;
462 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
469 while (
layers.size() > 0 && counter < 2 *
c)
492 SoSeparator* sep =
new SoSeparator;
493 SoUnits* u =
new SoUnits;
494 u->units = SoUnits::MILLIMETERS;
498 SoWriteAction writeAction;
499 writeAction.getOutput()->openFile(
filename.c_str());
500 writeAction.getOutput()->setBinary(
false);
501 writeAction.apply(sep);
502 writeAction.getOutput()->closeFile();
509 const std::string& layerName,
522 SoSeparator* sep =
new SoSeparator;
523 SoUnits* u =
new SoUnits;
524 u->units = SoUnits::MILLIMETERS;
526 sep->addChild(
layers[layerName].mainNode);
528 SoWriteAction writeAction;
529 writeAction.getOutput()->openFile(
filename.c_str());
530 writeAction.getOutput()->setBinary(
false);
531 writeAction.apply(sep);
532 writeAction.getOutput()->closeFile();
554 SoSeparator* newS =
new SoSeparator;
555 SoMatrixTransform* newM =
new SoMatrixTransform;
556 newS->addChild(newM);
557 std::string n = d.
name;
558 newS->addChild(CoinVisualizationFactory::CreateCoordSystemVisualization(d.
scale, &n));
559 layer.addedCoordVisualizations[d.
name] = newS;
560 layer.mainNode->addChild(newS);
562 SoSeparator*
s = layer.addedCoordVisualizations[d.
name];
563 SoMatrixTransform* m = (SoMatrixTransform*)(
s->getChild(0));
564 SbMatrix mNew = CoinVisualizationFactory::getSbMatrix(d.
globalPose);
565 m->matrix.setValue(mNew);
585 SoSeparator* newS =
new SoSeparator;
586 newS->addChild(CoinVisualizationFactory::createCoinLine(d.
p1, d.
p2, d.
scale, d.
color));
587 layer.addedLineVisualizations[d.
name] = newS;
588 layer.mainNode->addChild(newS);
607 if (d.
lineSet.points.size() % 2 != 0)
616 <<
"Amount of intensities has to be half the amount of points for a line set";
620 for (
const DebugDrawerPointCloudElement& e : d.
lineSet.points)
626 <<
" is not finite! this set will not be drawn!";
632 std::vector<VirtualRobot::VisualizationFactory::Color> colors;
635 d.
lineSet.colorNoIntensity.b));
637 d.
lineSet.colorFullIntensity.g,
638 d.
lineSet.colorFullIntensity.b));
639 VirtualRobot::ColorMap visualizationColorMap =
640 VirtualRobot::ColorMap::customColorMap(colors);
643 SoSeparator* sep =
new SoSeparator;
645 SoMaterialBinding* binding =
new SoMaterialBinding;
646 binding->value = SoMaterialBinding::PER_PART;
647 sep->addChild(binding);
649 SoDrawStyle* lineStyle =
new SoDrawStyle;
650 lineStyle->lineWidth.setValue(d.
lineSet.lineWidth);
651 sep->addChild(lineStyle);
653 SoCoordinate3* coordinateNode =
new SoCoordinate3;
654 sep->addChild(coordinateNode);
656 SoMaterial* materialNode =
new SoMaterial;
657 sep->addChild(materialNode);
659 SoLineSet* lineSetNode =
new SoLineSet;
660 lineSetNode->startIndex.setValue(0);
661 sep->addChild(lineSetNode);
665 SbVec3f* coordinateValues =
new SbVec3f[d.
lineSet.points.size()];
666 int32_t* lineSetValues =
new int32_t[d.
lineSet.intensities.size()];
667 SbColor* colorValues =
new SbColor[d.
lineSet.intensities.size()];
669 for (
unsigned int i = 0; i < d.
lineSet.intensities.size(); i++)
671 lineSetValues[i] = 2;
673 coordinateValues[2 * i].setValue(
675 coordinateValues[2 * i + 1].setValue(d.
lineSet.points[2 * i + 1].x,
677 d.
lineSet.points[2 * i + 1].z);
682 colorValues[i].setValue(
c.r,
c.g,
c.b);
687 visualizationColorMap.getColor(d.
lineSet.intensities[i]);
688 colorValues[i].setValue(
c.r,
c.g,
c.b);
692 coordinateNode->point.setValuesPointer(d.
lineSet.points.size(), coordinateValues);
693 lineSetNode->numVertices.setValuesPointer(d.
lineSet.intensities.size(), lineSetValues);
694 materialNode->ambientColor.setValuesPointer(d.
lineSet.intensities.size(), colorValues);
695 materialNode->diffuseColor.setValuesPointer(d.
lineSet.intensities.size(), colorValues);
697 layer.addedLineSetVisualizations[d.
name] = sep;
698 layer.mainNode->addChild(sep);
716 SoSeparator* newS =
new SoSeparator;
718 newS->addChild(CoinVisualizationFactory::getMatrixTransform(m));
720 SoMaterial* material =
new SoMaterial;
723 material->transparency.setValue(d.
color.transparency);
724 newS->addChild(material);
726 SoCube* cube =
new SoCube;
728 cube->width = d.
width;
730 cube->depth = d.
depth;
731 newS->addChild(cube);
733 layer.addedBoxVisualizations[d.
name] = newS;
734 layer.mainNode->addChild(newS);
752 SoSeparator* sep =
new SoSeparator;
753 SoAnnotation* ann =
new SoAnnotation;
756 SoMaterial* mat =
new SoMaterial;
759 mat->transparency.setValue(d.
color.transparency);
762 SoTransform* tr =
new SoTransform;
766 SoFont* font =
new SoFont;
767 font->name.setValue(
"TGS_Triplex_Roman");
772 SoText2* te =
new SoText2;
774 te->string = d.
text.c_str();
775 te->justification = SoText2::CENTER;
778 layer.addedTextVisualizations[d.
name] = sep;
779 layer.mainNode->addChild(sep);
803 <<
" is not finite! this sphere will not be drawn!";
807 SoSeparator* sep =
new SoSeparator;
808 SoMaterial* mat =
new SoMaterial;
811 mat->transparency.setValue(d.
color.transparency);
814 SoTransform* tr =
new SoTransform;
818 SoSphere* sphere =
new SoSphere;
820 sphere->radius = d.
radius;
821 sep->addChild(sphere);
823 layer.addedSphereVisualizations[d.
name] = sep;
824 layer.mainNode->addChild(sep);
842 SoSeparator* sep =
new SoSeparator;
843 SoMaterial* mat =
new SoMaterial;
846 mat->transparency.setValue(d.
color.transparency);
850 SoTransform* tr =
new SoTransform;
852 tr->rotation.setValue(SbRotation(
856 SoCylinder* cylinder =
new SoCylinder;
858 cylinder->height = d.
length;
859 cylinder->radius = d.
radius;
860 sep->addChild(cylinder);
862 layer.addedCylinderVisualizations[d.
name] = sep;
863 layer.mainNode->addChild(sep);
870 vec = vec.normalized();
872 dir1 = vec.cross(Eigen::Vector3f(0, 0, 1));
874 if (dir1.norm() < 0.1f)
878 dir1 = vec.cross(Eigen::Vector3f(0, 1, 0));
881 dir1 = -dir1.normalized();
883 dir2 = vec.cross(dir1).normalized();
903 SoSeparator* sep =
new SoSeparator;
904 SoMaterial* mat =
new SoMaterial;
907 mat->transparency.setValue(d.
color.transparency);
911 SoTransform* tr =
new SoTransform;
913 Eigen::Vector3f xDir, yDir;
916 rotGoal << xDir, yDir, zDir;
919 Eigen::AngleAxisf rotAA(rotGoal);
920 tr->rotation.setValue(SbVec3f(rotAA.axis().x(), rotAA.axis().y(), rotAA.axis().z()),
923 auto node = CoinVisualizationFactory().createCircleArrow(
925 SoNode* circle =
dynamic_cast<CoinVisualizationNode&
>(*node).getCoinVisualization();
927 sep->addChild(circle);
929 layer.addedCircleVisualizations[d.
name] = sep;
930 layer.mainNode->addChild(sep);
949 SoSeparator* pclSep =
new SoSeparator;
951 SoMaterial* pclMat =
new SoMaterial;
952 pclMat->diffuseColor.setValue(0.2, 0.2, 0.2);
953 pclMat->diffuseColor.setValue(0.2, 0.2, 0.2);
954 pclSep->addChild(pclMat);
956 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
957 pclMatBind->value = SoMaterialBinding::OVERALL;
958 pclSep->addChild(pclMatBind);
960 SoCoordinate3* pclCoords =
new SoCoordinate3;
961 std::vector<SbVec3f> coords;
962 coords.reserve(
pcl.size());
965 std::back_inserter(coords),
966 [](
const DebugDrawerPointCloudElement& elem) {
967 return SbVec3f{elem.x, elem.y, elem.z};
969 pclCoords->point.setValues(0, coords.size(), coords.data());
970 pclSep->addChild(pclCoords);
972 SoDrawStyle* pclStye =
new SoDrawStyle;
973 pclStye->pointSize = d.pointCloud.pointSize;
974 pclSep->addChild(pclStye);
976 pclSep->addChild(
new SoPointSet);
978 layer.addedPointCloudVisualizations[d.name] = pclSep;
979 layer.mainNode->addChild(pclSep);
985 auto l = getScopedVisuLock();
996 SoSeparator* sep =
new SoSeparator;
998 SoShapeHints* hints =
new SoShapeHints;
999 hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
1000 hints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
1001 hints->faceType = SoShapeHints::UNKNOWN_FACE_TYPE;
1002 sep->addChild(hints);
1004 sep->addChild(VirtualRobot::CoinVisualizationFactory::CreatePolygonVisualization(
1007 layer.addedPolygonVisualizations[d.
name] = sep;
1008 layer.mainNode->addChild(sep);
1014 auto l = getScopedVisuLock();
1016 auto& layer = requestLayer(d.
layerName);
1025 TriMeshModelPtr triMesh = TriMeshModelPtr(
new TriMeshModel());
1027 for (DrawColor color : d.
triMesh.colors)
1033 for (DebugDrawerVertex
v : d.
triMesh.vertices)
1035 triMesh->addVertex(Eigen::Vector3f(
v.x,
v.y,
v.z));
1038 for (DebugDrawerFace f : d.
triMesh.faces)
1040 MathTools::TriangleFace face;
1042 face.id1 = f.vertex1.vertexID;
1043 face.idNormal1 = f.vertex1.normalID;
1044 face.idColor1 = f.vertex1.colorID;
1046 face.id2 = f.vertex2.vertexID;
1047 face.idNormal2 = f.vertex2.normalID;
1048 face.idColor2 = f.vertex2.colorID;
1050 face.id3 = f.vertex3.vertexID;
1051 face.idNormal3 = f.vertex3.normalID;
1052 face.idColor3 = f.vertex3.colorID;
1054 face.normal = Eigen::Vector3f(f.normal.x, f.normal.y, f.normal.z);
1056 triMesh->addFace(face);
1059 SoSeparator* sep =
new SoSeparator();
1060 SoNode*
c = CoinVisualizationFactory::getCoinVisualization(triMesh);
1062 layer.addedTriMeshVisualizations[d.
name] = sep;
1063 layer.mainNode->addChild(sep);
1069 auto l = getScopedVisuLock();
1071 auto& layer = requestLayer(d.
layerName);
1080 SoSeparator* sep =
new SoSeparator;
1082 SoTransform* tr =
new SoTransform;
1086 SoSeparator* sepArrow = VirtualRobot::CoinVisualizationFactory::CreateArrow(
1088 sep->addChild(sepArrow);
1089 layer.addedArrowVisualizations[d.
name] = sep;
1090 layer.mainNode->addChild(sep);
1096 auto l = getScopedVisuLock();
1113 std::map<std::string, float>::iterator i = d.
configuration.begin();
1116 if (!rob->hasRobotNode(i->first))
1119 <<
" does not know RobotNode " << i->first;
1132 auto l = getScopedVisuLock();
1134 auto& layer = requestLayer(d.
layerName);
1164 if (layer.addedRobotVisualizations.find(d.
name) == layer.addedRobotVisualizations.end())
1170 SoSeparator* sep = layer.addedRobotVisualizations[d.
name];
1172 for (
int i = 0; i < sep->getNumChildren(); i++)
1174 SoSeparator* nodeSep =
dynamic_cast<SoSeparator*
>(sep->getChild(i));
1175 SoMaterial* m =
dynamic_cast<SoMaterial*
>(nodeSep->getChild(0));
1183 if (d.
color.isNone())
1185 m->setOverride(
false);
1194 m->ambientColor = SbColor(0, 0, 0);
1196 m->setOverride(
true);
1204 if (layer.addedRobotVisualizations.find(d.
name) == layer.addedRobotVisualizations.end())
1210 SoSeparator* sep = layer.addedRobotVisualizations[d.
name];
1212 if (!sep || sep->getNumChildren() < 2)
1218 std::string entryName = simox::alg::replace_all(
1219 std::string(
"__" + d.
layerName +
"__" + d.
name +
"__"),
" ",
"_");
1222 std::vector<std::string> nodeNameList;
1224 for (
size_t i = 0; i < robot->getRobotNodes().size(); ++i)
1226 nodeNameList.push_back(robot->getRobotNodes()[i]->getName());
1229 for (std::map<std::string,
1236 std::string nodeName = it->first;
1239 std::vector<std::string>::iterator strit;
1240 strit = std::find(nodeNameList.begin(), nodeNameList.end(), nodeName);
1242 if (strit == nodeNameList.end())
1244 ARMARX_WARNING <<
"Cannot find correct robot node name " + nodeName +
1245 " for DebugDrawer node color update !!!";
1249 size_t ind = strit - nodeNameList.begin();
1250 SoSeparator* nodeSep =
dynamic_cast<SoSeparator*
>(sep->getChild(ind));
1258 SoMaterial* nodeMat =
dynamic_cast<SoMaterial*
>(nodeSep->getChild(0));
1266 if (nodeColor.isNone())
1268 nodeMat->setOverride(
false);
1272 if (nodeColor.r < 0 || nodeColor.g < 0 || nodeColor.b < 0)
1274 ARMARX_ERROR <<
"Internal robot layer node color error";
1278 nodeMat->diffuseColor = SbColor(nodeColor.r, nodeColor.g, nodeColor.b);
1279 nodeMat->ambientColor = SbColor(0, 0, 0);
1280 nodeMat->transparency =
std::max(0.0f, nodeColor.transparency);
1281 nodeMat->setOverride(
true);
1291 auto l = getScopedVisuLock();
1293 auto& layer = requestLayer(d.
layerName);
1294 std::string entryName = simox::alg::replace_all(
1295 std::string(
"__" + d.
layerName +
"__" + d.
name +
"__"),
" ",
"_");
1299 if (activeRobots.find(entryName) != activeRobots.end())
1302 << activeRobots[entryName]->getName();
1303 return activeRobots[entryName];
1311 <<
", with name " << d.
name;
1335 VirtualRobot::SceneObject::VisualizationType visuType = VirtualRobot::SceneObject::Full;
1338 if (d.
drawStyle == DrawStyle::CollisionModel)
1340 visuType = VirtualRobot::SceneObject::Collision;
1341 loadMode = VirtualRobot::RobotIO::eCollisionModel;
1348 if (loadedRobots.find(
filename) == loadedRobots.end())
1365 SoSeparator* sep =
new SoSeparator;
1366 layer.mainNode->addChild(sep);
1368 for (
size_t i = 0; i < result->getRobotNodes().size(); ++i)
1370 VirtualRobot::RobotNodePtr robNode = result->getRobotNodes()[i];
1371 SoSeparator* nodeSep =
new SoSeparator;
1373 SoMaterial* nodeMat =
new SoMaterial;
1374 nodeMat->setOverride(
false);
1375 nodeSep->addChild(nodeMat);
1378 robNode->getVisualization<CoinVisualization>(visuType);
1382 SoNode* sepRobNode = robNodeVisu->getCoinVisualization();
1386 nodeSep->addChild(sepRobNode);
1390 sep->addChild(nodeSep);
1393 activeRobots[entryName] = result;
1394 ARMARX_DEBUG <<
"setting robot to activeRobots, entryName:" << entryName
1395 <<
", activeRobots.size():" << activeRobots.size();
1396 layer.addedRobotVisualizations[d.
name] = sep;
1397 ARMARX_DEBUG <<
"adding sep to layer.addedRobotVisualizations, d.name:" << d.
name
1398 <<
", layer:" << d.
layerName <<
", layer.addedRobotVisualizations.size():"
1399 << layer.addedRobotVisualizations.size();
1405 DebugDrawerComponent::removeLine(
const std::string& layerName,
const std::string& name)
1407 auto l = getScopedVisuLock();
1409 if (!hasLayer(layerName))
1414 auto& layer = layers.at(layerName);
1416 if (layer.addedLineVisualizations.find(name) == layer.addedLineVisualizations.end())
1421 layer.mainNode->removeChild(layer.addedLineVisualizations[name]);
1422 layer.addedLineVisualizations.erase(name);
1426 DebugDrawerComponent::removeLineSet(
const std::string& layerName,
const std::string& name)
1428 auto l = getScopedVisuLock();
1430 if (!hasLayer(layerName))
1435 auto& layer = layers.at(layerName);
1437 if (layer.addedLineSetVisualizations.find(name) == layer.addedLineSetVisualizations.end())
1442 layer.mainNode->removeChild(layer.addedLineSetVisualizations[name]);
1443 layer.addedLineSetVisualizations.erase(name);
1447 DebugDrawerComponent::removeBox(
const std::string& layerName,
const std::string& name)
1449 auto l = getScopedVisuLock();
1451 if (!hasLayer(layerName))
1456 auto& layer = layers.at(layerName);
1458 if (layer.addedBoxVisualizations.find(name) == layer.addedBoxVisualizations.end())
1463 layer.mainNode->removeChild(layer.addedBoxVisualizations[name]);
1464 layer.addedBoxVisualizations.erase(name);
1468 DebugDrawerComponent::removeText(
const std::string& layerName,
const std::string& name)
1470 auto l = getScopedVisuLock();
1472 if (!hasLayer(layerName))
1477 auto& layer = layers.at(layerName);
1479 if (layer.addedTextVisualizations.find(name) == layer.addedTextVisualizations.end())
1484 layer.mainNode->removeChild(layer.addedTextVisualizations[name]);
1485 layer.addedTextVisualizations.erase(name);
1489 DebugDrawerComponent::removeSphere(
const std::string& layerName,
const std::string& name)
1491 auto l = getScopedVisuLock();
1493 if (!hasLayer(layerName))
1498 auto& layer = layers.at(layerName);
1500 if (layer.addedSphereVisualizations.find(name) == layer.addedSphereVisualizations.end())
1505 layer.mainNode->removeChild(layer.addedSphereVisualizations[name]);
1506 layer.addedSphereVisualizations.erase(name);
1510 DebugDrawerComponent::removeCylinder(
const std::string& layerName,
const std::string& name)
1512 auto l = getScopedVisuLock();
1514 if (!hasLayer(layerName))
1519 auto& layer = layers.at(layerName);
1521 if (layer.addedCylinderVisualizations.find(name) == layer.addedCylinderVisualizations.end())
1526 layer.mainNode->removeChild(layer.addedCylinderVisualizations[name]);
1527 layer.addedCylinderVisualizations.erase(name);
1531 DebugDrawerComponent::removeCircle(
const std::string& layerName,
const std::string& name)
1533 auto l = getScopedVisuLock();
1535 if (!hasLayer(layerName))
1540 auto& layer = layers.at(layerName);
1542 if (layer.addedCircleVisualizations.find(name) == layer.addedCircleVisualizations.end())
1547 layer.mainNode->removeChild(layer.addedCircleVisualizations[name]);
1548 layer.addedCircleVisualizations.erase(name);
1552 DebugDrawerComponent::removePointCloud(
const std::string& layerName,
const std::string& name)
1554 auto l = getScopedVisuLock();
1556 if (!hasLayer(layerName))
1561 auto& layer = layers.at(layerName);
1563 if (layer.addedPointCloudVisualizations.find(name) ==
1564 layer.addedPointCloudVisualizations.end())
1569 layer.mainNode->removeChild(layer.addedPointCloudVisualizations[name]);
1570 layer.addedPointCloudVisualizations.erase(name);
1574 DebugDrawerComponent::removePolygon(
const std::string& layerName,
const std::string& name)
1576 auto l = getScopedVisuLock();
1578 if (!hasLayer(layerName))
1583 auto& layer = layers.at(layerName);
1585 if (layer.addedPolygonVisualizations.find(name) == layer.addedPolygonVisualizations.end())
1590 layer.mainNode->removeChild(layer.addedPolygonVisualizations[name]);
1591 layer.addedPolygonVisualizations.erase(name);
1595 DebugDrawerComponent::removeTriMesh(
const std::string& layerName,
const std::string& name)
1597 auto l = getScopedVisuLock();
1599 if (!hasLayer(layerName))
1604 auto& layer = layers.at(layerName);
1606 if (layer.addedTriMeshVisualizations.find(name) == layer.addedTriMeshVisualizations.end())
1611 layer.mainNode->removeChild(layer.addedTriMeshVisualizations[name]);
1612 layer.addedTriMeshVisualizations.erase(name);
1616 DebugDrawerComponent::removeArrow(
const std::string& layerName,
const std::string& name)
1618 auto l = getScopedVisuLock();
1620 if (!hasLayer(layerName))
1625 auto& layer = layers.at(layerName);
1627 if (layer.addedArrowVisualizations.find(name) == layer.addedArrowVisualizations.end())
1632 layer.mainNode->removeChild(layer.addedArrowVisualizations[name]);
1633 layer.addedArrowVisualizations.erase(name);
1637 DebugDrawerComponent::removeRobot(
const std::string& layerName,
const std::string& name)
1639 auto l = getScopedVisuLock();
1642 std::string entryName =
1643 simox::alg::replace_all(std::string(
"__" + layerName +
"__" + name +
"__"),
" ",
"_");
1646 if (activeRobots.find(entryName) != activeRobots.end())
1649 activeRobots.erase(entryName);
1650 ARMARX_DEBUG <<
"after Found robot to remove, activeRobots.size() = "
1651 << activeRobots.size();
1655 if (!hasLayer(layerName))
1661 auto& layer = layers.at(layerName);
1663 if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1665 ARMARX_INFO <<
"Could not find robot with name " << name;
1669 ARMARX_DEBUG <<
"Removing visualization for " << entryName;
1671 ARMARX_DEBUG <<
"removing sep from layer.addedRobotVisualizations, d.name:" << name
1672 <<
", layer:" << layerName <<
", layer.addedRobotVisualizations.size():"
1673 << layer.addedRobotVisualizations.size();
1675 if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1681 ARMARX_DEBUG <<
"removing from layer.mainNode, layer.mainNode->getNumChildren()="
1682 << layer.mainNode->getNumChildren();
1684 if (layer.mainNode->findChild(layer.addedRobotVisualizations[name]) < 0)
1690 layer.mainNode->removeChild(layer.addedRobotVisualizations[name]);
1691 layer.addedRobotVisualizations.erase(name);
1692 ARMARX_DEBUG <<
"after removing from layer.mainNode, layer.mainNode->getNumChildren()="
1693 << layer.mainNode->getNumChildren();
1694 ARMARX_DEBUG <<
"after removing sep from layer.addedRobotVisualizations, d.name:" << name
1695 <<
", layer:" << layerName <<
", layer.addedRobotVisualizations.size():"
1696 << layer.addedRobotVisualizations.size();
1700 DebugDrawerComponent::removeCoordSystem(
const std::string& layerName,
const std::string& name)
1702 auto l = getScopedVisuLock();
1704 if (!hasLayer(layerName))
1709 auto& layer = layers.at(layerName);
1711 if (layer.addedCoordVisualizations.find(name) == layer.addedCoordVisualizations.end())
1716 layer.mainNode->removeChild(layer.addedCoordVisualizations[name]);
1717 layer.addedCoordVisualizations.erase(name);
1721 DebugDrawerComponent::setLayerVisibility(
const std::string& layerName,
bool visible)
1723 auto l = getScopedVisuLock();
1725 if (!hasLayer(layerName))
1730 auto& layer = layers.at(layerName);
1731 layer.visible = visible;
1735 if (layerMainNode->findChild(layer.mainNode) < 0)
1737 layerMainNode->addChild(layer.mainNode);
1742 if (layerMainNode->findChild(layer.mainNode) >= 0)
1744 layerMainNode->removeChild(layer.mainNode);
1750 DebugDrawerComponent::disableAllLayers(const ::Ice::Current&)
1752 auto l = getScopedVisuLock();
1754 if (selectionNode->findChild(layerMainNode) >= 0)
1756 selectionNode->removeChild(layerMainNode);
1761 DebugDrawerComponent::enableAllLayers(const ::Ice::Current&)
1763 auto l = getScopedVisuLock();
1765 if (selectionNode->findChild(layerMainNode) < 0)
1767 selectionNode->addChild(layerMainNode);
1772 DebugDrawerComponent::setScaledPoseVisu(
const std::string& layerName,
1773 const std::string& poseName,
1774 const ::armarx::PoseBasePtr& globalPose,
1776 const ::Ice::Current&)
1781 auto l = getScopedAccumulatedDataLock();
1782 std::string entryName = simox::alg::replace_all(
1783 std::string(
"__" + layerName +
"__" + poseName +
"__"),
" ",
"_");
1784 CoordData& d = accumulatedUpdateData.coord[entryName];
1794 DebugDrawerComponent::setScaledPoseDebugLayerVisu(
const std::string& poseName,
1795 const ::armarx::PoseBasePtr& globalPose,
1797 const ::Ice::Current&)
1799 setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, scale);
1803 DebugDrawerComponent::setPoseVisu(
const std::string& layerName,
1804 const std::string& poseName,
1805 const PoseBasePtr& globalPose,
1806 const Ice::Current&)
1808 setScaledPoseVisu(layerName, poseName, globalPose, 1.f);
1812 DebugDrawerComponent::setPoseDebugLayerVisu(
const std::string& poseName,
1813 const PoseBasePtr& globalPose,
1814 const Ice::Current&)
1816 setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, 1.f);
1820 DebugDrawerComponent::removePoseVisu(
const std::string& layerName,
1821 const std::string& poseName,
1822 const Ice::Current&)
1825 auto l = getScopedAccumulatedDataLock();
1826 std::string entryName = simox::alg::replace_all(
1827 std::string(
"__" + layerName +
"__" + poseName +
"__"),
" ",
"_");
1828 CoordData& d = accumulatedUpdateData.coord[entryName];
1836 DebugDrawerComponent::removePoseDebugLayerVisu(
const std::string& poseName,
const Ice::Current&)
1838 removePoseVisu(DEBUG_LAYER_NAME, poseName);
1842 DebugDrawerComponent::setLineVisu(
const std::string& layerName,
1843 const std::string& lineName,
1844 const Vector3BasePtr& globalPosition1,
1845 const Vector3BasePtr& globalPosition2,
1847 const DrawColor& color,
1848 const Ice::Current&)
1850 Eigen::Vector3f p1 = Vector3Ptr::dynamicCast(globalPosition1)->toEigen();
1851 Eigen::Vector3f p2 = Vector3Ptr::dynamicCast(globalPosition2)->toEigen();
1854 auto l = getScopedAccumulatedDataLock();
1855 std::string entryName = simox::alg::replace_all(
1856 std::string(
"__" + layerName +
"__" + lineName +
"__"),
" ",
"_");
1857 LineData& d = accumulatedUpdateData.line[entryName];
1863 d.
scale = lineWidth;
1869 DebugDrawerComponent::setLineDebugLayerVisu(
const std::string& lineName,
1870 const Vector3BasePtr& globalPosition1,
1871 const Vector3BasePtr& globalPosition2,
1873 const DrawColor& color,
1874 const Ice::Current&)
1876 setLineVisu(DEBUG_LAYER_NAME, lineName, globalPosition1, globalPosition2, lineWidth, color);
1880 DebugDrawerComponent::removeLineVisu(
const std::string& layerName,
1881 const std::string& lineName,
1882 const Ice::Current&)
1885 auto l = getScopedAccumulatedDataLock();
1886 std::string entryName = simox::alg::replace_all(
1887 std::string(
"__" + layerName +
"__" + lineName +
"__"),
" ",
"_");
1888 LineData& d = accumulatedUpdateData.line[entryName];
1896 DebugDrawerComponent::removeLineDebugLayerVisu(
const std::string& lineName,
const Ice::Current&)
1898 removeLineVisu(DEBUG_LAYER_NAME, lineName);
1902 DebugDrawerComponent::setLineSetVisu(
const std::string& layerName,
1903 const std::string& lineSetName,
1904 const DebugDrawerLineSet& lineSet,
1905 const Ice::Current&)
1909 auto l = getScopedAccumulatedDataLock();
1910 std::string entryName = simox::alg::replace_all(
1911 std::string(
"__" + layerName +
"__" + lineSetName +
"__"),
" ",
"_");
1915 d.
name = lineSetName;
1921 DebugDrawerComponent::setLineSetDebugLayerVisu(
const std::string& lineSetName,
1922 const DebugDrawerLineSet& lineSet,
1923 const Ice::Current&)
1925 setLineSetVisu(DEBUG_LAYER_NAME, lineSetName, lineSet);
1929 DebugDrawerComponent::removeLineSetVisu(
const std::string& layerName,
1930 const std::string& lineSetName,
1931 const Ice::Current&)
1934 auto l = getScopedAccumulatedDataLock();
1935 std::string entryName = simox::alg::replace_all(
1936 std::string(
"__" + layerName +
"__" + lineSetName +
"__"),
" ",
"_");
1939 d.
name = lineSetName;
1945 DebugDrawerComponent::removeLineSetDebugLayerVisu(
const std::string& lineSetName,
1946 const Ice::Current&)
1948 removeLineSetVisu(DEBUG_LAYER_NAME, lineSetName);
1952 DebugDrawerComponent::setBoxVisu(
const std::string& layerName,
1953 const std::string& boxName,
1954 const PoseBasePtr& globalPose,
1955 const Vector3BasePtr& dimensions,
1956 const DrawColor& color,
1957 const Ice::Current&)
1962 auto l = getScopedAccumulatedDataLock();
1963 std::string entryName = simox::alg::replace_all(
1964 std::string(
"__" + layerName +
"__" + boxName +
"__"),
" ",
"_");
1965 BoxData& d = accumulatedUpdateData.box[entryName];
1966 d.
width = dimensions->x;
1967 d.
height = dimensions->y;
1968 d.
depth = dimensions->z;
1978 DebugDrawerComponent::setBoxDebugLayerVisu(
const std::string& boxName,
1979 const PoseBasePtr& globalPose,
1980 const Vector3BasePtr& dimensions,
1981 const DrawColor& color,
1982 const Ice::Current&)
1984 setBoxVisu(DEBUG_LAYER_NAME, boxName, globalPose, dimensions, color);
1988 DebugDrawerComponent::removeBoxVisu(
const std::string& layerName,
1989 const std::string& boxName,
1990 const Ice::Current&)
1993 auto l = getScopedAccumulatedDataLock();
1994 std::string entryName = simox::alg::replace_all(
1995 std::string(
"__" + layerName +
"__" + boxName +
"__"),
" ",
"_");
1996 BoxData& d = accumulatedUpdateData.box[entryName];
2004 DebugDrawerComponent::removeBoxDebugLayerVisu(
const std::string& boxName,
const Ice::Current&)
2006 removeBoxVisu(DEBUG_LAYER_NAME, boxName);
2010 DebugDrawerComponent::setTextVisu(
const std::string& layerName,
2011 const std::string& textName,
2012 const std::string& text,
2013 const Vector3BasePtr& globalPosition,
2014 const DrawColor& color,
2016 const Ice::Current&)
2020 auto l = getScopedAccumulatedDataLock();
2021 std::string entryName = simox::alg::replace_all(
2022 std::string(
"__" + layerName +
"__" + textName +
"__"),
" ",
"_");
2025 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
2036 DebugDrawerComponent::setTextDebugLayerVisu(
const std::string& textName,
2037 const std::string& text,
2038 const Vector3BasePtr& globalPosition,
2039 const DrawColor& color,
2041 const Ice::Current&)
2043 setTextVisu(DEBUG_LAYER_NAME, textName, text, globalPosition, color, size);
2047 DebugDrawerComponent::removeTextVisu(
const std::string& layerName,
2048 const std::string& textName,
2049 const Ice::Current&)
2052 auto l = getScopedAccumulatedDataLock();
2053 std::string entryName = simox::alg::replace_all(
2054 std::string(
"__" + layerName +
"__" + textName +
"__"),
" ",
"_");
2063 DebugDrawerComponent::removeTextDebugLayerVisu(
const std::string& textName,
const Ice::Current&)
2065 removeTextVisu(DEBUG_LAYER_NAME, textName);
2069 DebugDrawerComponent::setSphereVisu(
const std::string& layerName,
2070 const std::string& sphereName,
2071 const Vector3BasePtr& globalPosition,
2072 const DrawColor& color,
2074 const Ice::Current&)
2078 auto l = getScopedAccumulatedDataLock();
2079 std::string entryName = simox::alg::replace_all(
2080 std::string(
"__" + layerName +
"__" + sphereName +
"__"),
" ",
"_");
2081 SphereData& d = accumulatedUpdateData.sphere[entryName];
2083 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
2085 d.
name = sphereName;
2093 DebugDrawerComponent::setSphereDebugLayerVisu(
const std::string& sphereName,
2094 const Vector3BasePtr& globalPosition,
2095 const DrawColor& color,
2097 const Ice::Current&)
2099 setSphereVisu(DEBUG_LAYER_NAME, sphereName, globalPosition, color, radius);
2103 DebugDrawerComponent::removeSphereVisu(
const std::string& layerName,
2104 const std::string& sphereName,
2105 const Ice::Current&)
2108 auto l = getScopedAccumulatedDataLock();
2109 std::string entryName = simox::alg::replace_all(
2110 std::string(
"__" + layerName +
"__" + sphereName +
"__"),
" ",
"_");
2111 SphereData& d = accumulatedUpdateData.sphere[entryName];
2113 d.
name = sphereName;
2119 DebugDrawerComponent::removeSphereDebugLayerVisu(
const std::string& sphereName,
2120 const Ice::Current&)
2122 removeSphereVisu(DEBUG_LAYER_NAME, sphereName);
2126 DebugDrawerComponent::setCylinderVisu(
const std::string& layerName,
2127 const std::string& cylinderName,
2128 const Vector3BasePtr& globalPosition,
2129 const Vector3BasePtr& direction,
2132 const DrawColor& color,
2133 const Ice::Current&)
2137 auto l = getScopedAccumulatedDataLock();
2138 std::string entryName = simox::alg::replace_all(
2139 std::string(
"__" + layerName +
"__" + cylinderName +
"__"),
" ",
"_");
2140 CylinderData& d = accumulatedUpdateData.cylinder[entryName];
2141 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
2142 d.
direction = Vector3Ptr::dynamicCast(direction)->toEigen();
2146 d.
name = cylinderName;
2154 DebugDrawerComponent::setCylinderDebugLayerVisu(
const std::string& cylinderName,
2155 const Vector3BasePtr& globalPosition,
2156 const Vector3BasePtr& direction,
2159 const DrawColor& color,
2160 const Ice::Current&)
2163 DEBUG_LAYER_NAME, cylinderName, globalPosition, direction, length, radius, color);
2167 DebugDrawerComponent::removeCylinderVisu(
const std::string& layerName,
2168 const std::string& cylinderName,
2169 const Ice::Current&)
2172 auto l = getScopedAccumulatedDataLock();
2173 std::string entryName = simox::alg::replace_all(
2174 std::string(
"__" + layerName +
"__" + cylinderName +
"__"),
" ",
"_");
2175 CylinderData& d = accumulatedUpdateData.cylinder[entryName];
2177 d.
name = cylinderName;
2183 DebugDrawerComponent::removeCylinderDebugLayerVisu(
const std::string& cylinderName,
2184 const Ice::Current&)
2186 removeCylinderVisu(DEBUG_LAYER_NAME, cylinderName);
2190 DebugDrawerComponent::setPointCloudVisu(
const std::string& layerName,
2191 const std::string& pointCloudName,
2192 const DebugDrawerPointCloud& pointCloud,
2193 const Ice::Current&)
2197 auto l = getScopedAccumulatedDataLock();
2198 std::string entryName = simox::alg::replace_all(
2199 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2203 d.
name = pointCloudName;
2209 DebugDrawerComponent::setPointCloudDebugLayerVisu(
const std::string& pointCloudName,
2210 const DebugDrawerPointCloud& pointCloud,
2211 const Ice::Current&)
2213 setPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
2217 DebugDrawerComponent::removePointCloudVisu(
const std::string& layerName,
2218 const std::string& pointCloudName,
2219 const Ice::Current&)
2222 auto l = getScopedAccumulatedDataLock();
2223 std::string entryName = simox::alg::replace_all(
2224 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2227 d.
name = pointCloudName;
2233 DebugDrawerComponent::removePointCloudDebugLayerVisu(
const std::string& pointCloudName,
2234 const Ice::Current&)
2236 removePointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
2240 DebugDrawerComponent::setPolygonVisu(
const std::string& layerName,
2241 const std::string& polygonName,
2242 const std::vector<Vector3BasePtr>& polygonPoints,
2243 const DrawColor& colorInner,
2244 const DrawColor& colorBorder,
2246 const Ice::Current&)
2249 auto l = getScopedAccumulatedDataLock();
2250 std::string entryName = simox::alg::replace_all(
2251 std::string(
"__" + layerName +
"__" + polygonName +
"__"),
" ",
"_");
2252 PolygonData& d = accumulatedUpdateData.polygons[entryName];
2254 std::vector<Eigen::Vector3f> points;
2256 for (
size_t i = 0; i < polygonPoints.size(); i++)
2258 Eigen::Vector3f p = Vector3Ptr::dynamicCast(polygonPoints.at(i))->toEigen();
2260 points.push_back(p);
2265 colorInner.r, colorInner.g, colorInner.b, 1 - colorInner.a);
2268 colorBorder.r, colorBorder.g, colorBorder.b, 1 - colorBorder.a);
2273 d.
name = polygonName;
2279 DebugDrawerComponent::setPolygonDebugLayerVisu(
const std::string& polygonName,
2280 const std::vector<Vector3BasePtr>& polygonPoints,
2281 const DrawColor& colorInner,
2282 const DrawColor& colorBorder,
2284 const Ice::Current&)
2287 DEBUG_LAYER_NAME, polygonName, polygonPoints, colorInner, colorBorder, lineWidth);
2291 DebugDrawerComponent::removePolygonVisu(
const std::string& layerName,
2292 const std::string& polygonName,
2293 const Ice::Current&)
2296 auto l = getScopedAccumulatedDataLock();
2297 std::string entryName = simox::alg::replace_all(
2298 std::string(
"__" + layerName +
"__" + polygonName +
"__"),
" ",
"_");
2299 PolygonData& d = accumulatedUpdateData.polygons[entryName];
2301 d.
name = polygonName;
2307 DebugDrawerComponent::removePolygonDebugLayerVisu(
const std::string& polygonName,
2308 const Ice::Current&)
2310 removePolygonVisu(DEBUG_LAYER_NAME, polygonName);
2314 DebugDrawerComponent::setTriMeshVisu(
const std::string& layerName,
2315 const std::string& triMeshName,
2316 const DebugDrawerTriMesh& triMesh,
2317 const Ice::Current&)
2320 auto l = getScopedAccumulatedDataLock();
2321 std::string entryName = simox::alg::replace_all(
2322 std::string(
"__" + layerName +
"__" + triMeshName +
"__"),
" ",
"_");
2323 TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2326 d.
name = triMeshName;
2332 DebugDrawerComponent::setTriMeshDebugLayerVisu(
const std::string& triMeshName,
2333 const DebugDrawerTriMesh& triMesh,
2334 const Ice::Current&)
2336 setTriMeshVisu(DEBUG_LAYER_NAME, triMeshName, triMesh);
2340 DebugDrawerComponent::removeTriMeshVisu(
const std::string& layerName,
2341 const std::string& triMeshName,
2342 const Ice::Current&)
2345 auto l = getScopedAccumulatedDataLock();
2346 std::string entryName = simox::alg::replace_all(
2347 std::string(
"__" + layerName +
"__" + triMeshName +
"__"),
" ",
"_");
2348 TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2350 d.
name = triMeshName;
2356 DebugDrawerComponent::removeTriMeshDebugLayerVisu(
const std::string& triMeshName,
2357 const Ice::Current&)
2359 removeTriMeshVisu(DEBUG_LAYER_NAME, triMeshName);
2363 DebugDrawerComponent::setArrowVisu(
const std::string& layerName,
2364 const std::string& arrowName,
2365 const Vector3BasePtr& position,
2366 const Vector3BasePtr& direction,
2367 const DrawColor& color,
2370 const Ice::Current&)
2373 auto l = getScopedAccumulatedDataLock();
2374 std::string entryName = simox::alg::replace_all(
2375 std::string(
"__" + layerName +
"__" + arrowName +
"__"),
" ",
"_");
2376 ArrowData& d = accumulatedUpdateData.arrows[entryName];
2377 d.
position = Vector3Ptr::dynamicCast(position)->toEigen();
2378 d.
direction = Vector3Ptr::dynamicCast(direction)->toEigen();
2391 DebugDrawerComponent::setArrowDebugLayerVisu(
const std::string& arrowName,
2392 const Vector3BasePtr& position,
2393 const Vector3BasePtr& direction,
2394 const DrawColor& color,
2397 const Ice::Current&)
2399 setArrowVisu(DEBUG_LAYER_NAME, arrowName, position, direction, color, length, width);
2403 DebugDrawerComponent::removeArrowVisu(
const std::string& layerName,
2404 const std::string& arrowName,
2405 const Ice::Current&)
2408 auto l = getScopedAccumulatedDataLock();
2409 std::string entryName = simox::alg::replace_all(
2410 std::string(
"__" + layerName +
"__" + arrowName +
"__"),
" ",
"_");
2411 ArrowData& d = accumulatedUpdateData.arrows[entryName];
2419 DebugDrawerComponent::removeArrowDebugLayerVisu(
const std::string& arrowName,
2420 const Ice::Current&)
2422 removeArrowVisu(DEBUG_LAYER_NAME, arrowName);
2426 DebugDrawerComponent::setRobotVisu(
const std::string& layerName,
2427 const std::string& robotName,
2428 const std::string& robotFile,
2429 const std::string& armarxProject,
2430 DrawStyle drawStyle,
2431 const Ice::Current&)
2433 auto l = getScopedAccumulatedDataLock();
2434 std::string entryName = simox::alg::replace_all(
2435 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2436 ARMARX_DEBUG <<
"setting robot visualization for " << entryName;
2437 RobotData& d = accumulatedUpdateData.robots[entryName];
2449 DebugDrawerComponent::updateRobotPose(
const std::string& layerName,
2450 const std::string& robotName,
2451 const PoseBasePtr& globalPose,
2452 const Ice::Current&)
2454 auto l = getScopedAccumulatedDataLock();
2455 std::string entryName = simox::alg::replace_all(
2456 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2457 ARMARX_DEBUG <<
"updating robot pose for " << entryName;
2458 RobotData& d = accumulatedUpdateData.robots[entryName];
2463 d.
globalPose = PosePtr::dynamicCast(globalPose)->toEigen();
2471 DebugDrawerComponent::updateRobotConfig(
const std::string& layerName,
2472 const std::string& robotName,
2473 const std::map<std::string, float>& configuration,
2474 const Ice::Current&)
2476 auto l = getScopedAccumulatedDataLock();
2477 std::string entryName = simox::alg::replace_all(
2478 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2479 ARMARX_DEBUG <<
"updating robot config for " << entryName;
2480 RobotData& d = accumulatedUpdateData.robots[entryName];
2488 for (
auto& it : configuration)
2497 DebugDrawerComponent::updateRobotColor(
const std::string& layerName,
2498 const std::string& robotName,
2500 const Ice::Current&)
2502 auto l = getScopedAccumulatedDataLock();
2503 std::string entryName = simox::alg::replace_all(
2504 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2505 ARMARX_DEBUG <<
"updating robot color for " << entryName;
2506 RobotData& d = accumulatedUpdateData.robots[entryName];
2514 if (
c.a == 0 &&
c.b == 0 &&
c.r == 0 &&
c.g == 0)
2516 d.
color = VirtualRobot::VisualizationFactory::Color::None();
2527 DebugDrawerComponent::updateRobotNodeColor(
const std::string& layerName,
2528 const std::string& robotName,
2529 const std::string& robotNodeName,
2531 const Ice::Current&)
2533 auto l = getScopedAccumulatedDataLock();
2534 std::string entryName = simox::alg::replace_all(
2535 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2536 ARMARX_DEBUG <<
"updating robot color for " << entryName;
2537 RobotData& d = accumulatedUpdateData.robots[entryName];
2544 if (
c.a == 0 &&
c.b == 0 &&
c.r == 0 &&
c.g == 0)
2546 d.
nodeColors[robotNodeName] = VirtualRobot::VisualizationFactory::Color::None();
2558 DebugDrawerComponent::removeRobotVisu(
const std::string& layerName,
2559 const std::string& robotName,
2560 const Ice::Current&)
2562 auto l = getScopedAccumulatedDataLock();
2563 std::string entryName = simox::alg::replace_all(
2564 std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2565 ARMARX_DEBUG <<
"removing robot visu for " << entryName;
2566 RobotData& d = accumulatedUpdateData.robots[entryName];
2574 DebugDrawerComponent::clearAll(
const Ice::Current&)
2576 for (
auto& i : layers)
2578 clearLayer(i.first);
2583 DebugDrawerComponent::clearLayer(
const std::string& layerName,
const Ice::Current&)
2585 auto lockData = getScopedAccumulatedDataLock();
2589 removeAccumulatedData(layerName);
2590 accumulatedUpdateData.clearLayers.emplace(layerName);
2594 DebugDrawerComponent::clearLayerQt(
const std::string& layerName)
2596 auto lockData = getScopedAccumulatedDataLock();
2597 auto lockVisu = getScopedVisuLock();
2601 if (!hasLayer(layerName))
2606 <<
" can't be cleared, because it does not exist.";
2617 selectionNode->deselectAll();
2619 Layer& layer = layers.at(layerName);
2623 removePoseVisu(layerName, i.first);
2628 removeLineVisu(layerName, i.first);
2633 removeLineSetVisu(layerName, i.first);
2638 removeBoxVisu(layerName, i.first);
2643 removeTextVisu(layerName, i.first);
2648 removeSphereVisu(layerName, i.first);
2653 removeCylinderVisu(layerName, i.first);
2658 removeCircleVisu(layerName, i.first);
2663 removePointCloudVisu(layerName, i.first);
2668 removeColoredPointCloudVisu(layerName, i.first);
2673 removePolygonVisu(layerName, i.first);
2678 removeTriMeshVisu(layerName, i.first);
2683 remove24BitColoredPointCloudVisu(layerName, i.first);
2688 removeArrowVisu(layerName, i.first);
2693 removeRobotVisu(layerName, i.first);
2698 removeCustomVisu(layerName, i.first);
2703 DebugDrawerComponent::clearDebugLayer(
const Ice::Current&)
2705 clearLayer(DEBUG_LAYER_NAME);
2740 DebugDrawerComponent::getVisualization()
2746 DebugDrawerComponent::requestLayer(
const std::string& layerName)
2748 auto l = getScopedVisuLock();
2750 if (hasLayer(layerName))
2752 return layers.at(layerName);
2757 SoSeparator* mainNode =
new SoSeparator{};
2759 layers[layerName] =
Layer();
2760 layers.at(layerName).mainNode = mainNode;
2761 layers.at(layerName).visible = getDefaultLayerVisibility(layerName);
2762 if (layers.at(layerName).visible)
2764 layerMainNode->addChild(mainNode);
2766 return layers.at(layerName);
2770 DebugDrawerComponent::updateVisualization()
2772 auto lockData = getScopedAccumulatedDataLock();
2773 auto lockVisu = getScopedVisuLock();
2777 for (
const auto& layer : accumulatedUpdateData.clearLayers)
2779 clearLayerQt(layer);
2781 accumulatedUpdateData.clearLayers.clear();
2783 for (
const auto& layer : accumulatedUpdateData.removeLayers)
2785 removeLayerQt(layer);
2787 accumulatedUpdateData.removeLayers.clear();
2790 for (
auto& e : accumulatedUpdateData.coord)
2792 drawCoordSystem(e.second);
2794 accumulatedUpdateData.coord.clear();
2796 for (
auto& e : accumulatedUpdateData.box)
2800 accumulatedUpdateData.box.clear();
2802 for (
auto& e : accumulatedUpdateData.line)
2806 accumulatedUpdateData.line.clear();
2808 for (
auto& e : accumulatedUpdateData.lineSet)
2810 drawLineSet(e.second);
2812 accumulatedUpdateData.lineSet.clear();
2814 for (
auto& e : accumulatedUpdateData.sphere)
2816 drawSphere(e.second);
2818 accumulatedUpdateData.sphere.clear();
2820 for (
auto& e : accumulatedUpdateData.cylinder)
2822 drawCylinder(e.second);
2824 accumulatedUpdateData.cylinder.clear();
2826 for (
auto& e : accumulatedUpdateData.circle)
2828 drawCircle(e.second);
2830 accumulatedUpdateData.circle.clear();
2832 for (
auto& e : accumulatedUpdateData.text)
2836 accumulatedUpdateData.text.clear();
2838 for (
auto& e : accumulatedUpdateData.pointcloud)
2840 drawPointCloud(e.second);
2842 accumulatedUpdateData.pointcloud.clear();
2844 for (
auto& e : accumulatedUpdateData.polygons)
2846 drawPolygon(e.second);
2848 accumulatedUpdateData.polygons.clear();
2850 for (
auto& e : accumulatedUpdateData.arrows)
2852 drawArrow(e.second);
2854 accumulatedUpdateData.arrows.clear();
2856 for (
auto& e : accumulatedUpdateData.triMeshes)
2858 drawTriMesh(e.second);
2860 accumulatedUpdateData.triMeshes.clear();
2862 for (
auto& e : accumulatedUpdateData.robots)
2864 ARMARX_DEBUG <<
"update visu / drawRobot for robot " << e.first;
2865 ensureExistingRobotNodes(e.second);
2867 drawRobot(e.second);
2868 e.second.nodeColors.clear();
2870 accumulatedUpdateData.robots.clear();
2872 for (
auto& e : accumulatedUpdateData.coloredpointcloud)
2874 drawColoredPointCloud(e.second);
2876 accumulatedUpdateData.coloredpointcloud.clear();
2878 for (
auto& e : accumulatedUpdateData.colored24Bitpointcloud)
2880 draw24BitColoredPointCloud(e.second);
2882 accumulatedUpdateData.colored24Bitpointcloud.clear();
2884 onUpdateVisualization();
2888 DebugDrawerComponent::hasLayer(
const std::string& layerName, const ::Ice::Current&)
2890 auto l = getScopedVisuLock();
2891 return layers.find(layerName) != layers.end();
2895 DebugDrawerComponent::removeLayer(
const std::string& layerName, const ::Ice::Current&)
2897 auto lockData = getScopedAccumulatedDataLock();
2901 removeAccumulatedData(layerName);
2902 accumulatedUpdateData.removeLayers.emplace(layerName);
2906 DebugDrawerComponent::removeLayerQt(
const std::string& layerName)
2908 auto lockData = getScopedAccumulatedDataLock();
2909 auto lockVisu = getScopedVisuLock();
2910 if (!hasLayer(layerName))
2915 <<
" can't be removed, because it does not exist.";
2926 clearLayerQt(layerName);
2928 auto& layer = layers.at(layerName);
2929 layerMainNode->removeChild(layer.mainNode);
2930 layer.mainNode->unref();
2931 layers.erase(layerName);
2935 template <
class UpdateDataType>
2938 std::map<std::string, UpdateDataType>& map)
2940 auto it = map.begin();
2941 while (it != map.end())
2944 if (curr->second.layerName == layerName)
2952 DebugDrawerComponent::removeAccumulatedData(
const std::string& layerName)
2954 auto lockData = getScopedAccumulatedDataLock();
2971 onRemoveAccumulatedData(layerName);
2975 DebugDrawerComponent::enableLayerVisu(
const std::string& layerName,
2977 const ::Ice::Current&)
2979 setLayerVisibility(layerName, visible);
2983 DebugDrawerComponent::enableDebugLayerVisu(
bool visible, const ::Ice::Current&)
2985 enableLayerVisu(DEBUG_LAYER_NAME, visible);
2989 DebugDrawerComponent::layerNames(const ::Ice::Current&)
2991 auto l = getScopedVisuLock();
2992 Ice::StringSeq seq{};
2994 for (
const auto& layer : layers)
2996 seq.push_back(layer.first);
3002 ::armarx::LayerInformationSequence
3003 DebugDrawerComponent::layerInformation(const ::Ice::Current&)
3005 ::armarx::LayerInformationSequence seq{};
3006 auto l = getScopedVisuLock();
3008 for (
const auto& layer : layers)
3010 int count = layer.second.addedCoordVisualizations.size() +
3011 layer.second.addedLineVisualizations.size() +
3012 layer.second.addedLineSetVisualizations.size() +
3013 layer.second.addedBoxVisualizations.size() +
3014 layer.second.addedTextVisualizations.size() +
3015 layer.second.addedSphereVisualizations.size() +
3016 layer.second.addedCylinderVisualizations.size() +
3017 layer.second.addedCircleVisualizations.size() +
3018 layer.second.addedPointCloudVisualizations.size() +
3019 layer.second.addedColoredPointCloudVisualizations.size() +
3020 layer.second.added24BitColoredPointCloudVisualizations.size() +
3021 layer.second.addedPolygonVisualizations.size() +
3022 layer.second.addedTriMeshVisualizations.size() +
3023 layer.second.addedArrowVisualizations.size() +
3024 layer.second.addedRobotVisualizations.size() +
3025 layer.second.addedCustomVisualizations.size();
3026 ::armarx::LayerInformation info = {layer.first, layer.second.visible, count};
3027 seq.push_back(info);
3036 auto l = getScopedVisuLock();
3038 auto& layer = requestLayer(d.
layerName);
3049 SoSeparator* pclSep =
new SoSeparator;
3051 SoMaterial* pclMat =
new SoMaterial;
3052 std::vector<SbColor> colors;
3053 colors.reserve(
pcl.size());
3056 std::back_inserter(colors),
3057 [](
const DebugDrawerColoredPointCloudElement& elem) {
3058 return SbColor{elem.color.r, elem.color.g, elem.color.b};
3060 pclMat->diffuseColor.setValues(0, colors.size(), colors.data());
3061 pclMat->ambientColor.setValues(0, colors.size(), colors.data());
3062 pclSep->addChild(pclMat);
3064 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
3065 pclMatBind->value = SoMaterialBinding::PER_PART;
3066 pclSep->addChild(pclMatBind);
3068 SoCoordinate3* pclCoords =
new SoCoordinate3;
3069 std::vector<SbVec3f> coords;
3070 coords.reserve(
pcl.size());
3073 std::back_inserter(coords),
3074 [](
const DebugDrawerColoredPointCloudElement& elem) {
3075 return SbVec3f{elem.x, elem.y, elem.z};
3077 pclCoords->point.setValues(0, coords.size(), coords.data());
3078 pclSep->addChild(pclCoords);
3080 SoDrawStyle* pclStye =
new SoDrawStyle;
3081 pclStye->pointSize = d.pointCloud.pointSize;
3082 pclSep->addChild(pclStye);
3084 pclSep->addChild(
new SoPointSet);
3088 layer.addedColoredPointCloudVisualizations[d.name] = pclSep;
3089 layer.mainNode->addChild(pclSep);
3093 DebugDrawerComponent::removeColoredPointCloud(
const std::string& layerName,
3094 const std::string& name)
3096 auto l = getScopedVisuLock();
3098 if (!hasLayer(layerName))
3103 auto& layer = layers.at(layerName);
3105 if (layer.addedColoredPointCloudVisualizations.find(name) ==
3106 layer.addedColoredPointCloudVisualizations.end())
3111 layer.mainNode->removeChild(layer.addedColoredPointCloudVisualizations[name]);
3112 layer.addedColoredPointCloudVisualizations.erase(name);
3116 DebugDrawerComponent::setColoredPointCloudVisu(
const std::string& layerName,
3117 const std::string& pointCloudName,
3118 const DebugDrawerColoredPointCloud& pointCloud,
3119 const Ice::Current&)
3122 auto l = getScopedAccumulatedDataLock();
3123 std::string entryName = simox::alg::replace_all(
3124 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
3128 d.
name = pointCloudName;
3134 DebugDrawerComponent::setColoredPointCloudDebugLayerVisu(
3135 const std::string& pointCloudName,
3136 const DebugDrawerColoredPointCloud& pointCloud,
3137 const Ice::Current&)
3139 setColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
3143 DebugDrawerComponent::removeColoredPointCloudVisu(
const std::string& layerName,
3144 const std::string& pointCloudName,
3145 const Ice::Current&)
3148 auto l = getScopedAccumulatedDataLock();
3149 std::string entryName = simox::alg::replace_all(
3150 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
3153 d.
name = pointCloudName;
3159 DebugDrawerComponent::removeColoredPointCloudDebugLayerVisu(
const std::string& pointCloudName,
3160 const Ice::Current&)
3162 removeColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
3168 auto l = getScopedVisuLock();
3170 auto& layer = requestLayer(d.
layerName);
3181 SoSeparator* pclSep =
new SoSeparator;
3183 SoMaterial* pclMat =
new SoMaterial;
3184 std::vector<SbColor> colors;
3185 colors.reserve(
pcl.size());
3188 std::back_inserter(colors),
3189 [](
const DebugDrawer24BitColoredPointCloudElement& elem)
3191 return SbColor{static_cast<float>(elem.color.r) / 255.f,
3192 static_cast<float>(elem.color.g) / 255.f,
3193 static_cast<float>(elem.color.b) / 255.f};
3195 pclMat->diffuseColor.setValues(0, colors.size(), colors.data());
3196 pclMat->ambientColor.setValues(0, colors.size(), colors.data());
3197 pclMat->transparency = d.pointCloud.transparency;
3198 pclSep->addChild(pclMat);
3200 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
3201 pclMatBind->value = SoMaterialBinding::PER_PART;
3202 pclSep->addChild(pclMatBind);
3204 SoCoordinate3* pclCoords =
new SoCoordinate3;
3205 std::vector<SbVec3f> coords;
3206 coords.reserve(
pcl.size());
3209 std::back_inserter(coords),
3210 [](
const DebugDrawer24BitColoredPointCloudElement& elem) {
3211 return SbVec3f{elem.x, elem.y, elem.z};
3213 pclCoords->point.setValues(0, coords.size(), coords.data());
3214 pclSep->addChild(pclCoords);
3216 SoDrawStyle* pclStye =
new SoDrawStyle;
3217 pclStye->pointSize = d.pointCloud.pointSize;
3218 pclSep->addChild(pclStye);
3220 pclSep->addChild(
new SoPointSet);
3224 layer.added24BitColoredPointCloudVisualizations[d.name] = pclSep;
3225 layer.mainNode->addChild(pclSep);
3229 DebugDrawerComponent::remove24BitColoredPointCloud(
const std::string& layerName,
3230 const std::string& name)
3232 auto l = getScopedVisuLock();
3234 if (!hasLayer(layerName))
3239 auto& layer = layers.at(layerName);
3241 if (layer.added24BitColoredPointCloudVisualizations.find(name) ==
3242 layer.added24BitColoredPointCloudVisualizations.end())
3247 layer.mainNode->removeChild(layer.added24BitColoredPointCloudVisualizations[name]);
3248 layer.added24BitColoredPointCloudVisualizations.erase(name);
3252 DebugDrawerComponent::set24BitColoredPointCloudVisu(
3253 const std::string& layerName,
3254 const std::string& pointCloudName,
3255 const DebugDrawer24BitColoredPointCloud& pointCloud,
3256 const Ice::Current&)
3259 auto l = getScopedAccumulatedDataLock();
3260 std::string entryName = simox::alg::replace_all(
3261 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
3265 d.
name = pointCloudName;
3271 DebugDrawerComponent::set24BitColoredPointCloudDebugLayerVisu(
3272 const std::string& pointCloudName,
3273 const DebugDrawer24BitColoredPointCloud& pointCloud,
3274 const Ice::Current&)
3276 set24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
3280 DebugDrawerComponent::remove24BitColoredPointCloudVisu(
const std::string& layerName,
3281 const std::string& pointCloudName,
3282 const Ice::Current&)
3285 auto l = getScopedAccumulatedDataLock();
3286 std::string entryName = simox::alg::replace_all(
3287 std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
3290 d.
name = pointCloudName;
3296 DebugDrawerComponent::remove24BitColoredPointCloudDebugLayerVisu(
3297 const std::string& pointCloudName,
3298 const Ice::Current&)
3300 remove24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
3304 DebugDrawerComponent::setCircleArrowVisu(
const std::string& layerName,
3305 const std::string& circleName,
3306 const Vector3BasePtr& globalPosition,
3307 const Vector3BasePtr& directionVec,
3311 const DrawColor& color,
3312 const Ice::Current&)
3315 auto l = getScopedAccumulatedDataLock();
3316 std::string entryName = simox::alg::replace_all(
3317 std::string(
"__" + layerName +
"__" + circleName +
"__"),
" ",
"_");
3318 CircleData& d = accumulatedUpdateData.circle[entryName];
3319 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
3320 d.
direction = Vector3Ptr::dynamicCast(directionVec)->toEigen();
3325 d.
name = circleName;
3331 DebugDrawerComponent::setCircleDebugLayerVisu(
const std::string& circleName,
3332 const Vector3BasePtr& globalPosition,
3333 const Vector3BasePtr& directionVec,
3337 const DrawColor& color,
3338 const Ice::Current&
c)
3340 setCircleArrowVisu(DEBUG_LAYER_NAME,
3352 DebugDrawerComponent::removeCircleVisu(
const std::string& layerName,
3353 const std::string& circleName,
3354 const Ice::Current&)
3357 auto l = getScopedAccumulatedDataLock();
3358 std::string entryName = simox::alg::replace_all(
3359 std::string(
"__" + layerName +
"__" + circleName +
"__"),
" ",
"_");
3360 CircleData& d = accumulatedUpdateData.circle[entryName];
3362 d.
name = circleName;
3367 DebugDrawerComponent::removeCircleDebugLayerVisu(
const std::string& circleName,
3368 const Ice::Current&
c)
3370 removeCircleVisu(DEBUG_LAYER_NAME, circleName,
c);