Elements.h
Go to the documentation of this file.
1#pragma once
2
3
4#include "elements/Color.h"
6#include "elements/Line.h"
7#include "elements/Mesh.h"
8#include "elements/Path.h"
10#include "elements/Robot.h"
11//#include "elements/RobotHand.h" // Not included by default (exposes additional headers).
12
13#include <ctime>
14#include <string>
15
16#include <Eigen/Core>
17#include <Eigen/Geometry>
18
19#include <SimoxUtility/shapes/OrientedBoxBase.h>
20
21#include <RobotAPI/interface/ArViz/Elements.h>
22
23// The has_member macro causes compile errors if *any* other header uses
24// the identifier has_member. Boost.Thread does, so this causes compile
25// errors down the line.
26// Offending file: simox/SimoxUtility/meta/has_member_macros/has_member.hpp
27#ifdef has_member
28#undef has_member
29#endif
30
31
32namespace Eigen
33{
34 using Hyperplane3f = Hyperplane<float, 3>;
35}
36
37namespace armarx
38{
39 // <RobotAPI/libraries/ArmarXObjects/ObjectID.h>
40 class ObjectID;
41} // namespace armarx
42
43namespace armarx::viz
44{
45 using data::ColoredPoint;
46
47 struct Box : ElementOps<Box, data::ElementBox>
48 {
50
51 Box&
52 size(Eigen::Vector3f const& s)
53 {
54 data_->size.e0 = s.x();
55 data_->size.e1 = s.y();
56 data_->size.e2 = s.z();
57
58 return *this;
59 }
60
61 Box&
62 size(float s)
63 {
64 return size(Eigen::Vector3f(s, s, s));
65 }
66
67 Box& set(const simox::OrientedBoxBase<float>& b);
68 Box& set(const simox::OrientedBoxBase<double>& b);
69 };
70
71 struct Cylinder : ElementOps<Cylinder, data::ElementCylinder>
72 {
74
76 radius(float r)
77 {
78 data_->radius = r;
79
80 return *this;
81 }
82
84 height(float h)
85 {
86 data_->height = h;
87
88 return *this;
89 }
90
91 Cylinder& fromTo(Eigen::Vector3f from, Eigen::Vector3f to);
92
93 Cylinder& direction(Eigen::Vector3f direction);
94 };
95
96 struct Cylindroid : ElementOps<Cylindroid, data::ElementCylindroid>
97 {
98 Cylindroid(const std::string& name) : ElementOps(name)
99 {
100 data_->curvature.e0 = 1;
101 data_->curvature.e1 = 1;
102 }
103
106 {
107 data_->height = height;
108
109 return *this;
110 }
111
113 axisLengths(const Eigen::Vector2f& axisLengths)
114 {
115 data_->axisLengths.e0 = axisLengths.x();
116 data_->axisLengths.e1 = axisLengths.y();
117
118 return *this;
119 }
120
122 curvature(const Eigen::Vector2f& curvature)
123 {
124 // Warning: Custom curvatures are not yet supported by the visualization backend and
125 // are thus ignored.
126 data_->curvature.e0 = curvature.x();
127 data_->curvature.e1 = curvature.y();
128
129 return *this;
130 }
131 };
132
133 struct Sphere : ElementOps<Sphere, data::ElementSphere>
134 {
136
137 Sphere&
138 radius(float r)
139 {
140 data_->radius = r;
141
142 return *this;
143 }
144 };
145
146 struct Ellipsoid : ElementOps<Ellipsoid, data::ElementEllipsoid>
147 {
148 Ellipsoid(const std::string& name) : ElementOps(name)
149 {
150 data_->curvature.e0 = 1;
151 data_->curvature.e1 = 1;
152 data_->curvature.e2 = 1;
153 }
154
155 Ellipsoid&
156 axisLengths(const Eigen::Vector3f& axisLengths)
157 {
158 data_->axisLengths.e0 = axisLengths.x();
159 data_->axisLengths.e1 = axisLengths.y();
160 data_->axisLengths.e2 = axisLengths.z();
161
162 return *this;
163 }
164
165 Ellipsoid&
166 curvature(const Eigen::Vector3f& curvature)
167 {
168 // Warning: Custom curvatures are not yet supported by the visualization backend and
169 // are thus ignored.
170 data_->curvature.e0 = curvature.x();
171 data_->curvature.e1 = curvature.y();
172 data_->curvature.e2 = curvature.z();
173
174 return *this;
175 }
176 };
177
178 struct Pose : ElementOps<Pose, data::ElementPose>
179 {
181 };
182
183 struct Text : ElementOps<Text, data::ElementText>
184 {
186
187 Text&
188 text(std::string const& t)
189 {
190 data_->text = t;
191
192 return *this;
193 }
194 };
195
196 struct Arrow : ElementOps<Arrow, data::ElementArrow>
197 {
199
200 Arrow& direction(Eigen::Vector3f dir);
201
202 Arrow&
203 length(float l)
204 {
205 data_->length = l;
206
207 return *this;
208 }
209
210 Arrow&
211 width(float w)
212 {
213 data_->width = w;
214
215 return *this;
216 }
217
218 Arrow&
219 fromTo(const Eigen::Vector3f& from, const Eigen::Vector3f& to)
220 {
221 position(from);
222 direction((to - from).normalized());
223 length((to - from).norm());
224
225 return *this;
226 }
227 };
228
229 struct ArrowCircle : ElementOps<ArrowCircle, data::ElementArrowCircle>
230 {
232
233 ArrowCircle& normal(Eigen::Vector3f dir);
234
236 radius(float r)
237 {
238 data_->radius = r;
239
240 return *this;
241 }
242
244 width(float w)
245 {
246 data_->width = w;
247
248 return *this;
249 }
250
253 {
254 data_->completion = c;
255
256 return *this;
257 }
258 };
259
260 struct Polygon : ElementOps<Polygon, data::ElementPolygon>
261 {
263
264 Polygon&
266 {
267 data_->points.clear();
268 return *this;
269 }
270
271 Polygon&
273 {
274 data_->lineColor = color;
275
276 return *this;
277 }
278
279 Polygon&
280 lineColor(int r, int g, int b)
281 {
282 return lineColor(viz::Color(r, g, b));
283 }
284
285 Polygon&
286 lineColorGlasbeyLUT(std::size_t id, int alpha = 255)
287 {
288 return lineColor(Color::fromRGBA(simox::color::GlasbeyLUT::at(id, alpha)));
289 }
290
291 Polygon&
292 lineWidth(float w)
293 {
294 data_->lineWidth = w;
295
296 return *this;
297 }
298
299 Polygon& points(std::vector<Eigen::Vector3f> const& ps);
300
301 Polygon&
302 addPoint(Eigen::Vector3f p)
303 {
304 data_->points.push_back(armarx::Vector3f{p.x(), p.y(), p.z()});
305
306 return *this;
307 }
308
309 /**
310 * @brief Add points representing a plane as rectangle.
311 * @param plane The plane.
312 * @param at Center of rectangle, is projected onto plane.
313 * @param size Extents of rectangle.
314 */
315 Polygon& plane(Eigen::Hyperplane3f plane, Eigen::Vector3f at, Eigen::Vector2f size);
316
317 /**
318 * @brief Add points representing the XY-plane of the given coordinate system as rectangle.
319 * @param center The rectangle center.
320 * @param orientation The orientation of the coordinate system.
321 * @param size The XY-size of the rectangle.
322 */
323 Polygon&
324 plane(Eigen::Vector3f center, Eigen::Quaternionf orientation, Eigen::Vector2f size);
325
326 Polygon& circle(Eigen::Vector3f center,
327 Eigen::Vector3f normal,
328 float radius,
329 std::size_t tessellation = 64);
330 };
331
332 struct Object : ElementOps<Object, data::ElementObject>
333 {
334 static const std::string DefaultObjectsPackage;
335 static const std::string DefaultRelativeObjectsDirectory;
336
338
339 Object&
340 file(std::string const& project, std::string const& filename)
341 {
342 data_->project = project;
343 data_->filename = filename;
344
345 return *this;
346 }
347
348 Object&
349 file(std::string const& filename)
350 {
351 return file("", filename);
352 }
353
354 /**
355 * @brief Set the file so it could be found using `armarx::ObjectFinder` (also on remote machine).
356 * @param objectID The object ID, see <RobotAPI/libraries/ArmarXObjects/ObjectID.h>
357 * @param objectsPackage The objects package ("PriorKnowledgeData" by default)
358 * @see <RobotAPI/libraries/ArmarXObjects/ObjectFinder.h>
359 */
361 const armarx::ObjectID& objectID,
362 const std::string& objectsPackage = DefaultObjectsPackage,
363 const std::string& relativeObjectsDirectory = DefaultRelativeObjectsDirectory);
365 const std::string& objectID,
366 const std::string& objectsPackage = DefaultObjectsPackage,
367 const std::string& relativeObjectsDirectory = DefaultRelativeObjectsDirectory);
368
369 Object& alpha(float alpha);
370
371 Object&
373 {
374 data_->drawStyle |= data::ModelDrawStyle::COLLISION;
375
376 return *this;
377 }
378
379 Object&
381 {
382 data_->drawStyle &= ~data::ModelDrawStyle::COLLISION;
383
384 return *this;
385 }
386
387 Object&
389 {
390 data_->drawStyle |= data::ModelDrawStyle::OVERRIDE_COLOR;
391
392 return color(c);
393 }
394
395 Object&
397 {
398 data_->drawStyle &= ~data::ModelDrawStyle::OVERRIDE_COLOR;
399
400 return *this;
401 }
402 };
403
404} // namespace armarx::viz
constexpr T c
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
IceInternal::Handle< data::ElementBox > data_
Definition ElementOps.h:315
ElementOps(std::string const &id)
Definition ElementOps.h:119
Arrow & position(float x, float y, float z)
Definition ElementOps.h:136
Polygon & orientation(Eigen::Quaternionf const &ori)
Definition ElementOps.h:152
Quaternion< float, 0 > Quaternionf
Hyperplane< float, 3 > Hyperplane3f
Definition Elements.h:34
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
double norm(const Point &a)
Definition point.hpp:102
ArrowCircle & completion(float c)
Definition Elements.h:252
ArrowCircle & width(float w)
Definition Elements.h:244
ArrowCircle & normal(Eigen::Vector3f dir)
Definition Elements.cpp:117
ElementOps(std::string const &id)
Definition ElementOps.h:119
ArrowCircle & radius(float r)
Definition Elements.h:236
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition Elements.h:219
Arrow & direction(Eigen::Vector3f dir)
Definition Elements.cpp:111
Arrow & width(float w)
Definition Elements.h:211
ElementOps(std::string const &id)
Definition ElementOps.h:119
Arrow & length(float l)
Definition Elements.h:203
Box & size(float s)
Definition Elements.h:62
Box & set(const simox::OrientedBoxBase< float > &b)
Definition Elements.cpp:79
ElementOps(std::string const &id)
Definition ElementOps.h:119
Box & size(Eigen::Vector3f const &s)
Definition Elements.h:52
Cylinder & direction(Eigen::Vector3f direction)
Definition Elements.cpp:103
Cylinder & height(float h)
Definition Elements.h:84
ElementOps(std::string const &id)
Definition ElementOps.h:119
Cylinder & radius(float r)
Definition Elements.h:76
Cylinder & fromTo(Eigen::Vector3f from, Eigen::Vector3f to)
Definition Elements.cpp:93
Cylindroid & axisLengths(const Eigen::Vector2f &axisLengths)
Definition Elements.h:113
Cylindroid & height(float height)
Definition Elements.h:105
Cylindroid & curvature(const Eigen::Vector2f &curvature)
Definition Elements.h:122
Cylindroid(const std::string &name)
Definition Elements.h:98
Ellipsoid & curvature(const Eigen::Vector3f &curvature)
Definition Elements.h:166
Ellipsoid(const std::string &name)
Definition Elements.h:148
Ellipsoid & axisLengths(const Eigen::Vector3f &axisLengths)
Definition Elements.h:156
Object & file(std::string const &filename)
Definition Elements.h:349
Object & fileByObjectFinder(const armarx::ObjectID &objectID, const std::string &objectsPackage=DefaultObjectsPackage, const std::string &relativeObjectsDirectory=DefaultRelativeObjectsDirectory)
Set the file so it could be found using armarx::ObjectFinder (also on remote machine).
Definition Elements.cpp:59
Object & useCollisionModel()
Definition Elements.h:372
ElementOps(std::string const &id)
Definition ElementOps.h:119
Object & overrideColor(Color c)
Definition Elements.h:388
Object & file(std::string const &project, std::string const &filename)
Definition Elements.h:340
static const std::string DefaultObjectsPackage
Definition Elements.h:334
Object & useFullModel()
Definition Elements.h:380
Object & useOriginalColor()
Definition Elements.h:396
static const std::string DefaultRelativeObjectsDirectory
Definition Elements.h:335
Object & alpha(float alpha)
Definition Elements.cpp:69
Polygon & lineWidth(float w)
Definition Elements.h:292
Polygon & clear()
Definition Elements.h:265
Polygon & lineColorGlasbeyLUT(std::size_t id, int alpha=255)
Definition Elements.h:286
Polygon & addPoint(Eigen::Vector3f p)
Definition Elements.h:302
Polygon & lineColor(int r, int g, int b)
Definition Elements.h:280
Polygon & circle(Eigen::Vector3f center, Eigen::Vector3f normal, float radius, std::size_t tessellation=64)
Definition Elements.cpp:171
Polygon & lineColor(Color color)
Definition Elements.h:272
Polygon & points(std::vector< Eigen::Vector3f > const &ps)
Definition Elements.cpp:135
ElementOps(std::string const &id)
Definition ElementOps.h:119
Polygon & plane(Eigen::Hyperplane3f plane, Eigen::Vector3f at, Eigen::Vector2f size)
Add points representing a plane as rectangle.
Definition Elements.cpp:149
ElementOps(std::string const &id)
Definition ElementOps.h:119
ElementOps(std::string const &id)
Definition ElementOps.h:119
Sphere & radius(float r)
Definition Elements.h:138
ElementOps(std::string const &id)
Definition ElementOps.h:119
Text & text(std::string const &t)
Definition Elements.h:188