Elements.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include "elements/Color.h"
5 #include "elements/ElementOps.h"
6 #include "elements/Line.h"
7 #include "elements/Mesh.h"
8 #include "elements/Path.h"
9 #include "elements/PointCloud.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 
32 namespace Eigen
33 {
34  using Hyperplane3f = Hyperplane<float, 3>;
35 }
36 
37 namespace armarx
38 {
39  // <RobotAPI/libraries/ArmarXObjects/ObjectID.h>
40  class ObjectID;
41 } // namespace armarx
42 
43 namespace 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 
75  Cylinder&
76  radius(float r)
77  {
78  data_->radius = r;
79 
80  return *this;
81  }
82 
83  Cylinder&
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 
104  Cylindroid&
105  height(float height)
106  {
107  data_->height = height;
108 
109  return *this;
110  }
111 
112  Cylindroid&
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 
121  Cylindroid&
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 
235  ArrowCircle&
236  radius(float r)
237  {
238  data_->radius = r;
239 
240  return *this;
241  }
242 
243  ArrowCircle&
244  width(float w)
245  {
246  data_->width = w;
247 
248  return *this;
249  }
250 
251  ArrowCircle&
252  completion(float c)
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
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:280
armarx::viz::ArrowCircle::radius
ArrowCircle & radius(float r)
Definition: Elements.h:236
Eigen
Definition: Elements.h:32
armarx::viz::Arrow::length
Arrow & length(float l)
Definition: Elements.h:203
Robot.h
armarx::viz::Cylindroid::axisLengths
Cylindroid & axisLengths(const Eigen::Vector2f &axisLengths)
Definition: Elements.h:113
armarx::viz::Polygon::points
Polygon & points(std::vector< Eigen::Vector3f > const &ps)
Definition: Elements.cpp:135
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
Path.h
armarx::viz::Object::useFullModel
Object & useFullModel()
Definition: Elements.h:380
armarx::viz::Object::useCollisionModel
Object & useCollisionModel()
Definition: Elements.h:372
armarx::viz::Cylinder::radius
Cylinder & radius(float r)
Definition: Elements.h:76
armarx::viz::Cylinder::fromTo
Cylinder & fromTo(Eigen::Vector3f from, Eigen::Vector3f to)
Definition: Elements.cpp:93
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:59
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:340
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:46
armarx::viz::Arrow
Definition: Elements.h:196
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::viz::Object::file
Object & file(std::string const &filename)
Definition: Elements.h:349
armarx::viz::Cylinder::height
Cylinder & height(float h)
Definition: Elements.h:84
armarx::viz::ArrowCircle::normal
ArrowCircle & normal(Eigen::Vector3f dir)
Definition: Elements.cpp:117
armarx::viz::Text::text
Text & text(std::string const &t)
Definition: Elements.h:188
armarx::viz::ElementOps< Box, data::ElementBox >::data_
IceInternal::Handle< data::ElementBox > data_
Definition: ElementOps.h:315
armarx::viz::Object::alpha
Object & alpha(float alpha)
Definition: Elements.cpp:69
armarx::viz::Sphere
Definition: Elements.h:133
project
std::string project
Definition: VisualizationRobot.cpp:85
armarx::viz::Object::DefaultRelativeObjectsDirectory
static const std::string DefaultRelativeObjectsDirectory
Definition: Elements.h:335
armarx::viz::Cylindroid::Cylindroid
Cylindroid(const std::string &name)
Definition: Elements.h:98
armarx::viz::ElementOps::ElementOps
ElementOps(std::string const &id)
Definition: ElementOps.h:119
armarx::viz::ElementOps< Arrow, data::ElementArrow >::position
Arrow & position(float x, float y, float z)
Definition: ElementOps.h:136
armarx::viz::ElementOps
Definition: ElementOps.h:116
armarx::viz::Cylinder::direction
Cylinder & direction(Eigen::Vector3f direction)
Definition: Elements.cpp:103
armarx::viz::Polygon::lineColorGlasbeyLUT
Polygon & lineColorGlasbeyLUT(std::size_t id, int alpha=255)
Definition: Elements.h:286
armarx::viz::ArrowCircle::width
ArrowCircle & width(float w)
Definition: Elements.h:244
armarx::viz::Object
Definition: Elements.h:332
Line.h
armarx::viz::Polygon::addPoint
Polygon & addPoint(Eigen::Vector3f p)
Definition: Elements.h:302
armarx::viz::Arrow::width
Arrow & width(float w)
Definition: Elements.h:211
Color.h
armarx::viz::Polygon::clear
Polygon & clear()
Definition: Elements.h:265
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::viz::Cylinder
Definition: Elements.h:71
Eigen::Hyperplane3f
Hyperplane< float, 3 > Hyperplane3f
Definition: Elements.h:34
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:152
armarx::viz::Arrow::direction
Arrow & direction(Eigen::Vector3f dir)
Definition: Elements.cpp:111
armarx::viz::Polygon::lineWidth
Polygon & lineWidth(float w)
Definition: Elements.h:292
armarx::viz::Color
Definition: Color.h:12
armarx::viz::Cylindroid
Definition: Elements.h:96
armarx::viz::Ellipsoid
Definition: Elements.h:146
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:149
armarx::viz::Ellipsoid::axisLengths
Ellipsoid & axisLengths(const Eigen::Vector3f &axisLengths)
Definition: Elements.h:156
armarx::viz::Box
Definition: Elements.h:47
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::viz::Pose
Definition: Elements.h:178
armarx::viz::Polygon
Definition: Elements.h:260
armarx::viz::Object::overrideColor
Object & overrideColor(Color c)
Definition: Elements.h:388
armarx::viz::Polygon::circle
Polygon & circle(Eigen::Vector3f center, Eigen::Vector3f normal, float radius, std::size_t tessellation=64)
Definition: Elements.cpp:171
armarx::viz::Text
Definition: Elements.h:183
armarx::viz::Cylindroid::height
Cylindroid & height(float height)
Definition: Elements.h:105
Mesh.h
armarx::viz::Arrow::fromTo
Arrow & fromTo(const Eigen::Vector3f &from, const Eigen::Vector3f &to)
Definition: Elements.h:219
armarx::viz::Object::useOriginalColor
Object & useOriginalColor()
Definition: Elements.h:396
armarx::Quaternion< float, 0 >
armarx::viz::Box::size
Box & size(float s)
Definition: Elements.h:62
armarx::viz::Box::size
Box & size(Eigen::Vector3f const &s)
Definition: Elements.h:52
armarx::viz::ElementOps< Polygon, data::ElementPolygon >::color
Polygon & color(Color color)
Definition: ElementOps.h:218
armarx::viz::ArrowCircle::completion
ArrowCircle & completion(float c)
Definition: Elements.h:252
armarx::viz::Ellipsoid::Ellipsoid
Ellipsoid(const std::string &name)
Definition: Elements.h:148
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:334
armarx::viz::Box::set
Box & set(const simox::OrientedBoxBase< float > &b)
Definition: Elements.cpp:79
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:418
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
PointCloud.h
armarx::viz::Polygon::lineColor
Polygon & lineColor(Color color)
Definition: Elements.h:272
norm
double norm(const Point &a)
Definition: point.hpp:102
armarx::viz::ArrowCircle
Definition: Elements.h:229