ArmarXVisualizer.cpp
Go to the documentation of this file.
1#include "ArmarXVisualizer.h"
2
4
5namespace armarx::semantic
6{
7
9 toArmarx(const Eigen::Vector3f& v)
10 {
11 return armarx::Vector3Ptr(new armarx::Vector3(v));
12 }
13
15 toArmarx(const Eigen::Quaternionf& q)
16 {
17 return armarx::QuaternionPtr(new armarx::Quaternion(q));
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
211 const std::string semantic::properties::defaults::visualizationLevelName = "visu.level";
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 {
239 semrel::VisualizerInterface::setMinimumVisuLevel(getVisualizationLevel(defs, propertyName));
240 }
241
242} // namespace armarx::semantic
Default component property definition container.
Definition Component.h:70
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Abstract PropertyUser class.
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
virtual void drawCylinder(semrel::VisuMetaInfo id, const semrel::Cylinder &cylinder, semrel::DrawColor color) override
virtual void drawLine(semrel::VisuMetaInfo id, const Eigen::Vector3f &start, const Eigen::Vector3f &end, float lineWidth, semrel::DrawColor color) override
virtual void clearLayer(const std::string &layer) override
virtual void drawPointCloud(semrel::VisuMetaInfo id, const std::vector< Eigen::Vector3f > &cloud, float pointSize, semrel::DrawColor color) override
virtual void drawPolygon(semrel::VisuMetaInfo id, const std::vector< Eigen::Vector3f > &polygonPoints, float lineWidth, semrel::DrawColor colorInner, semrel::DrawColor colorBorder) override
virtual void drawTriMesh(semrel::VisuMetaInfo id, const semrel::TriMesh &mesh, semrel::DrawColor color) override
virtual void drawText(semrel::VisuMetaInfo id, const std::string &text, const Eigen::Vector3f &position, float size, semrel::DrawColor color) override
virtual void drawBox(semrel::VisuMetaInfo id, const semrel::Box &box, semrel::DrawColor color) override
virtual void drawArrow(semrel::VisuMetaInfo id, const Eigen::Vector3f &origin, const Eigen::Vector3f &direction, float length, float width, semrel::DrawColor color) override
ArmarXVisualizer(armarx::DebugDrawerInterfacePrx const &debugDrawer)
virtual void drawSphere(semrel::VisuMetaInfo id, const semrel::Sphere &sphere, semrel::DrawColor color) override
static void setAsImplementation(const armarx::DebugDrawerInterfacePrx &debugDrawer)
#define q
Quaternion< float, 0 > Quaternionf
const std::string visualizationLevelDescription
semrel::VisuLevel getVisualizationLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
void defineVisualizationLevel(armarx::ComponentPropertyDefinitions &defs, const std::string &propertyName=defaults::visualizationLevelName, semrel::VisuLevel defaultLevel=semrel::VisuLevel::RESULT, const std::string &description=defaults::visualizationLevelDescription)
void setMinimumVisuLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx