ArmarXVisualizer.cpp
Go to the documentation of this file.
1 #include "ArmarXVisualizer.h"
2 
4 
5 namespace armarx::semantic
6 {
7 
8  static armarx::Vector3Ptr
9  toArmarx(const Eigen::Vector3f& v)
10  {
12  }
13 
15  toArmarx(const Eigen::Quaternionf& q)
16  {
18  }
19 
20  static armarx::PosePtr
21  toArmarx(const Eigen::Vector3f& pos, const Eigen::Quaternionf& ori)
22  {
23  return armarx::PosePtr(new armarx::Pose(toArmarx(pos), toArmarx(ori)));
24  }
25 
26  static armarx::DrawColor
27  toArmarx(const semrel::DrawColor& color)
28  {
29  return armarx::DrawColor{color.r, color.g, color.b, color.a};
30  }
31 
32  void
34  {
35  semrel::VisualizerInterface::setImplementation(
36  std::make_shared<ArmarXVisualizer>(debugDrawer));
37  }
38 
40  drawer(debugDrawer)
41  {
42  }
43 
44  void
46  {
47  drawer->clearAll();
48  }
49 
50  void
51  ArmarXVisualizer::clearLayer(const std::string& layer)
52  {
53  drawer->clearLayer(layer);
54  }
55 
56  void
57  ArmarXVisualizer::drawLine(semrel::VisuMetaInfo id,
58  const Eigen::Vector3f& start,
59  const Eigen::Vector3f& end,
60  float lineWidth,
61  semrel::DrawColor color)
62  {
63  drawer->setLineVisu(
64  id.layer, id.name, toArmarx(start), toArmarx(end), lineWidth, toArmarx(color));
65  }
66 
67  void
68  ArmarXVisualizer::drawArrow(semrel::VisuMetaInfo id,
69  const Eigen::Vector3f& origin,
70  const Eigen::Vector3f& direction,
71  float length,
72  float width,
73  semrel::DrawColor color)
74  {
75  drawer->setArrowVisu(id.layer,
76  id.name,
77  toArmarx(origin),
78  toArmarx(direction),
79  toArmarx(color),
80  length,
81  width);
82  }
83 
84  void
85  ArmarXVisualizer::drawBox(semrel::VisuMetaInfo id,
86  const semrel::Box& box,
87  semrel::DrawColor color)
88  {
89  drawer->setBoxVisu(id.layer,
90  id.name,
91  toArmarx(box.getPosition(), box.getOrientation()),
92  toArmarx(box.getExtents()),
93  toArmarx(color));
94  }
95 
96  void
97  ArmarXVisualizer::drawCylinder(semrel::VisuMetaInfo id,
98  const semrel::Cylinder& cylinder,
99  semrel::DrawColor color)
100  {
101  drawer->setCylinderVisu(id.layer,
102  id.name,
103  toArmarx(cylinder.getPosition()),
104  toArmarx(cylinder.getAxisDirection()),
105  cylinder.getHeight(),
106  cylinder.getRadius(),
107  toArmarx(color));
108  }
109 
110  void
111  ArmarXVisualizer::drawSphere(semrel::VisuMetaInfo id,
112  const semrel::Sphere& sphere,
113  semrel::DrawColor color)
114  {
115  drawer->setSphereVisu(
116  id.layer, id.name, toArmarx(sphere.getPosition()), toArmarx(color), sphere.getRadius());
117  }
118 
119  void
120  ArmarXVisualizer::drawPolygon(semrel::VisuMetaInfo id,
121  const std::vector<Eigen::Vector3f>& polygonPoints,
122  float lineWidth,
123  semrel::DrawColor colorInner,
124  semrel::DrawColor colorBorder)
125  {
126  armarx::PolygonPointList armarxPoints;
127  for (const Eigen::Vector3f& v : polygonPoints)
128  {
129  armarxPoints.push_back(toArmarx(v));
130  }
131 
132  drawer->setPolygonVisu(id.layer,
133  id.name,
134  armarxPoints,
135  toArmarx(colorInner),
136  toArmarx(colorBorder),
137  lineWidth);
138  }
139 
140  void
141  ArmarXVisualizer::drawTriMesh(semrel::VisuMetaInfo id,
142  const semrel::TriMesh& mesh,
143  semrel::DrawColor color)
144  {
145  /*
146  // use variant to create armarx tri mesh (DebugDrawerTriMesh)
147  MeshShapeVariant variant(semrel::MeshShape(Eigen::Vector3f::Zero(), Eigen::Quaternionf::Identity(), mesh));
148  DebugDrawerTriMesh ddMesh = variant.getMesh();
149 
150  // replace default color
151  ddMesh.colors.front() = toArmarx(color);
152 
153  drawer->setTriMeshVisu(id.layer, id.name, ddMesh);
154  */
155 
156  int i = 0;
157  for (semrel::TriMesh::Triangle triangle : mesh.getTriangles())
158  {
159  semrel::VisuMetaInfo triID = id;
160  std::stringstream ss;
161  ss << triID.name << "_" << i;
162  triID.name = ss.str();
163 
164  Eigen::Vector3f v0 = mesh.getVertex(triangle.v0);
165  Eigen::Vector3f v1 = mesh.getVertex(triangle.v1);
166  Eigen::Vector3f v2 = mesh.getVertex(triangle.v2);
167  std::vector<Eigen::Vector3f> points;
168  points.push_back(v0);
169  points.push_back(v1);
170  points.push_back(v2);
171 
172  semrel::DrawColor inner = color;
173  color.a = 0.1f;
174 
175  drawPolygon(triID, points, 1, inner, color);
176  i++;
177  }
178  }
179 
180  void
181  ArmarXVisualizer::drawText(semrel::VisuMetaInfo id,
182  const std::string& text,
183  const Eigen::Vector3f& position,
184  float size,
185  semrel::DrawColor color)
186  {
187  drawer->setTextVisu(
188  id.layer, id.name, text, toArmarx(position), toArmarx(color), int(roundf(size)));
189  }
190 
191  void
192  ArmarXVisualizer::drawPointCloud(semrel::VisuMetaInfo id,
193  const std::vector<Eigen::Vector3f>& cloud,
194  float pointSize,
195  semrel::DrawColor color)
196  {
197  armarx::DrawColor armarxColor = toArmarx(color);
198 
199  armarx::DebugDrawerColoredPointCloud ddPointcloud;
200  ddPointcloud.pointSize = pointSize;
201 
202  for (const Eigen::Vector3f& v : cloud)
203  {
204  armarx::DebugDrawerColoredPointCloudElement el{v(0), v(1), v(2), armarxColor};
205  ddPointcloud.points.push_back(el);
206  }
207 
208  drawer->setColoredPointCloudVisu(id.layer, id.name, ddPointcloud);
209  }
210 
213  "Visualization level: Determines what is shown in the debug drawer.\n"
214  "Possible values: live, verbose, result, user, disabled";
215 
216  void
218  const std::string& propertyName,
219  semrel::VisuLevel defaultLevel,
220  const std::string& description)
221  {
222  defs.defineOptionalProperty<semrel::VisuLevel>(propertyName, defaultLevel, description)
223  .map("live", semrel::VisuLevel::LIVE_VISU)
224  .map("verbose", semrel::VisuLevel::VERBOSE)
225  .map("result", semrel::VisuLevel::RESULT)
226  .map("user", semrel::VisuLevel::USER)
227  .map("disabled", semrel::VisuLevel::DISABLED);
228  }
229 
230  semrel::VisuLevel
231  semantic::properties::getVisualizationLevel(PropertyUser& defs, const std::string& propertyName)
232  {
233  return defs.getProperty<semrel::VisuLevel>(propertyName);
234  }
235 
236  void
237  semantic::properties::setMinimumVisuLevel(PropertyUser& defs, const std::string& propertyName)
238  {
240  }
241 
242 } // namespace armarx::semantic
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:57
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:120
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:51
armarx::semantic::properties::defaults::visualizationLevelDescription
const std::string visualizationLevelDescription
Definition: ArmarXVisualizer.cpp:212
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:181
IceInternal::Handle< Vector3 >
armarx::semantic::ArmarXVisualizer::setAsImplementation
static void setAsImplementation(const armarx::DebugDrawerInterfacePrx &debugDrawer)
Definition: ArmarXVisualizer.cpp:33
armarx::semantic::ArmarXVisualizer::drawTriMesh
virtual void drawTriMesh(semrel::VisuMetaInfo id, const semrel::TriMesh &mesh, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:141
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:217
armarx::semantic::ArmarXVisualizer::drawCylinder
virtual void drawCylinder(semrel::VisuMetaInfo id, const semrel::Cylinder &cylinder, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:97
armarx::semantic::properties::getVisualizationLevel
semrel::VisuLevel getVisualizationLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
Definition: ArmarXVisualizer.cpp:231
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:39
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:68
q
#define q
armarx::semantic::ArmarXVisualizer::drawSphere
virtual void drawSphere(semrel::VisuMetaInfo id, const semrel::Sphere &sphere, semrel::DrawColor color) override
Definition: ArmarXVisualizer.cpp:111
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:69
armarx::semantic::properties::defaults::visualizationLevelName
const std::string visualizationLevelName
Definition: ArmarXVisualizer.cpp:211
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:180
armarx::Quaternion< float, 0 >
armarx::semantic::ArmarXVisualizer::clearAll
virtual void clearAll() override
Definition: ArmarXVisualizer.cpp:45
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:85
armarx::Vector3Ptr
IceInternal::Handle< Vector3 > Vector3Ptr
Definition: Pose.h:165
armarx::PropertyUser
Abstract PropertyUser class.
Definition: PropertyUser.h:63
armarx::semantic::properties::setMinimumVisuLevel
void setMinimumVisuLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
Definition: ArmarXVisualizer.cpp:237
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:192