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