7#include <Eigen/Geometry>
9#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
184 template <
typename Source>
237 const std::string& layer = DEFAULT_LAYER);
260 const std::string& topicNameOverride =
"")
const;
270 const std::string&
getLayer()
const;
272 void setLayer(
const std::string& layer);
300 template <
typename DurationT>
301 void sleepFor(
const DurationT& duration);
304 template <
typename DurationT>
320 void clearLayer(
const std::string& layer,
bool sleep =
false);
330 const Eigen::Vector3f& position,
331 const std::string& text,
333 const DrawColor color =
DEFAULTS.colorText,
334 bool ignoreLengthScale =
false);
339 const Eigen::Vector3f& position,
341 const Eigen::Vector3f& extents,
342 const DrawColor& color =
DEFAULTS.colorBox,
343 bool ignoreLengthScale =
false);
346 const Eigen::Matrix4f& pose,
347 const Eigen::Vector3f& extents,
348 const DrawColor& color =
DEFAULTS.colorBox,
349 bool ignoreLengthScale =
false);
353 const VirtualRobot::BoundingBox& boundingBox,
354 const DrawColor& color =
DEFAULTS.colorBox,
355 bool ignoreLengthScale =
false);
359 const VirtualRobot::BoundingBox& boundingBox,
360 const Eigen::Matrix4f& pose,
361 const DrawColor& color =
DEFAULTS.colorBox,
362 bool ignoreLengthScale =
false);
371 const Eigen::Vector3f& position,
373 const Eigen::Vector3f& extents,
374 float width =
DEFAULTS.boxEdgesWidth,
375 const DrawColor& color =
DEFAULTS.boxEdgesColor,
376 bool ignoreLengthScale =
false);
380 const Eigen::Matrix4f& pose,
381 const Eigen::Vector3f& extents,
382 float width =
DEFAULTS.boxEdgesWidth,
383 const DrawColor& color =
DEFAULTS.boxEdgesColor,
384 bool ignoreLengthScale =
false);
388 const VirtualRobot::BoundingBox& boundingBox,
389 float width =
DEFAULTS.boxEdgesWidth,
390 const DrawColor& color =
DEFAULTS.boxEdgesColor,
391 bool ignoreLengthScale =
false);
396 float width =
DEFAULTS.boxEdgesWidth,
397 const DrawColor& color =
DEFAULTS.boxEdgesColor,
398 bool ignoreLengthScale =
false);
402 const VirtualRobot::BoundingBox& boundingBox,
403 const Eigen::Matrix4f& pose,
404 float width =
DEFAULTS.boxEdgesWidth,
405 const DrawColor& color =
DEFAULTS.boxEdgesColor,
406 bool ignoreLengthScale =
false);
411 const Eigen::Matrix4f& pose,
412 float width =
DEFAULTS.boxEdgesWidth,
413 const DrawColor& color =
DEFAULTS.boxEdgesColor,
414 bool ignoreLengthScale =
false);
425 const Eigen::Vector3f& center,
426 const Eigen::Vector3f& direction,
429 const DrawColor& color =
DEFAULTS.colorCylinder,
430 bool ignoreLengthScale =
false);
438 const Eigen::Vector3f& center,
442 const DrawColor& color =
DEFAULTS.colorCylinder,
443 bool ignoreLengthScale =
false);
447 const Eigen::Vector3f& from,
448 const Eigen::Vector3f& to,
450 const DrawColor& color =
DEFAULTS.colorCylinder,
451 bool ignoreLengthScale =
false);
459 const Eigen::Vector3f& center,
461 const DrawColor& color =
DEFAULTS.colorSphere,
462 bool ignoreLengthScale =
false);
470 const Eigen::Vector3f& position,
471 const Eigen::Vector3f& direction,
474 const DrawColor& color =
DEFAULTS.colorArrow,
475 bool ignoreLengthScale =
false);
479 const Eigen::Vector3f& from,
480 const Eigen::Vector3f& to,
482 const DrawColor& color =
DEFAULTS.colorArrow,
483 bool ignoreLengthScale =
false);
491 const std::vector<Eigen::Vector3f>& points,
492 const DrawColor& colorFace,
494 const DrawColor& colorEdge =
DEFAULTS.colorPolygonEdge,
495 bool ignoreLengthScale =
false);
503 const Eigen::Vector3f& from,
504 const Eigen::Vector3f& to,
506 const DrawColor& color =
DEFAULTS.colorLine,
507 bool ignoreLengthScale =
false);
515 const DebugDrawerLineSet& lineSet,
516 bool ignoreLengthScale =
false);
523 const std::vector<Eigen::Vector3f>& points,
525 const DrawColor& color =
DEFAULTS.colorLine,
526 bool ignoreLengthScale =
false);
534 const std::vector<Eigen::Vector3f>& points,
536 const DrawColor& colorA,
537 const DrawColor& colorB,
538 const std::vector<float>& intensitiesB,
539 bool ignoreLengthScale =
false);
549 drawPose(
const VisuID&
id,
const Eigen::Matrix4f& pose,
bool ignoreLengthScale =
false);
552 const Eigen::Vector3f& pos,
554 bool ignoreLengthScale =
false);
558 const Eigen::Matrix4f& pose,
560 bool ignoreLengthScale =
false);
563 const Eigen::Vector3f& pos,
566 bool ignoreLengthScale =
false);
584 const std::string& robotFile,
585 const std::string& armarxProject,
586 armarx::DrawStyle drawStyle = armarx::DrawStyle::FullModel);
594 const Eigen::Vector3f& pos,
596 bool ignoreScale =
false);
615 const VirtualRobot::TriMeshModel& triMesh,
616 const DrawColor& color = {.5, .5, .5, 1},
617 bool ignoreLengthScale =
false);
621 const VirtualRobot::TriMeshModel& trimesh,
625 bool ignoreLengthScale =
false);
629 const VirtualRobot::TriMeshModel& trimesh,
630 const Eigen::Matrix4f& pose,
634 bool ignoreLengthScale =
false);
638 const VirtualRobot::TriMeshModel& trimesh,
639 const std::vector<DrawColor>& faceColorsInner,
642 bool ignoreLengthScale =
false);
655 template <
class Po
intCloudT>
660 bool ignoreLengthScale =
false);
668 template <
class Po
intCloudT>
672 bool ignoreLengthScale =
false);
680 template <
class Po
intCloudT>
684 bool ignoreLengthScale =
false);
695 template <
class Po
intCloudT,
class ColorFuncT>
698 const ColorFuncT& colorFunc,
700 bool ignoreLengthScale =
false);
706 void drawPointCloud(
const VisuID&
id,
const DebugDrawerPointCloud& pointCloud);
709 void drawPointCloud(
const VisuID&
id,
const DebugDrawerColoredPointCloud& pointCloud);
712 void drawPointCloud(
const VisuID&
id,
const DebugDrawer24BitColoredPointCloud& pointCloud);
727 void drawFloor(
const VisuID&
id = {
"floor"},
728 const Eigen::Vector3f& at = Eigen::Vector3f::Zero(),
729 const Eigen::Vector3f& up = Eigen::Vector3f::UnitZ(),
732 bool ignoreLengthScale =
false);
739 operator bool()
const;
756 static Eigen::Vector3f
rgb2hsv(
const Eigen::Vector3f& rgb);
763 static Eigen::Vector3f
hsv2rgb(
const Eigen::Vector3f& hsv);
777 template <
class ColorT>
779 toDrawColor(
const ColorT& color,
float alpha = 1,
bool byteToFloat =
false);
790 const std::string& layer(
const std::string& passedLayer)
const;
793 const std::string& layer(
const VisuID&
id)
const;
797 float lengthScale(
bool ignore =
false)
const;
800 static float scaled(
float scale,
float value);
802 static Vector3BasePtr scaled(
float scale,
const Eigen::Vector3f& vector);
804 static PoseBasePtr scaled(
float scale,
const Eigen::Matrix4f& pose);
808 template <
class ScaledT>
809 static ScaledT scaledT(
float scale,
const Eigen::Vector3f& vector);
812 template <
class XYZT>
813 static void scaleXYZ(
float scale, XYZT& xyz);
818 static const std::string TOPIC_NAME;
820 static const std::string DEFAULT_LAYER;
827 bool _enabled =
true;
830 std::string _layer = DEFAULT_LAYER;
833 float _lengthScale = 1;
836 float _poseScale = 1;
839 std::chrono::milliseconds _shortSleepDuration{100};
842 template <
typename DurationT>
848 std::this_thread::sleep_for(duration);
852 template <
typename DurationT>
856 this->_shortSleepDuration = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
859 template <
class ColorT>
863 const float scale = byteToFloat ? (1 / 255.f) : 1;
864 return {color.r * scale, color.g * scale, color.b * scale, alpha};
867 template <
class Po
intCloudT>
871 const DrawColor& color,
873 bool ignoreLengthScale)
876 id, pointCloud, [&color](
const auto&) {
return color; }, pointSize, ignoreLengthScale);
879 template <
class Po
intCloudT>
884 bool ignoreLengthScale)
894 template <
class Po
intCloudT>
899 bool ignoreLengthScale)
909 template <
class Po
intCloudT,
class ColorFuncT>
913 const ColorFuncT& colorFn,
915 bool ignoreLengthScale)
922 const float lf = ignoreLengthScale ? 1.0 : _lengthScale;
924 DebugDrawerColoredPointCloud dd;
925 dd.points.reserve(pointCloud.size());
927 dd.pointSize = pointSize;
929 for (
const auto& p : pointCloud)
932 DebugDrawerColoredPointCloudElement{lf * p.x, lf * p.y, lf * p.z, colorFn(p)});
938 template <
class ScaledT>
940 DebugDrawerTopic::scaledT(
float scale,
const Eigen::Vector3f& vector)
942 auto scaled = vector * scale;
943 return {scaled.x(), scaled.y(), scaled.z()};
946 template <
class XYZT>
948 DebugDrawerTopic::scaleXYZ(
float scale, XYZT& xyz)
void removeLine(const VisuID &id)
Remove a line.
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.
void updateRobotColor(const VisuID &id, const DrawColor &color)
Update / set the robot color.
void shortSleep()
Sleep for the shortSleepDuration. Useful after clearing.
static DrawColor getGlasbeyLUTColor(int id, float alpha=1.f)
Get a color from the Glasbey look-up-table.
static DrawColor toDrawColor(const ColorT &color, float alpha=1, bool byteToFloat=false)
Construct a DrawColor from the given color type.
void setShortSleepDuration(const DurationT &duration)
Set the duration for "short sleeps".
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.
void setEnabled(bool enabled)
Set whether drawing is enabled.
void drawPointCloudLabeled(const VisuID &id, const PointCloudT &pointCloud, float pointSize=DEFAULTS.pointCloudPointSize, bool ignoreLengthScale=false)
Draw a colored point cloud with colors according to labels.
const std::string & getLayer() const
Get the default layer (used if no layer is passed to a method).
float getLengthScale() const
Get the scaling for positions, lengths and distances.
DebugDrawerTopic(const std::string &layer=DEFAULT_LAYER)
Construct without topic, and optional layer.
void removeSphere(const VisuID &id)
Remove a sphere.
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.
void removePolygon(const VisuID &id)
Remove a polygon.
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.
void sleepFor(const DurationT &duration)
If enabled, sleep for the given duration (e.g. a chrono duration).
void setLayer(const std::string &layer)
Set the default layer (used if no layer is passed to a method).
void setPoseScaleMeters()
Set the pose scale to 0.001 (good when drawing in meters).
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.
void removeArrow(const VisuID &id)
Remove an arrow.
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.
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.
void removePose(const VisuID &id)
Remove a pose.
void clearLayer(bool sleep=false)
Clear the (set default) layer.
void updateRobotNodeColor(const VisuID &id, const std::string &nodeName, const DrawColor &color)
Update / set the color of a robot node.
void drawLineSet(const VisuID &id, const DebugDrawerLineSet &lineSet, bool ignoreLengthScale=false)
Draw a line set.
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.
void drawPose(const VisuID &id, const Eigen::Matrix4f &pose, bool ignoreLengthScale=false)
Draw a pose (with the preset scale).
void drawSphere(const VisuID &id, const Eigen::Vector3f ¢er, float radius, const DrawColor &color=DEFAULTS.colorSphere, bool ignoreLengthScale=false)
Draw a sphere.
void drawCylinder(const VisuID &id, const Eigen::Vector3f ¢er, const Eigen::Vector3f &direction, float length, float radius, const DrawColor &color=DEFAULTS.colorCylinder, bool ignoreLengthScale=false)
Draw a cylinder with center and direction.
void setLengthScaleMetersToMillimeters()
Set the scale for positions, lengths and distances to 1000.
void setPoseScale(float scale)
Set the scale for pose visualization. This value will be used for all successive calls to drawPose().
void setPoseScaleMillimeters()
Set the pose scale to 1 (good when drawing in millimeters).
static const Defaults DEFAULTS
void removeboxEdges(const VisuID &id)
Remove box edges (as a line set).
void drawPointCloudRGBA(const VisuID &id, const PointCloudT &pointCloud, float pointSize=DEFAULTS.pointCloudPointSize, bool ignoreLengthScale=false)
Draw a colored point cloud with RGBA information.
DebugDrawerInterfacePrx getTopic() const
Get the topic.
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.
void removeBox(const VisuID &id)
Remove a box.
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).
void removeCylinder(const VisuID &id)
Remove a cylinder.
void setTopic(const DebugDrawerInterfacePrx &topic)
Set the topic.
void updateRobotPose(const VisuID &id, const Eigen::Matrix4f &pose, bool ignoreScale=false)
Update / set the robot pose.
void removeLineSet(const VisuID &id)
Remove a line set.
void removeRobot(const VisuID &id)
Remove a robot visualization.
void clearColoredPointCloud(const VisuID &id)
Forces the "deletion" of a point cloud by drawing an empty one.
void clearAll(bool sleep=false)
Clear all layers.
void setLengthScale(float scale)
Set the scale for positions, lengths and distances.
static Eigen::Vector3f hsv2rgb(const Eigen::Vector3f &hsv)
Convert a HSV color RGB.
static Eigen::Vector3f rgb2hsv(const Eigen::Vector3f &rgb)
Convert a RGB color to HSV.
float getPoseScale() const
Get the scale for pose visualization.
void updateRobotConfig(const VisuID &id, const std::map< std::string, float > &config)
Update / set the robot configuration (joint angles).
DebugDrawerInterfacePrx & operator->()
Pointer member access operator to access the raw debug drawer proxy.
void drawRobot(const VisuID &id, const std::string &robotFile, const std::string &armarxProject, armarx::DrawStyle drawStyle=armarx::DrawStyle::FullModel)
Draw a robot.
bool enabled() const
Indicate whether visualization is enabled, i.e. a topic is set and enabled flag is set.
void drawTriMesh(const VisuID &id, const VirtualRobot::TriMeshModel &triMesh, const DrawColor &color={.5,.5,.5, 1}, bool ignoreLengthScale=false)
Draw a TriMeshModel as DebugDrawerTriMesh.
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.
void offeringTopic(ManagedIceObject &component, const std::string &topicNameOverride="") const
Call offeringTopic([topicName]) on the given component.
void setLengthScaleMillimetersToMeters()
Set the scale for positions, lengths and distances to 0.001.
The ManagedIceObject is the base class for all ArmarX objects.
Quaternion< float, 0 > Quaternionf
Matrix< float, 3, 2 > Matrix32f
A 3x2 matrix.
This file offers overloads of toIce() and fromIce() functions for STL container types.
pcl::PointCloud< PointT > PointCloudT
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
Default values for drawing functions.
float pointCloudPointSize
DrawColor colorPolygonEdge
DrawColor colorPolygonFace
DrawColor colorPointCloud
VisuID(const Source &name)
Construct a VisuID from a non-std::string source (e.g. char[]).
VisuID withName(const std::string &name) const
Get a VisuID with the given name and same layer as `*this.
std::string layer
The layer name (empty by default).
std::string name
The visu name (empty by default).
VisuID()
Empty constructor.
friend std::ostream & operator<<(std::ostream &os, const VisuID &rhs)
Streams a short human-readable description of rhs to os.