DebugDrawerTopic.cpp
Go to the documentation of this file.
1 #include "DebugDrawerTopic.h"
2 
3 #include <VirtualRobot/math/Helpers.h>
4 #include <VirtualRobot/Visualization/TriMeshModel.h>
5 
7 
8 #include "../Pose.h"
9 
10 #include "GlasbeyLUT.h"
11 
12 #include <SimoxUtility/color/hsv.h>
13 
14 
15 namespace armarx
16 {
17 
19  {}
20 
21  DebugDrawerTopic::VisuID::VisuID(const std::string& name) : VisuID("", name)
22  {}
23 
24  DebugDrawerTopic::VisuID::VisuID(const std::string& layer, const std::string& name) :
25  layer(layer), name(name)
26  {}
27 
29  {
30  return VisuID(this->layer, newName);
31  }
32 
33  std::ostream& operator<<(std::ostream& os, const DebugDrawerTopic::VisuID& rhs)
34  {
35  os << "Visu '" << rhs.name << "' on layer '" << rhs.layer << "'";
36  return os;
37  }
38 
39 
40  const std::string DebugDrawerTopic::TOPIC_NAME = "DebugDrawerUpdates";
41  const std::string DebugDrawerTopic::DEFAULT_LAYER = "debug";
42  const DebugDrawerTopic::Defaults DebugDrawerTopic::DEFAULTS = {};
43 
44  DebugDrawerTopic::DebugDrawerTopic(const std::string& layer) :
45  _layer(layer)
46  {}
47 
49  const DebugDrawerInterfacePrx& topic, const std::string& layer) :
50  topic(topic), _layer(layer)
51  {}
52 
54  {
55  this->topic = topic;
56  }
57 
59  {
60  return topic;
61  }
62 
64  {
65  this->_enabled = enabled;
66  }
67 
69  {
70  return _enabled && topic;
71  }
72 
73  void DebugDrawerTopic::offeringTopic(ManagedIceObject& component, const std::string& topicNameOverride) const
74  {
75  component.offeringTopic(topicNameOverride.empty() ? TOPIC_NAME : topicNameOverride);
76  }
77 
78  void DebugDrawerTopic::getTopic(ManagedIceObject& component, const std::string& topicNameOverride)
79  {
80  setTopic(component.getTopic<DebugDrawerInterfacePrx>(topicNameOverride.empty() ? TOPIC_NAME : topicNameOverride));
81  }
82 
83  const std::string& DebugDrawerTopic::getLayer() const
84  {
85  return _layer;
86  }
87 
88  void DebugDrawerTopic::setLayer(const std::string& layer)
89  {
90  this->_layer = layer;
91  }
92 
94  {
95  return _lengthScale;
96  }
97 
99  {
100  this->_lengthScale = scale;
101  }
102 
104  {
105  setLengthScale(1000);
106  }
107 
109  {
110  setLengthScale(0.001f);
111  }
112 
114  {
115  return _poseScale;
116  }
117 
119  {
120  this->_poseScale = scale;
121  }
122 
124  {
125  setPoseScale(0.001f);
126  }
127 
129  {
130  setPoseScale(1);
131  }
132 
134  {
135  this->sleepFor(_shortSleepDuration);
136  }
137 
138  void DebugDrawerTopic::clearAll(bool sleep)
139  {
140  if (enabled())
141  {
142  topic->clearAll();
143  if (sleep)
144  {
145  shortSleep();
146  }
147  }
148  }
149 
151  {
152  clearLayer(_layer, sleep);
153  }
154 
155  void DebugDrawerTopic::clearLayer(const std::string& layer, bool sleep)
156  {
157  if (enabled())
158  {
159  topic->clearLayer(layer);
160  if (sleep)
161  {
162  shortSleep();
163  }
164  }
165  }
166 
168  const VisuID& id, const Eigen::Vector3f& position, const std::string& text,
169  int size, const DrawColor color,
170  bool ignoreLengthScale)
171  {
172  if (enabled())
173  {
174  const float scale = lengthScale(ignoreLengthScale);
175  topic->setTextVisu(layer(id), id.name, text, scaled(scale, position), color, size);
176  }
177  }
178 
180  const VisuID& id, const Eigen::Vector3f& position, const Eigen::Quaternionf& orientation,
181  const Eigen::Vector3f& extents, const DrawColor& color,
182  bool ignoreLengthScale)
183  {
184  if (enabled())
185  {
186  const float scale = lengthScale(ignoreLengthScale);
187  topic->setBoxVisu(layer(id), id.name,
188  new Pose(scaled(scale, position), new Quaternion(orientation)),
189  scaled(scale, extents), color);
190  }
191  }
192 
193  void DebugDrawerTopic::drawBox(const VisuID& id, const Eigen::Matrix4f& pose, const Eigen::Vector3f& extents,
194  const DrawColor& color, bool ignoreLengthScale)
195  {
197  extents, color, ignoreLengthScale);
198  }
199 
200  void DebugDrawerTopic::drawBox(const DebugDrawerTopic::VisuID& id, const VirtualRobot::BoundingBox& boundingBox,
201  const DrawColor& color, bool ignoreLengthScale)
202  {
203  drawBox(id, boundingBox, Eigen::Matrix4f::Identity(), color, ignoreLengthScale);
204  }
205 
207  const DebugDrawerTopic::VisuID& id,
208  const VirtualRobot::BoundingBox& boundingBox, const Eigen::Matrix4f& pose,
209  const DrawColor& color, bool ignoreLengthScale)
210  {
211  const Eigen::Vector3f center = .5 * (boundingBox.getMin() + boundingBox.getMax());
212  drawBox(id, ::math::Helpers::TransformPosition(pose, center),
214  boundingBox.getMax() - boundingBox.getMin(), color, ignoreLengthScale);
215  }
216 
218  {
219  if (enabled())
220  {
221  topic->removeBoxVisu(layer(id), id.name);
222  }
223  }
224 
226  const DebugDrawerTopic::VisuID& id,
227  const Eigen::Vector3f& position, const Eigen::Quaternionf& orientation,
228  const Eigen::Vector3f& extents,
229  float width, const DrawColor& color, bool ignoreLengthScale)
230  {
231  drawBoxEdges(id, ::math::Helpers::Pose(position, orientation), extents, width, color, ignoreLengthScale);
232  }
233 
235  const DebugDrawerTopic::VisuID& id,
236  const Eigen::Matrix4f& pose, const Eigen::Vector3f& extents,
237  float width, const DrawColor& color, bool ignoreLengthScale)
238  {
239  if (!enabled())
240  {
241  return;
242  }
243 
244  std::vector<Eigen::Vector3f> points;
245 
247  bb.col(0) = -extents / 2;
248  bb.col(1) = extents / 2;
249 
250  auto addLine = [&](int x1, int y1, int z1, int x2, int y2, int z2)
251  {
252  Eigen::Vector3f start = { bb.col(x1).x(), bb.col(y1).y(), bb.col(z1).z() };
253  Eigen::Vector3f end = { bb.col(x2).x(), bb.col(y2).y(), bb.col(z2).z() };
254 
255  start = ::math::Helpers::TransformPosition(pose, start);
256  end = ::math::Helpers::TransformPosition(pose, end);
257 
258  points.push_back(start);
259  points.push_back(end);
260  };
261 
262  /* 001 +-----+ 011
263  * /| 111/|
264  * 101 +-----+ |
265  * | +---|-+ 010
266  * |/000 |/
267  * 100 +-----+ 110
268  */
269 
270  // 000 -> 100, 010, 001
271  addLine(0, 0, 0, 1, 0, 0);
272  addLine(0, 0, 0, 0, 1, 0);
273  addLine(0, 0, 0, 0, 0, 1);
274 
275  // 111 -> 011, 101, 110
276  addLine(1, 1, 1, 0, 1, 1);
277  addLine(1, 1, 1, 1, 0, 1);
278  addLine(1, 1, 1, 1, 1, 0);
279 
280  // 100 -> 101, 110
281  addLine(1, 0, 0, 1, 0, 1);
282  addLine(1, 0, 0, 1, 1, 0);
283 
284  // 010 -> 110, 011
285  addLine(0, 1, 0, 1, 1, 0);
286  addLine(0, 1, 0, 0, 1, 1);
287 
288  // 001 -> 101, 011
289  addLine(0, 0, 1, 1, 0, 1);
290  addLine(0, 0, 1, 0, 1, 1);
291 
292  drawLineSet(id, points, width, color, ignoreLengthScale);
293  }
294 
296  const DebugDrawerTopic::VisuID& id, const VirtualRobot::BoundingBox& boundingBox,
297  float width, const DrawColor& color, bool ignoreLengthScale)
298  {
299  drawBoxEdges(id, boundingBox, Eigen::Matrix4f::Identity(), width, color, ignoreLengthScale);
300  }
301 
303  const DebugDrawerTopic::VisuID& id, const Eigen::Matrix32f& aabb,
304  float width, const DrawColor& color, bool ignoreLengthScale)
305  {
306  drawBoxEdges(id, aabb, Eigen::Matrix4f::Identity(), width, color, ignoreLengthScale);
307  }
308 
310  const DebugDrawerTopic::VisuID& id,
311  const VirtualRobot::BoundingBox& boundingBox, const Eigen::Matrix4f& pose,
312  float width, const DrawColor& color, bool ignoreLengthScale)
313  {
314  const Eigen::Vector3f center = .5 * (boundingBox.getMin() + boundingBox.getMax());
315 
316  drawBoxEdges(id, ::math::Helpers::Pose(::math::Helpers::TransformPosition(pose, center),
318  boundingBox.getMax() - boundingBox.getMin(),
319  width, color, ignoreLengthScale);
320  }
321 
323  const DebugDrawerTopic::VisuID& id,
324  const Eigen::Matrix32f& aabb, const Eigen::Matrix4f& pose,
325  float width, const DrawColor& color, bool ignoreLengthScale)
326  {
327  const Eigen::Vector3f center = 0.5 * (aabb.col(0) + aabb.col(1));
328 
329  drawBoxEdges(id, ::math::Helpers::Pose(::math::Helpers::TransformPosition(pose, center),
331  aabb.col(1) - aabb.col(0),
332  width, color, ignoreLengthScale);
333  }
334 
336  {
337  removeLineSet(id);
338  }
339 
340 
342  const DebugDrawerTopic::VisuID& id,
343  const Eigen::Vector3f& center, const Eigen::Vector3f& direction,
344  float length, float radius,
345  const DrawColor& color, bool ignoreLengthScale)
346  {
347  if (enabled())
348  {
349  const float scale = lengthScale(ignoreLengthScale);
350  topic->setCylinderVisu(layer(id), id.name, scaled(scale, center), new Vector3(direction),
351  scaled(scale, length), scaled(scale, radius), color);
352  }
353  }
354 
356  const DebugDrawerTopic::VisuID& id,
357  const Eigen::Vector3f& center, const Eigen::Quaternionf& orientation,
358  float length, float radius,
359  const DrawColor& color, bool ignoreLengthScale)
360  {
361  drawCylinder(id, center, orientation * Eigen::Vector3f::UnitY(), radius, length, color,
362  ignoreLengthScale);
363  }
364 
366  const DebugDrawerTopic::VisuID& id,
367  const Eigen::Vector3f& from, const Eigen::Vector3f& to, float radius,
368  const DrawColor& color, bool ignoreLengthScale)
369  {
370  if (enabled())
371  {
372  const Eigen::Vector3f dir = (to - from); // no need for scaling at this point
373  const float length = dir.norm();
374  drawCylinder(id, .5 * (from + to), dir / length, radius, length, color, ignoreLengthScale);
375  }
376  }
377 
378 
380  {
381  if (enabled())
382  {
383  topic->removeCylinderVisu(layer(id), id.name);
384  }
385  }
386 
387 
389  const DebugDrawerTopic::VisuID& id,
390  const Eigen::Vector3f& center, float radius,
391  const DrawColor& color, bool ignoreLengthScale)
392  {
393  if (enabled())
394  {
395  const float scale = lengthScale(ignoreLengthScale);
396  topic->setSphereVisu(layer(id), id.name, scaled(scale, center), color,
397  scaled(scale, radius));
398  }
399  }
400 
401 
403  {
404  if (enabled())
405  {
406  topic->removeSphereVisu(layer(id), id.name);
407  }
408  }
409 
410 
412  const VisuID& id,
413  const Eigen::Vector3f& position, const Eigen::Vector3f& direction, float length,
414  float width, const DrawColor& color, bool ignoreLengthScale)
415  {
416  if (enabled())
417  {
418  const float scale = lengthScale(ignoreLengthScale);
419  topic->setArrowVisu(layer(id), id.name, scaled(scale, position), new Vector3(direction),
420  color, scaled(scale, length), scaled(scale, width));
421  }
422  }
423 
424 
426  const VisuID& id,
427  const Eigen::Vector3f& from, const Eigen::Vector3f& to,
428  float width, const DrawColor& color, bool ignoreLengthScale)
429  {
430  if (enabled())
431  {
432  const Eigen::Vector3f dir = (to - from); // no need for scaling at this point
433  const float length = dir.norm();
434  drawArrow(id, from, dir / length, length, width, color, ignoreLengthScale);
435  }
436  }
437 
438 
440  {
441  if (enabled())
442  {
443  topic->removeArrowVisu(layer(id), id.name);
444  }
445  }
446 
447 
449  const std::vector<Eigen::Vector3f>& points,
450  const DrawColor& colorFace, float lineWidth, const DrawColor& colorEdge,
451  bool ignoreLengthScale)
452  {
453  if (enabled())
454  {
455  const float scale = lengthScale(ignoreLengthScale);
456 
457  PolygonPointList polyPoints;
458  polyPoints.reserve(points.size());
459 
460  for (const auto& point : points)
461  {
462  polyPoints.push_back(scaled(scale, point));
463  }
464 
465  topic->setPolygonVisu(layer(id), id.name, polyPoints,
466  colorFace, colorEdge, lineWidth);
467  }
468  }
469 
470 
472  {
473  if (enabled())
474  {
475  topic->removePolygonVisu(layer(id), id.name);
476  }
477  }
478 
479 
481  const VisuID& id, const Eigen::Vector3f& from, const Eigen::Vector3f& to,
482  float width, const DrawColor& color, bool ignoreLengthScale)
483  {
484  if (enabled())
485  {
486  const float scale = lengthScale(ignoreLengthScale);
487 
488  topic->setLineVisu(layer(id), id.name, scaled(scale, from), scaled(scale, to),
489  width, color);
490  }
491  }
492 
493 
495  {
496  if (enabled())
497  {
498  topic->removeLineVisu(layer(id), id.name);
499  }
500  }
501 
502 
504  const VisuID& id, const DebugDrawerLineSet& lineSet, bool ignoreLengthScale)
505  {
506  if (enabled())
507  {
508  const float scale = lengthScale(ignoreLengthScale);
509 
510  if (1.f <= scale && scale <= 1.f)
511  {
512  // Can use lineSet directly.
513  topic->setLineSetVisu(layer(id), id.name, lineSet);
514  }
515  else
516  {
517  // Need to scale line set, hence, reconstruct it.
518  DebugDrawerLineSet scaledLineSet = lineSet;
519  for (auto& point : scaledLineSet.points)
520  {
521  scaleXYZ(scale, point);
522  }
523  topic->setLineSetVisu(layer(id), id.name, scaledLineSet);
524  }
525  }
526  }
527 
528 
530  const VisuID& id, const std::vector<Eigen::Vector3f>& points,
531  float width, const DrawColor& color, bool ignoreLengthScale)
532  {
533  if (enabled())
534  {
535  const float scale = lengthScale(ignoreLengthScale);
536 
537  DebugDrawerLineSet lineSet;
538  for (const auto& point : points)
539  {
540  lineSet.points.push_back(scaledT<DebugDrawerPointCloudElement>(scale, point));
541  }
542 
543  lineSet.lineWidth = width;
544  lineSet.colorNoIntensity = lineSet.colorFullIntensity = color;
545  lineSet.intensities.assign(points.size() / 2, 0.);
546 
547  topic->setLineSetVisu(layer(id), id.name, lineSet);
548  }
549  }
550 
551 
553  const VisuID& id, const std::vector<Eigen::Vector3f>& points, float width,
554  const DrawColor& colorA, const DrawColor& colorB, const std::vector<float>& intensitiesB,
555  bool ignoreLengthScale)
556  {
557  if (enabled())
558  {
559  const float scale = lengthScale(ignoreLengthScale);
560 
561  DebugDrawerLineSet lineSet;
562  for (const auto& point : points)
563  {
564  lineSet.points.push_back(scaledT<DebugDrawerPointCloudElement>(scale, point));
565  }
566 
567  lineSet.lineWidth = width;
568  lineSet.colorNoIntensity = colorA;
569  lineSet.colorFullIntensity = colorB;
570  lineSet.intensities = intensitiesB;
571 
572  topic->setLineSetVisu(layer(id), id.name, lineSet);
573  }
574  }
575 
576 
578  {
579  if (enabled())
580  {
581  topic->removeLineSetVisu(layer(id), id.name);
582  }
583  }
584 
585 
587  const VisuID& id, const Eigen::Matrix4f& pose, bool ignoreLengthScale)
588  {
589  drawPose(id, pose, _poseScale, ignoreLengthScale);
590  }
591 
592 
594  const VisuID& id,
595  const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori,
596  bool ignoreLengthScale)
597  {
598  drawPose(id, ::math::Helpers::Pose(pos, ori), _poseScale, ignoreLengthScale);
599  }
600 
601 
603  const VisuID& id, const Eigen::Matrix4f& pose, float scale,
604  bool ignoreLengthScale)
605  {
606  if (enabled())
607  {
608  const float lenghtScale = lengthScale(ignoreLengthScale);
609 
610  if (scale >= 1 && scale <= 1) // squelch compiler warning that == is unsafe
611  {
612  topic->setPoseVisu(layer(id), id.name, scaled(lenghtScale, pose));
613  }
614  else
615  {
616  topic->setScaledPoseVisu(layer(id), id.name, scaled(lenghtScale, pose), scale);
617  }
618  }
619 
620  }
621 
622 
624  const VisuID& id, const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori,
625  float scale, bool ignoreLengthScale)
626  {
627  drawPose(id, ::math::Helpers::Pose(pos, ori), scale, ignoreLengthScale);
628  }
629 
630 
632  {
633  if (enabled())
634  {
635  topic->removePoseVisu(layer(id), id.name);
636  }
637  }
638 
639 
641  const std::string& robotFile, const std::string& armarxProject,
642  DrawStyle drawStyle)
643  {
644  if (enabled())
645  {
646  topic->setRobotVisu(layer(id), id.name, robotFile, armarxProject, drawStyle);
647  }
648  }
649 
650 
652  const DebugDrawerTopic::VisuID& id,
653  const Eigen::Matrix4f& pose, bool ignoreScale)
654  {
655  if (enabled())
656  {
657  topic->updateRobotPose(layer(id), id.name, scaled(lengthScale(ignoreScale), pose));
658  }
659  }
660 
661 
663  const DebugDrawerTopic::VisuID& id,
664  const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori, bool ignoreScale)
665  {
666  updateRobotPose(id, ::math::Helpers::Pose(pos, ori), ignoreScale);
667  }
668 
669 
671  const DebugDrawerTopic::VisuID& id, const std::map<std::string, float>& config)
672  {
673  if (enabled())
674  {
675  topic->updateRobotConfig(layer(id), id.name, config);
676  }
677  }
678 
679 
681  const DebugDrawerTopic::VisuID& id, const DrawColor& color)
682  {
683  if (enabled())
684  {
685  topic->updateRobotColor(layer(id), id.name, color);
686  }
687  }
688 
689 
691  const DebugDrawerTopic::VisuID& id,
692  const std::string& nodeName, const DrawColor& color)
693  {
694  if (enabled())
695  {
696  topic->updateRobotNodeColor(layer(id), id.name, nodeName, color);
697  }
698  }
699 
700 
702  {
703  if (enabled())
704  {
705  topic->removeRobotVisu(layer(id), id.name);
706  }
707  }
708 
709 
711  const VisuID& id, const VirtualRobot::TriMeshModel& triMesh,
712  const DrawColor& color, bool ignoreLengthScale)
713  {
714  if (!enabled())
715  {
716  return;
717  }
718 
719  const float scale = lengthScale(ignoreLengthScale);
720 
721  DebugDrawerTriMesh dd;
722  dd.colors.push_back(color);
723 
724  for (const auto& vertex : triMesh.vertices)
725  {
726  auto scaled = vertex * scale;
727  dd.vertices.push_back({ scaled.x(), scaled.y(), scaled.z() });
728  }
729 
730  const std::size_t normalBase = dd.vertices.size();
731  for (const auto& normal : triMesh.normals)
732  {
733  dd.vertices.push_back({ normal.x(), normal.y(), normal.z() });
734  }
735 
736  for (const auto& face : triMesh.faces)
737  {
738  DebugDrawerFace ddf;
739  ddf.vertex1.vertexID = static_cast<Ice::Int>(face.id1);
740  ddf.vertex2.vertexID = static_cast<Ice::Int>(face.id2);
741  ddf.vertex3.vertexID = static_cast<Ice::Int>(face.id3);
742 
743  ddf.vertex1.colorID = ddf.vertex2.colorID = ddf.vertex3.colorID = 0;
744  ddf.vertex1.normalID = ddf.vertex2.normalID = ddf.vertex3.normalID = -1;
745 
746  bool validNormalIDs = true;
747  for (const auto& id :
748  {
749  face.idNormal1, face.idNormal2, face.idNormal3
750  })
751  {
752  validNormalIDs &= id < triMesh.normals.size();
753  }
754 
755  if (validNormalIDs)
756  {
757  ddf.vertex1.normalID = static_cast<Ice::Int>(normalBase + face.idNormal1);
758  ddf.vertex2.normalID = static_cast<Ice::Int>(normalBase + face.idNormal2);
759  ddf.vertex3.normalID = static_cast<Ice::Int>(normalBase + face.idNormal3);
760  }
761  else
762  {
763  const Eigen::Vector3f& normal = face.normal;
764  ddf.normal = { normal.x(), normal.y(), normal.z() };
765  }
766 
767  dd.faces.push_back(ddf);
768  }
769 
770  topic->setTriMeshVisu(layer(id), id.name, dd);
771  }
772 
773 
775  const VirtualRobot::TriMeshModel& trimesh,
776  const DrawColor& colorFace, float lineWidth, const DrawColor& colorEdge,
777  bool ignoreLengthScale)
778  {
780  colorFace, lineWidth, colorEdge, ignoreLengthScale);
781  }
782 
783 
785  const VirtualRobot::TriMeshModel& trimesh, const Eigen::Matrix4f& pose,
786  const DrawColor& colorFace, float lineWidth, const DrawColor& colorEdge,
787  bool ignoreLengthScale)
788  {
789  if (!enabled())
790  {
791  return;
792  }
793 
794  const float scale = lengthScale(ignoreLengthScale);
795  bool isIdentity = pose.isIdentity();
796 
797  auto toVector3 = [&scale, &isIdentity, &pose](const Eigen::Vector3f & v)
798  {
799  return scaled(scale, isIdentity ? v : ::math::Helpers::TransformPosition(pose, v));
800  };
801 
802  ARMARX_INFO << "Drawing trimesh as polygons";
803 
804  int counter = 0;
805  for (std::size_t i = 0; i < trimesh.faces.size(); ++i)
806  {
807  const auto& face = trimesh.faces[i];
808  PolygonPointList points
809  {
810  toVector3(trimesh.vertices.at(face.id1)),
811  toVector3(trimesh.vertices.at(face.id2)),
812  toVector3(trimesh.vertices.at(face.id3))
813  };
814 
815  topic->setPolygonVisu(layer(id), id.name + "_" + std::to_string(counter), points,
816  colorFace, colorEdge, lineWidth);
817  ++counter;
818  }
819  }
820 
821 
823  const VisuID& id,
824  const VirtualRobot::TriMeshModel& trimesh,
825  const std::vector<DrawColor>& faceColorsInner, float lineWidth,
826  const DrawColor& colorEdge, bool ignoreLengthScale)
827  {
828  if (!enabled())
829  {
830  return;
831  }
832 
833  //ARMARX_INFO << "Drawing trimesh as polygons colored by area";
834  const float scale = lengthScale(ignoreLengthScale);
835 
836  for (std::size_t i = 0; i < trimesh.faces.size(); ++i)
837  {
838  const auto& face = trimesh.faces[i];
839  PolygonPointList points
840  {
841  scaled(scale, trimesh.vertices[face.id1]),
842  scaled(scale, trimesh.vertices[face.id2]),
843  scaled(scale, trimesh.vertices[face.id3])
844  };
845 
846  topic->setPolygonVisu(layer(id), id.name + "_" + std::to_string(i), points,
847  faceColorsInner.at(i), colorEdge, lineWidth);
848  }
849  }
850 
852  const DebugDrawerTopic::VisuID& id,
853  const DebugDrawerPointCloud& pointCloud)
854  {
855  if (enabled())
856  {
857  topic->setPointCloudVisu(id.layer, id.name, pointCloud);
858  }
859  }
860 
862  const DebugDrawerTopic::VisuID& id,
863  const DebugDrawerColoredPointCloud& pointCloud)
864  {
865  if (enabled())
866  {
867  topic->setColoredPointCloudVisu(id.layer, id.name, pointCloud);
868  }
869  }
870 
872  const DebugDrawerTopic::VisuID& id,
873  const DebugDrawer24BitColoredPointCloud& pointCloud)
874  {
875  if (enabled())
876  {
877  topic->set24BitColoredPointCloudVisu(id.layer, id.name, pointCloud);
878  }
879  }
880 
882  {
883  // Draw an empty point cloud.
884  drawPointCloud(id, DebugDrawerColoredPointCloud{});
885  }
886 
888  const VisuID& id,
889  const Eigen::Vector3f& at, const Eigen::Vector3f& up, float size,
890  const DrawColor& color, bool ignoreLengthScale)
891  {
892  if (!enabled())
893  {
894  return;
895  }
896 
897  Eigen::Vector3f seed = seed.UnitX();
898  if (std::abs(up.dot(seed)) <= 1e-6f)
899  {
900  seed = seed.UnitY();
901  }
902 
903  /* ^ b
904  * | 3---0
905  * | | + |
906  * | 2---1
907  * +--------> a
908  */
909 
910  const float halfSize = size / 2;
911 
912  const Eigen::Vector3f a = halfSize * up.cross(seed).normalized();
913  const Eigen::Vector3f b = halfSize * up.cross(a).normalized();
914 
915  std::vector<Eigen::Vector3f> points;
916  points.push_back(at + a + b);
917  points.push_back(at + a - b);
918  points.push_back(at - a - b);
919  points.push_back(at - a + b);
920 
921  drawPolygon(id, points, color, ignoreLengthScale);
922  }
923 
924 
925  const std::string& DebugDrawerTopic::layer(const std::string& passedLayer) const
926  {
927  return passedLayer.empty() ? _layer : passedLayer;
928  }
929 
930  const std::string& DebugDrawerTopic::layer(const VisuID& id) const
931  {
932  return layer(id.layer);
933  }
934 
935  float DebugDrawerTopic::lengthScale(bool ignore) const
936  {
937  return ignore ? 1 : _lengthScale;
938  }
939 
940  float DebugDrawerTopic::scaled(float scale, float value)
941  {
942  return scale * value;
943  }
944 
945  Vector3BasePtr DebugDrawerTopic::scaled(float scale, const Eigen::Vector3f& vector)
946  {
947  if (scale >= 1 && scale <= 1)
948  {
949  return new Vector3(vector);
950  }
951  else
952  {
953  return new Vector3((vector * scale).eval());
954  }
955  }
956 
957  PoseBasePtr DebugDrawerTopic::scaled(float scale, const Eigen::Matrix4f& pose)
958  {
959  if (scale >= 1 && scale <= 1)
960  {
961  return new Pose(pose);
962  }
963  else
964  {
965  Eigen::Matrix4f out = pose;
966  ::math::Helpers::Position(out) *= scale;
967  return new Pose(out);
968  }
969  }
970 
971 
972  DebugDrawerTopic::operator bool() const
973  {
974  return enabled();
975  }
976 
977  armarx::DebugDrawerTopic::operator DebugDrawerInterfacePrx& ()
978  {
979  return topic;
980  }
981 
982  armarx::DebugDrawerTopic::operator const DebugDrawerInterfacePrx& () const
983  {
984  return topic;
985  }
986 
988  {
989  return topic;
990  }
991 
993  {
994  return topic;
995  }
996 
997  Eigen::Vector3f DebugDrawerTopic::rgb2hsv(const Eigen::Vector3f& rgb)
998  {
999  return simox::color::rgb_to_hsv(rgb);
1000  }
1001 
1002  Eigen::Vector3f DebugDrawerTopic::hsv2rgb(const Eigen::Vector3f& hsv)
1003  {
1004  return simox::color::hsv_to_rgb(hsv);
1005  }
1006 
1007 
1008  DrawColor DebugDrawerTopic::getGlasbeyLUTColor(int id, float alpha)
1009  {
1010  return GlasbeyLUT::at(id, alpha);
1011  }
1012 
1013  DrawColor DebugDrawerTopic::getGlasbeyLUTColor(uint32_t id, float alpha)
1014  {
1015  return GlasbeyLUT::at(id, alpha);
1016  }
1017 
1018  DrawColor DebugDrawerTopic::getGlasbeyLUTColor(std::size_t id, float alpha)
1019  {
1020  return GlasbeyLUT::at(id, alpha);
1021  }
1022 
1023 
1024 }
armarx::DebugDrawerTopic::setTopic
void setTopic(const DebugDrawerInterfacePrx &topic)
Set the topic.
Definition: DebugDrawerTopic.cpp:53
armarx::DebugDrawerTopic::sleepFor
void sleepFor(const DurationT &duration)
If enabled, sleep for the given duration (e.g. a chrono duration).
Definition: DebugDrawerTopic.h:826
armarx::DebugDrawerTopic::offeringTopic
void offeringTopic(ManagedIceObject &component, const std::string &topicNameOverride="") const
Call offeringTopic([topicName]) on the given component.
Definition: DebugDrawerTopic.cpp:73
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::DebugDrawerTopic::getGlasbeyLUTColor
static DrawColor getGlasbeyLUTColor(int id, float alpha=1.f)
Get a color from the Glasbey look-up-table.
Definition: DebugDrawerTopic.cpp:1008
armarx::DebugDrawerTopic::VisuID::layer
std::string layer
The layer name (empty by default).
Definition: DebugDrawerTopic.h:201
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::DebugDrawerTopic::drawLineSet
void drawLineSet(const VisuID &id, const DebugDrawerLineSet &lineSet, bool ignoreLengthScale=false)
Draw a line set.
Definition: DebugDrawerTopic.cpp:503
armarx::DebugDrawerTopic::enabled
bool enabled() const
Indicate whether visualization is enabled, i.e. a topic is set and enabled flag is set.
Definition: DebugDrawerTopic.cpp:68
armarx::ProxyType::component
@ component
armarx::DebugDrawerTopic::drawText
void drawText(const VisuID &id, const Eigen::Vector3f &position, const std::string &text, int size=10, const DrawColor color=DEFAULTS.colorText, bool ignoreLengthScale=false)
Draw text at the specified position.
Definition: DebugDrawerTopic.cpp:167
armarx::DebugDrawerTopic::DebugDrawerTopic
DebugDrawerTopic(const std::string &layer=DEFAULT_LAYER)
Construct without topic, and optional layer.
Definition: DebugDrawerTopic.cpp:44
armarx::DebugDrawerTopic::removeboxEdges
void removeboxEdges(const VisuID &id)
Remove box edges (as a line set).
Definition: DebugDrawerTopic.cpp:335
armarx::DebugDrawerTopic::drawLine
void drawLine(const VisuID &id, const Eigen::Vector3f &from, const Eigen::Vector3f &to, float width, const DrawColor &color=DEFAULTS.colorLine, bool ignoreLengthScale=false)
Draw a line from start to end.
Definition: DebugDrawerTopic.cpp:480
armarx::DebugDrawerTopic::drawFloor
void drawFloor(const VisuID &id={ "floor" }, const Eigen::Vector3f &at=Eigen::Vector3f::Zero(), const Eigen::Vector3f &up=Eigen::Vector3f::UnitZ(), float size=5, const DrawColor &color=DEFAULTS.colorFloor, bool ignoreLengthScale=false)
Draw a quad representing the floor.
Definition: DebugDrawerTopic.cpp:887
armarx::GlasbeyLUT::at
static DrawColor at(std::size_t id, float alpha=1.f)
Definition: GlasbeyLUT.cpp:25
armarx::DebugDrawerTopic::shortSleep
void shortSleep()
Sleep for the shortSleepDuration. Useful after clearing.
Definition: DebugDrawerTopic.cpp:133
armarx::DebugDrawerTopic::operator->
DebugDrawerInterfacePrx & operator->()
Pointer member access operator to access the raw debug drawer proxy.
Definition: DebugDrawerTopic.cpp:987
armarx::DebugDrawerTopic::setLengthScaleMillimetersToMeters
void setLengthScaleMillimetersToMeters()
Set the scale for positions, lengths and distances to 0.001.
Definition: DebugDrawerTopic.cpp:108
armarx::DebugDrawerTopic::VisuID::withName
VisuID withName(const std::string &name) const
Get a VisuID with the given name and same layer as `*this.
Definition: DebugDrawerTopic.cpp:28
armarx::DebugDrawerTopic::setLengthScale
void setLengthScale(float scale)
Set the scale for positions, lengths and distances.
Definition: DebugDrawerTopic.cpp:98
armarx::DebugDrawerTopic::hsv2rgb
static Eigen::Vector3f hsv2rgb(const Eigen::Vector3f &hsv)
Convert a HSV color RGB.
Definition: DebugDrawerTopic.cpp:1002
armarx::DebugDrawerTopic::VisuID::VisuID
VisuID()
Empty constructor.
Definition: DebugDrawerTopic.cpp:18
armarx::DebugDrawerTopic::removeRobot
void removeRobot(const VisuID &id)
Remove a robot visualization.
Definition: DebugDrawerTopic.cpp:701
armarx::DebugDrawerTopic::updateRobotNodeColor
void updateRobotNodeColor(const VisuID &id, const std::string &nodeName, const DrawColor &color)
Update / set the color of a robot node.
Definition: DebugDrawerTopic.cpp:690
armarx::DebugDrawerTopic::clearColoredPointCloud
void clearColoredPointCloud(const VisuID &id)
Forces the "deletion" of a point cloud by drawing an empty one.
Definition: DebugDrawerTopic.cpp:881
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
armarx::DebugDrawerTopic::clearLayer
void clearLayer(bool sleep=false)
Clear the (set default) layer.
Definition: DebugDrawerTopic.cpp:150
armarx::DebugDrawerTopic::rgb2hsv
static Eigen::Vector3f rgb2hsv(const Eigen::Vector3f &rgb)
Convert a RGB color to HSV.
Definition: DebugDrawerTopic.cpp:997
DebugDrawerTopic.h
armarx::DebugDrawerTopic::getLayer
const std::string & getLayer() const
Get the default layer (used if no layer is passed to a method).
Definition: DebugDrawerTopic.cpp:83
armarx::DebugDrawerTopic::updateRobotConfig
void updateRobotConfig(const VisuID &id, const std::map< std::string, float > &config)
Update / set the robot configuration (joint angles).
Definition: DebugDrawerTopic.cpp:670
armarx::DebugDrawerTopic::removeArrow
void removeArrow(const VisuID &id)
Remove an arrow.
Definition: DebugDrawerTopic.cpp:439
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::DebugDrawerTopic::drawCylinder
void drawCylinder(const VisuID &id, const Eigen::Vector3f &center, const Eigen::Vector3f &direction, float length, float radius, const DrawColor &color=DEFAULTS.colorCylinder, bool ignoreLengthScale=false)
Draw a cylinder with center and direction.
Definition: DebugDrawerTopic.cpp:341
ManagedIceObject.h
armarx::DebugDrawerTopic::setLengthScaleMetersToMillimeters
void setLengthScaleMetersToMillimeters()
Set the scale for positions, lengths and distances to 1000.
Definition: DebugDrawerTopic.cpp:103
armarx::DebugDrawerTopic::removePolygon
void removePolygon(const VisuID &id)
Remove a polygon.
Definition: DebugDrawerTopic.cpp:471
armarx::DebugDrawerTopic::updateRobotColor
void updateRobotColor(const VisuID &id, const DrawColor &color)
Update / set the robot color.
Definition: DebugDrawerTopic.cpp:680
armarx::ProxyType::topic
@ topic
armarx::DebugDrawerTopic::drawArrowFromTo
void drawArrowFromTo(const VisuID &id, const Eigen::Vector3f &from, const Eigen::Vector3f &to, float width, const DrawColor &color=DEFAULTS.colorArrow, bool ignoreLengthScale=false)
Draw an arrow with start and end.
Definition: DebugDrawerTopic.cpp:425
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::DebugDrawerTopic::setPoseScaleMeters
void setPoseScaleMeters()
Set the pose scale to 0.001 (good when drawing in meters).
Definition: DebugDrawerTopic.cpp:123
armarx::DebugDrawerTopic::VisuID::name
std::string name
The visu name (empty by default).
Definition: DebugDrawerTopic.h:202
armarx::DebugDrawerTopic::getLengthScale
float getLengthScale() const
Get the scaling for positions, lengths and distances.
Definition: DebugDrawerTopic.cpp:93
armarx::DebugDrawerTopic::drawBox
void drawBox(const VisuID &id, const Eigen::Vector3f &position, const Eigen::Quaternionf &orientation, const Eigen::Vector3f &extents, const DrawColor &color=DEFAULTS.colorBox, bool ignoreLengthScale=false)
Draw a box.
Definition: DebugDrawerTopic.cpp:179
armarx::DebugDrawerTopic::getPoseScale
float getPoseScale() const
Get the scale for pose visualization.
Definition: DebugDrawerTopic.cpp:113
GlasbeyLUT.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::DebugDrawerTopic::removeBox
void removeBox(const VisuID &id)
Remove a box.
Definition: DebugDrawerTopic.cpp:217
armarx::DebugDrawerTopic::drawPose
void drawPose(const VisuID &id, const Eigen::Matrix4f &pose, bool ignoreLengthScale=false)
Draw a pose (with the preset scale).
Definition: DebugDrawerTopic.cpp:586
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::DebugDrawerTopic::setPoseScale
void setPoseScale(float scale)
Set the scale for pose visualization.
Definition: DebugDrawerTopic.cpp:118
armarx::DebugDrawerTopic::setLayer
void setLayer(const std::string &layer)
Set the default layer (used if no layer is passed to a method).
Definition: DebugDrawerTopic.cpp:88
armarx::DebugDrawerTopic::drawBoxEdges
void drawBoxEdges(const VisuID &id, const Eigen::Vector3f &position, const Eigen::Quaternionf &orientation, const Eigen::Vector3f &extents, float width=DEFAULTS.boxEdgesWidth, const DrawColor &color=DEFAULTS.boxEdgesColor, bool ignoreLengthScale=false)
Draw box edges (as a line set).
Definition: DebugDrawerTopic.cpp:225
armarx::Quaternion< float, 0 >
armarx::DebugDrawerTopic::removeLine
void removeLine(const VisuID &id)
Remove a line.
Definition: DebugDrawerTopic.cpp:494
armarx::DebugDrawerTopic::drawTriMesh
void drawTriMesh(const VisuID &id, const VirtualRobot::TriMeshModel &triMesh, const DrawColor &color={.5,.5,.5, 1}, bool ignoreLengthScale=false)
Draw a TriMeshModel as DebugDrawerTriMesh.
Definition: DebugDrawerTopic.cpp:710
armarx::DebugDrawerTopic::updateRobotPose
void updateRobotPose(const VisuID &id, const Eigen::Matrix4f &pose, bool ignoreScale=false)
Update / set the robot pose.
Definition: DebugDrawerTopic.cpp:651
armarx::DebugDrawerTopic::drawPointCloud
void drawPointCloud(const VisuID &id, const PointCloudT &pointCloud, const DrawColor &color=DEFAULTS.colorPointCloud, float pointSize=DEFAULTS.pointCloudPointSize, bool ignoreLengthScale=false)
Draw a unicolored point cloud.
Definition: DebugDrawerTopic.h:849
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::DebugDrawerTopic::drawPolygon
void drawPolygon(const VisuID &id, const std::vector< Eigen::Vector3f > &points, const DrawColor &colorFace, float lineWidth=0, const DrawColor &colorEdge=DEFAULTS.colorPolygonEdge, bool ignoreLengthScale=false)
Draw a polygon.
Definition: DebugDrawerTopic.cpp:448
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:221
armarx::DebugDrawerTopic::drawTriMeshAsPolygons
void drawTriMeshAsPolygons(const VisuID &id, const VirtualRobot::TriMeshModel &trimesh, const DrawColor &colorFace=DEFAULTS.colorPolygonFace, float lineWidth=0, const DrawColor &colorEdge=DEFAULTS.colorPolygonEdge, bool ignoreLengthScale=false)
Draw a TriMeshModel as individual polygons.
Definition: DebugDrawerTopic.cpp:774
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::DebugDrawerTopic::removeCylinder
void removeCylinder(const VisuID &id)
Remove a cylinder.
Definition: DebugDrawerTopic.cpp:379
armarx::DebugDrawerTopic::setPoseScaleMillimeters
void setPoseScaleMillimeters()
Set the pose scale to 1 (good when drawing in millimeters).
Definition: DebugDrawerTopic.cpp:128
Eigen::Matrix
Definition: EigenForwardDeclarations.h:27
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
armarx::DebugDrawerTopic::drawSphere
void drawSphere(const VisuID &id, const Eigen::Vector3f &center, float radius, const DrawColor &color=DEFAULTS.colorSphere, bool ignoreLengthScale=false)
Draw a sphere.
Definition: DebugDrawerTopic.cpp:388
armarx::DebugDrawerTopic::getTopic
DebugDrawerInterfacePrx getTopic() const
Get the topic.
Definition: DebugDrawerTopic.cpp:58
armarx::DebugDrawerTopic::drawRobot
void drawRobot(const VisuID &id, const std::string &robotFile, const std::string &armarxProject, armarx::DrawStyle drawStyle=armarx::DrawStyle::FullModel)
Draw a robot.
Definition: DebugDrawerTopic.cpp:640
armarx::DebugDrawerTopic::setEnabled
void setEnabled(bool enabled)
Set whether drawing is enabled.
Definition: DebugDrawerTopic.cpp:63
armarx::DebugDrawerTopic::VisuID
A visualisation ID.
Definition: DebugDrawerTopic.h:175
armarx::DebugDrawerTopic::removeSphere
void removeSphere(const VisuID &id)
Remove a sphere.
Definition: DebugDrawerTopic.cpp:402
armarx::DebugDrawerTopic::clearAll
void clearAll(bool sleep=false)
Clear all layers.
Definition: DebugDrawerTopic.cpp:138
armarx::DebugDrawerTopic::removePose
void removePose(const VisuID &id)
Remove a pose.
Definition: DebugDrawerTopic.cpp:631
armarx::DebugDrawerTopic::drawCylinderFromTo
void drawCylinderFromTo(const VisuID &id, const Eigen::Vector3f &from, const Eigen::Vector3f &to, float radius, const DrawColor &color=DEFAULTS.colorCylinder, bool ignoreLengthScale=false)
Draw a cylinder from start to end.
Definition: DebugDrawerTopic.cpp:365
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::DebugDrawerTopic::DEFAULTS
static const Defaults DEFAULTS
Definition: DebugDrawerTopic.h:232
armarx::DebugDrawerTopic::drawArrow
void drawArrow(const VisuID &id, const Eigen::Vector3f &position, const Eigen::Vector3f &direction, float length, float width, const DrawColor &color=DEFAULTS.colorArrow, bool ignoreLengthScale=false)
Draw an arrow with position (start) and direction.
Definition: DebugDrawerTopic.cpp:411
armarx::DebugDrawerTopic::removeLineSet
void removeLineSet(const VisuID &id)
Remove a line set.
Definition: DebugDrawerTopic.cpp:577