30 #include <VirtualRobot/VirtualRobot.h>
31 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
32 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
33 #include <Inventor/nodes/SoUnits.h>
34 #include <Inventor/nodes/SoCube.h>
35 #include <Inventor/nodes/SoMaterial.h>
36 #include <Inventor/nodes/SoAnnotation.h>
37 #include <Inventor/nodes/SoTransform.h>
38 #include <Inventor/nodes/SoFont.h>
39 #include <Inventor/nodes/SoText2.h>
40 #include <Inventor/nodes/SoSphere.h>
41 #include <Inventor/nodes/SoCylinder.h>
42 #include <Inventor/nodes/SoComplexity.h>
43 #include <Inventor/nodes/SoCoordinate3.h>
44 #include <Inventor/nodes/SoPointSet.h>
45 #include <Inventor/actions/SoWriteAction.h>
46 #include <Inventor/nodes/SoTranslation.h>
47 #include <Inventor/nodes/SoMaterialBinding.h>
48 #include <Inventor/nodes/SoDrawStyle.h>
49 #include <Inventor/nodes/SoLineSet.h>
50 #include <Inventor/SbVec3f.h>
51 #include <Inventor/fields/SoMFVec3f.h>
52 #include <Inventor/fields/SoMFColor.h>
53 #include <Inventor/nodes/SoShapeHints.h>
58 #include <SimoxUtility/algorithm/string/string_tools.h>
60 #include <VirtualRobot/Robot.h>
61 #include <VirtualRobot/XML/RobotIO.h>
62 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
63 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationNode.h>
64 #include <VirtualRobot/Visualization/TriMeshModel.h>
68 #define SELECTION_NAME_PREFIX ("selection_" + std::to_string(reinterpret_cast<std::uintptr_t>(this)))
69 #define SELECTION_NAME_SPLITTER "____"
70 #define SELECTION_NAME(layerName, elementName) simox::alg::replace_all(std::string(SELECTION_NAME_PREFIX + "_" + layerName + SELECTION_NAME_SPLITTER + elementName), " ", "_").c_str()
74 std::recursive_mutex DebugDrawerComponent::selectionMutex;
92 static const std::string DEBUG_LAYER_NAME
97 DebugDrawerComponent::DebugDrawerComponent():
101 defaultLayerVisibility(true)
118 SoUnits* u =
new SoUnits();
119 u->units = SoUnits::MILLIMETERS;
128 ARMARX_INFO <<
"Enabling selections for layer " << layerName;
136 ARMARX_INFO <<
"Disabling selections for layer " << layerName;
154 ARMARX_INFO <<
"Clearing selections on layer " << layerName;
164 if (path->containsNode(
layers.at(layerName).mainNode))
181 ARMARX_DEBUG <<
"Selecting element '" << elementName <<
"' on layer '" << layerName <<
"' (internal name: " <<
SELECTION_NAME(layerName, elementName) <<
")";
183 SoNode* n = SoSelection::getByName(
SELECTION_NAME(layerName, elementName));
206 ARMARX_DEBUG <<
"Deselecting element '" << elementName <<
"' on layer '" << layerName <<
"' (internal name: " <<
SELECTION_NAME(layerName, elementName) <<
")";
208 SoNode* n = SoSelection::getByName(
SELECTION_NAME(layerName, elementName));
258 for (
auto& e : selectedElements)
260 SoNode* n = SoSelection::getByName(
SELECTION_NAME(e.layerName, e.elementName));
277 DebugDrawerSelectionList selectedElements;
283 for (
int j = 0; j < path->getLength(); j++)
285 SoNode* node = path->getNodeFromTail(j);
291 std::string name = node->getName().getString();
300 std::string layer = l.first;
301 if (
layers[layer].addedBoxVisualizations.find(name) !=
layers[layer].addedBoxVisualizations.end()
302 ||
layers[layer].addedTextVisualizations.find(name) !=
layers[layer].addedTextVisualizations.end()
303 ||
layers[layer].addedSphereVisualizations.find(name) !=
layers[layer].addedSphereVisualizations.end()
304 ||
layers[layer].addedCylinderVisualizations.find(name) !=
layers[layer].addedCylinderVisualizations.end()
305 ||
layers[layer].addedPolygonVisualizations.find(name) !=
layers[layer].addedPolygonVisualizations.end())
307 DebugDrawerSelectionElement e;
309 e.elementName = name;
311 selectedElements.push_back(e);
322 return selectedElements;
329 ARMARX_ERROR <<
"Cannot change the cycle time, once the thread has been started...";
333 if (visuUpdatesPerSec <= 0)
354 usingTopic(getProperty<std::string>(
"DebugDrawerTopic").getValue());
355 bool enabled = getProperty<bool>(
"ShowDebugDrawing").getValue();
364 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
374 offeringTopic(getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
375 usingTopic(getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
398 listenerPrx = getTopic<DebugDrawerListenerPrx>(getProperty<std::string>(
"DebugDrawerSelectionTopic").getValue());
403 std::cout <<
"onDisconnectComponent debug drawer" << std::endl;
428 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
435 while (
layers.size() > 0 && counter < 2 *
c)
457 SoSeparator* sep =
new SoSeparator;
458 SoUnits* u =
new SoUnits;
459 u->units = SoUnits::MILLIMETERS;
463 SoWriteAction writeAction;
464 writeAction.getOutput()->openFile(
filename.c_str());
465 writeAction.getOutput()->setBinary(
false);
466 writeAction.apply(sep);
467 writeAction.getOutput()->closeFile();
484 SoSeparator* sep =
new SoSeparator;
485 SoUnits* u =
new SoUnits;
486 u->units = SoUnits::MILLIMETERS;
488 sep->addChild(
layers[layerName].mainNode);
490 SoWriteAction writeAction;
491 writeAction.getOutput()->openFile(
filename.c_str());
492 writeAction.getOutput()->setBinary(
false);
493 writeAction.apply(sep);
494 writeAction.getOutput()->closeFile();
515 SoSeparator* newS =
new SoSeparator;
516 SoMatrixTransform* newM =
new SoMatrixTransform;
517 newS->addChild(newM);
518 std::string n = d.
name;
519 newS->addChild(CoinVisualizationFactory::CreateCoordSystemVisualization(d.
scale, &n));
520 layer.addedCoordVisualizations[d.
name] = newS;
521 layer.mainNode->addChild(newS);
523 SoSeparator*
s = layer.addedCoordVisualizations[d.
name];
524 SoMatrixTransform* m = (SoMatrixTransform*)(
s->getChild(0));
525 SbMatrix mNew = CoinVisualizationFactory::getSbMatrix(d.
globalPose);
526 m->matrix.setValue(mNew);
545 SoSeparator* newS =
new SoSeparator;
546 newS->addChild(CoinVisualizationFactory::createCoinLine(d.
p1, d.
p2, d.
scale, d.
color));
547 layer.addedLineVisualizations[d.
name] = newS;
548 layer.mainNode->addChild(newS);
566 if (d.
lineSet.points.size() % 2 != 0)
574 ARMARX_WARNING <<
"Amount of intensities has to be half the amount of points for a line set";
578 for (
const DebugDrawerPointCloudElement& e : d.
lineSet.points)
588 std::vector<VirtualRobot::VisualizationFactory::Color> colors;
591 VirtualRobot::ColorMap visualizationColorMap = VirtualRobot::ColorMap::customColorMap(colors);
594 SoSeparator* sep =
new SoSeparator;
596 SoMaterialBinding* binding =
new SoMaterialBinding;
597 binding->value = SoMaterialBinding::PER_PART;
598 sep->addChild(binding);
600 SoDrawStyle* lineStyle =
new SoDrawStyle;
601 lineStyle->lineWidth.setValue(d.
lineSet.lineWidth);
602 sep->addChild(lineStyle);
604 SoCoordinate3* coordinateNode =
new SoCoordinate3;
605 sep->addChild(coordinateNode);
607 SoMaterial* materialNode =
new SoMaterial;
608 sep->addChild(materialNode);
610 SoLineSet* lineSetNode =
new SoLineSet;
611 lineSetNode->startIndex.setValue(0);
612 sep->addChild(lineSetNode);
616 SbVec3f* coordinateValues =
new SbVec3f[d.
lineSet.points.size()];
617 int32_t* lineSetValues =
new int32_t[d.
lineSet.intensities.size()];
618 SbColor* colorValues =
new SbColor[d.
lineSet.intensities.size()];
620 for (
unsigned int i = 0; i < d.
lineSet.intensities.size(); i++)
622 lineSetValues[i] = 2;
624 coordinateValues[2 * i].setValue(d.
lineSet.points[2 * i].x, d.
lineSet.points[2 * i].y, d.
lineSet.points[2 * i].z);
625 coordinateValues[2 * i + 1].setValue(d.
lineSet.points[2 * i + 1].x, d.
lineSet.points[2 * i + 1].y, d.
lineSet.points[2 * i + 1].z);
630 colorValues[i].setValue(
c.r,
c.g,
c.b);
635 colorValues[i].setValue(
c.r,
c.g,
c.b);
639 coordinateNode->point.setValuesPointer(d.
lineSet.points.size(), coordinateValues);
640 lineSetNode->numVertices.setValuesPointer(d.
lineSet.intensities.size(), lineSetValues);
641 materialNode->ambientColor.setValuesPointer(d.
lineSet.intensities.size(), colorValues);
642 materialNode->diffuseColor.setValuesPointer(d.
lineSet.intensities.size(), colorValues);
644 layer.addedLineSetVisualizations[d.
name] = sep;
645 layer.mainNode->addChild(sep);
662 SoSeparator* newS =
new SoSeparator;
664 newS->addChild(CoinVisualizationFactory::getMatrixTransform(m));
666 SoMaterial* material =
new SoMaterial;
669 material->transparency.setValue(d.
color.transparency);
670 newS->addChild(material);
672 SoCube* cube =
new SoCube;
674 cube->width = d.
width;
676 cube->depth = d.
depth;
677 newS->addChild(cube);
679 layer.addedBoxVisualizations[d.
name] = newS;
680 layer.mainNode->addChild(newS);
697 SoSeparator* sep =
new SoSeparator;
698 SoAnnotation* ann =
new SoAnnotation;
701 SoMaterial* mat =
new SoMaterial;
704 mat->transparency.setValue(d.
color.transparency);
707 SoTransform* tr =
new SoTransform;
711 SoFont* font =
new SoFont;
712 font->name.setValue(
"TGS_Triplex_Roman");
717 SoText2* te =
new SoText2;
719 te->string = d.
text.c_str();
720 te->justification = SoText2::CENTER;
723 layer.addedTextVisualizations[d.
name] = sep;
724 layer.mainNode->addChild(sep);
749 SoSeparator* sep =
new SoSeparator;
750 SoMaterial* mat =
new SoMaterial;
753 mat->transparency.setValue(d.
color.transparency);
756 SoTransform* tr =
new SoTransform;
760 SoSphere* sphere =
new SoSphere;
762 sphere->radius = d.
radius;
763 sep->addChild(sphere);
765 layer.addedSphereVisualizations[d.
name] = sep;
766 layer.mainNode->addChild(sep);
783 SoSeparator* sep =
new SoSeparator;
784 SoMaterial* mat =
new SoMaterial;
787 mat->transparency.setValue(d.
color.transparency);
791 SoTransform* tr =
new SoTransform;
796 SoCylinder* cylinder =
new SoCylinder;
798 cylinder->height = d.
length;
799 cylinder->radius = d.
radius;
800 sep->addChild(cylinder);
802 layer.addedCylinderVisualizations[d.
name] = sep;
803 layer.mainNode->addChild(sep);
809 vec = vec.normalized();
811 dir1 = vec.cross(Eigen::Vector3f(0, 0, 1));
813 if (dir1.norm() < 0.1f)
817 dir1 = vec.cross(Eigen::Vector3f(0, 1, 0));
821 dir1 = -dir1.normalized();
823 dir2 = vec.cross(dir1).normalized();
845 SoSeparator* sep =
new SoSeparator;
846 SoMaterial* mat =
new SoMaterial;
849 mat->transparency.setValue(d.
color.transparency);
853 SoTransform* tr =
new SoTransform;
855 Eigen::Vector3f xDir, yDir;
858 rotGoal << xDir, yDir, zDir;
861 Eigen::AngleAxisf rotAA(rotGoal);
862 tr->rotation.setValue(SbVec3f(rotAA.axis().x(), rotAA.axis().y(), rotAA.axis().z()), rotAA.angle());
864 auto node = CoinVisualizationFactory().createCircleArrow(d.
radius,
869 SoNode* circle =
dynamic_cast<CoinVisualizationNode&
>(*node).getCoinVisualization();
871 sep->addChild(circle);
873 layer.addedCircleVisualizations[d.
name] = sep;
874 layer.mainNode->addChild(sep);
892 SoSeparator* pclSep =
new SoSeparator;
894 SoMaterial* pclMat =
new SoMaterial;
895 pclMat->diffuseColor.setValue(0.2, 0.2, 0.2);
896 pclMat->diffuseColor.setValue(0.2, 0.2, 0.2);
897 pclSep->addChild(pclMat);
899 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
900 pclMatBind->value = SoMaterialBinding::OVERALL;
901 pclSep->addChild(pclMatBind);
903 SoCoordinate3* pclCoords =
new SoCoordinate3;
904 std::vector<SbVec3f> coords;
905 coords.reserve(
pcl.size());
907 pcl.begin(),
pcl.end(), std::back_inserter(coords),
908 [](
const DebugDrawerPointCloudElement & elem)
910 return SbVec3f {elem.x, elem.y, elem.z};
913 pclCoords->point.setValues(0, coords.size(), coords.data());
914 pclSep->addChild(pclCoords);
916 SoDrawStyle* pclStye =
new SoDrawStyle;
917 pclStye->pointSize = d.pointCloud.pointSize;
918 pclSep->addChild(pclStye);
920 pclSep->addChild(
new SoPointSet);
922 layer.addedPointCloudVisualizations[d.name] = pclSep;
923 layer.mainNode->addChild(pclSep);
928 auto l = getScopedVisuLock();
939 SoSeparator* sep =
new SoSeparator;
941 SoShapeHints* hints =
new SoShapeHints;
942 hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
943 hints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
944 hints->faceType = SoShapeHints::UNKNOWN_FACE_TYPE;
945 sep->addChild(hints);
949 layer.addedPolygonVisualizations[d.
name] = sep;
950 layer.mainNode->addChild(sep);
955 auto l = getScopedVisuLock();
966 TriMeshModelPtr triMesh = TriMeshModelPtr(
new TriMeshModel());
968 for (DrawColor color : d.
triMesh.colors)
973 for (DebugDrawerVertex
v : d.
triMesh.vertices)
975 triMesh->addVertex(Eigen::Vector3f(
v.x,
v.y,
v.z));
978 for (DebugDrawerFace f : d.
triMesh.faces)
980 MathTools::TriangleFace face;
982 face.id1 = f.vertex1.vertexID;
983 face.idNormal1 = f.vertex1.normalID;
984 face.idColor1 = f.vertex1.colorID;
986 face.id2 = f.vertex2.vertexID;
987 face.idNormal2 = f.vertex2.normalID;
988 face.idColor2 = f.vertex2.colorID;
990 face.id3 = f.vertex3.vertexID;
991 face.idNormal3 = f.vertex3.normalID;
992 face.idColor3 = f.vertex3.colorID;
994 face.normal = Eigen::Vector3f(f.normal.x, f.normal.y, f.normal.z);
996 triMesh->addFace(face);
999 SoSeparator* sep =
new SoSeparator();
1000 SoNode*
c = CoinVisualizationFactory::getCoinVisualization(triMesh);
1002 layer.addedTriMeshVisualizations[d.
name] = sep;
1003 layer.mainNode->addChild(sep);
1009 auto l = getScopedVisuLock();
1011 auto& layer = requestLayer(d.
layerName);
1020 SoSeparator* sep =
new SoSeparator;
1022 SoTransform* tr =
new SoTransform;
1027 sep->addChild(sepArrow);
1028 layer.addedArrowVisualizations[d.
name] = sep;
1029 layer.mainNode->addChild(sep);
1034 auto l = getScopedVisuLock();
1050 std::map < std::string, float >::iterator i = d.
configuration.begin();
1053 if (!rob->hasRobotNode(i->first))
1067 auto l = getScopedVisuLock();
1069 auto& layer = requestLayer(d.
layerName);
1098 if (layer.addedRobotVisualizations.find(d.
name) == layer.addedRobotVisualizations.end())
1104 SoSeparator* sep = layer.addedRobotVisualizations[d.
name];
1106 for (
int i = 0; i < sep->getNumChildren(); i++)
1108 SoSeparator* nodeSep =
dynamic_cast<SoSeparator*
>(sep->getChild(i));
1109 SoMaterial* m =
dynamic_cast<SoMaterial*
>(nodeSep->getChild(0));
1117 if (d.
color.isNone())
1119 m->setOverride(
false);
1129 m->ambientColor = SbColor(0, 0, 0);
1131 m->setOverride(
true);
1139 if (layer.addedRobotVisualizations.find(d.
name) == layer.addedRobotVisualizations.end())
1145 SoSeparator* sep = layer.addedRobotVisualizations[d.
name];
1147 if (!sep || sep->getNumChildren() < 2)
1153 std::string entryName = simox::alg::replace_all(std::string(
"__" + d.
layerName +
"__" + d.
name +
"__"),
" ",
"_");
1156 std::vector<std::string> nodeNameList;
1158 for (
size_t i = 0; i < robot->getRobotNodes().size(); ++i)
1160 nodeNameList.push_back(robot->getRobotNodes()[i]->getName());
1163 for (std::map < std::string, VirtualRobot::VisualizationFactory::Color >::const_iterator it = d.
nodeColors.begin();
1168 std::string nodeName = it->first;
1171 std::vector<std::string>::iterator strit;
1172 strit = std::find(nodeNameList.begin(), nodeNameList.end(), nodeName);
1174 if (strit == nodeNameList.end())
1176 ARMARX_WARNING <<
"Cannot find correct robot node name " + nodeName +
" for DebugDrawer node color update !!!";
1180 size_t ind = strit - nodeNameList.begin();
1181 SoSeparator* nodeSep =
dynamic_cast<SoSeparator*
>(sep->getChild(ind));
1189 SoMaterial* nodeMat =
dynamic_cast<SoMaterial*
>(nodeSep->getChild(0));
1197 if (nodeColor.isNone())
1199 nodeMat->setOverride(
false);
1203 if (nodeColor.r < 0 || nodeColor.g < 0 || nodeColor.b < 0)
1205 ARMARX_ERROR <<
"Internal robot layer node color error";
1209 nodeMat->diffuseColor = SbColor(nodeColor.r, nodeColor.g, nodeColor.b);
1210 nodeMat->ambientColor = SbColor(0, 0, 0);
1211 nodeMat->transparency =
std::max(0.0f, nodeColor.transparency);
1212 nodeMat->setOverride(
true);
1222 auto l = getScopedVisuLock();
1224 auto& layer = requestLayer(d.
layerName);
1225 std::string entryName = simox::alg::replace_all(std::string(
"__" + d.
layerName +
"__" + d.
name +
"__"),
" ",
"_");
1229 if (activeRobots.find(entryName) != activeRobots.end())
1231 ARMARX_DEBUG <<
"Found robot " << entryName <<
":" << activeRobots[entryName]->getName();
1232 return activeRobots[entryName];
1263 VirtualRobot::SceneObject::VisualizationType visuType = VirtualRobot::SceneObject::Full;
1266 if (d.
drawStyle == DrawStyle::CollisionModel)
1268 visuType = VirtualRobot::SceneObject::Collision;
1269 loadMode = VirtualRobot::RobotIO::eCollisionModel;
1276 if (loadedRobots.find(
filename) == loadedRobots.end())
1294 SoSeparator* sep =
new SoSeparator;
1295 layer.mainNode->addChild(sep);
1297 for (
size_t i = 0; i < result->getRobotNodes().size(); ++i)
1299 VirtualRobot::RobotNodePtr robNode = result->getRobotNodes()[i];
1300 SoSeparator* nodeSep =
new SoSeparator;
1302 SoMaterial* nodeMat =
new SoMaterial;
1303 nodeMat->setOverride(
false);
1304 nodeSep->addChild(nodeMat);
1310 SoNode* sepRobNode = robNodeVisu->getCoinVisualization();
1314 nodeSep->addChild(sepRobNode);
1318 sep->addChild(nodeSep);
1321 activeRobots[entryName] = result;
1322 ARMARX_DEBUG <<
"setting robot to activeRobots, entryName:" << entryName <<
", activeRobots.size():" << activeRobots.size();
1323 layer.addedRobotVisualizations[d.
name] = sep;
1324 ARMARX_DEBUG <<
"adding sep to layer.addedRobotVisualizations, d.name:" << d.
name <<
", layer:" << d.
layerName <<
", layer.addedRobotVisualizations.size():" << layer.addedRobotVisualizations.size();
1329 void DebugDrawerComponent::removeLine(
const std::string& layerName,
const std::string& name)
1331 auto l = getScopedVisuLock();
1333 if (!hasLayer(layerName))
1338 auto& layer = layers.at(layerName);
1340 if (layer.addedLineVisualizations.find(name) == layer.addedLineVisualizations.end())
1345 layer.mainNode->removeChild(layer.addedLineVisualizations[name]);
1346 layer.addedLineVisualizations.erase(name);
1349 void DebugDrawerComponent::removeLineSet(
const std::string& layerName,
const std::string& name)
1351 auto l = getScopedVisuLock();
1353 if (!hasLayer(layerName))
1358 auto& layer = layers.at(layerName);
1360 if (layer.addedLineSetVisualizations.find(name) == layer.addedLineSetVisualizations.end())
1365 layer.mainNode->removeChild(layer.addedLineSetVisualizations[name]);
1366 layer.addedLineSetVisualizations.erase(name);
1369 void DebugDrawerComponent::removeBox(
const std::string& layerName,
const std::string& name)
1371 auto l = getScopedVisuLock();
1373 if (!hasLayer(layerName))
1378 auto& layer = layers.at(layerName);
1380 if (layer.addedBoxVisualizations.find(name) == layer.addedBoxVisualizations.end())
1385 layer.mainNode->removeChild(layer.addedBoxVisualizations[name]);
1386 layer.addedBoxVisualizations.erase(name);
1389 void DebugDrawerComponent::removeText(
const std::string& layerName,
const std::string& name)
1391 auto l = getScopedVisuLock();
1393 if (!hasLayer(layerName))
1398 auto& layer = layers.at(layerName);
1400 if (layer.addedTextVisualizations.find(name) == layer.addedTextVisualizations.end())
1405 layer.mainNode->removeChild(layer.addedTextVisualizations[name]);
1406 layer.addedTextVisualizations.erase(name);
1409 void DebugDrawerComponent::removeSphere(
const std::string& layerName,
const std::string& name)
1411 auto l = getScopedVisuLock();
1413 if (!hasLayer(layerName))
1418 auto& layer = layers.at(layerName);
1420 if (layer.addedSphereVisualizations.find(name) == layer.addedSphereVisualizations.end())
1425 layer.mainNode->removeChild(layer.addedSphereVisualizations[name]);
1426 layer.addedSphereVisualizations.erase(name);
1429 void DebugDrawerComponent::removeCylinder(
const std::string& layerName,
const std::string& name)
1431 auto l = getScopedVisuLock();
1433 if (!hasLayer(layerName))
1438 auto& layer = layers.at(layerName);
1440 if (layer.addedCylinderVisualizations.find(name) == layer.addedCylinderVisualizations.end())
1445 layer.mainNode->removeChild(layer.addedCylinderVisualizations[name]);
1446 layer.addedCylinderVisualizations.erase(name);
1449 void DebugDrawerComponent::removeCircle(
const std::string& layerName,
const std::string& name)
1451 auto l = getScopedVisuLock();
1453 if (!hasLayer(layerName))
1458 auto& layer = layers.at(layerName);
1460 if (layer.addedCircleVisualizations.find(name) == layer.addedCircleVisualizations.end())
1465 layer.mainNode->removeChild(layer.addedCircleVisualizations[name]);
1466 layer.addedCircleVisualizations.erase(name);
1469 void DebugDrawerComponent::removePointCloud(
const std::string& layerName,
const std::string& name)
1471 auto l = getScopedVisuLock();
1473 if (!hasLayer(layerName))
1478 auto& layer = layers.at(layerName);
1480 if (layer.addedPointCloudVisualizations.find(name) == layer.addedPointCloudVisualizations.end())
1485 layer.mainNode->removeChild(layer.addedPointCloudVisualizations[name]);
1486 layer.addedPointCloudVisualizations.erase(name);
1489 void DebugDrawerComponent::removePolygon(
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.addedPolygonVisualizations.find(name) == layer.addedPolygonVisualizations.end())
1505 layer.mainNode->removeChild(layer.addedPolygonVisualizations[name]);
1506 layer.addedPolygonVisualizations.erase(name);
1509 void DebugDrawerComponent::removeTriMesh(
const std::string& layerName,
const std::string& name)
1511 auto l = getScopedVisuLock();
1513 if (!hasLayer(layerName))
1518 auto& layer = layers.at(layerName);
1520 if (layer.addedTriMeshVisualizations.find(name) == layer.addedTriMeshVisualizations.end())
1525 layer.mainNode->removeChild(layer.addedTriMeshVisualizations[name]);
1526 layer.addedTriMeshVisualizations.erase(name);
1529 void DebugDrawerComponent::removeArrow(
const std::string& layerName,
const std::string& name)
1531 auto l = getScopedVisuLock();
1533 if (!hasLayer(layerName))
1538 auto& layer = layers.at(layerName);
1540 if (layer.addedArrowVisualizations.find(name) == layer.addedArrowVisualizations.end())
1545 layer.mainNode->removeChild(layer.addedArrowVisualizations[name]);
1546 layer.addedArrowVisualizations.erase(name);
1549 void DebugDrawerComponent::removeRobot(
const std::string& layerName,
const std::string& name)
1551 auto l = getScopedVisuLock();
1554 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + name +
"__"),
" ",
"_");
1557 if (activeRobots.find(entryName) != activeRobots.end())
1560 activeRobots.erase(entryName);
1561 ARMARX_DEBUG <<
"after Found robot to remove, activeRobots.size() = " << activeRobots.size();
1565 if (!hasLayer(layerName))
1571 auto& layer = layers.at(layerName);
1573 if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1575 ARMARX_INFO <<
"Could not find robot with name " << name;
1579 ARMARX_DEBUG <<
"Removing visualization for " << entryName;
1581 ARMARX_DEBUG <<
"removing sep from layer.addedRobotVisualizations, d.name:" << name <<
", layer:" << layerName <<
", layer.addedRobotVisualizations.size():" << layer.addedRobotVisualizations.size();
1583 if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1589 ARMARX_DEBUG <<
"removing from layer.mainNode, layer.mainNode->getNumChildren()=" << layer.mainNode->getNumChildren();
1591 if (layer.mainNode->findChild(layer.addedRobotVisualizations[name]) < 0)
1597 layer.mainNode->removeChild(layer.addedRobotVisualizations[name]);
1598 layer.addedRobotVisualizations.erase(name);
1599 ARMARX_DEBUG <<
"after removing from layer.mainNode, layer.mainNode->getNumChildren()=" << layer.mainNode->getNumChildren();
1600 ARMARX_DEBUG <<
"after removing sep from layer.addedRobotVisualizations, d.name:" << name <<
", layer:" << layerName <<
", layer.addedRobotVisualizations.size():" << layer.addedRobotVisualizations.size();
1603 void DebugDrawerComponent::removeCoordSystem(
const std::string& layerName,
const std::string& name)
1605 auto l = getScopedVisuLock();
1607 if (!hasLayer(layerName))
1612 auto& layer = layers.at(layerName);
1614 if (layer.addedCoordVisualizations.find(name) == layer.addedCoordVisualizations.end())
1619 layer.mainNode->removeChild(layer.addedCoordVisualizations[name]);
1620 layer.addedCoordVisualizations.erase(name);
1623 void DebugDrawerComponent::setLayerVisibility(
const std::string& layerName,
bool visible)
1625 auto l = getScopedVisuLock();
1627 if (!hasLayer(layerName))
1632 auto& layer = layers.at(layerName);
1633 layer.visible = visible;
1637 if (layerMainNode->findChild(layer.mainNode) < 0)
1639 layerMainNode->addChild(layer.mainNode);
1644 if (layerMainNode->findChild(layer.mainNode) >= 0)
1646 layerMainNode->removeChild(layer.mainNode);
1651 void DebugDrawerComponent::disableAllLayers(const ::Ice::Current&)
1653 auto l = getScopedVisuLock();
1655 if (selectionNode->findChild(layerMainNode) >= 0)
1657 selectionNode->removeChild(layerMainNode);
1661 void DebugDrawerComponent::enableAllLayers(const ::Ice::Current&)
1663 auto l = getScopedVisuLock();
1665 if (selectionNode->findChild(layerMainNode) < 0)
1667 selectionNode->addChild(layerMainNode);
1671 void DebugDrawerComponent::setScaledPoseVisu(
const std::string& layerName,
const std::string& poseName, const ::armarx::PoseBasePtr& globalPose,
const ::Ice::Float scale, const ::Ice::Current&)
1676 auto l = getScopedAccumulatedDataLock();
1677 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + poseName +
"__"),
" ",
"_");
1678 CoordData& d = accumulatedUpdateData.coord[entryName];
1687 void DebugDrawerComponent::setScaledPoseDebugLayerVisu(
const std::string& poseName, const ::armarx::PoseBasePtr& globalPose,
const ::Ice::Float scale, const ::Ice::Current&)
1689 setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, scale);
1692 void DebugDrawerComponent::setPoseVisu(
const std::string& layerName,
const std::string& poseName,
const PoseBasePtr& globalPose,
const Ice::Current&)
1694 setScaledPoseVisu(layerName, poseName, globalPose, 1.f);
1697 void DebugDrawerComponent::setPoseDebugLayerVisu(
const std::string& poseName,
const PoseBasePtr& globalPose,
const Ice::Current&)
1699 setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, 1.f);
1702 void DebugDrawerComponent::removePoseVisu(
const std::string& layerName,
const std::string& poseName,
const Ice::Current&)
1705 auto l = getScopedAccumulatedDataLock();
1706 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + poseName +
"__"),
" ",
"_");
1707 CoordData& d = accumulatedUpdateData.coord[entryName];
1714 void DebugDrawerComponent::removePoseDebugLayerVisu(
const std::string& poseName,
const Ice::Current&)
1716 removePoseVisu(DEBUG_LAYER_NAME, poseName);
1719 void DebugDrawerComponent::setLineVisu(
const std::string& layerName,
const std::string& lineName,
const Vector3BasePtr& globalPosition1,
const Vector3BasePtr& globalPosition2,
float lineWidth,
const DrawColor& color,
const Ice::Current&)
1721 Eigen::Vector3f p1 = Vector3Ptr::dynamicCast(globalPosition1)->toEigen();
1722 Eigen::Vector3f p2 = Vector3Ptr::dynamicCast(globalPosition2)->toEigen();
1725 auto l = getScopedAccumulatedDataLock();
1726 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + lineName +
"__"),
" ",
"_");
1727 LineData& d = accumulatedUpdateData.line[entryName];
1733 d.
scale = lineWidth;
1738 void DebugDrawerComponent::setLineDebugLayerVisu(
const std::string& lineName,
const Vector3BasePtr& globalPosition1,
const Vector3BasePtr& globalPosition2,
float lineWidth,
const DrawColor& color,
const Ice::Current&)
1740 setLineVisu(DEBUG_LAYER_NAME, lineName, globalPosition1, globalPosition2, lineWidth, color);
1743 void DebugDrawerComponent::removeLineVisu(
const std::string& layerName,
const std::string& lineName,
const Ice::Current&)
1746 auto l = getScopedAccumulatedDataLock();
1747 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + lineName +
"__"),
" ",
"_");
1748 LineData& d = accumulatedUpdateData.line[entryName];
1755 void DebugDrawerComponent::removeLineDebugLayerVisu(
const std::string& lineName,
const Ice::Current&)
1757 removeLineVisu(DEBUG_LAYER_NAME, lineName);
1760 void DebugDrawerComponent::setLineSetVisu(
const std::string& layerName,
const std::string& lineSetName,
const DebugDrawerLineSet& lineSet,
const Ice::Current&)
1764 auto l = getScopedAccumulatedDataLock();
1765 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + lineSetName +
"__"),
" ",
"_");
1769 d.
name = lineSetName;
1774 void DebugDrawerComponent::setLineSetDebugLayerVisu(
const std::string& lineSetName,
const DebugDrawerLineSet& lineSet,
const Ice::Current&)
1776 setLineSetVisu(DEBUG_LAYER_NAME, lineSetName, lineSet);
1779 void DebugDrawerComponent::removeLineSetVisu(
const std::string& layerName,
const std::string& lineSetName,
const Ice::Current&)
1782 auto l = getScopedAccumulatedDataLock();
1783 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + lineSetName +
"__"),
" ",
"_");
1786 d.
name = lineSetName;
1791 void DebugDrawerComponent::removeLineSetDebugLayerVisu(
const std::string& lineSetName,
const Ice::Current&)
1793 removeLineSetVisu(DEBUG_LAYER_NAME, lineSetName);
1796 void DebugDrawerComponent::setBoxVisu(
const std::string& layerName,
const std::string& boxName,
const PoseBasePtr& globalPose,
const Vector3BasePtr& dimensions,
const DrawColor& color,
const Ice::Current&)
1801 auto l = getScopedAccumulatedDataLock();
1802 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + boxName +
"__"),
" ",
"_");
1803 BoxData& d = accumulatedUpdateData.box[entryName];
1804 d.
width = dimensions->x;
1805 d.
height = dimensions->y;
1806 d.
depth = dimensions->z;
1815 void DebugDrawerComponent::setBoxDebugLayerVisu(
const std::string& boxName,
const PoseBasePtr& globalPose,
const Vector3BasePtr& dimensions,
const DrawColor& color,
const Ice::Current&)
1817 setBoxVisu(DEBUG_LAYER_NAME, boxName, globalPose, dimensions, color);
1820 void DebugDrawerComponent::removeBoxVisu(
const std::string& layerName,
const std::string& boxName,
const Ice::Current&)
1823 auto l = getScopedAccumulatedDataLock();
1824 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + boxName +
"__"),
" ",
"_");
1825 BoxData& d = accumulatedUpdateData.box[entryName];
1832 void DebugDrawerComponent::removeBoxDebugLayerVisu(
const std::string& boxName,
const Ice::Current&)
1834 removeBoxVisu(DEBUG_LAYER_NAME, boxName);
1837 void DebugDrawerComponent::setTextVisu(
const std::string& layerName,
const std::string& textName,
const std::string& text,
const Vector3BasePtr& globalPosition,
const DrawColor& color,
int size,
const Ice::Current&)
1841 auto l = getScopedAccumulatedDataLock();
1842 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + textName +
"__"),
" ",
"_");
1845 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
1854 void DebugDrawerComponent::setTextDebugLayerVisu(
const std::string& textName,
const std::string& text,
const Vector3BasePtr& globalPosition,
const DrawColor& color,
int size,
const Ice::Current&)
1856 setTextVisu(DEBUG_LAYER_NAME, textName, text, globalPosition, color, size);
1859 void DebugDrawerComponent::removeTextVisu(
const std::string& layerName,
const std::string& textName,
const Ice::Current&)
1862 auto l = getScopedAccumulatedDataLock();
1863 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + textName +
"__"),
" ",
"_");
1871 void DebugDrawerComponent::removeTextDebugLayerVisu(
const std::string& textName,
const Ice::Current&)
1873 removeTextVisu(DEBUG_LAYER_NAME, textName);
1876 void DebugDrawerComponent::setSphereVisu(
const std::string& layerName,
const std::string& sphereName,
const Vector3BasePtr& globalPosition,
const DrawColor& color,
float radius,
const Ice::Current&)
1880 auto l = getScopedAccumulatedDataLock();
1881 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + sphereName +
"__"),
" ",
"_");
1882 SphereData& d = accumulatedUpdateData.sphere[entryName];
1884 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
1886 d.
name = sphereName;
1892 void DebugDrawerComponent::setSphereDebugLayerVisu(
const std::string& sphereName,
const Vector3BasePtr& globalPosition,
const DrawColor& color,
float radius,
const Ice::Current&)
1894 setSphereVisu(DEBUG_LAYER_NAME, sphereName, globalPosition, color, radius);
1897 void DebugDrawerComponent::removeSphereVisu(
const std::string& layerName,
const std::string& sphereName,
const Ice::Current&)
1900 auto l = getScopedAccumulatedDataLock();
1901 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + sphereName +
"__"),
" ",
"_");
1902 SphereData& d = accumulatedUpdateData.sphere[entryName];
1904 d.
name = sphereName;
1909 void DebugDrawerComponent::removeSphereDebugLayerVisu(
const std::string& sphereName,
const Ice::Current&)
1911 removeSphereVisu(DEBUG_LAYER_NAME, sphereName);
1914 void DebugDrawerComponent::setCylinderVisu(
const std::string& layerName,
const std::string& cylinderName,
const Vector3BasePtr& globalPosition,
const Vector3BasePtr& direction,
float length,
float radius,
const DrawColor& color,
const Ice::Current&)
1918 auto l = getScopedAccumulatedDataLock();
1919 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + cylinderName +
"__"),
" ",
"_");
1920 CylinderData& d = accumulatedUpdateData.cylinder[entryName];
1921 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
1922 d.
direction = Vector3Ptr::dynamicCast(direction)->toEigen();
1926 d.
name = cylinderName;
1932 void DebugDrawerComponent::setCylinderDebugLayerVisu(
const std::string& cylinderName,
const Vector3BasePtr& globalPosition,
const Vector3BasePtr& direction,
float length,
float radius,
const DrawColor& color,
const Ice::Current&)
1934 setCylinderVisu(DEBUG_LAYER_NAME, cylinderName, globalPosition, direction, length, radius, color);
1937 void DebugDrawerComponent::removeCylinderVisu(
const std::string& layerName,
const std::string& cylinderName,
const Ice::Current&)
1940 auto l = getScopedAccumulatedDataLock();
1941 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + cylinderName +
"__"),
" ",
"_");
1942 CylinderData& d = accumulatedUpdateData.cylinder[entryName];
1944 d.
name = cylinderName;
1949 void DebugDrawerComponent::removeCylinderDebugLayerVisu(
const std::string& cylinderName,
const Ice::Current&)
1951 removeCylinderVisu(DEBUG_LAYER_NAME, cylinderName);
1954 void DebugDrawerComponent::setPointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const DebugDrawerPointCloud& pointCloud,
const Ice::Current&)
1958 auto l = getScopedAccumulatedDataLock();
1959 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
1963 d.
name = pointCloudName;
1968 void DebugDrawerComponent::setPointCloudDebugLayerVisu(
const std::string& pointCloudName,
const DebugDrawerPointCloud& pointCloud,
const Ice::Current&)
1970 setPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
1973 void DebugDrawerComponent::removePointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const Ice::Current&)
1976 auto l = getScopedAccumulatedDataLock();
1977 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
1980 d.
name = pointCloudName;
1985 void DebugDrawerComponent::removePointCloudDebugLayerVisu(
const std::string& pointCloudName,
const Ice::Current&)
1987 removePointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
1990 void DebugDrawerComponent::setPolygonVisu(
const std::string& layerName,
const std::string& polygonName,
const std::vector<Vector3BasePtr>& polygonPoints,
const DrawColor& colorInner,
const DrawColor& colorBorder,
float lineWidth,
const Ice::Current&)
1993 auto l = getScopedAccumulatedDataLock();
1994 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + polygonName +
"__"),
" ",
"_");
1995 PolygonData& d = accumulatedUpdateData.polygons[entryName];
1997 std::vector< Eigen::Vector3f > points;
1999 for (
size_t i = 0; i < polygonPoints.size(); i++)
2001 Eigen::Vector3f p = Vector3Ptr::dynamicCast(polygonPoints.at(i))->toEigen();;
2002 points.push_back(p);
2011 d.
name = polygonName;
2016 void DebugDrawerComponent::setPolygonDebugLayerVisu(
const std::string& polygonName,
const std::vector<Vector3BasePtr>& polygonPoints,
const DrawColor& colorInner,
const DrawColor& colorBorder,
float lineWidth,
const Ice::Current&)
2018 setPolygonVisu(DEBUG_LAYER_NAME, polygonName, polygonPoints, colorInner, colorBorder, lineWidth);
2021 void DebugDrawerComponent::removePolygonVisu(
const std::string& layerName,
const std::string& polygonName,
const Ice::Current&)
2024 auto l = getScopedAccumulatedDataLock();
2025 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + polygonName +
"__"),
" ",
"_");
2026 PolygonData& d = accumulatedUpdateData.polygons[entryName];
2028 d.
name = polygonName;
2033 void DebugDrawerComponent::removePolygonDebugLayerVisu(
const std::string& polygonName,
const Ice::Current&)
2035 removePolygonVisu(DEBUG_LAYER_NAME, polygonName);
2038 void DebugDrawerComponent::setTriMeshVisu(
const std::string& layerName,
const std::string& triMeshName,
const DebugDrawerTriMesh& triMesh,
const Ice::Current&)
2041 auto l = getScopedAccumulatedDataLock();
2042 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + triMeshName +
"__"),
" ",
"_");
2043 TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2046 d.
name = triMeshName;
2051 void DebugDrawerComponent::setTriMeshDebugLayerVisu(
const std::string& triMeshName,
const DebugDrawerTriMesh& triMesh,
const Ice::Current&)
2053 setTriMeshVisu(DEBUG_LAYER_NAME, triMeshName, triMesh);
2056 void DebugDrawerComponent::removeTriMeshVisu(
const std::string& layerName,
const std::string& triMeshName,
const Ice::Current&)
2059 auto l = getScopedAccumulatedDataLock();
2060 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + triMeshName +
"__"),
" ",
"_");
2061 TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2063 d.
name = triMeshName;
2068 void DebugDrawerComponent::removeTriMeshDebugLayerVisu(
const std::string& triMeshName,
const Ice::Current&)
2070 removeTriMeshVisu(DEBUG_LAYER_NAME, triMeshName);
2073 void DebugDrawerComponent::setArrowVisu(
const std::string& layerName,
const std::string& arrowName,
const Vector3BasePtr& position,
const Vector3BasePtr& direction,
const DrawColor& color,
float length,
float width,
const Ice::Current&)
2076 auto l = getScopedAccumulatedDataLock();
2077 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + arrowName +
"__"),
" ",
"_");
2078 ArrowData& d = accumulatedUpdateData.arrows[entryName];
2079 d.
position = Vector3Ptr::dynamicCast(position)->toEigen();
2080 d.
direction = Vector3Ptr::dynamicCast(direction)->toEigen();
2090 void DebugDrawerComponent::setArrowDebugLayerVisu(
const std::string& arrowName,
const Vector3BasePtr& position,
const Vector3BasePtr& direction,
const DrawColor& color,
float length,
float width,
const Ice::Current&)
2092 setArrowVisu(DEBUG_LAYER_NAME, arrowName, position, direction, color, length, width);
2095 void DebugDrawerComponent::removeArrowVisu(
const std::string& layerName,
const std::string& arrowName,
const Ice::Current&)
2098 auto l = getScopedAccumulatedDataLock();
2099 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + arrowName +
"__"),
" ",
"_");
2100 ArrowData& d = accumulatedUpdateData.arrows[entryName];
2107 void DebugDrawerComponent::removeArrowDebugLayerVisu(
const std::string& arrowName,
const Ice::Current&)
2109 removeArrowVisu(DEBUG_LAYER_NAME, arrowName);
2112 void DebugDrawerComponent::setRobotVisu(
const std::string& layerName,
const std::string& robotName,
const std::string& robotFile,
const std::string& armarxProject, DrawStyle drawStyle,
const Ice::Current&)
2114 auto l = getScopedAccumulatedDataLock();
2115 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2116 ARMARX_DEBUG <<
"setting robot visualization for " << entryName;
2117 RobotData& d = accumulatedUpdateData.robots[entryName];
2128 void DebugDrawerComponent::updateRobotPose(
const std::string& layerName,
const std::string& robotName,
const PoseBasePtr& globalPose,
const Ice::Current&)
2130 auto l = getScopedAccumulatedDataLock();
2131 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2132 ARMARX_DEBUG <<
"updating robot pose for " << entryName;
2133 RobotData& d = accumulatedUpdateData.robots[entryName];
2138 d.
globalPose = PosePtr::dynamicCast(globalPose)->toEigen();
2145 void DebugDrawerComponent::updateRobotConfig(
const std::string& layerName,
const std::string& robotName,
const std::map<std::string, float>& configuration,
const Ice::Current&)
2147 auto l = getScopedAccumulatedDataLock();
2148 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2149 ARMARX_DEBUG <<
"updating robot config for " << entryName;
2150 RobotData& d = accumulatedUpdateData.robots[entryName];
2158 for (
auto& it : configuration)
2166 void DebugDrawerComponent::updateRobotColor(
const std::string& layerName,
const std::string& robotName,
const DrawColor&
c,
const Ice::Current&)
2168 auto l = getScopedAccumulatedDataLock();
2169 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2170 ARMARX_DEBUG <<
"updating robot color for " << entryName;
2171 RobotData& d = accumulatedUpdateData.robots[entryName];
2179 if (
c.a == 0 &&
c.b == 0 &&
c.r == 0 &&
c.g == 0)
2181 d.
color = VirtualRobot::VisualizationFactory::Color::None();
2191 void DebugDrawerComponent::updateRobotNodeColor(
const std::string& layerName,
const std::string& robotName,
const std::string& robotNodeName,
const DrawColor&
c,
const Ice::Current&)
2193 auto l = getScopedAccumulatedDataLock();
2194 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2195 ARMARX_DEBUG <<
"updating robot color for " << entryName;
2196 RobotData& d = accumulatedUpdateData.robots[entryName];
2203 if (
c.a == 0 &&
c.b == 0 &&
c.r == 0 &&
c.g == 0)
2205 d.
nodeColors[robotNodeName] = VirtualRobot::VisualizationFactory::Color::None();
2217 void DebugDrawerComponent::removeRobotVisu(
const std::string& layerName,
const std::string& robotName,
const Ice::Current&)
2219 auto l = getScopedAccumulatedDataLock();
2220 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + robotName +
"__"),
" ",
"_");
2221 ARMARX_DEBUG <<
"removing robot visu for " << entryName;
2222 RobotData& d = accumulatedUpdateData.robots[entryName];
2229 void DebugDrawerComponent::clearAll(
const Ice::Current&)
2231 for (
auto& i : layers)
2233 clearLayer(i.first);
2237 void DebugDrawerComponent::clearLayer(
const std::string& layerName,
const Ice::Current&)
2239 auto lockData = getScopedAccumulatedDataLock();
2243 removeAccumulatedData(layerName);
2244 accumulatedUpdateData.clearLayers.emplace(layerName);
2248 void DebugDrawerComponent::clearLayerQt(
const std::string& layerName)
2250 auto lockData = getScopedAccumulatedDataLock();
2251 auto lockVisu = getScopedVisuLock();
2255 if (!hasLayer(layerName))
2259 ARMARX_VERBOSE <<
"Layer " << layerName <<
" can't be cleared, because it does not exist.";
2270 selectionNode->deselectAll();
2272 Layer& layer = layers.at(layerName);
2276 removePoseVisu(layerName, i.first);
2281 removeLineVisu(layerName, i.first);
2286 removeLineSetVisu(layerName, i.first);
2291 removeBoxVisu(layerName, i.first);
2296 removeTextVisu(layerName, i.first);
2301 removeSphereVisu(layerName, i.first);
2306 removeCylinderVisu(layerName, i.first);
2311 removeCircleVisu(layerName, i.first);
2316 removePointCloudVisu(layerName, i.first);
2321 removeColoredPointCloudVisu(layerName, i.first);
2326 removePolygonVisu(layerName, i.first);
2331 removeTriMeshVisu(layerName, i.first);
2336 remove24BitColoredPointCloudVisu(layerName, i.first);
2341 removeArrowVisu(layerName, i.first);
2346 removeRobotVisu(layerName, i.first);
2351 removeCustomVisu(layerName, i.first);
2355 void DebugDrawerComponent::clearDebugLayer(
const Ice::Current&)
2357 clearLayer(DEBUG_LAYER_NAME);
2388 SoSeparator* DebugDrawerComponent::getVisualization()
2395 auto l = getScopedVisuLock();
2397 if (hasLayer(layerName))
2399 return layers.at(layerName);
2404 SoSeparator* mainNode =
new SoSeparator {};
2406 layers[layerName] =
Layer();
2407 layers.at(layerName).mainNode = mainNode;
2408 layers.at(layerName).visible = getDefaultLayerVisibility(layerName);
2409 if (layers.at(layerName).visible)
2411 layerMainNode->addChild(mainNode);
2413 return layers.at(layerName);
2416 void DebugDrawerComponent::updateVisualization()
2418 auto lockData = getScopedAccumulatedDataLock();
2419 auto lockVisu = getScopedVisuLock();
2423 for (
const auto& layer : accumulatedUpdateData.clearLayers)
2425 clearLayerQt(layer);
2427 accumulatedUpdateData.clearLayers.clear();
2429 for (
const auto& layer : accumulatedUpdateData.removeLayers)
2431 removeLayerQt(layer);
2433 accumulatedUpdateData.removeLayers.clear();
2436 for (
auto& e : accumulatedUpdateData.coord)
2438 drawCoordSystem(e.second);
2440 accumulatedUpdateData.coord.clear();
2442 for (
auto& e : accumulatedUpdateData.box)
2446 accumulatedUpdateData.box.clear();
2448 for (
auto& e : accumulatedUpdateData.line)
2452 accumulatedUpdateData.line.clear();
2454 for (
auto& e : accumulatedUpdateData.lineSet)
2456 drawLineSet(e.second);
2458 accumulatedUpdateData.lineSet.clear();
2460 for (
auto& e : accumulatedUpdateData.sphere)
2462 drawSphere(e.second);
2464 accumulatedUpdateData.sphere.clear();
2466 for (
auto& e : accumulatedUpdateData.cylinder)
2468 drawCylinder(e.second);
2470 accumulatedUpdateData.cylinder.clear();
2472 for (
auto& e : accumulatedUpdateData.circle)
2474 drawCircle(e.second);
2476 accumulatedUpdateData.circle.clear();
2478 for (
auto& e : accumulatedUpdateData.text)
2482 accumulatedUpdateData.text.clear();
2484 for (
auto& e : accumulatedUpdateData.pointcloud)
2486 drawPointCloud(e.second);
2488 accumulatedUpdateData.pointcloud.clear();
2490 for (
auto& e : accumulatedUpdateData.polygons)
2492 drawPolygon(e.second);
2494 accumulatedUpdateData.polygons.clear();
2496 for (
auto& e : accumulatedUpdateData.arrows)
2498 drawArrow(e.second);
2500 accumulatedUpdateData.arrows.clear();
2502 for (
auto& e : accumulatedUpdateData.triMeshes)
2504 drawTriMesh(e.second);
2506 accumulatedUpdateData.triMeshes.clear();
2508 for (
auto& e : accumulatedUpdateData.robots)
2510 ARMARX_DEBUG <<
"update visu / drawRobot for robot " << e.first;
2511 ensureExistingRobotNodes(e.second);
2513 drawRobot(e.second);
2514 e.second.nodeColors.clear();
2516 accumulatedUpdateData.robots.clear();
2518 for (
auto& e : accumulatedUpdateData.coloredpointcloud)
2520 drawColoredPointCloud(e.second);
2522 accumulatedUpdateData.coloredpointcloud.clear();
2524 for (
auto& e : accumulatedUpdateData.colored24Bitpointcloud)
2526 draw24BitColoredPointCloud(e.second);
2528 accumulatedUpdateData.colored24Bitpointcloud.clear();
2530 onUpdateVisualization();
2533 bool DebugDrawerComponent::hasLayer(
const std::string& layerName, const ::Ice::Current&)
2535 auto l = getScopedVisuLock();
2536 return layers.find(layerName) != layers.end();
2539 void DebugDrawerComponent::removeLayer(
const std::string& layerName, const ::Ice::Current&)
2541 auto lockData = getScopedAccumulatedDataLock();
2545 removeAccumulatedData(layerName);
2546 accumulatedUpdateData.removeLayers.emplace(layerName);
2549 void DebugDrawerComponent::removeLayerQt(
const std::string& layerName)
2551 auto lockData = getScopedAccumulatedDataLock();
2552 auto lockVisu = getScopedVisuLock();
2553 if (!hasLayer(layerName))
2557 ARMARX_VERBOSE <<
"Layer " << layerName <<
" can't be removed, because it does not exist.";
2568 clearLayerQt(layerName);
2570 auto& layer = layers.at(layerName);
2571 layerMainNode->removeChild(layer.mainNode);
2572 layer.mainNode->unref();
2573 layers.erase(layerName);
2577 template<
class UpdateDataType>
2580 auto it = map.begin();
2581 while (it != map.end())
2584 if (curr->second.layerName == layerName)
2591 void DebugDrawerComponent::removeAccumulatedData(
const std::string& layerName)
2593 auto lockData = getScopedAccumulatedDataLock();
2610 onRemoveAccumulatedData(layerName);
2614 void DebugDrawerComponent::enableLayerVisu(
const std::string& layerName,
bool visible, const ::Ice::Current&)
2616 setLayerVisibility(layerName, visible);
2619 void DebugDrawerComponent::enableDebugLayerVisu(
bool visible, const ::Ice::Current&)
2621 enableLayerVisu(DEBUG_LAYER_NAME, visible);
2624 Ice::StringSeq DebugDrawerComponent::layerNames(const ::Ice::Current&)
2626 auto l = getScopedVisuLock();
2627 Ice::StringSeq seq {};
2629 for (
const auto& layer : layers)
2631 seq.push_back(layer.first);
2637 ::armarx::LayerInformationSequence DebugDrawerComponent::layerInformation(const ::Ice::Current&)
2639 ::armarx::LayerInformationSequence seq {};
2640 auto l = getScopedVisuLock();
2642 for (
const auto& layer : layers)
2644 int count = layer.second.addedCoordVisualizations.size() +
2645 layer.second.addedLineVisualizations.size() +
2646 layer.second.addedLineSetVisualizations.size() +
2647 layer.second.addedBoxVisualizations.size() +
2648 layer.second.addedTextVisualizations.size() +
2649 layer.second.addedSphereVisualizations.size() +
2650 layer.second.addedCylinderVisualizations.size() +
2651 layer.second.addedCircleVisualizations.size() +
2652 layer.second.addedPointCloudVisualizations.size() +
2653 layer.second.addedColoredPointCloudVisualizations.size() +
2654 layer.second.added24BitColoredPointCloudVisualizations.size() +
2655 layer.second.addedPolygonVisualizations.size() +
2656 layer.second.addedTriMeshVisualizations.size() +
2657 layer.second.addedArrowVisualizations.size() +
2658 layer.second.addedRobotVisualizations.size() +
2659 layer.second.addedCustomVisualizations.size();
2660 ::armarx::LayerInformation info = {layer.first, layer.second.visible, count};
2661 seq.push_back(info);
2669 auto l = getScopedVisuLock();
2671 auto& layer = requestLayer(d.
layerName);
2682 SoSeparator* pclSep =
new SoSeparator;
2684 SoMaterial* pclMat =
new SoMaterial;
2685 std::vector<SbColor> colors;
2686 colors.reserve(
pcl.size());
2688 pcl.begin(),
pcl.end(), std::back_inserter(colors),
2689 [](
const DebugDrawerColoredPointCloudElement & elem)
2691 return SbColor {elem.color.r, elem.color.g, elem.color.b};
2694 pclMat->diffuseColor.setValues(0, colors.size(), colors.data());
2695 pclMat->ambientColor.setValues(0, colors.size(), colors.data());
2696 pclSep->addChild(pclMat);
2698 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
2699 pclMatBind->value = SoMaterialBinding::PER_PART;
2700 pclSep->addChild(pclMatBind);
2702 SoCoordinate3* pclCoords =
new SoCoordinate3;
2703 std::vector<SbVec3f> coords;
2704 coords.reserve(
pcl.size());
2706 pcl.begin(),
pcl.end(), std::back_inserter(coords),
2707 [](
const DebugDrawerColoredPointCloudElement & elem)
2709 return SbVec3f {elem.x, elem.y, elem.z};
2712 pclCoords->point.setValues(0, coords.size(), coords.data());
2713 pclSep->addChild(pclCoords);
2715 SoDrawStyle* pclStye =
new SoDrawStyle;
2716 pclStye->pointSize = d.pointCloud.pointSize;
2717 pclSep->addChild(pclStye);
2719 pclSep->addChild(
new SoPointSet);
2723 layer.addedColoredPointCloudVisualizations[d.name] = pclSep;
2724 layer.mainNode->addChild(pclSep);
2727 void DebugDrawerComponent::removeColoredPointCloud(
const std::string& layerName,
const std::string& name)
2729 auto l = getScopedVisuLock();
2731 if (!hasLayer(layerName))
2736 auto& layer = layers.at(layerName);
2738 if (layer.addedColoredPointCloudVisualizations.find(name) == layer.addedColoredPointCloudVisualizations.end())
2743 layer.mainNode->removeChild(layer.addedColoredPointCloudVisualizations[name]);
2744 layer.addedColoredPointCloudVisualizations.erase(name);
2747 void DebugDrawerComponent::setColoredPointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const DebugDrawerColoredPointCloud& pointCloud,
const Ice::Current&)
2750 auto l = getScopedAccumulatedDataLock();
2751 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2755 d.
name = pointCloudName;
2760 void DebugDrawerComponent::setColoredPointCloudDebugLayerVisu(
const std::string& pointCloudName,
const DebugDrawerColoredPointCloud& pointCloud,
const Ice::Current&)
2762 setColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
2765 void DebugDrawerComponent::removeColoredPointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const Ice::Current&)
2768 auto l = getScopedAccumulatedDataLock();
2769 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2772 d.
name = pointCloudName;
2777 void DebugDrawerComponent::removeColoredPointCloudDebugLayerVisu(
const std::string& pointCloudName,
const Ice::Current&)
2779 removeColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
2784 auto l = getScopedVisuLock();
2786 auto& layer = requestLayer(d.
layerName);
2797 SoSeparator* pclSep =
new SoSeparator;
2799 SoMaterial* pclMat =
new SoMaterial;
2800 std::vector<SbColor> colors;
2801 colors.reserve(
pcl.size());
2803 pcl.begin(),
pcl.end(), std::back_inserter(colors),
2804 [](
const DebugDrawer24BitColoredPointCloudElement & elem)
2806 return SbColor {static_cast<float>(elem.color.r) / 255.f, static_cast<float>(elem.color.g) / 255.f, static_cast<float>(elem.color.b) / 255.f};
2809 pclMat->diffuseColor.setValues(0, colors.size(), colors.data());
2810 pclMat->ambientColor.setValues(0, colors.size(), colors.data());
2811 pclMat->transparency = d.pointCloud.transparency;
2812 pclSep->addChild(pclMat);
2814 SoMaterialBinding* pclMatBind =
new SoMaterialBinding;
2815 pclMatBind->value = SoMaterialBinding::PER_PART;
2816 pclSep->addChild(pclMatBind);
2818 SoCoordinate3* pclCoords =
new SoCoordinate3;
2819 std::vector<SbVec3f> coords;
2820 coords.reserve(
pcl.size());
2822 pcl.begin(),
pcl.end(), std::back_inserter(coords),
2823 [](
const DebugDrawer24BitColoredPointCloudElement & elem)
2825 return SbVec3f {elem.x, elem.y, elem.z};
2828 pclCoords->point.setValues(0, coords.size(), coords.data());
2829 pclSep->addChild(pclCoords);
2831 SoDrawStyle* pclStye =
new SoDrawStyle;
2832 pclStye->pointSize = d.pointCloud.pointSize;
2833 pclSep->addChild(pclStye);
2835 pclSep->addChild(
new SoPointSet);
2839 layer.added24BitColoredPointCloudVisualizations[d.name] = pclSep;
2840 layer.mainNode->addChild(pclSep);
2843 void DebugDrawerComponent::remove24BitColoredPointCloud(
const std::string& layerName,
const std::string& name)
2845 auto l = getScopedVisuLock();
2847 if (!hasLayer(layerName))
2852 auto& layer = layers.at(layerName);
2854 if (layer.added24BitColoredPointCloudVisualizations.find(name) == layer.added24BitColoredPointCloudVisualizations.end())
2859 layer.mainNode->removeChild(layer.added24BitColoredPointCloudVisualizations[name]);
2860 layer.added24BitColoredPointCloudVisualizations.erase(name);
2863 void DebugDrawerComponent::set24BitColoredPointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const DebugDrawer24BitColoredPointCloud& pointCloud,
const Ice::Current&)
2866 auto l = getScopedAccumulatedDataLock();
2867 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2871 d.
name = pointCloudName;
2876 void DebugDrawerComponent::set24BitColoredPointCloudDebugLayerVisu(
const std::string& pointCloudName,
const DebugDrawer24BitColoredPointCloud& pointCloud,
const Ice::Current&)
2878 set24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
2881 void DebugDrawerComponent::remove24BitColoredPointCloudVisu(
const std::string& layerName,
const std::string& pointCloudName,
const Ice::Current&)
2884 auto l = getScopedAccumulatedDataLock();
2885 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + pointCloudName +
"__"),
" ",
"_");
2888 d.
name = pointCloudName;
2893 void DebugDrawerComponent::remove24BitColoredPointCloudDebugLayerVisu(
const std::string& pointCloudName,
const Ice::Current&)
2895 remove24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
2898 void DebugDrawerComponent::setCircleArrowVisu(
const std::string& layerName,
const std::string& circleName,
const Vector3BasePtr& globalPosition,
const Vector3BasePtr& directionVec,
Ice::Float radius,
Ice::Float circleCompletion,
Ice::Float width,
const DrawColor& color,
const Ice::Current&)
2901 auto l = getScopedAccumulatedDataLock();
2902 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + circleName +
"__"),
" ",
"_");
2903 CircleData& d = accumulatedUpdateData.circle[entryName];
2904 d.
position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
2905 d.
direction = Vector3Ptr::dynamicCast(directionVec)->toEigen();
2910 d.
name = circleName;
2916 void DebugDrawerComponent::setCircleDebugLayerVisu(
const std::string& circleName,
const Vector3BasePtr& globalPosition,
const Vector3BasePtr& directionVec,
Ice::Float radius,
Ice::Float circleCompletion,
Ice::Float width,
const DrawColor& color,
const Ice::Current&
c)
2918 setCircleArrowVisu(DEBUG_LAYER_NAME, circleName, globalPosition, directionVec, radius, circleCompletion, width, color,
c);
2921 void DebugDrawerComponent::removeCircleVisu(
const std::string& layerName,
const std::string& circleName,
const Ice::Current&)
2924 auto l = getScopedAccumulatedDataLock();
2925 std::string entryName = simox::alg::replace_all(std::string(
"__" + layerName +
"__" + circleName +
"__"),
" ",
"_");
2926 CircleData& d = accumulatedUpdateData.circle[entryName];
2928 d.
name = circleName;
2933 void DebugDrawerComponent::removeCircleDebugLayerVisu(
const std::string& circleName,
const Ice::Current&
c)
2935 removeCircleVisu(DEBUG_LAYER_NAME, circleName,
c);