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
35namespace 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
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)
106 .color(viz::Color::red())
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)
128 .color(viz::Color::green())
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)
152 .color(viz::Color::black());
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 {
428 viz::PointCloud pc = viz::PointCloud("points")
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
#define float
Definition 16_Level.h:22
#define ARMARX_DECOUPLED_REGISTER_COMPONENT(ComponentT)
Definition Decoupled.h:34
uint8_t index
#define M_PI
Definition MathTools.h:17
constexpr T c
An example for how to use ArViz.
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.
Default component property definition container.
Definition Component.h:70
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
DerivedT & enable(InteractionDescription const &interactionDescription)
Definition ElementOps.h:309
DerivedT & visible(bool visible)
Definition ElementOps.h:296
DerivedT & color(Color color)
Definition ElementOps.h:218
DerivedT & position(float x, float y, float z)
Definition ElementOps.h:136
DerivedT & orientation(Eigen::Quaternionf const &ori)
Definition ElementOps.h:152
DerivedT & scale(Eigen::Vector3f scale)
Definition ElementOps.h:254
Line & fromTo(Eigen::Vector3f from, Eigen::Vector3f to)
Definition Line.cpp:16
Line & lineWidth(float w)
Definition Line.cpp:8
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.
Mesh & colors(const data::Color *cs, std::size_t size)
Definition Mesh.h:69
Mesh & vertices(const Eigen::Vector3f *vs, std::size_t size)
Definition Mesh.h:34
Mesh & faces(const data::Face *fs, std::size_t size)
Definition Mesh.h:83
Path & points(std::vector< Eigen::Vector3f > const &ps)
Definition Path.cpp:28
Path & width(float w)
Definition Path.cpp:20
Path & addPoint(Eigen::Vector3f p)
Definition Path.cpp:43
PointCloud & transparency(float t)
Definition PointCloud.h:45
PointCloud & addPointUnchecked(ColoredPoint const &p)
Definition PointCloud.h:92
Robot & useFullModel()
Definition Robot.h:42
Robot & useCollisionModel()
Definition Robot.h:34
Robot & joint(std::string const &name, float value)
Definition Robot.h:66
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
Quaternion< float, 0 > Quaternionf
InteractionDescription interaction()
Definition ElementOps.h:109
@ Transform
The element was transformed (translated or rotated).
Definition Interaction.h:24
@ ContextMenuChosen
A context menu entry was chosen.
Definition Interaction.h:21
const char * toString(InteractionFeedbackType type)
Definition Interaction.h:28
This file offers overloads of toIce() and fromIce() functions for STL container types.
void fillObjectsLayer(viz::Layer &layer, double timeInSeconds)
void fillInteractionLayer(viz::Layer &layer)
void fillRobotHandsLayer(viz::Layer &layer)
void fillDisAppearingLayer(viz::Layer &layer, double timeInSeconds)
void fillTestLayer(viz::Layer &layer, double timeInSeconds)
void fillManyElementsLayer(viz::Layer &layer, double timeInSeconds)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void fillPointsLayer(viz::Layer &layer, double timeInSeconds)
void fillPathsAndLinesLayer(viz::Layer &layer)
void fillColorMapsLayer(viz::Layer &layer, double timeInSeconds)
void fillExampleLayer(viz::Layer &layer, double timeInSeconds)
void fillPermanentLayer(viz::Layer &layer)
double angle(const Point &a, const Point &b, const Point &c)
Definition point.hpp:109
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
ArrowCircle & radius(float r)
Definition Elements.h:236
Arrow & direction(Eigen::Vector3f dir)
Definition Elements.cpp:111
Arrow & length(float l)
Definition Elements.h:203
Box & size(Eigen::Vector3f const &s)
Definition Elements.h:52
long revision() const
Definition Client.h:79
InteractionFeedbackRange interactions() const
Definition Client.h:85
Cylinder & direction(Eigen::Vector3f direction)
Definition Elements.cpp:103
Cylinder & height(float h)
Definition Elements.h:84
Cylinder & radius(float r)
Definition Elements.h:76
void add(ElementT const &element)
Definition Layer.h:31
Object & file(std::string const &project, std::string const &filename)
Definition Elements.h:340
Polygon & lineWidth(float w)
Definition Elements.h:292
Polygon & addPoint(Eigen::Vector3f p)
Definition Elements.h:302
Polygon & lineColor(Color color)
Definition Elements.h:272
Sphere & radius(float r)
Definition Elements.h:138
void requestInteraction(Layer const &layer)
Request interaction feedback for a particular layer.
Definition Client.h:56
void add(Layer const &layer)
Stage a layer to be committed later via client.apply(*this)
Definition Client.h:36
void reset()
Reset all staged layers and interaction requests.
Definition Client.h:66
Text & text(std::string const &t)
Definition Elements.h:188