25 #include <Eigen/Eigen>
27 #include <SimoxUtility/color/cmaps.h>
47 defs->defineOptionalProperty<std::string>(
"ArVizTopicName",
"ArVizTopic",
"Layer updates are sent over this topic.");
50 defs->optional(properties.manyLayers,
"layers.ManyElements",
51 "Show a layer with a lot of elements (used for testing, may impact performance).");
59 return "ArVizExample";
83 const bool join =
true;
97 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
98 pos.x() = 100.0f * std::sin(timeInSeconds);
103 .
size(Eigen::Vector3f(100.0f, 100.0f, 100.0f));
105 bool toggleVisibility = (
static_cast<int>(timeInSeconds) % 2 == 0);
111 const float delta = 20. * std::sin(timeInSeconds);
113 .
position(Eigen::Vector3f{0, 100, 150})
115 .axisLengths(Eigen::Vector3f{70.f + delta, 70.f - delta, 30.f}));
118 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
119 pos.y() = 100.0f * std::sin(timeInSeconds);
132 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
133 pos.z() = 100.0f * std::sin(timeInSeconds);
143 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
157 float modTime = std::fmod(timeInSeconds, 2.0 *
M_PI);
158 arrow.
length(200.0f + 100.0f * std::sin(modTime));
160 Eigen::AngleAxisf dirRot(modTime, Eigen::Vector3f::UnitZ());
161 Eigen::Vector3f direction = dirRot * Eigen::Vector3f::UnitX();
164 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
177 Eigen::Vector3f offset = {-800, 0, 500};
178 std::vector<Eigen::Vector3f> pathPoints {
183 Eigen::Vector3f additionalPoint = {-200, 200, 200};
190 .color(simox::Color::magenta()).width(10)
198 pathPoints.push_back(additionalPoint);
202 offset = offset - 300 * Eigen::Vector3f::UnitX();
204 for (
size_t i = 0; i < pathPoints.size() - 1; i += 2)
207 .fromTo(pathPoints.at(i) + offset, pathPoints.at(i+1) + offset)
208 .color(simox::Color::lime()).lineWidth(10)
217 offset = offset - 300 * Eigen::Vector3f::UnitX();
219 for (
size_t i = 0; i < pathPoints.size() - 1; ++i)
222 .fromTo(pathPoints.at(i) + offset, pathPoints.at(i+1) + offset)
230 offset = offset - 300 * Eigen::Vector3f::UnitX();
232 for (
size_t i = 0; i < pathPoints.size(); ++i)
237 if (i < pathPoints.size() - 1)
240 .fromTo(pathPoints.at(i) + offset, pathPoints.at(i+1) + offset)
246 .position(pathPoints.at(i) + offset)
256 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
258 for (
int i = 0; i < 10; ++i)
261 int randomIndex = std::rand();
265 pos.y() = i * 200.0f;
268 .file(
"armar6_rt",
"armar6_rt/robotmodel/Armar6-SH/Armar6-RightHand-v3.xml")
278 for (
int i = 0; i < 6; ++i)
280 Eigen::Vector3f pos = Eigen::Vector3f(-200.0, 200.0, 300);
283 Eigen::Vector3f normal = Eigen::Vector3f::Zero();
284 normal(i / 2) = (i % 2 == 0 ? 1.0 : -1.0);
293 float modTime = std::fmod(timeInSeconds, 2.0 *
M_PI);
299 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
308 float t = 1.0f + std::sin(timeInSeconds);
309 float offset = 50.0f * t;
310 poly.
addPoint(Eigen::Vector3f{-200.0f - offset, -200.0f - offset, 0.0f});
311 poly.
addPoint(Eigen::Vector3f{-200.0f, +200.0f, 0.0f});
312 poly.
addPoint(Eigen::Vector3f{+200.0f + offset, +200.0f + offset, 0.0f});
313 poly.
addPoint(Eigen::Vector3f{+200.0f, -200.0f, 0.0f});
318 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
326 float t = 1.0f + std::sin(timeInSeconds);
327 float offset = 20.0f * t;
328 poly.
addPoint(Eigen::Vector3f{-100.0f - offset, -100.0f - offset, 0.0f});
329 poly.
addPoint(Eigen::Vector3f{-100.0f, +100.0f, 0.0f});
330 poly.
addPoint(Eigen::Vector3f{+100.0f + offset, +100.0f + offset, 0.0f});
331 poly.
addPoint(Eigen::Vector3f{+100.0f, -100.0f, 0.0f});
336 armarx::Vector3f vertices[] =
338 {-100.0f, -100.0f, 0.0f},
339 {-100.0f, +100.0f, 0.0f},
340 {+100.0f, +100.0f, 0.0f},
341 {+100.0f, +100.0f, 200.0f},
343 std::size_t verticesSize =
sizeof(vertices) /
sizeof(vertices[0]);
351 std::size_t colorsSize =
sizeof(colors) /
sizeof(colors[0]);
353 viz::data::Face faces[] =
364 std::size_t facesSize =
sizeof(faces) /
sizeof(faces[0]);
366 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
373 .
colors(colors, colorsSize)
374 .
faces(faces, facesSize);
379 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
384 .file(
"armar6_rt",
"armar6_rt/robotmodel/Armar6-SH/Armar6-SH.xml");
397 float value = 0.5f * (1.0f + std::sin(timeInSeconds));
409 .
position(Eigen::Vector3f(2000.0f, 0.0f, 0.0f))
410 .
size(Eigen::Vector3f(200.0f, 200.0f, 200.0f))
420 .position(Eigen::Vector3f(2000.0f, 0.0f, 400.0f))
426 for (
int x = -200; x <= 200; ++x)
429 double phase = timeInSeconds + x / 50.0;
430 double heightT =
std::max(0.0,
std::min(0.5 * (1.0 + std::sin(phase)), 1.0));
431 for (
int y = -200; y <= 200; ++y)
434 p.z = 100.0 * heightT;
436 p.color.g = 255.0 * heightT;
437 p.color.b = 255.0 * (1.0 - heightT);
438 pc.addPointUnchecked(p);
449 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
450 pos.x() = 100.0f * std::sin(timeInSeconds);
456 .
file(
"PriorKnowledgeData",
457 "PriorKnowledgeData/objects/Maintenance/bauhaus-screwbox-large/bauhaus-screwbox-large.xml");
463 Eigen::Vector3f pos = Eigen::Vector3f::Zero();
464 pos.x() = 300.0f + 100.0f * std::sin(timeInSeconds);
467 Eigen::AngleAxisf orientation(M_PI_2, Eigen::Vector3f::UnitX());
473 .
file(
"PriorKnowledgeData",
474 "PriorKnowledgeData/objects/Maintenance/cable-ties/cable-ties.wrl");
476 layer.
add(spraybottle);
477 layer.
add(
viz::Pose(
"spraybottle pose").pose(pos, orientation.toRotationMatrix()));
484 int time = int(timeInSeconds);
486 const Eigen::Vector3f at = {-400, 0, 100};
487 const Eigen::Vector3f dir = {-150, 0, 0};
490 .position(at).size(100)
491 .color(simox::Color::azure())
494 .position(at + Eigen::Vector3f(0, 0, 100))
495 .orientation(Eigen::AngleAxisf(
float(
M_PI), Eigen::Vector3f::UnitZ())
496 * Eigen::Quaternionf::FromTwoVectors(Eigen::Vector3f::UnitZ(), - Eigen::Vector3f::UnitY()))
499 .color(simox::Color::black())
505 layer.
add(
viz::Sphere(
"sphere_0_1").position(at + 1.0 * dir).radius(50)
506 .color(simox::Color::purple()));
509 layer.
add(
viz::Sphere(
"sphere_1").position(at + 2.0 * dir).radius(50)
510 .color(simox::Color::pink()));
513 layer.
add(
viz::Cylinder(
"cylinder_2").position(at + 3.0 * dir).radius(50).height(100)
514 .color(simox::Color::turquoise()));
522 const Eigen::Vector3f at = {-800, 0, 500};
523 const float size = 5;
524 const float dist = 10;
526 const double period = 10;
527 const float angle =
float(2 *
M_PI * std::fmod(timeInSeconds, period) / period);
530 float cf = 1.f / num;
531 for (
int x = 0; x < num; ++x)
533 for (
int y = 0; y < num; ++y)
535 for (
int z = 0; z < num; ++z)
537 std::stringstream ss;
538 ss <<
"box_" << x <<
"_" << y <<
"_" << z;
540 .
position(at + dist * Eigen::Vector3f(x, y, z))
541 .
orientation(Eigen::AngleAxisf(
angle, Eigen::Vector3f::UnitZ()).toRotationMatrix())
552 (void) timeInSeconds;
555 const E::Vector3f at(-500, -500, 1500);
556 const E::Quaternionf ori = E::Quaternionf::FromTwoVectors(E::Vector3f::UnitZ(), - E::Vector3f::UnitY());
557 const E::Vector2f size(200, 20);
558 const E::Vector2i num(64, 2);
563 std::string
const& name = pair.first;
564 const simox::color::ColorMap& cmap = pair.second;
566 Eigen::Vector3f shift(0, 0, - 1.5f *
index * size.y());
570 .
grid2D(size, num, [&cmap](
size_t,
size_t,
const E::Vector3f & p)
572 return viz::Color(cmap((p.x() + 100.f) / 200.f));
578 .
position(at + shift + E::Vector3f(2 + size.x() / 2, -2, 2 - size.y() / 2))
590 .
position(Eigen::Vector3f(2000.0f, 0.0f, 2000.0f))
591 .
size(Eigen::Vector3f(200.0f, 200.0f, 200.0f))
597 .contextMenu({
"First Option",
"Second Option",
"Third Option"})
599 .translation(viz::AXES_XY)
600 .scaling(viz::AXES_XYZ));
605 .
position(Eigen::Vector3f(1000.0f, 0.0f, 2000.0f))
613 .contextMenu({
"Cyl Option 1",
"Cyl Option 2"})
615 .translation(viz::AXES_YZ)
622 void ArVizExample::run()
654 stage.
add(permanentLayer);
656 bool manyElements = getProperty<bool>(
"layers.ManyElements");
661 stage.
add(manyElementsLayer);
666 stage.
add(colorMapsLayer);
670 stage.
add(interactionLayer);
674 ARMARX_INFO <<
"Permanent layers committed in revision: "
679 while (!task->isStopped())
685 exampleLayer.
clear();
687 pathsAndLinesLayer.
clear();
691 objectsLayer.
clear();
693 disAppearingLayer.
clear();
698 robotHandsLayer.
clear();
706 stage.
add({testLayer,
722 if (interactions.
size() > 0)
731 <<
"] Chosen context menu: "
736 std::string transformState;
739 transformState =
"Begin";
743 transformState =
"During";
747 transformState =
"End";
751 transformState =
"<Unknwon>";
755 <<
"] Transformation " << transformState
757 <<
"\n scale: " <<
interaction.scale().transpose();
768 c.waitForCycleDuration();