DebugDrawerComponent.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotAPI::ArmarXObjects::DebugDrawerComponent
19  * @author Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu )
20  * @author Peter Kaiser ( peter dot kaiser at kit dot edu )
21  * @date 2014
22  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23  * GNU General Public License
24  */
25 
26 #include "DebugDrawerComponent.h"
27 
29 
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>
54 
57 
58 #include <SimoxUtility/algorithm/string/string_tools.h>
59 
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>
65 
66 using namespace VirtualRobot;
67 
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()
71 
72 namespace armarx
73 {
74  std::recursive_mutex DebugDrawerComponent::selectionMutex;
75 
76  void selection_callback(void* userdata, SoPath* path)
77  {
78  if (userdata)
79  {
80  ((DebugDrawerComponent*) userdata)->selectionCallback();
81  }
82  }
83 
84  void deselection_callback(void* userdata, SoPath* path)
85  {
86  if (userdata)
87  {
88  ((DebugDrawerComponent*) userdata)->deselectionCallback();
89  }
90  }
91 
92  static const std::string DEBUG_LAYER_NAME
93  {
94  "debug"
95  };
96 
97  DebugDrawerComponent::DebugDrawerComponent():
98  mutex(new RecursiveMutex()),
99  dataUpdateMutex(new RecursiveMutex()),
100  topicMutex(new RecursiveMutex()),
101  defaultLayerVisibility(true)
102  {
103  cycleTimeMS = 1000.0f / 30.0f;
104  timerSensor = NULL;
105  verbose = true;
106 
107  coinVisu = new SoSeparator;
108  coinVisu->ref();
109 
110  selectionNode = new SoSelection;
111  selectionNode->policy = SoSelection::SHIFT;
112  selectionNode->ref();
113  coinVisu->addChild(selectionNode);
114 
115  layerMainNode = new SoSeparator;
116  layerMainNode->ref();
117 
118  SoUnits* u = new SoUnits();
119  u->units = SoUnits::MILLIMETERS;
120  selectionNode->addChild(u);
121  selectionNode->addChild(layerMainNode);
122  }
123 
124  void DebugDrawerComponent::enableSelections(const std::string& layerName, const ::Ice::Current&)
125  {
126  auto l = getScopedVisuLock();
127 
128  ARMARX_INFO << "Enabling selections for layer " << layerName;
129  selectableLayers.insert(layerName);
130  }
131 
132  void DebugDrawerComponent::disableSelections(const std::string& layerName, const ::Ice::Current&)
133  {
134  auto l = getScopedVisuLock();
135 
136  ARMARX_INFO << "Disabling selections for layer " << layerName;
137  if (layerName == "")
138  {
139  selectableLayers.clear();
140  }
141  else if (layers.find(layerName) != layers.end())
142  {
143  selectableLayers.erase(layerName);
144  }
145  }
146 
147  void DebugDrawerComponent::clearSelections(const std::string& layerName, const Ice::Current&)
148  {
149  auto l = getScopedVisuLock();
150  std::unique_lock l2(selectionMutex);
151 
153 
154  ARMARX_INFO << "Clearing selections on layer " << layerName;
155  if (layerName == "")
156  {
157  selectionNode->deselectAll();
158  }
159  else if (layers.find(layerName) != layers.end())
160  {
161  for (int i = 0; i < selectionNode->getNumSelected(); i++)
162  {
163  SoPath* path = selectionNode->getPath(i);
164  if (path->containsNode(layers.at(layerName).mainNode))
165  {
166  selectionNode->deselect(path);
167  }
168  }
169  }
170 
172  }
173 
174  void DebugDrawerComponent::select(const std::string& layerName, const std::string& elementName, const Ice::Current&)
175  {
176  auto l = getScopedVisuLock();
177  std::unique_lock l2(selectionMutex);
178 
180 
181  ARMARX_DEBUG << "Selecting element '" << elementName << "' on layer '" << layerName << "' (internal name: " << SELECTION_NAME(layerName, elementName) << ")";
182 
183  SoNode* n = SoSelection::getByName(SELECTION_NAME(layerName, elementName));
184  if (n)
185  {
186  selectionNode->select(n);
187  }
188  else
189  {
190  ARMARX_WARNING << "Element to select not found";
191  }
192 
193  // Force visualization update
194  selectionNode->touch();
195 
197  }
198 
199  void DebugDrawerComponent::deselect(const std::string& layerName, const std::string& elementName, const Ice::Current&)
200  {
201  auto l = getScopedVisuLock();
202  std::unique_lock l2(selectionMutex);
203 
205 
206  ARMARX_DEBUG << "Deselecting element '" << elementName << "' on layer '" << layerName << "' (internal name: " << SELECTION_NAME(layerName, elementName) << ")";
207 
208  SoNode* n = SoSelection::getByName(SELECTION_NAME(layerName, elementName));
209  if (n)
210  {
211  selectionNode->deselect(n);
212  }
213  else
214  {
215  ARMARX_WARNING << "Element to deselect not found";
216  }
217 
218  // Force visualization update
219  selectionNode->touch();
220 
222  }
223 
225  {
226  std::unique_lock l(*topicMutex);
227  listenerPrx->reportSelectionChanged(getSelections());
228  }
229 
231  {
232  std::unique_lock l(*topicMutex);
233  listenerPrx->reportSelectionChanged(getSelections());
234  }
235 
237  {
238  auto l = getScopedVisuLock();
239  selectionNode->addSelectionCallback(selection_callback, this);
240  selectionNode->addDeselectionCallback(deselection_callback, this);
241  }
242 
244  {
245  auto l = getScopedVisuLock();
246  selectionNode->removeSelectionCallback(selection_callback, this);
247  selectionNode->removeDeselectionCallback(deselection_callback, this);
248  }
249 
250  void DebugDrawerComponent::reportSelectionChanged(const DebugDrawerSelectionList& selectedElements, const Ice::Current&)
251  {
252  auto l = getScopedVisuLock();
253  std::unique_lock l2(selectionMutex);
254 
256  selectionNode->deselectAll();
257 
258  for (auto& e : selectedElements)
259  {
260  SoNode* n = SoSelection::getByName(SELECTION_NAME(e.layerName, e.elementName));
261  if (n)
262  {
263  selectionNode->select(n);
264  }
265  }
266 
267  // Force visualization update
268  selectionNode->touch();
269 
271  }
272 
273  DebugDrawerSelectionList DebugDrawerComponent::getSelections(const ::Ice::Current&)
274  {
275  auto l = getScopedVisuLock();
276 
277  DebugDrawerSelectionList selectedElements;
278 
279  for (int i = 0; i < selectionNode->getNumSelected(); i++)
280  {
281  SoPath* path = selectionNode->getPath(i);
282 
283  for (int j = 0; j < path->getLength(); j++)
284  {
285  SoNode* node = path->getNodeFromTail(j);
286  if (!node)
287  {
288  continue;
289  }
290 
291  std::string name = node->getName().getString();
292  if (name.length() > 0 && name.find(SELECTION_NAME_PREFIX) == 0)
293  {
294  int index = name.rfind(SELECTION_NAME_SPLITTER);
295  name = name.substr(index + strlen(SELECTION_NAME_SPLITTER));
296 
297  // Check if selected element is 'selectable'
298  for (auto& l : layers)
299  {
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())
306  {
307  DebugDrawerSelectionElement e;
308  e.layerName = layer;
309  e.elementName = name;
310 
311  selectedElements.push_back(e);
312  break;
313  }
314  }
315 
316  // We only process the first node that matches the naming scheme
317  break;
318  }
319  }
320  }
321 
322  return selectedElements;
323  }
324 
325  void DebugDrawerComponent::setVisuUpdateTime(float visuUpdatesPerSec)
326  {
327  if (timerSensor)
328  {
329  ARMARX_ERROR << "Cannot change the cycle time, once the thread has been started...";
330  return;
331  }
332 
333  if (visuUpdatesPerSec <= 0)
334  {
335  cycleTimeMS = 0;
336  }
337  else
338  {
339  cycleTimeMS = 1000.0f / (float)visuUpdatesPerSec;
340  }
341  }
342 
344  {
345  /*{
346  auto l = getScopedLock();
347  layerMainNode->unref();
348  coinVisu->unref();
349  }*/
350  }
351 
353  {
354  usingTopic(getProperty<std::string>("DebugDrawerTopic").getValue());
355  bool enabled = getProperty<bool>("ShowDebugDrawing").getValue();
356 
357  if (!enabled)
358  {
360  }
361 
362  if (cycleTimeMS > 0)
363  {
364  SoSensorManager* sensor_mgr = SoDB::getSensorManager();
365  timerSensor = new SoTimerSensor(updateVisualizationCB, this);
366  timerSensor->setInterval(SbTime(cycleTimeMS / 1000.0f));
367  sensor_mgr->insertTimerSensor(timerSensor);
368 
369  /*execTaskVisuUpdates = new PeriodicTask<DebugDrawerComponent>(this, &DebugDrawerComponent::updateVisualization, cycleTimeMS, false, "DebugDrawerComponentVisuUpdates");
370  execTaskVisuUpdates->start();
371  execTaskVisuUpdates->setDelayWarningTolerance(100);*/
372  }
373 
374  offeringTopic(getProperty<std::string>("DebugDrawerSelectionTopic").getValue());
375  usingTopic(getProperty<std::string>("DebugDrawerSelectionTopic").getValue());
376 
378  }
379 
380  void DebugDrawerComponent::updateVisualizationCB(void* data, SoSensor* sensor)
381  {
382  DebugDrawerComponent* drawer = static_cast<DebugDrawerComponent*>(data);
383 
384  if (!drawer)
385  {
386  return;
387  }
388 
389  std::unique_lock lock(drawer->timerSensorMutex);
390  drawer->updateVisualization();
391  }
392 
393 
395  {
396  verbose = true;
397 
398  listenerPrx = getTopic<DebugDrawerListenerPrx>(getProperty<std::string>("DebugDrawerSelectionTopic").getValue());
399  }
400 
402  {
403  std::cout << "onDisconnectComponent debug drawer" << std::endl;
404  /*verbose = false;
405  size_t c = layers.size();
406  size_t counter = 0;
407  while (layers.size()>0 && counter < 2*c)
408  {
409  std::cout << "removing layer " << layers.begin()->first;
410  removeLayer(layers.begin()->first);
411  counter++; // sec counter
412  }
413  {
414  auto l = getScopedLock();
415  coinVisu->removeAllChildren();
416  }*/
417  }
418 
420  {
421  ARMARX_INFO << "onExitComponent debug drawer";
422  verbose = false;
423 
424  //ARMARX_DEBUG << "onExitComponent";
425  if (timerSensor)
426  {
427  std::unique_lock lock(timerSensorMutex);
428  SoSensorManager* sensor_mgr = SoDB::getSensorManager();
429  sensor_mgr->removeTimerSensor(timerSensor);
430  }
431 
432  size_t c = layers.size();
433  size_t counter = 0;
434 
435  while (layers.size() > 0 && counter < 2 * c)
436  {
437  ARMARX_INFO << "removing layer " << layers.begin()->first;
438  removeLayer(layers.begin()->first);
439  counter++; // sec counter
440  }
441 
442  {
443  auto l = getScopedVisuLock();
444  coinVisu->removeAllChildren();
445  layerMainNode->unref();
446  selectionNode->unref();
447  coinVisu->unref();
448  }
449  }
450 
451  void DebugDrawerComponent::exportScene(const std::string& filename, const Ice::Current&)
452  {
453  auto l = getScopedVisuLock();
454 
455  ARMARX_INFO << "Exporting scene to '" << filename << "'";
456 
457  SoSeparator* sep = new SoSeparator;
458  SoUnits* u = new SoUnits;
459  u->units = SoUnits::MILLIMETERS;
460  sep->addChild(u);
461  sep->addChild(layerMainNode);
462 
463  SoWriteAction writeAction;
464  writeAction.getOutput()->openFile(filename.c_str());
465  writeAction.getOutput()->setBinary(false);
466  writeAction.apply(sep);
467  writeAction.getOutput()->closeFile();
468 
469  sep->unref();
470  }
471 
472  void DebugDrawerComponent::exportLayer(const std::string& filename, const std::string& layerName, const Ice::Current&)
473  {
474  auto l = getScopedVisuLock();
475 
476  ARMARX_INFO << "Exporting layer '" << layerName << "' to '" << filename << "'";
477 
478  if (!hasLayer(layerName))
479  {
480  ARMARX_WARNING << "Unknown layer to export";
481  return;
482  }
483 
484  SoSeparator* sep = new SoSeparator;
485  SoUnits* u = new SoUnits;
486  u->units = SoUnits::MILLIMETERS;
487  sep->addChild(u);
488  sep->addChild(layers[layerName].mainNode);
489 
490  SoWriteAction writeAction;
491  writeAction.getOutput()->openFile(filename.c_str());
492  writeAction.getOutput()->setBinary(false);
493  writeAction.apply(sep);
494  writeAction.getOutput()->closeFile();
495 
496  sep->unref();
497  }
498 
500  {
501  auto l = getScopedVisuLock();
502  ARMARX_DEBUG << "drawing coord system";
503 
504  auto& layer = requestLayer(d.layerName);
505 
507 
508  if (d.scale <= 0 || !d.active)
509  {
510  return;
511  }
512 
513  //if (layer->addedCoordVisualizations.find(name) == layer->addedCoordVisualizations.end())
514  //{
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);
522  //}
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);
527 
528  ARMARX_DEBUG << "end";
529  }
530 
532  {
533  auto l = getScopedVisuLock();
534  ARMARX_DEBUG << "drawLine1" << flush;
535 
536  auto& layer = requestLayer(d.layerName);
537 
538  removeLine(d.layerName, d.name);
539 
540  if (!d.active)
541  {
542  return;
543  }
544 
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);
549  ARMARX_DEBUG << "drawLine2" << flush;
550  }
551 
553  {
554  auto l = getScopedVisuLock();
555  ARMARX_DEBUG << "drawLineSet";
556 
557  auto& layer = requestLayer(d.layerName);
558 
560 
561  if (!d.active)
562  {
563  return;
564  }
565 
566  if (d.lineSet.points.size() % 2 != 0)
567  {
568  ARMARX_WARNING << "A line set requires an even amount of points";
569  return;
570  }
571 
572  if (d.lineSet.points.size() != 2 * d.lineSet.intensities.size())
573  {
574  ARMARX_WARNING << "Amount of intensities has to be half the amount of points for a line set";
575  return;
576  }
577 
578  for (const DebugDrawerPointCloudElement& e : d.lineSet.points)
579  {
580  if (!std::isfinite(e.x) || !std::isfinite(e.y) || !std::isfinite(e.z))
581  {
582  ARMARX_WARNING << deactivateSpam(10, d.layerName + d.name) << "A point of lineset " << d.name << " on layer " << d.layerName << " is not finite! this set will not be drawn!";
583  return;
584  }
585  }
586 
587  // Initialize color map for affordance visualization
588  std::vector<VirtualRobot::VisualizationFactory::Color> colors;
589  colors.push_back(VirtualRobot::VisualizationFactory::Color(d.lineSet.colorNoIntensity.r, d.lineSet.colorNoIntensity.g, d.lineSet.colorNoIntensity.b));
590  colors.push_back(VirtualRobot::VisualizationFactory::Color(d.lineSet.colorFullIntensity.r, d.lineSet.colorFullIntensity.g, d.lineSet.colorFullIntensity.b));
591  VirtualRobot::ColorMap visualizationColorMap = VirtualRobot::ColorMap::customColorMap(colors);
592 
593  // Initialize visualization nodes
594  SoSeparator* sep = new SoSeparator;
595 
596  SoMaterialBinding* binding = new SoMaterialBinding;
597  binding->value = SoMaterialBinding::PER_PART;
598  sep->addChild(binding);
599 
600  SoDrawStyle* lineStyle = new SoDrawStyle;
601  lineStyle->lineWidth.setValue(d.lineSet.lineWidth);
602  sep->addChild(lineStyle);
603 
604  SoCoordinate3* coordinateNode = new SoCoordinate3;
605  sep->addChild(coordinateNode);
606 
607  SoMaterial* materialNode = new SoMaterial;
608  sep->addChild(materialNode);
609 
610  SoLineSet* lineSetNode = new SoLineSet;
611  lineSetNode->startIndex.setValue(0);
612  sep->addChild(lineSetNode);
613 
614 
615  // Allocate index and material arrays
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()];
619 
620  for (unsigned int i = 0; i < d.lineSet.intensities.size(); i++)
621  {
622  lineSetValues[i] = 2;
623 
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);
626 
627  if (d.lineSet.useHeatMap)
628  {
629  auto c = colorutils::HeatMapRGBAColor(d.lineSet.intensities[i]);
630  colorValues[i].setValue(c.r, c.g, c.b);
631  }
632  else
633  {
634  VirtualRobot::VisualizationFactory::Color c = visualizationColorMap.getColor(d.lineSet.intensities[i]);
635  colorValues[i].setValue(c.r, c.g, c.b);
636  }
637  }
638 
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);
643 
644  layer.addedLineSetVisualizations[d.name] = sep;
645  layer.mainNode->addChild(sep);
646  }
647 
649  {
650  auto l = getScopedVisuLock();
651  ARMARX_DEBUG << "drawBox";
652 
653  auto& layer = requestLayer(d.layerName);
654 
655  removeBox(d.layerName, d.name);
656 
657  if (!d.active)
658  {
659  return;
660  }
661 
662  SoSeparator* newS = new SoSeparator;
664  newS->addChild(CoinVisualizationFactory::getMatrixTransform(m));
665 
666  SoMaterial* material = new SoMaterial;
667  material->ambientColor.setValue(d.color.r, d.color.g, d.color.b);
668  material->diffuseColor.setValue(d.color.r, d.color.g, d.color.b);
669  material->transparency.setValue(d.color.transparency);
670  newS->addChild(material);
671 
672  SoCube* cube = new SoCube;
673  cube->setName(SELECTION_NAME(d.layerName, d.name));
674  cube->width = d.width;
675  cube->height = d.height;
676  cube->depth = d.depth;
677  newS->addChild(cube);
678 
679  layer.addedBoxVisualizations[d.name] = newS;
680  layer.mainNode->addChild(newS);
681  }
682 
684  {
685  auto l = getScopedVisuLock();
686  ARMARX_DEBUG << "drawText1";
687 
688  auto& layer = requestLayer(d.layerName);
689 
690  removeText(d.layerName, d.name);
691 
692  if (!d.active)
693  {
694  return;
695  }
696 
697  SoSeparator* sep = new SoSeparator;
698  SoAnnotation* ann = new SoAnnotation;
699  sep->addChild(ann);
700 
701  SoMaterial* mat = new SoMaterial;
702  mat->ambientColor.setValue(d.color.r, d.color.g, d.color.b);
703  mat->diffuseColor.setValue(d.color.r, d.color.g, d.color.b);
704  mat->transparency.setValue(d.color.transparency);
705  ann->addChild(mat);
706 
707  SoTransform* tr = new SoTransform;
708  tr->translation.setValue(d.position.x(), d.position.y(), d.position.z());
709  ann->addChild(tr);
710 
711  SoFont* font = new SoFont;
712  font->name.setValue("TGS_Triplex_Roman");
713  font->size = d.size;
714 
715  ann->addChild(font);
716 
717  SoText2* te = new SoText2;
718  te->setName(SELECTION_NAME(d.layerName, d.name));
719  te->string = d.text.c_str();
720  te->justification = SoText2::CENTER;
721  ann->addChild(te);
722 
723  layer.addedTextVisualizations[d.name] = sep;
724  layer.mainNode->addChild(sep);
725  ARMARX_DEBUG << "drawText2";
726  }
727 
728 
730  {
731  auto l = getScopedVisuLock();
732  ARMARX_DEBUG << "drawSphere";
733 
734  auto& layer = requestLayer(d.layerName);
735 
737 
738  if (!d.active)
739  {
740  return;
741  }
742 
743  if (!std::isfinite(d.position(0)) || !std::isfinite(d.position(1)) || !std::isfinite(d.position(2)))
744  {
745  ARMARX_WARNING << deactivateSpam(10, d.layerName + d.name) << "A coordinate of sphere " << d.name << " on layer " << d.layerName << " is not finite! this sphere will not be drawn!";
746  return;
747  }
748 
749  SoSeparator* sep = new SoSeparator;
750  SoMaterial* mat = new SoMaterial;
751  mat->ambientColor.setValue(d.color.r, d.color.g, d.color.b);
752  mat->diffuseColor.setValue(d.color.r, d.color.g, d.color.b);
753  mat->transparency.setValue(d.color.transparency);
754  sep->addChild(mat);
755 
756  SoTransform* tr = new SoTransform;
757  tr->translation.setValue(d.position.x(), d.position.y(), d.position.z());
758  sep->addChild(tr);
759 
760  SoSphere* sphere = new SoSphere;
761  sphere->setName(SELECTION_NAME(d.layerName, d.name));
762  sphere->radius = d.radius;
763  sep->addChild(sphere);
764 
765  layer.addedSphereVisualizations[d.name] = sep;
766  layer.mainNode->addChild(sep);
767  }
768 
770  {
771  auto l = getScopedVisuLock();
772  ARMARX_DEBUG << "drawCylinder";
773 
774  auto& layer = requestLayer(d.layerName);
775 
777 
778  if (!d.active)
779  {
780  return;
781  }
782 
783  SoSeparator* sep = new SoSeparator;
784  SoMaterial* mat = new SoMaterial;
785  mat->ambientColor.setValue(d.color.r, d.color.g, d.color.b);
786  mat->diffuseColor.setValue(d.color.r, d.color.g, d.color.b);
787  mat->transparency.setValue(d.color.transparency);
788  sep->addChild(mat);
789 
790  // The cylinder extends in y-direction, hence choose the transformation
791  SoTransform* tr = new SoTransform;
792  tr->translation.setValue(d.position.x(), d.position.y(), d.position.z());
793  tr->rotation.setValue(SbRotation(SbVec3f(0, 1, 0), SbVec3f(d.direction.x(), d.direction.y(), d.direction.z())));
794  sep->addChild(tr);
795 
796  SoCylinder* cylinder = new SoCylinder;
797  cylinder->setName(SELECTION_NAME(d.layerName, d.name));
798  cylinder->height = d.length;
799  cylinder->radius = d.radius;
800  sep->addChild(cylinder);
801 
802  layer.addedCylinderVisualizations[d.name] = sep;
803  layer.mainNode->addChild(sep);
804  }
805 
806  Eigen::Vector3f GetOrthonormalVectors(Eigen::Vector3f vec, Eigen::Vector3f& dir1, Eigen::Vector3f& dir2)
807  {
808 
809  vec = vec.normalized();
810 
811  dir1 = vec.cross(Eigen::Vector3f(0, 0, 1));
812 
813  if (dir1.norm() < 0.1f)
814 
815  {
816 
817  dir1 = vec.cross(Eigen::Vector3f(0, 1, 0));
818 
819  }
820 
821  dir1 = -dir1.normalized();
822 
823  dir2 = vec.cross(dir1).normalized();
824 
825  return vec;
826 
827 
828  }
829 
831  {
832  auto l = getScopedVisuLock();
833 
834  auto& layer = requestLayer(d.layerName);
835 
837 
838  if (!d.active)
839  {
840  return;
841  }
842 
843 
844 
845  SoSeparator* sep = new SoSeparator;
846  SoMaterial* mat = new SoMaterial;
847  mat->ambientColor.setValue(d.color.r, d.color.g, d.color.b);
848  mat->diffuseColor.setValue(d.color.r, d.color.g, d.color.b);
849  mat->transparency.setValue(d.color.transparency);
850  sep->addChild(mat);
851 
852  // The circle extends in x-y-plane, hence choose the transformation
853  SoTransform* tr = new SoTransform;
854  tr->translation.setValue(d.position.x(), d.position.y(), d.position.z());
855  Eigen::Vector3f xDir, yDir;
856  Eigen::Vector3f zDir = GetOrthonormalVectors(d.direction, xDir, yDir);
857  Eigen::Matrix3f rotGoal;
858  rotGoal << xDir, yDir, zDir;
859  // auto quat = VirtualRobot::MathTools::getRotation(Eigen::Vector3f::UnitZ(), d.direction);
860  // Eigen::AngleAxisf rotAA(Eigen::Quaternionf(quat.w, quat.x, quat.y, quat.z));
861  Eigen::AngleAxisf rotAA(rotGoal);
862  tr->rotation.setValue(SbVec3f(rotAA.axis().x(), rotAA.axis().y(), rotAA.axis().z()), rotAA.angle());
863  sep->addChild(tr);
864  auto node = CoinVisualizationFactory().createCircleArrow(d.radius,
865  d.width,
867  d.color,
868  16, 30);
869  SoNode* circle = dynamic_cast<CoinVisualizationNode&>(*node).getCoinVisualization();
870  circle->setName(SELECTION_NAME(d.layerName, d.name));
871  sep->addChild(circle);
872 
873  layer.addedCircleVisualizations[d.name] = sep;
874  layer.mainNode->addChild(sep);
875  }
876 
878  {
879  auto l = getScopedVisuLock();
880 
881  auto& layer = requestLayer(d.layerName);
882 
884 
885  if (!d.active)
886  {
887  return;
888  }
889 
890  const auto& pcl = d.pointCloud.points;
891 
892  SoSeparator* pclSep = new SoSeparator;
893 
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);
898 
899  SoMaterialBinding* pclMatBind = new SoMaterialBinding;
900  pclMatBind->value = SoMaterialBinding::OVERALL;
901  pclSep->addChild(pclMatBind);
902 
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)
909  {
910  return SbVec3f {elem.x, elem.y, elem.z};
911  }
912  );
913  pclCoords->point.setValues(0, coords.size(), coords.data());
914  pclSep->addChild(pclCoords);
915 
916  SoDrawStyle* pclStye = new SoDrawStyle;
917  pclStye->pointSize = d.pointCloud.pointSize;
918  pclSep->addChild(pclStye);
919 
920  pclSep->addChild(new SoPointSet);
921 
922  layer.addedPointCloudVisualizations[d.name] = pclSep;
923  layer.mainNode->addChild(pclSep);
924  }
925 
926  void DebugDrawerComponent::drawPolygon(const DebugDrawerComponent::PolygonData& d)
927  {
928  auto l = getScopedVisuLock();
929 
930  auto& layer = requestLayer(d.layerName);
931 
932  removePolygon(d.layerName, d.name);
933 
934  if (!d.active)
935  {
936  return;
937  }
938 
939  SoSeparator* sep = new SoSeparator;
940 
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);
946 
947  sep->addChild(VirtualRobot::CoinVisualizationFactory::CreatePolygonVisualization(d.points, d.colorInner, d.colorBorder, d.lineWidth));
948  sep->setName(SELECTION_NAME(d.layerName, d.name));
949  layer.addedPolygonVisualizations[d.name] = sep;
950  layer.mainNode->addChild(sep);
951  }
952 
953  void DebugDrawerComponent::drawTriMesh(const DebugDrawerComponent::TriMeshData& d)
954  {
955  auto l = getScopedVisuLock();
956 
957  auto& layer = requestLayer(d.layerName);
958 
959  removeTriMesh(d.layerName, d.name);
960 
961  if (!d.active)
962  {
963  return;
964  }
965 
966  TriMeshModelPtr triMesh = TriMeshModelPtr(new TriMeshModel());
967 
968  for (DrawColor color : d.triMesh.colors)
969  {
970  triMesh->addColor(VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, color.a));
971  }
972 
973  for (DebugDrawerVertex v : d.triMesh.vertices)
974  {
975  triMesh->addVertex(Eigen::Vector3f(v.x, v.y, v.z));
976  }
977 
978  for (DebugDrawerFace f : d.triMesh.faces)
979  {
980  MathTools::TriangleFace face;
981 
982  face.id1 = f.vertex1.vertexID;
983  face.idNormal1 = f.vertex1.normalID;
984  face.idColor1 = f.vertex1.colorID;
985 
986  face.id2 = f.vertex2.vertexID;
987  face.idNormal2 = f.vertex2.normalID;
988  face.idColor2 = f.vertex2.colorID;
989 
990  face.id3 = f.vertex3.vertexID;
991  face.idNormal3 = f.vertex3.normalID;
992  face.idColor3 = f.vertex3.colorID;
993 
994  face.normal = Eigen::Vector3f(f.normal.x, f.normal.y, f.normal.z);
995 
996  triMesh->addFace(face);
997  }
998 
999  SoSeparator* sep = new SoSeparator();
1000  SoNode* c = CoinVisualizationFactory::getCoinVisualization(triMesh);
1001  sep->addChild(c);
1002  layer.addedTriMeshVisualizations[d.name] = sep;
1003  layer.mainNode->addChild(sep);
1004 
1005  }
1006 
1007  void DebugDrawerComponent::drawArrow(const DebugDrawerComponent::ArrowData& d)
1008  {
1009  auto l = getScopedVisuLock();
1010 
1011  auto& layer = requestLayer(d.layerName);
1012 
1013  removeArrow(d.layerName, d.name);
1014 
1015  if (!d.active)
1016  {
1017  return;
1018  }
1019 
1020  SoSeparator* sep = new SoSeparator;
1021 
1022  SoTransform* tr = new SoTransform;
1023  tr->translation.setValue(d.position.x(), d.position.y(), d.position.z());
1024  sep->addChild(tr);
1025 
1026  SoSeparator* sepArrow = VirtualRobot::CoinVisualizationFactory::CreateArrow(d.direction, d.length, d.width, d.color);
1027  sep->addChild(sepArrow);
1028  layer.addedArrowVisualizations[d.name] = sep;
1029  layer.mainNode->addChild(sep);
1030  }
1031 
1032  void DebugDrawerComponent::ensureExistingRobotNodes(DebugDrawerComponent::RobotData& d)
1033  {
1034  auto l = getScopedVisuLock();
1035 
1036  if (!d.active)
1037  {
1038  return;
1039  }
1040 
1041  // load or get robot
1042  RobotPtr rob = requestRobot(d);
1043 
1044  if (!rob)
1045  {
1046  ARMARX_ERROR << deactivateSpam() << "Could not determine robot " << d.name << " at layer " << d.layerName;
1047  return;
1048  }
1049 
1050  std::map < std::string, float >::iterator i = d.configuration.begin();
1051  while (i != d.configuration.end())
1052  {
1053  if (!rob->hasRobotNode(i->first))
1054  {
1055  ARMARX_WARNING << deactivateSpam() << "Robot " << rob->getName() << " does not know RobotNode " << i->first;
1056  i = d.configuration.erase(i);
1057  }
1058  else
1059  {
1060  i++;
1061  }
1062  }
1063  }
1064 
1065  void DebugDrawerComponent::drawRobot(const DebugDrawerComponent::RobotData& d)
1066  {
1067  auto l = getScopedVisuLock();
1068 
1069  auto& layer = requestLayer(d.layerName);
1070 
1071  if (!d.active)
1072  {
1073  removeRobot(d.layerName, d.name);
1074  return;
1075  }
1076 
1077  // load or get robot
1078  RobotPtr rob = requestRobot(d);
1079 
1080  if (!rob)
1081  {
1082  ARMARX_ERROR << deactivateSpam() << "Could not determine robot " << d.name << " at layer " << d.layerName;
1083  return;
1084  }
1085 
1086  if (d.updatePose)
1087  {
1088  rob->setGlobalPose(d.globalPose);
1089  }
1090 
1091  if (d.updateConfig)
1092  {
1093  rob->setJointValues(d.configuration);
1094  }
1095 
1096  if (d.updateColor)
1097  {
1098  if (layer.addedRobotVisualizations.find(d.name) == layer.addedRobotVisualizations.end())
1099  {
1100  ARMARX_WARNING << deactivateSpam() << "Internal robot visu error";
1101  }
1102  else
1103  {
1104  SoSeparator* sep = layer.addedRobotVisualizations[d.name];
1105 
1106  for (int i = 0; i < sep->getNumChildren(); i++)
1107  {
1108  SoSeparator* nodeSep = dynamic_cast<SoSeparator*>(sep->getChild(i));
1109  SoMaterial* m = dynamic_cast<SoMaterial*>(nodeSep->getChild(0));
1110 
1111  if (!m)
1112  {
1113  ARMARX_ERROR << "Internal robot layer error2";
1114  return;
1115  }
1116 
1117  if (d.color.isNone())
1118  {
1119  m->setOverride(false);
1120  }
1121  else
1122  {
1123  if (d.color.r < 0 || d.color.g < 0 || d.color.b < 0)
1124  {
1125 
1126  }
1127 
1128  m->diffuseColor = SbColor(d.color.r, d.color.g, d.color.b);
1129  m->ambientColor = SbColor(0, 0, 0);
1130  m->transparency = std::max(0.0f, d.color.transparency);
1131  m->setOverride(true);
1132  }
1133  }
1134  }
1135  }
1136 
1137  if (d.updateNodeColor)
1138  {
1139  if (layer.addedRobotVisualizations.find(d.name) == layer.addedRobotVisualizations.end())
1140  {
1141  ARMARX_WARNING << deactivateSpam() << "Internal robot visu error";
1142  }
1143  else
1144  {
1145  SoSeparator* sep = layer.addedRobotVisualizations[d.name];
1146 
1147  if (!sep || sep->getNumChildren() < 2)
1148  {
1149  ARMARX_ERROR << "Internal robot layer error1";
1150  return;
1151  }
1152 
1153  std::string entryName = simox::alg::replace_all(std::string("__" + d.layerName + "__" + d.name + "__"), " ", "_");
1154  VirtualRobot::RobotPtr robot = activeRobots[entryName];
1155 
1156  std::vector<std::string> nodeNameList;
1157 
1158  for (size_t i = 0; i < robot->getRobotNodes().size(); ++i)
1159  {
1160  nodeNameList.push_back(robot->getRobotNodes()[i]->getName());
1161  }
1162 
1163  for (std::map < std::string, VirtualRobot::VisualizationFactory::Color >::const_iterator it = d.nodeColors.begin();
1164  it != d.nodeColors.end();
1165  it++)
1166  {
1167 
1168  std::string nodeName = it->first;
1169  VirtualRobot::VisualizationFactory::Color nodeColor = it->second;
1170 
1171  std::vector<std::string>::iterator strit;
1172  strit = std::find(nodeNameList.begin(), nodeNameList.end(), nodeName);
1173 
1174  if (strit == nodeNameList.end())
1175  {
1176  ARMARX_WARNING << "Cannot find correct robot node name " + nodeName + " for DebugDrawer node color update !!!";
1177  continue;
1178  }
1179 
1180  size_t ind = strit - nodeNameList.begin();
1181  SoSeparator* nodeSep = dynamic_cast<SoSeparator*>(sep->getChild(ind));
1182 
1183  if (!nodeSep)
1184  {
1185  ARMARX_ERROR << "Internal robot layer error3";
1186  return;
1187  }
1188 
1189  SoMaterial* nodeMat = dynamic_cast<SoMaterial*>(nodeSep->getChild(0));
1190 
1191  if (!nodeMat)
1192  {
1193  ARMARX_ERROR << "Internal robot layer error4";
1194  return;
1195  }
1196 
1197  if (nodeColor.isNone())
1198  {
1199  nodeMat->setOverride(false);
1200  }
1201  else
1202  {
1203  if (nodeColor.r < 0 || nodeColor.g < 0 || nodeColor.b < 0)
1204  {
1205  ARMARX_ERROR << "Internal robot layer node color error";
1206  return;
1207  }
1208 
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);
1213  }
1214 
1215  }
1216  }
1217  }
1218  }
1219 
1220  VirtualRobot::RobotPtr DebugDrawerComponent::requestRobot(const DebugDrawerComponent::RobotData& d)
1221  {
1222  auto l = getScopedVisuLock();
1223 
1224  auto& layer = requestLayer(d.layerName);
1225  std::string entryName = simox::alg::replace_all(std::string("__" + d.layerName + "__" + d.name + "__"), " ", "_");
1226 
1227  ARMARX_DEBUG << "Requesting robot " << entryName;
1228 
1229  if (activeRobots.find(entryName) != activeRobots.end())
1230  {
1231  ARMARX_DEBUG << "Found robot " << entryName << ":" << activeRobots[entryName]->getName();
1232  return activeRobots[entryName];
1233  }
1234 
1235  VirtualRobot::RobotPtr result;
1236 
1237  if (d.robotFile.empty())
1238  {
1239  ARMARX_INFO << deactivateSpam() << "No robot defined for layer " << d.layerName << ", with name " << d.name;
1240  return result;
1241  }
1242 
1243  if (!d.armarxProject.empty())
1244  {
1245  ARMARX_INFO << "Adding to datapaths of " << d.armarxProject;
1247 
1248  if (!finder.packageFound())
1249  {
1250  ARMARX_WARNING << "ArmarX Package " << d.armarxProject << " has not been found!";
1251  }
1252  else
1253  {
1254  ARMARX_INFO << "Adding to datapaths: " << finder.getDataDir();
1256  }
1257  }
1258 
1259  // load robot
1260  std::string filename = d.robotFile;
1261  ArmarXDataPath::getAbsolutePath(filename, filename);
1262 
1263  VirtualRobot::SceneObject::VisualizationType visuType = VirtualRobot::SceneObject::Full;
1264  VirtualRobot::RobotIO::RobotDescription loadMode = VirtualRobot::RobotIO::eFull;
1265 
1266  if (d.drawStyle == DrawStyle::CollisionModel)
1267  {
1268  visuType = VirtualRobot::SceneObject::Collision;
1269  loadMode = VirtualRobot::RobotIO::eCollisionModel;
1270  }
1271 
1272  ARMARX_INFO << "Loading robot from " << filename;
1273 
1274  try
1275  {
1276  if (loadedRobots.find(filename) == loadedRobots.end())
1277  {
1278  loadedRobots[filename] = RobotIO::loadRobot(filename, loadMode);
1279  }
1280 
1281  result = loadedRobots[filename]->clone(d.name);
1282  }
1283  catch (...)
1284  {
1285 
1286  }
1287 
1288  if (!result)
1289  {
1290  ARMARX_IMPORTANT << "Robot loading failed, file:" << filename;
1291  return result;
1292  }
1293 
1294  SoSeparator* sep = new SoSeparator;
1295  layer.mainNode->addChild(sep);
1296 
1297  for (size_t i = 0; i < result->getRobotNodes().size(); ++i)
1298  {
1299  VirtualRobot::RobotNodePtr robNode = result->getRobotNodes()[i];
1300  SoSeparator* nodeSep = new SoSeparator;
1301 
1302  SoMaterial* nodeMat = new SoMaterial;
1303  nodeMat->setOverride(false);
1304  nodeSep->addChild(nodeMat);
1305 
1306  CoinVisualizationPtr robNodeVisu = robNode->getVisualization<CoinVisualization>(visuType);
1307 
1308  if (robNodeVisu)
1309  {
1310  SoNode* sepRobNode = robNodeVisu->getCoinVisualization();
1311 
1312  if (sepRobNode)
1313  {
1314  nodeSep->addChild(sepRobNode);
1315  }
1316  }
1317 
1318  sep->addChild(nodeSep);
1319  }
1320 
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();
1325 
1326  return result;
1327  }
1328 
1329  void DebugDrawerComponent::removeLine(const std::string& layerName, const std::string& name)
1330  {
1331  auto l = getScopedVisuLock();
1332 
1333  if (!hasLayer(layerName))
1334  {
1335  return;
1336  }
1337 
1338  auto& layer = layers.at(layerName);
1339 
1340  if (layer.addedLineVisualizations.find(name) == layer.addedLineVisualizations.end())
1341  {
1342  return;
1343  }
1344 
1345  layer.mainNode->removeChild(layer.addedLineVisualizations[name]);
1346  layer.addedLineVisualizations.erase(name);
1347  }
1348 
1349  void DebugDrawerComponent::removeLineSet(const std::string& layerName, const std::string& name)
1350  {
1351  auto l = getScopedVisuLock();
1352 
1353  if (!hasLayer(layerName))
1354  {
1355  return;
1356  }
1357 
1358  auto& layer = layers.at(layerName);
1359 
1360  if (layer.addedLineSetVisualizations.find(name) == layer.addedLineSetVisualizations.end())
1361  {
1362  return;
1363  }
1364 
1365  layer.mainNode->removeChild(layer.addedLineSetVisualizations[name]);
1366  layer.addedLineSetVisualizations.erase(name);
1367  }
1368 
1369  void DebugDrawerComponent::removeBox(const std::string& layerName, const std::string& name)
1370  {
1371  auto l = getScopedVisuLock();
1372 
1373  if (!hasLayer(layerName))
1374  {
1375  return;
1376  }
1377 
1378  auto& layer = layers.at(layerName);
1379 
1380  if (layer.addedBoxVisualizations.find(name) == layer.addedBoxVisualizations.end())
1381  {
1382  return;
1383  }
1384 
1385  layer.mainNode->removeChild(layer.addedBoxVisualizations[name]);
1386  layer.addedBoxVisualizations.erase(name);
1387  }
1388 
1389  void DebugDrawerComponent::removeText(const std::string& layerName, const std::string& name)
1390  {
1391  auto l = getScopedVisuLock();
1392 
1393  if (!hasLayer(layerName))
1394  {
1395  return;
1396  }
1397 
1398  auto& layer = layers.at(layerName);
1399 
1400  if (layer.addedTextVisualizations.find(name) == layer.addedTextVisualizations.end())
1401  {
1402  return;
1403  }
1404 
1405  layer.mainNode->removeChild(layer.addedTextVisualizations[name]);
1406  layer.addedTextVisualizations.erase(name);
1407  }
1408 
1409  void DebugDrawerComponent::removeSphere(const std::string& layerName, const std::string& name)
1410  {
1411  auto l = getScopedVisuLock();
1412 
1413  if (!hasLayer(layerName))
1414  {
1415  return;
1416  }
1417 
1418  auto& layer = layers.at(layerName);
1419 
1420  if (layer.addedSphereVisualizations.find(name) == layer.addedSphereVisualizations.end())
1421  {
1422  return;
1423  }
1424 
1425  layer.mainNode->removeChild(layer.addedSphereVisualizations[name]);
1426  layer.addedSphereVisualizations.erase(name);
1427  }
1428 
1429  void DebugDrawerComponent::removeCylinder(const std::string& layerName, const std::string& name)
1430  {
1431  auto l = getScopedVisuLock();
1432 
1433  if (!hasLayer(layerName))
1434  {
1435  return;
1436  }
1437 
1438  auto& layer = layers.at(layerName);
1439 
1440  if (layer.addedCylinderVisualizations.find(name) == layer.addedCylinderVisualizations.end())
1441  {
1442  return;
1443  }
1444 
1445  layer.mainNode->removeChild(layer.addedCylinderVisualizations[name]);
1446  layer.addedCylinderVisualizations.erase(name);
1447  }
1448 
1449  void DebugDrawerComponent::removeCircle(const std::string& layerName, const std::string& name)
1450  {
1451  auto l = getScopedVisuLock();
1452 
1453  if (!hasLayer(layerName))
1454  {
1455  return;
1456  }
1457 
1458  auto& layer = layers.at(layerName);
1459 
1460  if (layer.addedCircleVisualizations.find(name) == layer.addedCircleVisualizations.end())
1461  {
1462  return;
1463  }
1464 
1465  layer.mainNode->removeChild(layer.addedCircleVisualizations[name]);
1466  layer.addedCircleVisualizations.erase(name);
1467  }
1468 
1469  void DebugDrawerComponent::removePointCloud(const std::string& layerName, const std::string& name)
1470  {
1471  auto l = getScopedVisuLock();
1472 
1473  if (!hasLayer(layerName))
1474  {
1475  return;
1476  }
1477 
1478  auto& layer = layers.at(layerName);
1479 
1480  if (layer.addedPointCloudVisualizations.find(name) == layer.addedPointCloudVisualizations.end())
1481  {
1482  return;
1483  }
1484 
1485  layer.mainNode->removeChild(layer.addedPointCloudVisualizations[name]);
1486  layer.addedPointCloudVisualizations.erase(name);
1487  }
1488 
1489  void DebugDrawerComponent::removePolygon(const std::string& layerName, const std::string& name)
1490  {
1491  auto l = getScopedVisuLock();
1492 
1493  if (!hasLayer(layerName))
1494  {
1495  return;
1496  }
1497 
1498  auto& layer = layers.at(layerName);
1499 
1500  if (layer.addedPolygonVisualizations.find(name) == layer.addedPolygonVisualizations.end())
1501  {
1502  return;
1503  }
1504 
1505  layer.mainNode->removeChild(layer.addedPolygonVisualizations[name]);
1506  layer.addedPolygonVisualizations.erase(name);
1507  }
1508 
1509  void DebugDrawerComponent::removeTriMesh(const std::string& layerName, const std::string& name)
1510  {
1511  auto l = getScopedVisuLock();
1512 
1513  if (!hasLayer(layerName))
1514  {
1515  return;
1516  }
1517 
1518  auto& layer = layers.at(layerName);
1519 
1520  if (layer.addedTriMeshVisualizations.find(name) == layer.addedTriMeshVisualizations.end())
1521  {
1522  return;
1523  }
1524 
1525  layer.mainNode->removeChild(layer.addedTriMeshVisualizations[name]);
1526  layer.addedTriMeshVisualizations.erase(name);
1527  }
1528 
1529  void DebugDrawerComponent::removeArrow(const std::string& layerName, const std::string& name)
1530  {
1531  auto l = getScopedVisuLock();
1532 
1533  if (!hasLayer(layerName))
1534  {
1535  return;
1536  }
1537 
1538  auto& layer = layers.at(layerName);
1539 
1540  if (layer.addedArrowVisualizations.find(name) == layer.addedArrowVisualizations.end())
1541  {
1542  return;
1543  }
1544 
1545  layer.mainNode->removeChild(layer.addedArrowVisualizations[name]);
1546  layer.addedArrowVisualizations.erase(name);
1547  }
1548 
1549  void DebugDrawerComponent::removeRobot(const std::string& layerName, const std::string& name)
1550  {
1551  auto l = getScopedVisuLock();
1552 
1553  // process active robots
1554  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + name + "__"), " ", "_");
1555  ARMARX_DEBUG << "Removing robot " << entryName;
1556 
1557  if (activeRobots.find(entryName) != activeRobots.end())
1558  {
1559  ARMARX_DEBUG << "Found robot to remove " << entryName;
1560  activeRobots.erase(entryName);
1561  ARMARX_DEBUG << "after Found robot to remove, activeRobots.size() = " << activeRobots.size();
1562  }
1563 
1564  // process visualizations
1565  if (!hasLayer(layerName))
1566  {
1567  ARMARX_DEBUG << "Layer not found " << layerName;
1568  return;
1569  }
1570 
1571  auto& layer = layers.at(layerName);
1572 
1573  if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1574  {
1575  ARMARX_INFO << "Could not find robot with name " << name;
1576  return;
1577  }
1578 
1579  ARMARX_DEBUG << "Removing visualization for " << entryName;
1580 
1581  ARMARX_DEBUG << "removing sep from layer.addedRobotVisualizations, d.name:" << name << ", layer:" << layerName << ", layer.addedRobotVisualizations.size():" << layer.addedRobotVisualizations.size();
1582 
1583  if (layer.addedRobotVisualizations.find(name) == layer.addedRobotVisualizations.end())
1584  {
1585  ARMARX_WARNING << "separator not found...";
1586  return;
1587  }
1588 
1589  ARMARX_DEBUG << "removing from layer.mainNode, layer.mainNode->getNumChildren()=" << layer.mainNode->getNumChildren();
1590 
1591  if (layer.mainNode->findChild(layer.addedRobotVisualizations[name]) < 0)
1592  {
1593  ARMARX_WARNING << "separator with wrong index...";
1594  return;
1595  }
1596 
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();
1601  }
1602 
1603  void DebugDrawerComponent::removeCoordSystem(const std::string& layerName, const std::string& name)
1604  {
1605  auto l = getScopedVisuLock();
1606 
1607  if (!hasLayer(layerName))
1608  {
1609  return;
1610  }
1611 
1612  auto& layer = layers.at(layerName);
1613 
1614  if (layer.addedCoordVisualizations.find(name) == layer.addedCoordVisualizations.end())
1615  {
1616  return;
1617  }
1618 
1619  layer.mainNode->removeChild(layer.addedCoordVisualizations[name]);
1620  layer.addedCoordVisualizations.erase(name);
1621  }
1622 
1623  void DebugDrawerComponent::setLayerVisibility(const std::string& layerName, bool visible)
1624  {
1625  auto l = getScopedVisuLock();
1626 
1627  if (!hasLayer(layerName))
1628  {
1629  return;
1630  }
1631 
1632  auto& layer = layers.at(layerName);
1633  layer.visible = visible;
1634 
1635  if (visible)
1636  {
1637  if (layerMainNode->findChild(layer.mainNode) < 0)
1638  {
1639  layerMainNode->addChild(layer.mainNode);
1640  }
1641  }
1642  else
1643  {
1644  if (layerMainNode->findChild(layer.mainNode) >= 0)
1645  {
1646  layerMainNode->removeChild(layer.mainNode);
1647  }
1648  }
1649  }
1650 
1651  void DebugDrawerComponent::disableAllLayers(const ::Ice::Current&)
1652  {
1653  auto l = getScopedVisuLock();
1654 
1655  if (selectionNode->findChild(layerMainNode) >= 0)
1656  {
1657  selectionNode->removeChild(layerMainNode);
1658  }
1659  }
1660 
1661  void DebugDrawerComponent::enableAllLayers(const ::Ice::Current&)
1662  {
1663  auto l = getScopedVisuLock();
1664 
1665  if (selectionNode->findChild(layerMainNode) < 0)
1666  {
1667  selectionNode->addChild(layerMainNode);
1668  }
1669  }
1670 
1671  void DebugDrawerComponent::setScaledPoseVisu(const std::string& layerName, const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current&)
1672  {
1673  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(poseName);
1674  Eigen::Matrix4f gp = PosePtr::dynamicCast(globalPose)->toEigen();
1675  {
1676  auto l = getScopedAccumulatedDataLock();
1677  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + poseName + "__"), " ", "_");
1678  CoordData& d = accumulatedUpdateData.coord[entryName];
1679  d.globalPose = gp;
1680  d.layerName = layerName;
1681  d.name = poseName;
1682  d.scale = scale;
1683  d.active = true;
1684  }
1685  }
1686 
1687  void DebugDrawerComponent::setScaledPoseDebugLayerVisu(const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current&)
1688  {
1689  setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, scale);
1690  }
1691 
1692  void DebugDrawerComponent::setPoseVisu(const std::string& layerName, const std::string& poseName, const PoseBasePtr& globalPose, const Ice::Current&)
1693  {
1694  setScaledPoseVisu(layerName, poseName, globalPose, 1.f);
1695  }
1696 
1697  void DebugDrawerComponent::setPoseDebugLayerVisu(const std::string& poseName, const PoseBasePtr& globalPose, const Ice::Current&)
1698  {
1699  setScaledPoseVisu(DEBUG_LAYER_NAME, poseName, globalPose, 1.f);
1700  }
1701 
1702  void DebugDrawerComponent::removePoseVisu(const std::string& layerName, const std::string& poseName, const Ice::Current&)
1703  {
1704  {
1705  auto l = getScopedAccumulatedDataLock();
1706  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + poseName + "__"), " ", "_");
1707  CoordData& d = accumulatedUpdateData.coord[entryName];
1708  d.layerName = layerName;
1709  d.name = poseName;
1710  d.active = false;
1711  }
1712  }
1713 
1714  void DebugDrawerComponent::removePoseDebugLayerVisu(const std::string& poseName, const Ice::Current&)
1715  {
1716  removePoseVisu(DEBUG_LAYER_NAME, poseName);
1717  }
1718 
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&)
1720  {
1721  Eigen::Vector3f p1 = Vector3Ptr::dynamicCast(globalPosition1)->toEigen();
1722  Eigen::Vector3f p2 = Vector3Ptr::dynamicCast(globalPosition2)->toEigen();
1723  VirtualRobot::VisualizationFactory::Color c(color.r, color.g, color.b, 1 - color.a);
1724  {
1725  auto l = getScopedAccumulatedDataLock();
1726  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + lineName + "__"), " ", "_");
1727  LineData& d = accumulatedUpdateData.line[entryName];
1728  d.p1 = p1;
1729  d.p2 = p2;
1730  d.layerName = layerName;
1731  d.name = lineName;
1732  d.color = c;
1733  d.scale = lineWidth;
1734  d.active = true;
1735  }
1736  }
1737 
1738  void DebugDrawerComponent::setLineDebugLayerVisu(const std::string& lineName, const Vector3BasePtr& globalPosition1, const Vector3BasePtr& globalPosition2, float lineWidth, const DrawColor& color, const Ice::Current&)
1739  {
1740  setLineVisu(DEBUG_LAYER_NAME, lineName, globalPosition1, globalPosition2, lineWidth, color);
1741  }
1742 
1743  void DebugDrawerComponent::removeLineVisu(const std::string& layerName, const std::string& lineName, const Ice::Current&)
1744  {
1745  {
1746  auto l = getScopedAccumulatedDataLock();
1747  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + lineName + "__"), " ", "_");
1748  LineData& d = accumulatedUpdateData.line[entryName];
1749  d.layerName = layerName;
1750  d.name = lineName;
1751  d.active = false;
1752  }
1753  }
1754 
1755  void DebugDrawerComponent::removeLineDebugLayerVisu(const std::string& lineName, const Ice::Current&)
1756  {
1757  removeLineVisu(DEBUG_LAYER_NAME, lineName);
1758  }
1759 
1760  void DebugDrawerComponent::setLineSetVisu(const std::string& layerName, const std::string& lineSetName, const DebugDrawerLineSet& lineSet, const Ice::Current&)
1761  {
1762  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(lineSetName);
1763  {
1764  auto l = getScopedAccumulatedDataLock();
1765  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + lineSetName + "__"), " ", "_");
1766  LineSetData& d = accumulatedUpdateData.lineSet[entryName];
1767  d.lineSet = lineSet;
1768  d.layerName = layerName;
1769  d.name = lineSetName;
1770  d.active = true;
1771  }
1772  }
1773 
1774  void DebugDrawerComponent::setLineSetDebugLayerVisu(const std::string& lineSetName, const DebugDrawerLineSet& lineSet, const Ice::Current&)
1775  {
1776  setLineSetVisu(DEBUG_LAYER_NAME, lineSetName, lineSet);
1777  }
1778 
1779  void DebugDrawerComponent::removeLineSetVisu(const std::string& layerName, const std::string& lineSetName, const Ice::Current&)
1780  {
1781  {
1782  auto l = getScopedAccumulatedDataLock();
1783  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + lineSetName + "__"), " ", "_");
1784  LineSetData& d = accumulatedUpdateData.lineSet[entryName];
1785  d.layerName = layerName;
1786  d.name = lineSetName;
1787  d.active = false;
1788  }
1789  }
1790 
1791  void DebugDrawerComponent::removeLineSetDebugLayerVisu(const std::string& lineSetName, const Ice::Current&)
1792  {
1793  removeLineSetVisu(DEBUG_LAYER_NAME, lineSetName);
1794  }
1795 
1796  void DebugDrawerComponent::setBoxVisu(const std::string& layerName, const std::string& boxName, const PoseBasePtr& globalPose, const Vector3BasePtr& dimensions, const DrawColor& color, const Ice::Current&)
1797  {
1798  Eigen::Matrix4f gp = PosePtr::dynamicCast(globalPose)->toEigen();
1799  VirtualRobot::VisualizationFactory::Color c(color.r, color.g, color.b, 1 - color.a);
1800  {
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;
1807  d.layerName = layerName;
1808  d.name = boxName;
1809  d.color = c;
1810  d.globalPose = gp;
1811  d.active = true;
1812  }
1813  }
1814 
1815  void DebugDrawerComponent::setBoxDebugLayerVisu(const std::string& boxName, const PoseBasePtr& globalPose, const Vector3BasePtr& dimensions, const DrawColor& color, const Ice::Current&)
1816  {
1817  setBoxVisu(DEBUG_LAYER_NAME, boxName, globalPose, dimensions, color);
1818  }
1819 
1820  void DebugDrawerComponent::removeBoxVisu(const std::string& layerName, const std::string& boxName, const Ice::Current&)
1821  {
1822  {
1823  auto l = getScopedAccumulatedDataLock();
1824  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + boxName + "__"), " ", "_");
1825  BoxData& d = accumulatedUpdateData.box[entryName];
1826  d.layerName = layerName;
1827  d.name = boxName;
1828  d.active = false;
1829  }
1830  }
1831 
1832  void DebugDrawerComponent::removeBoxDebugLayerVisu(const std::string& boxName, const Ice::Current&)
1833  {
1834  removeBoxVisu(DEBUG_LAYER_NAME, boxName);
1835  }
1836 
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&)
1838  {
1839  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(textName);
1840  {
1841  auto l = getScopedAccumulatedDataLock();
1842  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + textName + "__"), " ", "_");
1843  TextData& d = accumulatedUpdateData.text[entryName];
1844  d.text = text;
1845  d.position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
1846  d.layerName = layerName;
1847  d.name = textName;
1848  d.color = VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, 1 - color.a);
1849  d.size = size;
1850  d.active = true;
1851  }
1852  }
1853 
1854  void DebugDrawerComponent::setTextDebugLayerVisu(const std::string& textName, const std::string& text, const Vector3BasePtr& globalPosition, const DrawColor& color, int size, const Ice::Current&)
1855  {
1856  setTextVisu(DEBUG_LAYER_NAME, textName, text, globalPosition, color, size);
1857  }
1858 
1859  void DebugDrawerComponent::removeTextVisu(const std::string& layerName, const std::string& textName, const Ice::Current&)
1860  {
1861  {
1862  auto l = getScopedAccumulatedDataLock();
1863  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + textName + "__"), " ", "_");
1864  TextData& d = accumulatedUpdateData.text[entryName];
1865  d.layerName = layerName;
1866  d.name = textName;
1867  d.active = false;
1868  }
1869  }
1870 
1871  void DebugDrawerComponent::removeTextDebugLayerVisu(const std::string& textName, const Ice::Current&)
1872  {
1873  removeTextVisu(DEBUG_LAYER_NAME, textName);
1874  }
1875 
1876  void DebugDrawerComponent::setSphereVisu(const std::string& layerName, const std::string& sphereName, const Vector3BasePtr& globalPosition, const DrawColor& color, float radius, const Ice::Current&)
1877  {
1878  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(sphereName);
1879  {
1880  auto l = getScopedAccumulatedDataLock();
1881  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + sphereName + "__"), " ", "_");
1882  SphereData& d = accumulatedUpdateData.sphere[entryName];
1883  d.radius = radius;
1884  d.position = Vector3Ptr::dynamicCast(globalPosition)->toEigen();
1885  d.layerName = layerName;
1886  d.name = sphereName;
1887  d.color = VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, 1 - color.a);
1888  d.active = true;
1889  }
1890  }
1891 
1892  void DebugDrawerComponent::setSphereDebugLayerVisu(const std::string& sphereName, const Vector3BasePtr& globalPosition, const DrawColor& color, float radius, const Ice::Current&)
1893  {
1894  setSphereVisu(DEBUG_LAYER_NAME, sphereName, globalPosition, color, radius);
1895  }
1896 
1897  void DebugDrawerComponent::removeSphereVisu(const std::string& layerName, const std::string& sphereName, const Ice::Current&)
1898  {
1899  {
1900  auto l = getScopedAccumulatedDataLock();
1901  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + sphereName + "__"), " ", "_");
1902  SphereData& d = accumulatedUpdateData.sphere[entryName];
1903  d.layerName = layerName;
1904  d.name = sphereName;
1905  d.active = false;
1906  }
1907  }
1908 
1909  void DebugDrawerComponent::removeSphereDebugLayerVisu(const std::string& sphereName, const Ice::Current&)
1910  {
1911  removeSphereVisu(DEBUG_LAYER_NAME, sphereName);
1912  }
1913 
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&)
1915  {
1916  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(cylinderName);
1917  {
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();
1923  d.length = length;
1924  d.radius = radius;
1925  d.layerName = layerName;
1926  d.name = cylinderName;
1927  d.color = VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, 1 - color.a);
1928  d.active = true;
1929  }
1930  }
1931 
1932  void DebugDrawerComponent::setCylinderDebugLayerVisu(const std::string& cylinderName, const Vector3BasePtr& globalPosition, const Vector3BasePtr& direction, float length, float radius, const DrawColor& color, const Ice::Current&)
1933  {
1934  setCylinderVisu(DEBUG_LAYER_NAME, cylinderName, globalPosition, direction, length, radius, color);
1935  }
1936 
1937  void DebugDrawerComponent::removeCylinderVisu(const std::string& layerName, const std::string& cylinderName, const Ice::Current&)
1938  {
1939  {
1940  auto l = getScopedAccumulatedDataLock();
1941  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + cylinderName + "__"), " ", "_");
1942  CylinderData& d = accumulatedUpdateData.cylinder[entryName];
1943  d.layerName = layerName;
1944  d.name = cylinderName;
1945  d.active = false;
1946  }
1947  }
1948 
1949  void DebugDrawerComponent::removeCylinderDebugLayerVisu(const std::string& cylinderName, const Ice::Current&)
1950  {
1951  removeCylinderVisu(DEBUG_LAYER_NAME, cylinderName);
1952  }
1953 
1954  void DebugDrawerComponent::setPointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const DebugDrawerPointCloud& pointCloud, const Ice::Current&)
1955  {
1956  ARMARX_DEBUG << VAROUT(layerName) << VAROUT(pointCloudName);
1957  {
1958  auto l = getScopedAccumulatedDataLock();
1959  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
1960  PointCloudData& d = accumulatedUpdateData.pointcloud[entryName];
1961  d.pointCloud = pointCloud;
1962  d.layerName = layerName;
1963  d.name = pointCloudName;
1964  d.active = true;
1965  }
1966  }
1967 
1968  void DebugDrawerComponent::setPointCloudDebugLayerVisu(const std::string& pointCloudName, const DebugDrawerPointCloud& pointCloud, const Ice::Current&)
1969  {
1970  setPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
1971  }
1972 
1973  void DebugDrawerComponent::removePointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const Ice::Current&)
1974  {
1975  {
1976  auto l = getScopedAccumulatedDataLock();
1977  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
1978  PointCloudData& d = accumulatedUpdateData.pointcloud[entryName];
1979  d.layerName = layerName;
1980  d.name = pointCloudName;
1981  d.active = false;
1982  }
1983  }
1984 
1985  void DebugDrawerComponent::removePointCloudDebugLayerVisu(const std::string& pointCloudName, const Ice::Current&)
1986  {
1987  removePointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
1988  }
1989 
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&)
1991  {
1992  {
1993  auto l = getScopedAccumulatedDataLock();
1994  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + polygonName + "__"), " ", "_");
1995  PolygonData& d = accumulatedUpdateData.polygons[entryName];
1996 
1997  std::vector< Eigen::Vector3f > points;
1998 
1999  for (size_t i = 0; i < polygonPoints.size(); i++)
2000  {
2001  Eigen::Vector3f p = Vector3Ptr::dynamicCast(polygonPoints.at(i))->toEigen();;
2002  points.push_back(p);
2003  }
2004 
2005  d.points = points;
2006  d.colorInner = VirtualRobot::VisualizationFactory::Color(colorInner.r, colorInner.g, colorInner.b, 1 - colorInner.a);;
2007  d.colorBorder = VirtualRobot::VisualizationFactory::Color(colorBorder.r, colorBorder.g, colorBorder.b, 1 - colorBorder.a);;
2008 
2009  d.lineWidth = lineWidth;
2010  d.layerName = layerName;
2011  d.name = polygonName;
2012  d.active = true;
2013  }
2014  }
2015 
2016  void DebugDrawerComponent::setPolygonDebugLayerVisu(const std::string& polygonName, const std::vector<Vector3BasePtr>& polygonPoints, const DrawColor& colorInner, const DrawColor& colorBorder, float lineWidth, const Ice::Current&)
2017  {
2018  setPolygonVisu(DEBUG_LAYER_NAME, polygonName, polygonPoints, colorInner, colorBorder, lineWidth);
2019  }
2020 
2021  void DebugDrawerComponent::removePolygonVisu(const std::string& layerName, const std::string& polygonName, const Ice::Current&)
2022  {
2023  {
2024  auto l = getScopedAccumulatedDataLock();
2025  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + polygonName + "__"), " ", "_");
2026  PolygonData& d = accumulatedUpdateData.polygons[entryName];
2027  d.layerName = layerName;
2028  d.name = polygonName;
2029  d.active = false;
2030  }
2031  }
2032 
2033  void DebugDrawerComponent::removePolygonDebugLayerVisu(const std::string& polygonName, const Ice::Current&)
2034  {
2035  removePolygonVisu(DEBUG_LAYER_NAME, polygonName);
2036  }
2037 
2038  void DebugDrawerComponent::setTriMeshVisu(const std::string& layerName, const std::string& triMeshName, const DebugDrawerTriMesh& triMesh, const Ice::Current&)
2039  {
2040  {
2041  auto l = getScopedAccumulatedDataLock();
2042  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + triMeshName + "__"), " ", "_");
2043  TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2044  d.triMesh = triMesh;
2045  d.layerName = layerName;
2046  d.name = triMeshName;
2047  d.active = true;
2048  }
2049  }
2050 
2051  void DebugDrawerComponent::setTriMeshDebugLayerVisu(const std::string& triMeshName, const DebugDrawerTriMesh& triMesh, const Ice::Current&)
2052  {
2053  setTriMeshVisu(DEBUG_LAYER_NAME, triMeshName, triMesh);
2054  }
2055 
2056  void DebugDrawerComponent::removeTriMeshVisu(const std::string& layerName, const std::string& triMeshName, const Ice::Current&)
2057  {
2058  {
2059  auto l = getScopedAccumulatedDataLock();
2060  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + triMeshName + "__"), " ", "_");
2061  TriMeshData& d = accumulatedUpdateData.triMeshes[entryName];
2062  d.layerName = layerName;
2063  d.name = triMeshName;
2064  d.active = false;
2065  }
2066  }
2067 
2068  void DebugDrawerComponent::removeTriMeshDebugLayerVisu(const std::string& triMeshName, const Ice::Current&)
2069  {
2070  removeTriMeshVisu(DEBUG_LAYER_NAME, triMeshName);
2071  }
2072 
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&)
2074  {
2075  {
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();
2081  d.color = VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, 1 - color.a);;
2082  d.length = length;
2083  d.width = width;
2084  d.layerName = layerName;
2085  d.name = arrowName;
2086  d.active = true;
2087  }
2088  }
2089 
2090  void DebugDrawerComponent::setArrowDebugLayerVisu(const std::string& arrowName, const Vector3BasePtr& position, const Vector3BasePtr& direction, const DrawColor& color, float length, float width, const Ice::Current&)
2091  {
2092  setArrowVisu(DEBUG_LAYER_NAME, arrowName, position, direction, color, length, width);
2093  }
2094 
2095  void DebugDrawerComponent::removeArrowVisu(const std::string& layerName, const std::string& arrowName, const Ice::Current&)
2096  {
2097  {
2098  auto l = getScopedAccumulatedDataLock();
2099  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + arrowName + "__"), " ", "_");
2100  ArrowData& d = accumulatedUpdateData.arrows[entryName];
2101  d.layerName = layerName;
2102  d.name = arrowName;
2103  d.active = false;
2104  }
2105  }
2106 
2107  void DebugDrawerComponent::removeArrowDebugLayerVisu(const std::string& arrowName, const Ice::Current&)
2108  {
2109  removeArrowVisu(DEBUG_LAYER_NAME, arrowName);
2110  }
2111 
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&)
2113  {
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];
2118 
2119  d.robotFile = robotFile;
2120  d.armarxProject = armarxProject;
2121  d.drawStyle = drawStyle;
2122 
2123  d.layerName = layerName;
2124  d.name = robotName;
2125  d.active = true;
2126  }
2127 
2128  void DebugDrawerComponent::updateRobotPose(const std::string& layerName, const std::string& robotName, const PoseBasePtr& globalPose, const Ice::Current&)
2129  {
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];
2134 
2135  // update data
2136  d.update = true;
2137  d.updatePose = true;
2138  d.globalPose = PosePtr::dynamicCast(globalPose)->toEigen();
2139 
2140  d.layerName = layerName;
2141  d.name = robotName;
2142  d.active = true;
2143  }
2144 
2145  void DebugDrawerComponent::updateRobotConfig(const std::string& layerName, const std::string& robotName, const std::map<std::string, float>& configuration, const Ice::Current&)
2146  {
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];
2151 
2152  // update data
2153  d.update = true;
2154  d.updateConfig = true;
2155  d.layerName = layerName;
2156  d.name = robotName;
2157 
2158  for (auto& it : configuration)
2159  {
2160  d.configuration[it.first] = it.second;
2161  }
2162 
2163  d.active = true;
2164  }
2165 
2166  void DebugDrawerComponent::updateRobotColor(const std::string& layerName, const std::string& robotName, const DrawColor& c, const Ice::Current&)
2167  {
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];
2172 
2173  // update data
2174  d.update = true;
2175  d.updateColor = true;
2176  d.layerName = layerName;
2177  d.name = robotName;
2178 
2179  if (c.a == 0 && c.b == 0 && c.r == 0 && c.g == 0)
2180  {
2181  d.color = VirtualRobot::VisualizationFactory::Color::None();
2182  }
2183  else
2184  {
2185  d.color = VirtualRobot::VisualizationFactory::Color(c.r, c.g, c.b, 1 - c.a);
2186  }
2187 
2188  d.active = true;
2189  }
2190 
2191  void DebugDrawerComponent::updateRobotNodeColor(const std::string& layerName, const std::string& robotName, const std::string& robotNodeName, const DrawColor& c, const Ice::Current&)
2192  {
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];
2197 
2198  d.update = true;
2199  d.updateNodeColor = true;
2200  d.layerName = layerName;
2201  d.name = robotName;
2202 
2203  if (c.a == 0 && c.b == 0 && c.r == 0 && c.g == 0)
2204  {
2205  d.nodeColors[robotNodeName] = VirtualRobot::VisualizationFactory::Color::None();
2206  }
2207  else
2208  {
2209  d.nodeColors[robotNodeName] = VirtualRobot::VisualizationFactory::Color(c.r, c.g, c.b, 1 - c.a);
2210  }
2211 
2212  d.active = true;
2213 
2214 
2215  }
2216 
2217  void DebugDrawerComponent::removeRobotVisu(const std::string& layerName, const std::string& robotName, const Ice::Current&)
2218  {
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];
2223 
2224  d.layerName = layerName;
2225  d.name = robotName;
2226  d.active = false;
2227  }
2228 
2229  void DebugDrawerComponent::clearAll(const Ice::Current&)
2230  {
2231  for (auto& i : layers)
2232  {
2233  clearLayer(i.first);
2234  }
2235  }
2236 
2237  void DebugDrawerComponent::clearLayer(const std::string& layerName, const Ice::Current&)
2238  {
2239  auto lockData = getScopedAccumulatedDataLock();
2240  //updates should only contain elements to add for each layer after the last clear for this layer was executed
2241  //this prevents a sequence add,clear,add to result in an empty layer
2242  //=>remove all objects pending for this layer
2243  removeAccumulatedData(layerName);
2244  accumulatedUpdateData.clearLayers.emplace(layerName);
2245 
2246  }
2247 
2248  void DebugDrawerComponent::clearLayerQt(const std::string& layerName)
2249  {
2250  auto lockData = getScopedAccumulatedDataLock();
2251  auto lockVisu = getScopedVisuLock();
2252 
2253  ARMARX_DEBUG << "clearing layer " << layerName;
2254 
2255  if (!hasLayer(layerName))
2256  {
2257  if (verbose)
2258  {
2259  ARMARX_VERBOSE << "Layer " << layerName << " can't be cleared, because it does not exist.";
2260  }
2261 
2262  return;
2263  }
2264 
2265  if (verbose)
2266  {
2267  ARMARX_VERBOSE << "Clearing layer " << layerName;
2268  }
2269 
2270  selectionNode->deselectAll();
2271 
2272  Layer& layer = layers.at(layerName);
2273 
2274  for (const auto& i : layer.addedCoordVisualizations)
2275  {
2276  removePoseVisu(layerName, i.first);
2277  }
2278 
2279  for (const auto& i : layer.addedLineVisualizations)
2280  {
2281  removeLineVisu(layerName, i.first);
2282  }
2283 
2284  for (const auto& i : layer.addedLineSetVisualizations)
2285  {
2286  removeLineSetVisu(layerName, i.first);
2287  }
2288 
2289  for (const auto& i : layer.addedBoxVisualizations)
2290  {
2291  removeBoxVisu(layerName, i.first);
2292  }
2293 
2294  for (const auto& i : layer.addedTextVisualizations)
2295  {
2296  removeTextVisu(layerName, i.first);
2297  }
2298 
2299  for (const auto& i : layer.addedSphereVisualizations)
2300  {
2301  removeSphereVisu(layerName, i.first);
2302  }
2303 
2304  for (const auto& i : layer.addedCylinderVisualizations)
2305  {
2306  removeCylinderVisu(layerName, i.first);
2307  }
2308 
2309  for (const auto& i : layer.addedCircleVisualizations)
2310  {
2311  removeCircleVisu(layerName, i.first);
2312  }
2313 
2314  for (const auto& i : layer.addedPointCloudVisualizations)
2315  {
2316  removePointCloudVisu(layerName, i.first);
2317  }
2318 
2319  for (const auto& i : layer.addedColoredPointCloudVisualizations)
2320  {
2321  removeColoredPointCloudVisu(layerName, i.first);
2322  }
2323 
2324  for (const auto& i : layer.addedPolygonVisualizations)
2325  {
2326  removePolygonVisu(layerName, i.first);
2327  }
2328 
2329  for (const auto& i : layer.addedTriMeshVisualizations)
2330  {
2331  removeTriMeshVisu(layerName, i.first);
2332  }
2333 
2334  for (const auto& i : layer.added24BitColoredPointCloudVisualizations)
2335  {
2336  remove24BitColoredPointCloudVisu(layerName, i.first);
2337  }
2338 
2339  for (const auto& i : layer.addedArrowVisualizations)
2340  {
2341  removeArrowVisu(layerName, i.first);
2342  }
2343 
2344  for (const auto& i : layer.addedRobotVisualizations)
2345  {
2346  removeRobotVisu(layerName, i.first);
2347  }
2348 
2349  for (const auto& i : layer.addedCustomVisualizations)
2350  {
2351  removeCustomVisu(layerName, i.first);
2352  }
2353  }
2354 
2355  void DebugDrawerComponent::clearDebugLayer(const Ice::Current&)
2356  {
2357  clearLayer(DEBUG_LAYER_NAME);
2358  }
2359 
2360  void DebugDrawerComponent::setMutex(RecursiveMutexPtr const& m)
2361  {
2362  mutex = m;
2363  }
2364 
2365  auto DebugDrawerComponent::getScopedVisuLock() -> RecursiveMutexLockPtr
2366  {
2368 
2369  if (mutex)
2370  {
2371  //ARMARX_IMPORTANT << mutex.get();
2372  l.reset(new RecursiveMutexLock(*mutex));
2373  }
2374  else
2375  {
2376  ARMARX_IMPORTANT << deactivateSpam(5) << "NO 3D MUTEX!!!";
2377  }
2378 
2379  return l;
2380  }
2381 
2382  auto DebugDrawerComponent::getScopedAccumulatedDataLock() -> RecursiveMutexLockPtr
2383  {
2384  RecursiveMutexLockPtr l(new RecursiveMutexLock(*dataUpdateMutex));
2385  return l;
2386  }
2387 
2388  SoSeparator* DebugDrawerComponent::getVisualization()
2389  {
2390  return coinVisu;
2391  }
2392 
2393  DebugDrawerComponent::Layer& DebugDrawerComponent::requestLayer(const std::string& layerName)
2394  {
2395  auto l = getScopedVisuLock();
2396 
2397  if (hasLayer(layerName))
2398  {
2399  return layers.at(layerName);
2400  }
2401 
2402  ARMARX_VERBOSE << "Created layer " << layerName;
2403 
2404  SoSeparator* mainNode = new SoSeparator {};
2405  mainNode->ref();
2406  layers[layerName] = Layer();
2407  layers.at(layerName).mainNode = mainNode;
2408  layers.at(layerName).visible = getDefaultLayerVisibility(layerName);
2409  if (layers.at(layerName).visible)
2410  {
2411  layerMainNode->addChild(mainNode);
2412  }
2413  return layers.at(layerName);
2414  }
2415 
2416  void DebugDrawerComponent::updateVisualization()
2417  {
2418  auto lockData = getScopedAccumulatedDataLock();
2419  auto lockVisu = getScopedVisuLock();
2420  // check for clear&remove
2421  //(updates only contain elements to add for each layer after the last clear for this layer was executed)
2422  //this prevents a sequence add,clear,add to result in an empty layer
2423  for (const auto& layer : accumulatedUpdateData.clearLayers)
2424  {
2425  clearLayerQt(layer);
2426  }
2427  accumulatedUpdateData.clearLayers.clear();
2428 
2429  for (const auto& layer : accumulatedUpdateData.removeLayers)
2430  {
2431  removeLayerQt(layer);
2432  }
2433  accumulatedUpdateData.removeLayers.clear();
2434 
2435  //add elements
2436  for (auto& e : accumulatedUpdateData.coord)
2437  {
2438  drawCoordSystem(e.second);
2439  }
2440  accumulatedUpdateData.coord.clear();
2441 
2442  for (auto& e : accumulatedUpdateData.box)
2443  {
2444  drawBox(e.second);
2445  }
2446  accumulatedUpdateData.box.clear();
2447 
2448  for (auto& e : accumulatedUpdateData.line)
2449  {
2450  drawLine(e.second);
2451  }
2452  accumulatedUpdateData.line.clear();
2453 
2454  for (auto& e : accumulatedUpdateData.lineSet)
2455  {
2456  drawLineSet(e.second);
2457  }
2458  accumulatedUpdateData.lineSet.clear();
2459 
2460  for (auto& e : accumulatedUpdateData.sphere)
2461  {
2462  drawSphere(e.second);
2463  }
2464  accumulatedUpdateData.sphere.clear();
2465 
2466  for (auto& e : accumulatedUpdateData.cylinder)
2467  {
2468  drawCylinder(e.second);
2469  }
2470  accumulatedUpdateData.cylinder.clear();
2471 
2472  for (auto& e : accumulatedUpdateData.circle)
2473  {
2474  drawCircle(e.second);
2475  }
2476  accumulatedUpdateData.circle.clear();
2477 
2478  for (auto& e : accumulatedUpdateData.text)
2479  {
2480  drawText(e.second);
2481  }
2482  accumulatedUpdateData.text.clear();
2483 
2484  for (auto& e : accumulatedUpdateData.pointcloud)
2485  {
2486  drawPointCloud(e.second);
2487  }
2488  accumulatedUpdateData.pointcloud.clear();
2489 
2490  for (auto& e : accumulatedUpdateData.polygons)
2491  {
2492  drawPolygon(e.second);
2493  }
2494  accumulatedUpdateData.polygons.clear();
2495 
2496  for (auto& e : accumulatedUpdateData.arrows)
2497  {
2498  drawArrow(e.second);
2499  }
2500  accumulatedUpdateData.arrows.clear();
2501 
2502  for (auto& e : accumulatedUpdateData.triMeshes)
2503  {
2504  drawTriMesh(e.second);
2505  }
2506  accumulatedUpdateData.triMeshes.clear();
2507 
2508  for (auto& e : accumulatedUpdateData.robots)
2509  {
2510  ARMARX_DEBUG << "update visu / drawRobot for robot " << e.first;
2511  ensureExistingRobotNodes(e.second);
2512 
2513  drawRobot(e.second);
2514  e.second.nodeColors.clear();
2515  }
2516  accumulatedUpdateData.robots.clear();
2517 
2518  for (auto& e : accumulatedUpdateData.coloredpointcloud)
2519  {
2520  drawColoredPointCloud(e.second);
2521  }
2522  accumulatedUpdateData.coloredpointcloud.clear();
2523 
2524  for (auto& e : accumulatedUpdateData.colored24Bitpointcloud)
2525  {
2526  draw24BitColoredPointCloud(e.second);
2527  }
2528  accumulatedUpdateData.colored24Bitpointcloud.clear();
2529 
2530  onUpdateVisualization();
2531  }
2532 
2533  bool DebugDrawerComponent::hasLayer(const std::string& layerName, const ::Ice::Current&)
2534  {
2535  auto l = getScopedVisuLock();
2536  return layers.find(layerName) != layers.end();
2537  }
2538 
2539  void DebugDrawerComponent::removeLayer(const std::string& layerName, const ::Ice::Current&)
2540  {
2541  auto lockData = getScopedAccumulatedDataLock();
2542  //updates should only contain elements to add for each layer after the last clear/remove for this layer was executed
2543  //this prevents a sequence add,clear,add to result in an empty layer
2544  //=>remove all objects pending for this layer
2545  removeAccumulatedData(layerName);
2546  accumulatedUpdateData.removeLayers.emplace(layerName);
2547  }
2548 
2549  void DebugDrawerComponent::removeLayerQt(const std::string& layerName)
2550  {
2551  auto lockData = getScopedAccumulatedDataLock();
2552  auto lockVisu = getScopedVisuLock();
2553  if (!hasLayer(layerName))
2554  {
2555  if (verbose)
2556  {
2557  ARMARX_VERBOSE << "Layer " << layerName << " can't be removed, because it does not exist.";
2558  }
2559 
2560  return;
2561  }
2562 
2563  if (verbose)
2564  {
2565  ARMARX_VERBOSE << "Removing layer " << layerName;
2566  }
2567 
2568  clearLayerQt(layerName);
2569  {
2570  auto& layer = layers.at(layerName);
2571  layerMainNode->removeChild(layer.mainNode);
2572  layer.mainNode->unref();
2573  layers.erase(layerName);
2574  }
2575  }
2576 
2577  template<class UpdateDataType>
2578  void removeUpdateDataFromMap(const std::string& layerName, std::map<std::string, UpdateDataType>& map)
2579  {
2580  auto it = map.begin();
2581  while (it != map.end())
2582  {
2583  auto curr = it++;
2584  if (curr->second.layerName == layerName)
2585  {
2586  map.erase(curr);
2587  }
2588  }
2589  }
2590 
2591  void DebugDrawerComponent::removeAccumulatedData(const std::string& layerName)
2592  {
2593  auto lockData = getScopedAccumulatedDataLock();
2594 
2595  removeUpdateDataFromMap(layerName, accumulatedUpdateData.coord);
2596  removeUpdateDataFromMap(layerName, accumulatedUpdateData.line);
2597  removeUpdateDataFromMap(layerName, accumulatedUpdateData.lineSet);
2598  removeUpdateDataFromMap(layerName, accumulatedUpdateData.box);
2599  removeUpdateDataFromMap(layerName, accumulatedUpdateData.text);
2600  removeUpdateDataFromMap(layerName, accumulatedUpdateData.sphere);
2601  removeUpdateDataFromMap(layerName, accumulatedUpdateData.cylinder);
2602  removeUpdateDataFromMap(layerName, accumulatedUpdateData.pointcloud);
2603  removeUpdateDataFromMap(layerName, accumulatedUpdateData.coloredpointcloud);
2604  removeUpdateDataFromMap(layerName, accumulatedUpdateData.colored24Bitpointcloud);
2605  removeUpdateDataFromMap(layerName, accumulatedUpdateData.polygons);
2606  removeUpdateDataFromMap(layerName, accumulatedUpdateData.arrows);
2607  removeUpdateDataFromMap(layerName, accumulatedUpdateData.robots);
2608  removeUpdateDataFromMap(layerName, accumulatedUpdateData.triMeshes);
2609 
2610  onRemoveAccumulatedData(layerName);
2611 
2612  }
2613 
2614  void DebugDrawerComponent::enableLayerVisu(const std::string& layerName, bool visible, const ::Ice::Current&)
2615  {
2616  setLayerVisibility(layerName, visible);
2617  }
2618 
2619  void DebugDrawerComponent::enableDebugLayerVisu(bool visible, const ::Ice::Current&)
2620  {
2621  enableLayerVisu(DEBUG_LAYER_NAME, visible);
2622  }
2623 
2624  Ice::StringSeq DebugDrawerComponent::layerNames(const ::Ice::Current&)
2625  {
2626  auto l = getScopedVisuLock();
2627  Ice::StringSeq seq {};
2628 
2629  for (const auto& layer : layers)
2630  {
2631  seq.push_back(layer.first);
2632  }
2633 
2634  return seq;
2635  }
2636 
2637  ::armarx::LayerInformationSequence DebugDrawerComponent::layerInformation(const ::Ice::Current&)
2638  {
2639  ::armarx::LayerInformationSequence seq {};
2640  auto l = getScopedVisuLock();
2641 
2642  for (const auto& layer : layers)
2643  {
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);
2662  }
2663 
2664  return seq;
2665  }
2666 
2667  void DebugDrawerComponent::drawColoredPointCloud(const ColoredPointCloudData& d)
2668  {
2669  auto l = getScopedVisuLock();
2670 
2671  auto& layer = requestLayer(d.layerName);
2672 
2673  removeColoredPointCloud(d.layerName, d.name);
2674 
2675  if (!d.active)
2676  {
2677  return;
2678  }
2679 
2680  const auto& pcl = d.pointCloud.points;
2681 
2682  SoSeparator* pclSep = new SoSeparator;
2683 
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)
2690  {
2691  return SbColor {elem.color.r, elem.color.g, elem.color.b};
2692  }
2693  );
2694  pclMat->diffuseColor.setValues(0, colors.size(), colors.data());
2695  pclMat->ambientColor.setValues(0, colors.size(), colors.data());
2696  pclSep->addChild(pclMat);
2697 
2698  SoMaterialBinding* pclMatBind = new SoMaterialBinding;
2699  pclMatBind->value = SoMaterialBinding::PER_PART;
2700  pclSep->addChild(pclMatBind);
2701 
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)
2708  {
2709  return SbVec3f {elem.x, elem.y, elem.z};
2710  }
2711  );
2712  pclCoords->point.setValues(0, coords.size(), coords.data());
2713  pclSep->addChild(pclCoords);
2714 
2715  SoDrawStyle* pclStye = new SoDrawStyle;
2716  pclStye->pointSize = d.pointCloud.pointSize;
2717  pclSep->addChild(pclStye);
2718 
2719  pclSep->addChild(new SoPointSet);
2720 
2721  ARMARX_DEBUG << d.name << "PointCloud Update " << pcl.size();
2722 
2723  layer.addedColoredPointCloudVisualizations[d.name] = pclSep;
2724  layer.mainNode->addChild(pclSep);
2725  }
2726 
2727  void DebugDrawerComponent::removeColoredPointCloud(const std::string& layerName, const std::string& name)
2728  {
2729  auto l = getScopedVisuLock();
2730 
2731  if (!hasLayer(layerName))
2732  {
2733  return;
2734  }
2735 
2736  auto& layer = layers.at(layerName);
2737 
2738  if (layer.addedColoredPointCloudVisualizations.find(name) == layer.addedColoredPointCloudVisualizations.end())
2739  {
2740  return;
2741  }
2742 
2743  layer.mainNode->removeChild(layer.addedColoredPointCloudVisualizations[name]);
2744  layer.addedColoredPointCloudVisualizations.erase(name);
2745  }
2746 
2747  void DebugDrawerComponent::setColoredPointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const DebugDrawerColoredPointCloud& pointCloud, const Ice::Current&)
2748  {
2749  {
2750  auto l = getScopedAccumulatedDataLock();
2751  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
2752  ColoredPointCloudData& d = accumulatedUpdateData.coloredpointcloud[entryName];
2753  d.pointCloud = pointCloud;
2754  d.layerName = layerName;
2755  d.name = pointCloudName;
2756  d.active = true;
2757  }
2758  }
2759 
2760  void DebugDrawerComponent::setColoredPointCloudDebugLayerVisu(const std::string& pointCloudName, const DebugDrawerColoredPointCloud& pointCloud, const Ice::Current&)
2761  {
2762  setColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
2763  }
2764 
2765  void DebugDrawerComponent::removeColoredPointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const Ice::Current&)
2766  {
2767  {
2768  auto l = getScopedAccumulatedDataLock();
2769  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
2770  ColoredPointCloudData& d = accumulatedUpdateData.coloredpointcloud[entryName];
2771  d.layerName = layerName;
2772  d.name = pointCloudName;
2773  d.active = false;
2774  }
2775  }
2776 
2777  void DebugDrawerComponent::removeColoredPointCloudDebugLayerVisu(const std::string& pointCloudName, const Ice::Current&)
2778  {
2779  removeColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
2780  }
2781 
2782  void DebugDrawerComponent::draw24BitColoredPointCloud(const Colored24BitPointCloudData& d)
2783  {
2784  auto l = getScopedVisuLock();
2785 
2786  auto& layer = requestLayer(d.layerName);
2787 
2788  remove24BitColoredPointCloud(d.layerName, d.name);
2789 
2790  if (!d.active)
2791  {
2792  return;
2793  }
2794 
2795  const auto& pcl = d.pointCloud.points;
2796 
2797  SoSeparator* pclSep = new SoSeparator;
2798 
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)
2805  {
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};
2807  }
2808  );
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);
2813 
2814  SoMaterialBinding* pclMatBind = new SoMaterialBinding;
2815  pclMatBind->value = SoMaterialBinding::PER_PART;
2816  pclSep->addChild(pclMatBind);
2817 
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)
2824  {
2825  return SbVec3f {elem.x, elem.y, elem.z};
2826  }
2827  );
2828  pclCoords->point.setValues(0, coords.size(), coords.data());
2829  pclSep->addChild(pclCoords);
2830 
2831  SoDrawStyle* pclStye = new SoDrawStyle;
2832  pclStye->pointSize = d.pointCloud.pointSize;
2833  pclSep->addChild(pclStye);
2834 
2835  pclSep->addChild(new SoPointSet);
2836 
2837  ARMARX_DEBUG << d.name << "PointCloud Update " << pcl.size();
2838 
2839  layer.added24BitColoredPointCloudVisualizations[d.name] = pclSep;
2840  layer.mainNode->addChild(pclSep);
2841  }
2842 
2843  void DebugDrawerComponent::remove24BitColoredPointCloud(const std::string& layerName, const std::string& name)
2844  {
2845  auto l = getScopedVisuLock();
2846 
2847  if (!hasLayer(layerName))
2848  {
2849  return;
2850  }
2851 
2852  auto& layer = layers.at(layerName);
2853 
2854  if (layer.added24BitColoredPointCloudVisualizations.find(name) == layer.added24BitColoredPointCloudVisualizations.end())
2855  {
2856  return;
2857  }
2858 
2859  layer.mainNode->removeChild(layer.added24BitColoredPointCloudVisualizations[name]);
2860  layer.added24BitColoredPointCloudVisualizations.erase(name);
2861  }
2862 
2863  void DebugDrawerComponent::set24BitColoredPointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const DebugDrawer24BitColoredPointCloud& pointCloud, const Ice::Current&)
2864  {
2865  {
2866  auto l = getScopedAccumulatedDataLock();
2867  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
2868  Colored24BitPointCloudData& d = accumulatedUpdateData.colored24Bitpointcloud[entryName];
2869  d.pointCloud = pointCloud;
2870  d.layerName = layerName;
2871  d.name = pointCloudName;
2872  d.active = true;
2873  }
2874  }
2875 
2876  void DebugDrawerComponent::set24BitColoredPointCloudDebugLayerVisu(const std::string& pointCloudName, const DebugDrawer24BitColoredPointCloud& pointCloud, const Ice::Current&)
2877  {
2878  set24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName, pointCloud);
2879  }
2880 
2881  void DebugDrawerComponent::remove24BitColoredPointCloudVisu(const std::string& layerName, const std::string& pointCloudName, const Ice::Current&)
2882  {
2883  {
2884  auto l = getScopedAccumulatedDataLock();
2885  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + pointCloudName + "__"), " ", "_");
2886  Colored24BitPointCloudData& d = accumulatedUpdateData.colored24Bitpointcloud[entryName];
2887  d.layerName = layerName;
2888  d.name = pointCloudName;
2889  d.active = false;
2890  }
2891  }
2892 
2893  void DebugDrawerComponent::remove24BitColoredPointCloudDebugLayerVisu(const std::string& pointCloudName, const Ice::Current&)
2894  {
2895  remove24BitColoredPointCloudVisu(DEBUG_LAYER_NAME, pointCloudName);
2896  }
2897 
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&)
2899  {
2900 
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();
2906  d.circleCompletion = circleCompletion;
2907  d.radius = radius;
2908  d.width = width;
2909  d.layerName = layerName;
2910  d.name = circleName;
2911  d.color = VirtualRobot::VisualizationFactory::Color(color.r, color.g, color.b, 1 - color.a);
2912  d.active = true;
2913 
2914  }
2915 
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)
2917  {
2918  setCircleArrowVisu(DEBUG_LAYER_NAME, circleName, globalPosition, directionVec, radius, circleCompletion, width, color, c);
2919  }
2920 
2921  void DebugDrawerComponent::removeCircleVisu(const std::string& layerName, const std::string& circleName, const Ice::Current&)
2922  {
2923 
2924  auto l = getScopedAccumulatedDataLock();
2925  std::string entryName = simox::alg::replace_all(std::string("__" + layerName + "__" + circleName + "__"), " ", "_");
2926  CircleData& d = accumulatedUpdateData.circle[entryName];
2927  d.layerName = layerName;
2928  d.name = circleName;
2929  d.active = false;
2930 
2931  }
2932 
2933  void DebugDrawerComponent::removeCircleDebugLayerVisu(const std::string& circleName, const Ice::Current& c)
2934  {
2935  removeCircleVisu(DEBUG_LAYER_NAME, circleName, c);
2936  }
2937 }
armarx::DebugDrawerComponent::LineData::scale
float scale
Definition: DebugDrawerComponent.h:362
DebugDrawerComponent.h
armarx::GetOrthonormalVectors
Eigen::Vector3f GetOrthonormalVectors(Eigen::Vector3f vec, Eigen::Vector3f &dir1, Eigen::Vector3f &dir2)
Definition: DebugDrawerComponent.cpp:806
armarx::DebugDrawerComponent::Layer
Contains data for a layer.
Definition: DebugDrawerComponent.h:545
armarx::DebugDrawerComponent::removeSelectionCallbacks
void removeSelectionCallbacks()
Definition: DebugDrawerComponent.cpp:243
armarx::DebugDrawerComponent::drawPointCloud
void drawPointCloud(const PointCloudData &d)
Definition: DebugDrawerComponent.cpp:877
pcl
Definition: pcl_point_operators.cpp:4
armarx::DebugDrawerComponent::CircleData::circleCompletion
float circleCompletion
Definition: DebugDrawerComponent.h:404
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::DebugDrawerComponent::ColoredPointCloudData
Definition: DebugDrawerComponent.h:411
armarx::DebugDrawerComponent::Layer::added24BitColoredPointCloudVisualizations
std::map< std::string, SoSeparator * > added24BitColoredPointCloudVisualizations
Definition: DebugDrawerComponent.h:558
armarx::DebugDrawerComponent::selectionMutex
static std::recursive_mutex selectionMutex
Definition: DebugDrawerComponent.h:606
armarx::eFull
@ eFull
Definition: MorphingItem.h:35
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::DebugDrawerComponent::RobotData::updatePose
bool updatePose
Definition: DebugDrawerComponent.h:456
armarx::DebugDrawerComponent
The DebugDrawerComponent class.
Definition: DebugDrawerComponent.h:108
armarx::DebugDrawerComponent::PolygonData::colorBorder
VirtualRobot::VisualizationFactory::Color colorBorder
Definition: DebugDrawerComponent.h:424
armarx::DebugDrawerComponent::Layer::addedPolygonVisualizations
std::map< std::string, SoSeparator * > addedPolygonVisualizations
Definition: DebugDrawerComponent.h:559
armarx::DebugDrawerComponent::BoxData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:375
armarx::DebugDrawerComponent::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: DebugDrawerComponent.cpp:352
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::DebugDrawerComponent::Colored24BitPointCloudData::pointCloud
DebugDrawer24BitColoredPointCloud pointCloud
Definition: DebugDrawerComponent.h:417
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
boost::shared_ptr< VirtualRobot::CoinVisualization >
armarx::DebugDrawerComponent::TextData::position
Eigen::Vector3f position
Definition: DebugDrawerComponent.h:380
armarx::DebugDrawerComponent::Layer::addedCircleVisualizations
std::map< std::string, SoSeparator * > addedCircleVisualizations
Definition: DebugDrawerComponent.h:555
armarx::DebugDrawerComponent::RobotData::drawStyle
armarx::DrawStyle drawStyle
Definition: DebugDrawerComponent.h:462
armarx::DebugDrawerComponent::CylinderData::radius
float radius
Definition: DebugDrawerComponent.h:395
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::DebugDrawerComponent::RobotData::configuration
std::map< std::string, float > configuration
Definition: DebugDrawerComponent.h:460
VirtualRobot
Definition: FramedPose.h:43
armarx::DebugDrawerComponent::ArrowData::width
float width
Definition: DebugDrawerComponent.h:436
armarx::DebugDrawerComponent::TextData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:381
armarx::DebugDrawerComponent::getScopedVisuLock
RecursiveMutexLockPtr getScopedVisuLock()
getScopedLock If using the coin visualization it must be ensured that all rendering calls are protect...
Definition: DebugDrawerComponent.cpp:2365
armarx::DebugDrawerComponent::reportSelectionChanged
void reportSelectionChanged(const DebugDrawerSelectionList &selectedElements, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:250
armarx::DebugDrawerComponent::Layer::addedColoredPointCloudVisualizations
std::map< std::string, SoSeparator * > addedColoredPointCloudVisualizations
Definition: DebugDrawerComponent.h:557
armarx::DebugDrawerComponent::Layer::addedLineVisualizations
std::map< std::string, SoSeparator * > addedLineVisualizations
Definition: DebugDrawerComponent.h:549
armarx::DebugDrawerComponent::selectableLayers
std::set< std::string > selectableLayers
Definition: DebugDrawerComponent.h:607
armarx::DebugDrawerComponent::verbose
bool verbose
Definition: DebugDrawerComponent.h:586
armarx::DebugDrawerComponent::updateVisualization
void updateVisualization()
Definition: DebugDrawerComponent.cpp:2416
armarx::DebugDrawerComponent::Layer::addedCoordVisualizations
std::map< std::string, SoSeparator * > addedCoordVisualizations
Definition: DebugDrawerComponent.h:548
armarx::DebugDrawerComponent::CylinderData
Definition: DebugDrawerComponent.h:390
armarx::DebugDrawerComponent::deselect
void deselect(const std::string &layerName, const std::string &elementName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:199
armarx::DebugDrawerComponent::DrawData::update
bool update
Whether an existing visu should be updated.
Definition: DebugDrawerComponent.h:350
armarx::DebugDrawerComponent::BoxData::globalPose
Eigen::Matrix4f globalPose
Definition: DebugDrawerComponent.h:371
SELECTION_NAME_SPLITTER
#define SELECTION_NAME_SPLITTER
Definition: DebugDrawerComponent.cpp:69
armarx::DebugDrawerComponent::ArrowData
Definition: DebugDrawerComponent.h:431
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::DebugDrawerComponent::LineData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:363
armarx::DebugDrawerComponent::timerSensor
SoTimerSensor * timerSensor
Definition: DebugDrawerComponent.h:615
armarx::DebugDrawerComponent::drawCircle
void drawCircle(const DebugDrawerComponent::CircleData &d)
Definition: DebugDrawerComponent.cpp:830
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::DebugDrawerComponent::hasLayer
bool hasLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:2533
armarx::DebugDrawerComponent::removeLineSet
void removeLineSet(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1349
SELECTION_NAME
#define SELECTION_NAME(layerName, elementName)
Definition: DebugDrawerComponent.cpp:70
armarx::DebugDrawerComponent::SphereData::position
Eigen::Vector3f position
Definition: DebugDrawerComponent.h:386
armarx::DebugDrawerComponent::Layer::addedArrowVisualizations
std::map< std::string, SoSeparator * > addedArrowVisualizations
Definition: DebugDrawerComponent.h:561
armarx::DebugDrawerComponent::RobotData::updateNodeColor
bool updateNodeColor
Definition: DebugDrawerComponent.h:453
armarx::DebugDrawerComponent::getSelections
DebugDrawerSelectionList getSelections(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:273
armarx::DebugDrawerComponent::PolygonData::colorInner
VirtualRobot::VisualizationFactory::Color colorInner
Definition: DebugDrawerComponent.h:423
armarx::DebugDrawerComponent::exportLayer
void exportLayer(const std::string &filename, const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:472
armarx::DebugDrawerComponent::DrawData::name
std::string name
Definition: DebugDrawerComponent.h:345
armarx::DebugDrawerComponent::topicMutex
RecursiveMutexPtr topicMutex
Definition: DebugDrawerComponent.h:604
armarx::DebugDrawerComponent::updateVisualizationCB
static void updateVisualizationCB(void *data, SoSensor *sensor)
Definition: DebugDrawerComponent.cpp:380
armarx::DebugDrawerComponent::removeCoordSystem
void removeCoordSystem(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1603
armarx::DebugDrawerComponent::Layer::addedTextVisualizations
std::map< std::string, SoSeparator * > addedTextVisualizations
Definition: DebugDrawerComponent.h:552
armarx::DebugDrawerComponent::coinVisu
SoSeparator * coinVisu
Definition: DebugDrawerComponent.h:583
ColorUtils.h
armarx::DebugDrawerComponent::removeSphere
void removeSphere(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1409
armarx::DebugDrawerComponent::PolygonData::points
std::vector< Eigen::Vector3f > points
Definition: DebugDrawerComponent.h:421
armarx::DebugDrawerComponent::PointCloudData
Definition: DebugDrawerComponent.h:407
armarx::DebugDrawerComponent::RecursiveMutexLock
std::unique_lock< RecursiveMutex > RecursiveMutexLock
Definition: DebugDrawerComponent.h:280
std::isfinite
bool isfinite(const std::vector< T, Ts... > &v)
Definition: algorithm.h:327
armarx::DebugDrawerComponent::RobotData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:451
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::DebugDrawerComponent::drawCylinder
void drawCylinder(const CylinderData &d)
Definition: DebugDrawerComponent.cpp:769
armarx::DebugDrawerComponent::RobotData::updateColor
bool updateColor
Definition: DebugDrawerComponent.h:450
armarx::DebugDrawerComponent::RobotData
Definition: DebugDrawerComponent.h:439
armarx::DebugDrawerComponent::Layer::addedCylinderVisualizations
std::map< std::string, SoSeparator * > addedCylinderVisualizations
Definition: DebugDrawerComponent.h:554
armarx::DebugDrawerComponent::CoordData
Definition: DebugDrawerComponent.h:353
armarx::DebugDrawerComponent::deselectionCallback
void deselectionCallback()
Definition: DebugDrawerComponent.cpp:230
Color
uint32_t Color
RGBA color.
Definition: color.h:8
armarx::DebugDrawerComponent::Layer::addedCustomVisualizations
std::map< std::string, SoSeparator * > addedCustomVisualizations
Definition: DebugDrawerComponent.h:563
armarx::DebugDrawerComponent::LineData::p1
Eigen::Vector3f p1
Definition: DebugDrawerComponent.h:360
armarx::DebugDrawerComponent::SphereData
Definition: DebugDrawerComponent.h:384
armarx::DebugDrawerComponent::CircleData::radius
float radius
Definition: DebugDrawerComponent.h:402
armarx::DebugDrawerComponent::CylinderData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:396
armarx::DebugDrawerComponent::Layer::addedBoxVisualizations
std::map< std::string, SoSeparator * > addedBoxVisualizations
Definition: DebugDrawerComponent.h:551
armarx::DebugDrawerComponent::SphereData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:387
armarx::DebugDrawerComponent::BoxData::height
float height
Definition: DebugDrawerComponent.h:373
armarx::DebugDrawerComponent::DrawData::active
bool active
Definition: DebugDrawerComponent.h:346
armarx::DebugDrawerComponent::Layer::addedPointCloudVisualizations
std::map< std::string, SoSeparator * > addedPointCloudVisualizations
Definition: DebugDrawerComponent.h:556
armarx::DebugDrawerComponent::RobotData::updateConfig
bool updateConfig
Definition: DebugDrawerComponent.h:459
armarx::DebugDrawerComponent::enableSelections
void enableSelections(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:124
armarx::DebugDrawerComponent::TextData
Definition: DebugDrawerComponent.h:377
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::DebugDrawerComponent::CircleData::width
float width
Definition: DebugDrawerComponent.h:403
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::DebugDrawerComponent::RecursiveMutex
std::recursive_mutex RecursiveMutex
Definition: DebugDrawerComponent.h:278
armarx::selection_callback
void selection_callback(void *userdata, SoPath *path)
Definition: DebugDrawerComponent.cpp:76
armarx::DebugDrawerComponent::TriMeshData
Definition: DebugDrawerComponent.h:426
armarx::DebugDrawerComponent::removeBox
void removeBox(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1369
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
armarx::DebugDrawerComponent::listenerPrx
DebugDrawerListenerPrx listenerPrx
Definition: DebugDrawerComponent.h:611
armarx::DebugDrawerComponent::ArrowData::length
float length
Definition: DebugDrawerComponent.h:435
armarx::DebugDrawerComponent::CylinderData::length
float length
Definition: DebugDrawerComponent.h:394
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::DebugDrawerComponent::TextData::text
std::string text
Definition: DebugDrawerComponent.h:379
armarx::DebugDrawerComponent::CylinderData::direction
Eigen::Vector3f direction
Definition: DebugDrawerComponent.h:393
armarx::DebugDrawerComponent::timerSensorMutex
std::mutex timerSensorMutex
Definition: DebugDrawerComponent.h:616
filename
std::string filename
Definition: VisualizationRobot.cpp:84
armarx::DebugDrawerComponent::exportScene
void exportScene(const std::string &filename, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:451
armarx::DebugDrawerComponent::CircleData
Definition: DebugDrawerComponent.h:398
armarx::DebugDrawerComponent::ColoredPointCloudData::pointCloud
DebugDrawerColoredPointCloud pointCloud
Definition: DebugDrawerComponent.h:413
max
T max(T t1, T t2)
Definition: gdiam.h:48
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::removeUpdateDataFromMap
void removeUpdateDataFromMap(const std::string &layerName, std::map< std::string, UpdateDataType > &map)
Definition: DebugDrawerComponent.cpp:2578
armarx::DebugDrawerComponent::BoxData
Definition: DebugDrawerComponent.h:369
armarx::deselection_callback
void deselection_callback(void *userdata, SoPath *path)
Definition: DebugDrawerComponent.cpp:84
armarx::DebugDrawerComponent::requestLayer
Layer & requestLayer(const std::string &layerName)
If a layer with layerName exists it is returned. Otherwise a new layer with given name is created and...
Definition: DebugDrawerComponent.cpp:2393
armarx::DebugDrawerComponent::PointCloudData::pointCloud
DebugDrawerPointCloud pointCloud
Definition: DebugDrawerComponent.h:409
armarx::DebugDrawerComponent::RobotData::nodeColors
std::map< std::string, VirtualRobot::VisualizationFactory::Color > nodeColors
Definition: DebugDrawerComponent.h:454
armarx::DebugDrawerComponent::removeCylinder
void removeCylinder(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1429
armarx::DebugDrawerComponent::CircleData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:405
armarx::DebugDrawerComponent::cycleTimeMS
float cycleTimeMS
Definition: DebugDrawerComponent.h:613
armarx::DebugDrawerComponent::RobotData::armarxProject
std::string armarxProject
Definition: DebugDrawerComponent.h:448
armarx::DebugDrawerComponent::Layer::addedSphereVisualizations
std::map< std::string, SoSeparator * > addedSphereVisualizations
Definition: DebugDrawerComponent.h:553
armarx::DebugDrawerComponent::removeCircle
void removeCircle(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1449
armarx::DebugDrawerComponent::RecursiveMutexPtr
std::shared_ptr< RecursiveMutex > RecursiveMutexPtr
Definition: DebugDrawerComponent.h:279
armarx::DebugDrawerComponent::PolygonData
Definition: DebugDrawerComponent.h:419
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
CMakePackageFinder.h
armarx::DebugDrawerComponent::RobotData::robotFile
std::string robotFile
Definition: DebugDrawerComponent.h:447
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::DebugDrawerComponent::drawLine
void drawLine(const LineData &d)
Definition: DebugDrawerComponent.cpp:531
armarx::DebugDrawerComponent::RobotData::globalPose
Eigen::Matrix4f globalPose
Definition: DebugDrawerComponent.h:457
armarx::DebugDrawerComponent::Layer::addedLineSetVisualizations
std::map< std::string, SoSeparator * > addedLineSetVisualizations
Definition: DebugDrawerComponent.h:550
float
#define float
Definition: 16_Level.h:22
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ArmarXDataPath::addDataPaths
static void addDataPaths(const std::string &dataPathList)
Definition: ArmarXDataPath.cpp:559
armarx::DebugDrawerComponent::removeText
void removeText(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1389
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
armarx::DebugDrawerComponent::CircleData::position
Eigen::Vector3f position
Definition: DebugDrawerComponent.h:400
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
armarx::DebugDrawerComponent::CylinderData::position
Eigen::Vector3f position
Definition: DebugDrawerComponent.h:392
armarx::DebugDrawerComponent::installSelectionCallbacks
void installSelectionCallbacks()
Definition: DebugDrawerComponent.cpp:236
armarx::DebugDrawerComponent::CircleData::direction
Eigen::Vector3f direction
Definition: DebugDrawerComponent.h:401
armarx::DebugDrawerComponent::BoxData::depth
float depth
Definition: DebugDrawerComponent.h:374
armarx::DebugDrawerComponent::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: DebugDrawerComponent.cpp:394
armarx::DebugDrawerComponent::LineSetData::lineSet
DebugDrawerLineSet lineSet
Definition: DebugDrawerComponent.h:367
armarx::DebugDrawerComponent::Layer::addedTriMeshVisualizations
std::map< std::string, SoSeparator * > addedTriMeshVisualizations
Definition: DebugDrawerComponent.h:560
armarx::DebugDrawerComponent::LineData
Definition: DebugDrawerComponent.h:358
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:92
armarx::DebugDrawerComponent::drawBox
void drawBox(const BoxData &d)
Definition: DebugDrawerComponent.cpp:648
armarx::DebugDrawerComponent::removePointCloud
void removePointCloud(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1469
armarx::DebugDrawerComponent::LineData::p2
Eigen::Vector3f p2
Definition: DebugDrawerComponent.h:361
armarx::DebugDrawerComponent::RecursiveMutexLockPtr
std::shared_ptr< RecursiveMutexLock > RecursiveMutexLockPtr
Definition: DebugDrawerComponent.h:281
armarx::DebugDrawerComponent::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: DebugDrawerComponent.cpp:419
armarx::colorutils::HeatMapRGBAColor
DrawColor HeatMapRGBAColor(float percentage)
Definition: ColorUtils.h:170
armarx::DebugDrawerComponent::CoordData::globalPose
Eigen::Matrix4f globalPose
Definition: DebugDrawerComponent.h:355
armarx::DebugDrawerComponent::selectionCallback
void selectionCallback()
Definition: DebugDrawerComponent.cpp:224
armarx::DebugDrawerComponent::drawLineSet
void drawLineSet(const LineSetData &d)
Definition: DebugDrawerComponent.cpp:552
armarx::DebugDrawerComponent::ArrowData::color
VirtualRobot::VisualizationFactory::Color color
Definition: DebugDrawerComponent.h:437
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::DebugDrawerComponent::TriMeshData::triMesh
DebugDrawerTriMesh triMesh
Definition: DebugDrawerComponent.h:428
SELECTION_NAME_PREFIX
#define SELECTION_NAME_PREFIX
Definition: DebugDrawerComponent.cpp:68
armarx::DebugDrawerComponent::drawSphere
void drawSphere(const SphereData &d)
Definition: DebugDrawerComponent.cpp:729
armarx::DebugDrawerComponent::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: DebugDrawerComponent.cpp:401
ArmarXDataPath.h
armarx::DebugDrawerComponent::ArrowData::position
Eigen::Vector3f position
Definition: DebugDrawerComponent.h:433
armarx::DebugDrawerComponent::SphereData::radius
float radius
Definition: DebugDrawerComponent.h:388
armarx::DebugDrawerComponent::DrawData::layerName
std::string layerName
Definition: DebugDrawerComponent.h:344
armarx::DebugDrawerComponent::setVisuUpdateTime
void setVisuUpdateTime(float visuUpdatesPerSec)
setVisuUpdateTime Specifies how often the accumulated draw commands should be applied to the visualiz...
Definition: DebugDrawerComponent.cpp:325
armarx::DebugDrawerComponent::LineSetData
Definition: DebugDrawerComponent.h:365
armarx::DebugDrawerComponent::~DebugDrawerComponent
~DebugDrawerComponent() override
Definition: DebugDrawerComponent.cpp:343
armarx::DebugDrawerComponent::PolygonData::lineWidth
float lineWidth
Definition: DebugDrawerComponent.h:422
armarx::DebugDrawerComponent::layerMainNode
SoSeparator * layerMainNode
Main node for all layers.
Definition: DebugDrawerComponent.h:591
armarx::DebugDrawerComponent::drawCoordSystem
void drawCoordSystem(const CoordData &d)
Definition: DebugDrawerComponent.cpp:499
armarx::DebugDrawerComponent::clearSelections
void clearSelections(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:147
armarx::DebugDrawerComponent::TextData::size
int size
Definition: DebugDrawerComponent.h:382
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::DebugDrawerComponent::disableSelections
void disableSelections(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:132
armarx::DebugDrawerComponent::CoordData::scale
float scale
Definition: DebugDrawerComponent.h:356
armarx::DebugDrawerComponent::Colored24BitPointCloudData
Definition: DebugDrawerComponent.h:415
armarx::DebugDrawerComponent::drawText
void drawText(const TextData &d)
Definition: DebugDrawerComponent.cpp:683
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::DebugDrawerComponent::ArrowData::direction
Eigen::Vector3f direction
Definition: DebugDrawerComponent.h:434
armarx::DebugDrawerComponent::removeLayer
void removeLayer(const std::string &layerName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:2539
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::DebugDrawerComponent::select
void select(const std::string &layerName, const std::string &elementName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:174
armarx::DebugDrawerComponent::Layer::addedRobotVisualizations
std::map< std::string, SoSeparator * > addedRobotVisualizations
Definition: DebugDrawerComponent.h:562
armarx::DebugDrawerComponent::BoxData::width
float width
Definition: DebugDrawerComponent.h:372
armarx::DebugDrawerComponent::disableAllLayers
void disableAllLayers(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DebugDrawerComponent.cpp:1651
armarx::DebugDrawerComponent::selectionNode
SoSelection * selectionNode
Definition: DebugDrawerComponent.h:584
armarx::DebugDrawerComponent::removeLine
void removeLine(const std::string &layerName, const std::string &name)
Definition: DebugDrawerComponent.cpp:1329
armarx::DebugDrawerComponent::layers
std::map< const std::string, Layer > layers
All existing layers.
Definition: DebugDrawerComponent.h:596