ArVizExample.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::ArVizExample
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "ArVizExample.h"
24 
25 #include <Eigen/Eigen>
26 
27 #include <SimoxUtility/color/cmaps.h>
28 
32 
34 
35 namespace armarx
36 {
37 
40  {
43 
44  // In this example, this is automatically done by deriving the component
45  // from armarx::ArVizComponentPluginUser.
46  if (false)
47  {
48  defs->defineOptionalProperty<std::string>(
49  "ArVizTopicName", "ArVizTopic", "Layer updates are sent over this topic.");
50  }
51 
52  defs->optional(
53  properties.manyLayers,
54  "layers.ManyElements",
55  "Show a layer with a lot of elements (used for testing, may impact performance).");
56 
57  return defs;
58  }
59 
60  std::string
62  {
63  return "ArVizExample";
64  }
65 
66  void
68  {
69  // In this example, this is automatically done by deriving the component
70  // from armarx::ArVizComponentPluginUser.
71  if (false)
72  {
73  offeringTopicFromProperty("ArVizTopicName");
74  }
75  }
76 
77  void
79  {
80  task = new RunningTask<ArVizExample>(this, &ArVizExample::run);
81  task->start();
82  }
83 
84  void
86  {
87  const bool join = true;
88  task->stop(join);
89  task = nullptr;
90  }
91 
92  void
94  {
95  }
96 
97  void
98  fillTestLayer(viz::Layer& layer, double timeInSeconds)
99  {
100  {
101  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
102  pos.x() = 100.0f * std::sin(timeInSeconds);
103 
104  viz::Box box = viz::Box("box")
105  .position(pos)
107  .size(Eigen::Vector3f(100.0f, 100.0f, 100.0f));
108 
109  bool toggleVisibility = (static_cast<int>(timeInSeconds) % 2 == 0);
110  box.visible(toggleVisibility);
111 
112  layer.add(box);
113  }
114  {
115  const float delta = 20. * std::sin(timeInSeconds);
116  layer.add(viz::Ellipsoid{"ellipsoid"}
117  .position(Eigen::Vector3f{0, 100, 150})
118  .color(viz::Color::blue())
119  .axisLengths(Eigen::Vector3f{70.f + delta, 70.f - delta, 30.f}));
120  }
121  {
122  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
123  pos.y() = 100.0f * std::sin(timeInSeconds);
124  pos.x() = 150.0f;
125 
126  viz::Cylinder cyl = viz::Cylinder("cylinder")
127  .position(pos)
129  .radius(50.0f)
130  .height(100.0f);
131 
132  layer.add(cyl);
133  }
134 
135  {
136  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
137  pos.z() = 100.0f * std::sin(timeInSeconds);
138  pos.x() = -150.0f;
139 
140  viz::Pose pose = viz::Pose("pose").position(pos).scale(1.0f);
141 
142  layer.add(pose);
143  }
144  {
145  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
146  pos.z() = +300.0f;
147 
148  viz::Text text = viz::Text("text")
149  .text("Test Text")
150  .scale(4.0f)
151  .position(pos)
153 
154  layer.add(text);
155  }
156  {
157  viz::Arrow arrow = viz::Arrow("arrow");
158 
159  float modTime = std::fmod(timeInSeconds, 2.0 * M_PI);
160  arrow.length(200.0f + 100.0f * std::sin(modTime));
161 
162  Eigen::AngleAxisf dirRot(modTime, Eigen::Vector3f::UnitZ());
163  Eigen::Vector3f direction = dirRot * Eigen::Vector3f::UnitX();
164  arrow.direction(direction);
165 
166  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
167  pos.z() = +300.0f;
168  pos.x() = -500.0f;
169  arrow.position(pos);
170  arrow.color(viz::Color::blue());
171 
172  layer.add(arrow);
173  }
174  }
175 
176  void
178  {
179  Eigen::Vector3f offset = {-800, 0, 500};
180  std::vector<Eigen::Vector3f> pathPoints{
181  {0, 0, 0},
182  {-200, 0, 0},
183  {-200, 200, 0},
184  };
185  Eigen::Vector3f additionalPoint = {-200, 200, 200};
186 
187  // Path: Connected sequence of lines.
188  {
189  viz::Path path = viz::Path("path")
190  .position(offset)
191  .points(pathPoints)
192  .color(simox::Color::magenta())
193  .width(10);
194 
195  path.addPoint(additionalPoint);
196 
197  layer.add(path);
198  }
199 
200  pathPoints.push_back(additionalPoint);
201 
202  // Line: Single line segments between 2 points.
203  {
204  offset = offset - 300 * Eigen::Vector3f::UnitX();
205 
206  for (size_t i = 0; i < pathPoints.size() - 1; i += 2)
207  {
208  viz::Line line =
209  viz::Line("line " + std::to_string(i) + " -> " + std::to_string(i + 1))
210  .fromTo(pathPoints.at(i) + offset, pathPoints.at(i + 1) + offset)
211  .color(simox::Color::lime())
212  .lineWidth(10);
213 
214  layer.add(line);
215  }
216  }
217 
218  // Line and Path are drawn in pixel space. For a more consistent 3D look, use cylinders:
219  {
220  offset = offset - 300 * Eigen::Vector3f::UnitX();
221 
222  for (size_t i = 0; i < pathPoints.size() - 1; ++i)
223  {
224  layer.add(viz::Cylinder("path cylinder " + std::to_string(i) + " -> " +
225  std::to_string(i + 1))
226  .fromTo(pathPoints.at(i) + offset, pathPoints.at(i + 1) + offset)
227  .color(simox::Color::cyan())
228  .radius(10));
229  }
230  }
231 
232  // Optional: Add spheres for an even nicer look.
233  {
234  offset = offset - 300 * Eigen::Vector3f::UnitX();
235 
236  for (size_t i = 0; i < pathPoints.size(); ++i)
237  {
238  float radius = 10;
239  simox::Color color = simox::Color::azure();
240 
241  if (i < pathPoints.size() - 1)
242  {
243  layer.add(viz::Cylinder("path cylinder with spheres " + std::to_string(i) +
244  " -> " + std::to_string(i + 1))
245  .fromTo(pathPoints.at(i) + offset, pathPoints.at(i + 1) + offset)
246  .color(color)
247  .radius(radius));
248  }
249 
250  layer.add(viz::Sphere("path sphere " + std::to_string(i))
251  .position(pathPoints.at(i) + offset)
252  .color(color)
253  .radius(radius));
254  }
255  }
256  }
257 
258  void
260  {
261  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
262 
263  for (int i = 0; i < 10; ++i)
264  {
265  // Always generate a new name, so the robot needs to be cached through the instance pool
266  int randomIndex = std::rand();
267  std::string name = "Hand_" + std::to_string(randomIndex);
268 
269  pos.x() = 1500.0f;
270  pos.y() = i * 200.0f;
271  viz::Robot robot =
272  viz::Robot(name)
273  .position(pos)
274  .file("armar6_rt", "armar6_rt/robotmodel/Armar6-SH/Armar6-RightHand-v3.xml")
275  .overrideColor(simox::Color::green(64 + i * 8));
276 
277  layer.add(robot);
278  }
279  }
280 
281  void
282  fillExampleLayer(viz::Layer& layer, double timeInSeconds)
283  {
284  for (int i = 0; i < 6; ++i)
285  {
286  Eigen::Vector3f pos = Eigen::Vector3f(-200.0, 200.0, 300);
287  pos.x() += -300 * i;
288 
289  Eigen::Vector3f normal = Eigen::Vector3f::Zero();
290  normal(i / 2) = (i % 2 == 0 ? 1.0 : -1.0);
291 
292  viz::ArrowCircle circle = viz::ArrowCircle("circle " + std::to_string(i))
293  .position(pos)
294  .radius(100.0f)
295  .normal(normal)
296  .width(10.0f)
297  .color(viz::Color::fromRGBA(255, 0, 255));
298 
299  float modTime = std::fmod(timeInSeconds, 2.0 * M_PI);
300  circle.completion(std::sin(modTime));
301 
302  layer.add(circle);
303  }
304  {
305  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
306  pos.z() = +1000.0f;
307 
308  viz::Polygon poly = viz::Polygon("poly")
309  .position(pos)
310  .color(viz::Color::fromRGBA(0, 128, 255, 128))
311  .lineColor(viz::Color::fromRGBA(0, 0, 255))
312  .lineWidth(1.0f);
313 
314  float t = 1.0f + std::sin(timeInSeconds);
315  float offset = 50.0f * t;
316  poly.addPoint(Eigen::Vector3f{-200.0f - offset, -200.0f - offset, 0.0f});
317  poly.addPoint(Eigen::Vector3f{-200.0f, +200.0f, 0.0f});
318  poly.addPoint(Eigen::Vector3f{+200.0f + offset, +200.0f + offset, 0.0f});
319  poly.addPoint(Eigen::Vector3f{+200.0f, -200.0f, 0.0f});
320 
321  layer.add(poly);
322  }
323  {
324  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
325  pos.z() = +1500.0f;
326 
327  viz::Polygon poly = viz::Polygon("poly2")
328  .position(pos)
329  .color(viz::Color::fromRGBA(255, 128, 0, 128))
330  .lineWidth(0.0f);
331 
332  float t = 1.0f + std::sin(timeInSeconds);
333  float offset = 20.0f * t;
334  poly.addPoint(Eigen::Vector3f{-100.0f - offset, -100.0f - offset, 0.0f});
335  poly.addPoint(Eigen::Vector3f{-100.0f, +100.0f, 0.0f});
336  poly.addPoint(Eigen::Vector3f{+100.0f + offset, +100.0f + offset, 0.0f});
337  poly.addPoint(Eigen::Vector3f{+100.0f, -100.0f, 0.0f});
338 
339  layer.add(poly);
340  }
341  {
342  armarx::Vector3f vertices[] = {
343  {-100.0f, -100.0f, 0.0f},
344  {-100.0f, +100.0f, 0.0f},
345  {+100.0f, +100.0f, 0.0f},
346  {+100.0f, +100.0f, 200.0f},
347  };
348  std::size_t verticesSize = sizeof(vertices) / sizeof(vertices[0]);
349 
350  armarx::viz::data::Color colors[] = {
351  {255, 255, 0, 0},
352  {255, 0, 255, 0},
353  {255, 0, 0, 255},
354  };
355  std::size_t colorsSize = sizeof(colors) / sizeof(colors[0]);
356 
357  viz::data::Face faces[] = {
358  {
359  0,
360  1,
361  2,
362  0,
363  1,
364  2,
365  },
366  {
367  1,
368  2,
369  3,
370  0,
371  1,
372  2,
373  },
374  };
375  std::size_t facesSize = sizeof(faces) / sizeof(faces[0]);
376 
377  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
378  pos.z() = +1000.0f;
379  pos.x() = -500.0f;
380 
381  viz::Mesh mesh = viz::Mesh("mesh")
382  .position(pos)
383  .vertices(vertices, verticesSize)
384  .colors(colors, colorsSize)
385  .faces(faces, facesSize);
386 
387  layer.add(mesh);
388  }
389  {
390  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
391  pos.x() = 500.0f;
392 
393  viz::Robot robot = viz::Robot("robot").position(pos).file(
394  "armar6_rt", "armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml");
395 
396  // Full model
397  if (true)
398  {
399  robot.useFullModel();
400  }
401  else
402  {
403  robot.useCollisionModel().overrideColor(viz::Color::fromRGBA(0, 255, 128, 128));
404  }
405 
406  float value = 0.5f * (1.0f + std::sin(timeInSeconds));
407  robot.joint("ArmR2_Sho1", value);
408  robot.joint("ArmR3_Sho2", value);
409 
410  layer.add(robot);
411  }
412  }
413 
414  void
416  {
417  viz::Box box = viz::Box("permBox")
418  .position(Eigen::Vector3f(2000.0f, 0.0f, 0.0f))
419  .size(Eigen::Vector3f(200.0f, 200.0f, 200.0f))
420  .color(viz::Color::fromRGBA(255, 165, 0));
421 
422  layer.add(box);
423  }
424 
425  void
426  fillPointsLayer(viz::Layer& layer, double timeInSeconds)
427  {
429  .position(Eigen::Vector3f(2000.0f, 0.0f, 400.0f))
430  .transparency(0.0f);
431  pc.enable(viz::interaction().selection());
432 
433  viz::ColoredPoint p;
434  p.color = viz::Color::fromRGBA(255, 255, 0, 255);
435  for (int x = -200; x <= 200; ++x)
436  {
437  p.x = 2.0f * x;
438  double phase = timeInSeconds + x / 50.0;
439  double heightT = std::max(0.0, std::min(0.5 * (1.0 + std::sin(phase)), 1.0));
440  for (int y = -200; y <= 200; ++y)
441  {
442  p.y = 2.0f * y;
443  p.z = 100.0 * heightT;
444 
445  p.color.g = 255.0 * heightT;
446  p.color.b = 255.0 * (1.0 - heightT);
447  pc.addPointUnchecked(p);
448  }
449  }
450 
451  layer.add(pc);
452  }
453 
454  void
455  fillObjectsLayer(viz::Layer& layer, double timeInSeconds)
456  {
457  {
458  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
459  pos.x() = 100.0f * std::sin(timeInSeconds);
460  pos.y() = 1000.0f;
461 
462  viz::Object sponge = viz::Object("screwbox")
463  .position(pos)
464  .file("PriorKnowledgeData",
465  "PriorKnowledgeData/objects/Maintenance/"
466  "bauhaus-screwbox-large/bauhaus-screwbox-large.xml");
467 
468  layer.add(sponge);
469  layer.add(viz::Pose("screwbox pose").position(pos));
470  }
471  {
472  Eigen::Vector3f pos = Eigen::Vector3f::Zero();
473  pos.x() = 300.0f + 100.0f * std::sin(timeInSeconds);
474  pos.y() = 1000.0f;
475 
476  Eigen::AngleAxisf orientation(M_PI_2, Eigen::Vector3f::UnitX());
477 
478  viz::Object spraybottle =
479  viz::Object("spraybottle")
480  .position(pos)
481  .orientation(Eigen::Quaternionf(orientation))
482  .file("PriorKnowledgeData",
483  "PriorKnowledgeData/objects/Maintenance/cable-ties/cable-ties.wrl");
484 
485  layer.add(spraybottle);
486  layer.add(viz::Pose("spraybottle pose").pose(pos, orientation.toRotationMatrix()));
487  }
488  }
489 
490  void
491  fillDisAppearingLayer(viz::Layer& layer, double timeInSeconds)
492  {
493  int time = int(timeInSeconds);
494 
495  const Eigen::Vector3f at = {-400, 0, 100};
496  const Eigen::Vector3f dir = {-150, 0, 0};
497 
498  layer.add(viz::Box("box_always").position(at).size(100).color(simox::Color::azure()));
499  layer.add(viz::Text("text_seconds")
500  .position(at + Eigen::Vector3f(0, 0, 100))
501  .orientation(Eigen::AngleAxisf(float(M_PI), Eigen::Vector3f::UnitZ()) *
502  Eigen::Quaternionf::FromTwoVectors(Eigen::Vector3f::UnitZ(),
503  -Eigen::Vector3f::UnitY()))
504  .text(std::to_string(time % 3))
505  .scale(5)
506  .color(simox::Color::black()));
507 
508  switch (time % 3)
509  {
510  case 0:
511  layer.add(viz::Sphere("sphere_0_1")
512  .position(at + 1.0 * dir)
513  .radius(50)
514  .color(simox::Color::purple()));
515  // fallthrough
516  case 1:
517  layer.add(viz::Sphere("sphere_1")
518  .position(at + 2.0 * dir)
519  .radius(50)
520  .color(simox::Color::pink()));
521  break;
522  case 2:
523  layer.add(viz::Cylinder("cylinder_2")
524  .position(at + 3.0 * dir)
525  .radius(50)
526  .height(100)
527  .color(simox::Color::turquoise()));
528  break;
529  }
530  }
531 
532  void
533  fillManyElementsLayer(viz::Layer& layer, double timeInSeconds)
534  {
535  const Eigen::Vector3f at = {-800, 0, 500};
536  const float size = 5;
537  const float dist = 10;
538 
539  const double period = 10;
540  const float angle = float(2 * M_PI * std::fmod(timeInSeconds, period) / period);
541 
542  const int num = 10;
543  float cf = 1.f / num; // Color factor
544  for (int x = 0; x < num; ++x)
545  {
546  for (int y = 0; y < num; ++y)
547  {
548  for (int z = 0; z < num; ++z)
549  {
550  std::stringstream ss;
551  ss << "box_" << x << "_" << y << "_" << z;
552  layer.add(viz::Box(ss.str())
553  .position(at + dist * Eigen::Vector3f(x, y, z))
554  .orientation(Eigen::AngleAxisf(angle, Eigen::Vector3f::UnitZ())
555  .toRotationMatrix())
556  .size(size)
557  .color(simox::Color(cf * x, cf * y, cf * z)));
558  }
559  }
560  }
561  }
562 
563  void
564  fillColorMapsLayer(viz::Layer& layer, double timeInSeconds)
565  {
566  (void)timeInSeconds;
567  namespace E = Eigen;
568 
569  const E::Vector3f at(-500, -500, 1500);
570  const E::Quaternionf ori =
571  E::Quaternionf::FromTwoVectors(E::Vector3f::UnitZ(), -E::Vector3f::UnitY());
572  const E::Vector2f size(200, 20);
573  const E::Vector2i num(64, 2);
574 
575  int index = 0;
576  for (const auto& pair : simox::color::cmaps::Named::all())
577  {
578  std::string const& name = pair.first;
579  const simox::color::ColorMap& cmap = pair.second;
580 
581  Eigen::Vector3f shift(0, 0, -1.5f * index * size.y());
582  viz::Mesh mesh = viz::Mesh(name + "_mesh")
583  .position(at + shift)
584  .orientation(ori)
585  .grid2D(size,
586  num,
587  [&cmap](size_t, size_t, const E::Vector3f& p)
588  { return viz::Color(cmap((p.x() + 100.f) / 200.f)); });
589 
590  layer.add(mesh);
591 
592  layer.add(
593  viz::Text(name + "_text")
594  .text(name)
595  .position(at + shift + E::Vector3f(2 + size.x() / 2, -2, 2 - size.y() / 2))
596  .orientation(ori)
597  .scale(1.5)
598  .color(simox::Color::black()));
599 
600  index++;
601  }
602  }
603 
604  void
606  {
607  // Make box selectable
608  viz::Box box = viz::Box("box")
609  .position(Eigen::Vector3f(2000.0f, 0.0f, 2000.0f))
610  .size(Eigen::Vector3f(200.0f, 200.0f, 200.0f))
611  .color(viz::Color::fromRGBA(0, 165, 255))
612  .scale(2.0f);
613  // Enable some interaction possibilities
615  .selection()
616  .contextMenu({"First Option", "Second Option", "Third Option"})
617  .rotation()
618  .translation(viz::AXES_XY)
619  .scaling(viz::AXES_XYZ));
620 
621  layer.add(box);
622 
623  viz::Cylinder cyl = viz::Cylinder("cylinder")
624  .position(Eigen::Vector3f(1000.0f, 0.0f, 2000.0f))
625  .direction(Eigen::Vector3f::UnitZ())
626  .height(200.0f)
627  .radius(50.0f)
628  .color(viz::Color::fromRGBA(255, 165, 0));
629  // Enable some interaction possibilities
631  .selection()
632  .contextMenu({"Cyl Option 1", "Cyl Option 2"})
633  .rotation()
634  .translation(viz::AXES_YZ)
635  .scaling());
636 
637  layer.add(cyl);
638  }
639 
640  void
641  ArVizExample::run()
642  {
643  // This example uses the member `arviz` provided by armarx::ArVizComponentPluginUser.
644  {
645  // Alternatively, you can instantiate a new client in a component like this: */
646  viz::Client arviz(*this);
647  // The plugin also offers a helper function if you need to create new clients:
649  }
650 
651  /*
652  * General Usage Scheme:
653  * 1. Create a layer (using the client).
654  * 2. Create elements and add them to the layer.
655  * 3. Commit layers (using the client). This is the only network call.
656  */
657 
658  viz::Layer testLayer = arviz.layer("Test");
659  viz::Layer exampleLayer = arviz.layer("Example");
660  viz::Layer pathsAndLinesLayer = arviz.layer("Paths and Lines");
661  viz::Layer pointsLayer = arviz.layer("Points");
662  viz::Layer objectsLayer = arviz.layer("Objects");
663  viz::Layer disAppearingLayer = arviz.layer("DisAppearing");
664  viz::Layer robotHandsLayer = arviz.layer("RobotHands");
665  viz::Layer interactionLayer = arviz.layer("Interaction");
666 
667  viz::StagedCommit stage = arviz.stage();
668 
669  // These layers are not updated in the loop.
670  {
671  viz::Layer permanentLayer = arviz.layer("Permanent");
672  fillPermanentLayer(permanentLayer);
673  stage.add(permanentLayer);
674  }
675  bool manyElements = getProperty<bool>("layers.ManyElements");
676  if (manyElements)
677  {
678  viz::Layer manyElementsLayer = arviz.layer("ManyElements");
679  fillManyElementsLayer(manyElementsLayer, 0);
680  stage.add(manyElementsLayer);
681  }
682  {
683  viz::Layer colorMapsLayer = arviz.layer("ColorMaps");
684  fillColorMapsLayer(colorMapsLayer, 0);
685  stage.add(colorMapsLayer);
686  }
687 
688  fillInteractionLayer(interactionLayer);
689  stage.add(interactionLayer);
690 
691  // Apply the staged commits in a single network call
692  viz::CommitResult result = arviz.commit(stage);
693  ARMARX_INFO << "Permanent layers committed in revision: " << result.revision();
694 
695 
696  CycleUtil c(25);
697  while (!task->isStopped())
698  {
699  double timeInSeconds = TimeUtil::GetTime().toSecondsDouble();
700 
701  testLayer.clear();
702  fillTestLayer(testLayer, timeInSeconds);
703  exampleLayer.clear();
704  fillExampleLayer(exampleLayer, timeInSeconds);
705  pathsAndLinesLayer.clear();
706  fillPathsAndLinesLayer(pathsAndLinesLayer);
707  pointsLayer.clear();
708  fillPointsLayer(pointsLayer, timeInSeconds);
709  objectsLayer.clear();
710  fillObjectsLayer(objectsLayer, timeInSeconds);
711  disAppearingLayer.clear();
712  fillDisAppearingLayer(disAppearingLayer, timeInSeconds);
713 
714  if (manyElements)
715  {
716  robotHandsLayer.clear();
717  fillRobotHandsLayer(robotHandsLayer);
718  }
719 
720  // We can reuse a staged commit
721  stage.reset();
722  // We can stage multiple layers at once.
723  // This is equivalent to calling add(layer) multiple times.
724  stage.add({testLayer,
725  exampleLayer,
726  pathsAndLinesLayer,
727  pointsLayer,
728  objectsLayer,
729  disAppearingLayer,
730  robotHandsLayer});
731  // We can request interaction feedback for specific layers
732  stage.requestInteraction(interactionLayer);
733 
734  // This sends the layer updates and receives interaction feedback in a single network call
735  result = arviz.commit(stage);
736  // Be careful: The interactions are stored in the CommitResult
737  // So the range is only valid as long as result is in scope and not overriden.
738  viz::InteractionFeedbackRange interactions = result.interactions();
739  if (interactions.size() > 0)
740  {
741  ARMARX_INFO << "We got some interactions: " << interactions.size();
742  for (viz::InteractionFeedback const& interaction : interactions)
743  {
745  {
747  << "[" << interaction.layer() << "/" << interaction.element()
748  << "] Chosen context menu: " << interaction.chosenContextMenuEntry();
749  }
751  {
752  std::string transformState;
753  if (interaction.isTransformBegin())
754  {
755  transformState = "Begin";
756  }
757  else if (interaction.isTransformDuring())
758  {
759  transformState = "During";
760  }
761  else if (interaction.isTransformEnd())
762  {
763  transformState = "End";
764  }
765  else
766  {
767  transformState = "<Unknwon>";
768  }
769  ARMARX_INFO << "[" << interaction.layer() << "/" << interaction.element()
770  << "] Transformation " << transformState << ": \n"
771  << interaction.transformation()
772  << "\n scale: " << interaction.scale().transpose();
773  }
774  else
775  {
776  ARMARX_INFO << "[" << interaction.layer() << "/" << interaction.element()
777  << "] " << toString(interaction.type());
778  }
779  }
780  }
781 
782  c.waitForCycleDuration();
783  }
784  }
785 
787 
788 } // namespace armarx
armarx::viz::Color::black
static Color black(int a=255)
Definition: Color.h:68
Client.h
armarx::fillRobotHandsLayer
void fillRobotHandsLayer(viz::Layer &layer)
Definition: ArVizExample.cpp:259
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
armarx::viz::StagedCommit::add
void add(Layer const &layer)
Stage a layer to be committed later via client.apply(*this)
Definition: Client.h:37
armarx::viz::ArrowCircle::radius
ArrowCircle & radius(float r)
Definition: Elements.h:236
Eigen
Definition: Elements.h:32
armarx::viz::InteractionFeedbackType::ContextMenuChosen
@ ContextMenuChosen
A context menu entry was chosen.
armarx::viz::Arrow::length
Arrow & length(float l)
Definition: Elements.h:203
armarx::viz::Client::stage
StagedCommit stage()
Definition: Client.h:145
armarx::viz::Cylinder::radius
Cylinder & radius(float r)
Definition: Elements.h:76
armarx::viz::CommitResult::revision
long revision() const
Definition: Client.h:80
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::viz::interaction
InteractionDescription interaction()
Definition: ElementOps.h:109
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::viz::Layer::clear
void clear()
Definition: Layer.h:24
armarx::fillColorMapsLayer
void fillColorMapsLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:564
armarx::viz::Object::file
Object & file(std::string const &project, std::string const &filename)
Definition: Elements.h:340
armarx::viz::Path::addPoint
Path & addPoint(Eigen::Vector3f p)
Definition: Path.cpp:43
armarx::viz::Mesh
Definition: Mesh.h:28
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::Color::blue
static Color blue(int b=255, int a=255)
Definition: Color.h:100
armarx::fillObjectsLayer
void fillObjectsLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:455
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:159
armarx::viz::Robot::joint
Robot & joint(std::string const &name, float value)
Definition: Robot.h:66
armarx::fillPathsAndLinesLayer
void fillPathsAndLinesLayer(viz::Layer &layer)
Definition: ArVizExample.cpp:177
armarx::viz::Arrow
Definition: Elements.h:196
armarx::ArVizExample::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ArVizExample.cpp:39
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::viz::Cylinder::height
Cylinder & height(float h)
Definition: Elements.h:84
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::viz::StagedCommit
A staged commit prepares multiple layers to be committed.
Definition: Client.h:30
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::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::viz::Sphere
Definition: Elements.h:133
armarx::viz::Robot::useFullModel
Robot & useFullModel()
Definition: Robot.h:42
armarx::viz::ElementOps::position
DerivedT & position(float x, float y, float z)
Definition: ElementOps.h:136
armarx::viz::StagedCommit::reset
void reset()
Reset all staged layers and interaction requests.
Definition: Client.h:67
armarx::viz::Cylinder::direction
Cylinder & direction(Eigen::Vector3f direction)
Definition: Elements.cpp:103
armarx::armem::client::query_fns::all
auto all()
Definition: query_fns.h:9
armarx::ARMARX_DECOUPLED_REGISTER_COMPONENT
ARMARX_DECOUPLED_REGISTER_COMPONENT(JsonStorage)
Color
uint32_t Color
RGBA color.
Definition: color.h:8
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::viz::Mesh::faces
Mesh & faces(const data::Face *fs, std::size_t size)
Definition: Mesh.h:83
armarx::viz::ArrowCircle::width
ArrowCircle & width(float w)
Definition: Elements.h:244
armarx::viz::Object
Definition: Elements.h:332
armarx::viz::Polygon::addPoint
Polygon & addPoint(Eigen::Vector3f p)
Definition: Elements.h:302
M_PI
#define M_PI
Definition: MathTools.h:17
armarx::ArVizExample::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ArVizExample.cpp:61
armarx::wykobi::Polygon
::wykobi::polygon< float, 2 > Polygon
Definition: wykobi_types.h:30
armarx::fillPointsLayer
void fillPointsLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:426
armarx::fillManyElementsLayer
void fillManyElementsLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:533
armarx::fillExampleLayer
void fillExampleLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:282
armarx::viz::CommitResult::interactions
InteractionFeedbackRange interactions() const
Definition: Client.h:86
armarx::ArVizExample::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ArVizExample.cpp:67
armarx::armem::human::Robot
@ Robot
Definition: util.h:17
armarx::viz::InteractionFeedbackType::Transform
@ Transform
The element was transformed (translated or rotated).
armarx::viz::Cylinder
Definition: Elements.h:71
armarx::viz::Sphere::radius
Sphere & radius(float r)
Definition: Elements.h:138
armarx::viz::StagedCommit::requestInteraction
void requestInteraction(Layer const &layer)
Request interaction feedback for a particular layer.
Definition: Client.h:57
armarx::viz::Mesh::colors
Mesh & colors(const data::Color *cs, std::size_t size)
Definition: Mesh.h:69
armarx::viz::ElementOps::orientation
DerivedT & orientation(Eigen::Quaternionf const &ori)
Definition: ElementOps.h:152
armarx::viz::Arrow::direction
Arrow & direction(Eigen::Vector3f dir)
Definition: Elements.cpp:111
armarx::viz::Robot::useCollisionModel
Robot & useCollisionModel()
Definition: Robot.h:34
armarx::viz::Ellipsoid
Definition: Elements.h:146
armarx::viz::Robot::overrideColor
Robot & overrideColor(Color c)
Definition: Robot.h:50
armarx::viz::PointCloud
Definition: PointCloud.h:19
armarx::viz::Box
Definition: Elements.h:47
armarx::viz::Pose
Definition: Elements.h:178
armarx::viz::Robot
Definition: Robot.h:10
armarx::viz::InteractionFeedbackRange
Definition: Interaction.h:147
max
T max(T t1, T t2)
Definition: gdiam.h:51
Eigen::Quaternionf
Quaternion< float, 0 > Quaternionf
Definition: EigenForwardDeclarations.h:61
armarx::viz::CommitResult
Definition: Client.h:77
armarx::viz::InteractionFeedback
Definition: Interaction.h:59
armarx::viz::Polygon
Definition: Elements.h:260
armarx::viz::Color::red
static Color red(int r=255, int a=255)
Definition: Color.h:88
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::viz::Text
Definition: Elements.h:183
visionx::PointCloud
pcl::PointCloud< Point > PointCloud
Definition: RCPointCloudProvider.cpp:55
armarx::fillDisAppearingLayer
void fillDisAppearingLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:491
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
CycleUtil.h
ArVizExample.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
Decoupled.h
armarx::viz::Mesh::vertices
Mesh & vertices(const Eigen::Vector3f *vs, std::size_t size)
Definition: Mesh.h:34
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
TimeUtil.h
float
#define float
Definition: 16_Level.h:22
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:42
armarx::viz::ElementOps::scale
DerivedT & scale(Eigen::Vector3f scale)
Definition: ElementOps.h:254
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::viz::Box::size
Box & size(Eigen::Vector3f const &s)
Definition: Elements.h:52
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:218
armarx::navigation::core::Path
std::vector< Pose > Path
Definition: basic_types.h:46
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:28
armarx::viz::ArrowCircle::completion
ArrowCircle & completion(float c)
Definition: Elements.h:252
armarx::ArVizExample::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ArVizExample.cpp:85
angle
double angle(const Point &a, const Point &b, const Point &c)
Definition: point.hpp:109
armarx::fillInteractionLayer
void fillInteractionLayer(viz::Layer &layer)
Definition: ArVizExample.cpp:605
armarx::viz::InteractionFeedbackRange::size
std::size_t size() const
Definition: Interaction.h:162
pc
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics Blackwell June If you use this software you should cite the aforementioned paper in any resulting publication Please send comments or bug reports to Ruwen Roland BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE Example usage This section shows how to use the library to detect the shapes in a point cloud PointCloud pc
Definition: ReadMe.txt:68
armarx::viz::Color::green
static Color green(int g=255, int a=255)
Definition: Color.h:94
min
T min(T t1, T t2)
Definition: gdiam.h:44
armarx::viz::Path
Definition: Path.h:31
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:80
armarx::viz::Line
Definition: Line.h:29
armarx::viz::Client
Definition: Client.h:117
armarx::ArVizComponentPluginUser::createArVizClient
armarx::viz::Client createArVizClient()
Definition: ArVizComponentPlugin.cpp:79
armarx::viz::Layer
Definition: Layer.h:12
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::green
QColor green()
Definition: StyleSheets.h:72
Line
Eigen::ParametrizedLine< float, 2 > Line
Definition: LaserScannerSelfLocalisation.cpp:52
armarx::ArVizExample::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ArVizExample.cpp:78
armarx::ArVizExample::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ArVizExample.cpp:93
armarx::viz::ElementOps::enable
DerivedT & enable(InteractionDescription const &interactionDescription)
Definition: ElementOps.h:309
armarx::fillPermanentLayer
void fillPermanentLayer(viz::Layer &layer)
Definition: ArVizExample.cpp:415
armarx::viz::ElementOps::visible
DerivedT & visible(bool visible)
Definition: ElementOps.h:296
armarx::viz::Mesh::grid2D
Mesh & grid2D(Eigen::Vector2f extents, Eigen::Vector2i numPoints, std::function< viz::Color(size_t i, size_t j, const Eigen::Vector3f &p)> colorFunc)
Builds a regular 2D grid in the xy-plane.
armarx::fillTestLayer
void fillTestLayer(viz::Layer &layer, double timeInSeconds)
Definition: ArVizExample.cpp:98
armarx::viz::ArrowCircle
Definition: Elements.h:229