ArmarXVisualizer.cpp
Go to the documentation of this file.
1 #include "ArmarXVisualizer.h"
2 
4 
5 
6 namespace armarx::semantic
7 {
8 
9  static armarx::Vector3Ptr toArmarx(const Eigen::Vector3f& v)
10  {
12  }
13 
14  static armarx::QuaternionPtr toArmarx(const Eigen::Quaternionf& q)
15  {
17  }
18 
19  static armarx::PosePtr toArmarx(const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori)
20  {
21  return armarx::PosePtr(new armarx::Pose(toArmarx(pos), toArmarx(ori)));
22  }
23 
24  static armarx::DrawColor toArmarx(const semrel::DrawColor& color)
25  {
26  return armarx::DrawColor { color.r, color.g, color.b, color.a };
27  }
28 
30  {
31  semrel::VisualizerInterface::setImplementation(std::make_shared<ArmarXVisualizer>(debugDrawer));
32  }
33 
35  drawer(debugDrawer)
36  {
37  }
38 
40  {
41  drawer->clearAll();
42  }
43 
44  void ArmarXVisualizer::clearLayer(const std::string& layer)
45  {
46  drawer->clearLayer(layer);
47  }
48 
49  void ArmarXVisualizer::drawLine(semrel::VisuMetaInfo id, const Eigen::Vector3f& start, const Eigen::Vector3f& end, float lineWidth, semrel::DrawColor color)
50  {
51  drawer->setLineVisu(id.layer, id.name, toArmarx(start), toArmarx(end), lineWidth, toArmarx(color));
52  }
53 
54  void ArmarXVisualizer::drawArrow(semrel::VisuMetaInfo id, const Eigen::Vector3f& origin, const Eigen::Vector3f& direction, float length, float width, semrel::DrawColor color)
55  {
56  drawer->setArrowVisu(id.layer, id.name, toArmarx(origin), toArmarx(direction), toArmarx(color), length, width);
57  }
58 
59  void ArmarXVisualizer::drawBox(semrel::VisuMetaInfo id, const semrel::Box& box, semrel::DrawColor color)
60  {
61  drawer->setBoxVisu(id.layer, id.name, toArmarx(box.getPosition(), box.getOrientation()),
62  toArmarx(box.getExtents()), toArmarx(color));
63  }
64 
65  void ArmarXVisualizer::drawCylinder(semrel::VisuMetaInfo id, const semrel::Cylinder& cylinder, semrel::DrawColor color)
66  {
67  drawer->setCylinderVisu(id.layer, id.name, toArmarx(cylinder.getPosition()), toArmarx(cylinder.getAxisDirection()),
68  cylinder.getHeight(), cylinder.getRadius(), toArmarx(color));
69  }
70 
71  void ArmarXVisualizer::drawSphere(semrel::VisuMetaInfo id, const semrel::Sphere& sphere, semrel::DrawColor color)
72  {
73  drawer->setSphereVisu(id.layer, id.name, toArmarx(sphere.getPosition()), toArmarx(color), sphere.getRadius());
74  }
75 
76  void ArmarXVisualizer::drawPolygon(semrel::VisuMetaInfo id, const std::vector<Eigen::Vector3f>& polygonPoints, float lineWidth, semrel::DrawColor colorInner, semrel::DrawColor colorBorder)
77  {
78  armarx::PolygonPointList armarxPoints;
79  for (const Eigen::Vector3f& v : polygonPoints)
80  {
81  armarxPoints.push_back(toArmarx(v));
82  }
83 
84  drawer->setPolygonVisu(id.layer, id.name, armarxPoints, toArmarx(colorInner), toArmarx(colorBorder), lineWidth);
85  }
86 
87  void ArmarXVisualizer::drawTriMesh(semrel::VisuMetaInfo id, const semrel::TriMesh& mesh, semrel::DrawColor color)
88  {
89  /*
90  // use variant to create armarx tri mesh (DebugDrawerTriMesh)
91  MeshShapeVariant variant(semrel::MeshShape(Eigen::Vector3f::Zero(), Eigen::Quaternionf::Identity(), mesh));
92  DebugDrawerTriMesh ddMesh = variant.getMesh();
93 
94  // replace default color
95  ddMesh.colors.front() = toArmarx(color);
96 
97  drawer->setTriMeshVisu(id.layer, id.name, ddMesh);
98  */
99 
100  int i = 0;
101  for (semrel::TriMesh::Triangle triangle : mesh.getTriangles())
102  {
103  semrel::VisuMetaInfo triID = id;
104  std::stringstream ss;
105  ss << triID.name << "_" << i;
106  triID.name = ss.str();
107 
108  Eigen::Vector3f v0 = mesh.getVertex(triangle.v0);
109  Eigen::Vector3f v1 = mesh.getVertex(triangle.v1);
110  Eigen::Vector3f v2 = mesh.getVertex(triangle.v2);
111  std::vector<Eigen::Vector3f> points;
112  points.push_back(v0);
113  points.push_back(v1);
114  points.push_back(v2);
115 
116  semrel::DrawColor inner = color;
117  color.a = 0.1f;
118 
119  drawPolygon(triID, points, 1, inner, color);
120  i++;
121  }
122  }
123 
124  void ArmarXVisualizer::drawText(semrel::VisuMetaInfo id, const std::string& text, const Eigen::Vector3f& position, float size, semrel::DrawColor color)
125  {
126  drawer->setTextVisu(id.layer, id.name, text, toArmarx(position), toArmarx(color), int(roundf(size)));
127  }
128 
129  void ArmarXVisualizer::drawPointCloud(semrel::VisuMetaInfo id, const std::vector<Eigen::Vector3f>& cloud, float pointSize, semrel::DrawColor color)
130  {
131  armarx::DrawColor armarxColor = toArmarx(color);
132 
133  armarx::DebugDrawerColoredPointCloud ddPointcloud;
134  ddPointcloud.pointSize = pointSize;
135 
136  for (const Eigen::Vector3f& v : cloud)
137  {
138  armarx::DebugDrawerColoredPointCloudElement el { v(0), v(1), v(2), armarxColor };
139  ddPointcloud.points.push_back(el);
140  }
141 
142  drawer->setColoredPointCloudVisu(id.layer, id.name, ddPointcloud);
143  }
144 
147  "Visualization level: Determines what is shown in the debug drawer.\n"
148  "Possible values: live, verbose, result, user, disabled";
149 
150 
152  ComponentPropertyDefinitions& defs, const std::string& propertyName,
153  semrel::VisuLevel defaultLevel, const std::string& description)
154  {
155  defs.defineOptionalProperty<semrel::VisuLevel>(propertyName, defaultLevel, description)
156  .map("live", semrel::VisuLevel::LIVE_VISU)
157  .map("verbose", semrel::VisuLevel::VERBOSE)
158  .map("result", semrel::VisuLevel::RESULT)
159  .map("user", semrel::VisuLevel::USER)
160  .map("disabled", semrel::VisuLevel::DISABLED);
161  }
162 
163  semrel::VisuLevel semantic::properties::getVisualizationLevel(PropertyUser& defs, const std::string& propertyName)
164  {
165  return defs.getProperty<semrel::VisuLevel>(propertyName);
166  }
167 
168  void semantic::properties::setMinimumVisuLevel(PropertyUser& defs, const std::string& propertyName)
169  {
171  }
172 
173 }
armarx::semantic::ArmarXVisualizer::drawLine
virtual void drawLine(semrel::VisuMetaInfo id, const Eigen::Vector3f &start, const Eigen::Vector3f &end, float lineWidth, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:49
armarx::PropertyDefinitionContainer::defineOptionalProperty
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Definition: PropertyDefinitionContainer.h:533
armarx::semantic::ArmarXVisualizer::drawPolygon
virtual void drawPolygon(semrel::VisuMetaInfo id, const std::vector< Eigen::Vector3f > &polygonPoints, float lineWidth, semrel::DrawColor colorInner, semrel::DrawColor colorBorder) override
Definition: ArmarXVisualizer.cpp:76
armarx::PosePtr
IceInternal::Handle< Pose > PosePtr
Definition: Pose.h:306
Pose.h
armarx::semantic::ArmarXVisualizer::clearLayer
virtual void clearLayer(const std::string &layer) override
Definition: ArmarXVisualizer.cpp:44
armarx::semantic::properties::defaults::visualizationLevelDescription
const std::string visualizationLevelDescription
Definition: ArmarXVisualizer.cpp:146
ArmarXVisualizer.h
armarx::semantic::ArmarXVisualizer::drawText
virtual void drawText(semrel::VisuMetaInfo id, const std::string &text, const Eigen::Vector3f &position, float size, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:124
IceInternal::Handle< Vector3 >
armarx::semantic::ArmarXVisualizer::setAsImplementation
static void setAsImplementation(const armarx::DebugDrawerInterfacePrx &debugDrawer)
Definition: ArmarXVisualizer.cpp:29
armarx::semantic::ArmarXVisualizer::drawTriMesh
virtual void drawTriMesh(semrel::VisuMetaInfo id, const semrel::TriMesh &mesh, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:87
armarx::semantic::properties::defineVisualizationLevel
void defineVisualizationLevel(armarx::ComponentPropertyDefinitions &defs, const std::string &propertyName=defaults::visualizationLevelName, semrel::VisuLevel defaultLevel=semrel::VisuLevel::RESULT, const std::string &description=defaults::visualizationLevelDescription)
Definition: ArmarXVisualizer.cpp:151
armarx::semantic::ArmarXVisualizer::drawCylinder
virtual void drawCylinder(semrel::VisuMetaInfo id, const semrel::Cylinder &cylinder, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:65
armarx::semantic::properties::getVisualizationLevel
semrel::VisuLevel getVisualizationLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
Definition: ArmarXVisualizer.cpp:163
armarx::QuaternionPtr
IceInternal::Handle< Quaternion > QuaternionPtr
Definition: Pose.h:234
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::semantic::ArmarXVisualizer::ArmarXVisualizer
ArmarXVisualizer(armarx::DebugDrawerInterfacePrx const &debugDrawer)
Definition: ArmarXVisualizer.cpp:34
armarx::semantic::ArmarXVisualizer::drawArrow
virtual void drawArrow(semrel::VisuMetaInfo id, const Eigen::Vector3f &origin, const Eigen::Vector3f &direction, float length, float width, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:54
q
#define q
armarx::semantic::ArmarXVisualizer::drawSphere
virtual void drawSphere(semrel::VisuMetaInfo id, const semrel::Sphere &sphere, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:71
armarx::semantic
Definition: ShapesSupportRelations.cpp:32
armarx::Pose
The Pose class.
Definition: Pose.h:242
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::semantic::properties::defaults::visualizationLevelName
const std::string visualizationLevelName
Definition: ArmarXVisualizer.cpp:145
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
armarx::Quaternion< float, 0 >
armarx::semantic::ArmarXVisualizer::clearAll
virtual void clearAll() override
Definition: ArmarXVisualizer.cpp:39
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::semantic::ArmarXVisualizer::drawBox
virtual void drawBox(semrel::VisuMetaInfo id, const semrel::Box &box, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:59
armarx::Vector3Ptr
IceInternal::Handle< Vector3 > Vector3Ptr
Definition: Pose.h:165
armarx::PropertyUser
Abstract PropertyUser class.
Definition: PropertyUser.h:62
armarx::semantic::properties::setMinimumVisuLevel
void setMinimumVisuLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
Definition: ArmarXVisualizer.cpp:168
armarx::semantic::ArmarXVisualizer::drawPointCloud
virtual void drawPointCloud(semrel::VisuMetaInfo id, const std::vector< Eigen::Vector3f > &cloud, float pointSize, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:129