AffordancePipelineVisualization.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 Lesser General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * ArmarX is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * @package VisionX
18 * @author Peter Kaiser (peter dot kaiser at kit dot edu)
19 * @date 2015
20 * @copyright http://www.gnu.org/licenses/gpl.txt
21 * GNU General Public License
22 */
23
25
26#include <cmath>
27#include <fstream>
28#include <memory>
29
30#include <pcl/common/colors.h>
31#include <pcl/point_types.h>
32
33#include <SimoxUtility/algorithm/string/string_tools.h>
34#include <VirtualRobot/MathTools.h>
35
37
40
45
46// Alternate layer names in order to have safe clears,
47// even in case of overtaking TCP calls
48#define PRIMITIVE_LAYER_NAME(n) \
49 (std::string("primitivesLayer") + std::string(((n) % 2 == 0) ? "" : "_2"))
50#define PRIMITIVE_LABELS_LAYER_NAME(n) \
51 (std::string("primitiveLabelsLayer") + std::string(((n) % 2 == 0) ? "" : "_2"))
52#define PRIMITIVE_FRAMES_LAYER_NAME(n) \
53 (std::string("primitiveFramesLayer") + std::string(((n) % 2 == 0) ? "" : "_2"))
54#define PRIMITIVE_GRASP_POINTS_LAYER_NAME(n) \
55 (std::string("graspPointLayer") + std::string(((n) % 2 == 0) ? "" : "_2"))
56#define AFFORDANCES_LAYER_NAME(n) \
57 (std::string("affordancesLayer") + std::string(((n) % 2 == 0) ? "" : "_2"))
58
62
63using namespace armarx;
64
73
74void
76{
77 offeringTopic(getProperty<std::string>("DebugDrawerTopicName").getValue());
78 offeringTopic(getProperty<std::string>("VisualizationUpdateTopicName").getValue());
79 usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
80 usingTopic("ExtractedAffordances");
81 usingTopic("SegmentedPointCloud");
82
83 primitiveColor = {0.4, 0.6, 1.0, 0.7};
84 primitiveColorFrame = {0.2, 0.4, 0.8, 0.7};
85 affordanceLabelColor = {0.96, 0.82, 0.3, 1};
86
87 primitiveVisualizationEnabled = getProperty<bool>("EnablePrimitiveVisualization").getValue();
88 affordanceVisualizationEnabled = getProperty<bool>("EnableAffordanceVisualization").getValue();
89 debugVisualizationEnabled = getProperty<bool>("EnableDebugVisualization").getValue();
90
91 std::string beliefFunction =
92 getProperty<std::string>("VisualizeAffordanceBeliefFunction").getValue();
93
94 if (beliefFunction != "")
95 {
96 std::vector<std::string> primitives;
97
98 std::vector<std::string> affordances;
99 affordances.push_back(beliefFunction);
100
101 configureAffordanceVisualization(eAffordanceBeliefFunctions,
102 primitives,
103 affordances,
104 getProperty<float>("MinExpectedProbability").getValue());
105 }
106}
107
108void
110{
111
112
114 getProperty<std::string>("DebugDrawerTopicName").getValue());
116 {
117 ARMARX_ERROR << "Failed to obtain debug drawer proxy";
118 return;
119 }
120
122 getProperty<std::string>("VisualizationUpdateTopicName").getValue());
124 {
125 ARMARX_ERROR << "Failed to obtain affordance visualization topic proxy";
126 return;
127 }
128
129 usingTopic(getProperty<std::string>("DebugDrawerSelectionsTopicName").getValue());
130 offeringTopic(getProperty<std::string>("VisualizationUpdateTopicName").getValue());
131
132 std::string fileName = getProperty<std::string>("FileName").getValue();
133 if (!fileName.empty())
134 {
135 ARMARX_INFO << "Visualizing affordances from file " << VAROUT(fileName);
137 scene->load(fileName);
138 visualize();
139 ARMARX_INFO << "Done visualizing affordances.";
140 return;
141 }
142
144 getProperty<std::string>("WorkingMemoryName").getValue());
145 if (!workingMemoryPrx)
146 {
147 ARMARX_ERROR << "Failed to obtain working memory proxy";
148 return;
149 }
150
151 affordanceSegment = workingMemoryPrx->getAffordanceSegment();
153 {
154 ARMARX_ERROR << "Failed to obtain affordance segment pointer";
155 return;
156 }
157
158 environmentalPrimitiveSegment = workingMemoryPrx->getEnvironmentalPrimitiveSegment();
160 {
161 ARMARX_ERROR << "Failed to obtain environmental primitive segment pointer";
162 return;
163 }
164}
165
166void
170
171void
175
182
183void
185{
186 ARMARX_INFO << "Receiving new primitives";
187
188 if (getProperty<bool>("NoAffordanceExtractionConfigured").getValue())
189 {
190 sceneMutex.lock();
191 scene.reset(
193 sceneMutex.unlock();
194
195 visualize();
196 }
197}
198
199void
201{
202 ARMARX_INFO << "Receiving new affordances";
203
204 if (!getProperty<bool>("NoAffordanceExtractionConfigured").getValue())
205 {
206 sceneMutex.lock();
207 scene.reset(
209 sceneMutex.unlock();
210
211 visualize();
212 }
213}
214
215void
216AffordancePipelineVisualization::selectPrimitive(const std::string& id, const Ice::Current& c)
217{
218 selections.insert(id);
219
220 if (getProperty<bool>("EnableDebugDrawerSelections").getValue())
221 {
223 id);
224 }
225}
226
227void
228AffordancePipelineVisualization::deselectPrimitive(const std::string& id, const Ice::Current& c)
229{
230 selections.erase(id);
231
232 if (getProperty<bool>("EnableDebugDrawerSelections").getValue())
233 {
235 id);
236 }
237}
238
239void
241{
242 selections.clear();
243
244 if (getProperty<bool>("EnableDebugDrawerSelections").getValue())
245 {
246 debugDrawerTopicPrx->clearSelections(
248 }
249}
250
251void
253 bool enableAffordances,
254 bool enableDebugInformation,
255 const Ice::Current& c)
256{
257 ARMARX_INFO << "Visualization configuration changed: primitives="
258 << (enablePrimitives ? "enabled" : "disabled")
259 << ", affordances=" << (enableAffordances ? "enabled" : "disabled")
260 << ", debug=" << (enableDebugInformation ? "enabled" : "disabled");
261
262 bool updatePrimitives = (primitiveVisualizationEnabled != enablePrimitives);
263 bool updateAffordances = (affordanceVisualizationEnabled != enableAffordances);
264 bool updateDebugInfo = (debugVisualizationEnabled != enableDebugInformation);
265
266 primitiveVisualizationEnabled = enablePrimitives;
267 affordanceVisualizationEnabled = enableAffordances;
268 debugVisualizationEnabled = enableDebugInformation;
269
270 visualize(updatePrimitives, updateAffordances, updateDebugInfo);
271}
272
273void
275 AffordanceVisualizationStyle style,
276 const std::vector<std::string>& primitives,
277 const std::vector<std::string>& affordances,
278 float minExpectedProbability,
279 const Ice::Current& c)
280{
281 visualizationStyle = style;
282 visualizationPrimitiveSet = primitives;
283 visualizationAffordanceSet = affordances;
284 visualizationMinExpectedProbability = minExpectedProbability;
285
286 visualize(true, true, false);
287}
288
289void
294
295void
297 bool updatePrimitives,
298 bool updateAffordances,
299 bool updateDebugInfo)
300{
301 if (primitiveVisualizationEnabled && updatePrimitives)
302 {
303 visualizePrimitives(scene->getPrimitives());
304 }
305
306 if (affordanceVisualizationEnabled && updateAffordances)
307 {
309 }
310
311 if (debugVisualizationEnabled && updateDebugInfo)
312 {
314 }
315}
316
317void
319 const AffordanceKit::PrimitiveSetPtr& primitives)
320{
321 for (auto& primitive : *primitives)
322 {
323 visualizePrimitive(primitive);
324 }
325}
326
327void
328AffordancePipelineVisualization::visualizePrimitive(const AffordanceKit::PrimitivePtr& primitive)
329{
330 if (auto plane = std::dynamic_pointer_cast<AffordanceKit::Plane>(primitive))
331 {
332 visualizePlane(plane);
333 }
334 else if (auto cyl = std::dynamic_pointer_cast<AffordanceKit::Cylinder>(primitive))
335 {
337 }
338 else if (auto sphere = std::dynamic_pointer_cast<AffordanceKit::Sphere>(primitive))
339 {
340 visualizeSphere(sphere);
341 }
342 else if (auto box = std::dynamic_pointer_cast<AffordanceKit::Box>(primitive))
343 {
344 visualizeBox(box);
345 }
346 else
347 {
348 ARMARX_WARNING << "Attempt to visualize primitive of unknown type";
349 return;
350 }
351}
352
353void
355{
356 AffordanceKit::PrimitiveSetPtr primitives = scene->getPrimitives();
357 const std::vector<AffordanceKit::AffordancePtr>& affordances = scene->getAffordances();
358
359 for (auto& primitive : *primitives)
360 {
361 if (visualizationPrimitiveSet.size() > 0 &&
362 std::find(visualizationPrimitiveSet.begin(),
364 primitive->getId()) == visualizationPrimitiveSet.end())
365 {
366 // This primitive is not configured to be visualized
367 continue;
368 }
369
370 std::vector<std::string> labels;
371
372 int i = 0;
373 for (auto& affordance : affordances)
374 {
375 if (visualizationAffordanceSet.size() > 0 &&
376 std::find(visualizationAffordanceSet.begin(),
378 affordance->getName()) == visualizationAffordanceSet.end())
379 {
380 // This affordance is not configured to be visualized
381 continue;
382 }
383
384 if (visualizationStyle == AffordanceVisualizationStyle::eAffordanceLabels &&
385 affordance->existsForPrimitive(primitive))
386 {
387 labels.push_back(affordance->getName());
388 }
389 else if (visualizationStyle == AffordanceVisualizationStyle::eAffordanceBeliefFunctions)
390 {
391 visualizeAffordance(affordance, primitive, i++);
392 }
393 }
394
395 if (visualizationStyle == AffordanceVisualizationStyle::eAffordanceLabels)
396 {
397 visualizeAffordanceLabels(primitive, labels);
398 }
399 }
400}
401
402void
403AffordancePipelineVisualization::visualizeAffordance(const AffordanceKit::AffordancePtr& affordance,
404 const AffordanceKit::PrimitivePtr& primitive,
405 unsigned int index)
406{
407 std::string id = "affordance_" + affordance->getName() + "_" + std::to_string(index) + "_" +
408 primitive->getId();
409
410 if (affordance->getTimestamp() != primitive->getTimestamp())
411 {
412 IceUtil::Time affordanceTimestamp = IceUtil::Time::microSeconds(affordance->getTimestamp());
413 IceUtil::Time primitiveTimestamp = IceUtil::Time::microSeconds(primitive->getTimestamp());
414
415 std::string t1 =
416 affordanceTimestamp.toDateTime().substr(affordanceTimestamp.toDateTime().find(' ') + 1);
417 std::string t2 =
418 primitiveTimestamp.toDateTime().substr(primitiveTimestamp.toDateTime().find(' ') + 1);
419
420 ARMARX_WARNING << "Timestamp of visualized affordance does not match the primitive "
421 "timestamp (Affordance: "
422 << t1 << ", Primitive: " << t2 << ")";
423 }
424
425 if (visualizationStyle == AffordanceVisualizationStyle::eAffordanceBeliefFunctions)
426 {
427 if (auto unimanualA =
428 std::dynamic_pointer_cast<AffordanceKit::UnimanualAffordance>(affordance))
429 {
431 a.visualize(debugDrawerTopicPrx,
433 id,
435 primitive);
436 }
437 else if (auto bimanualA =
438 std::dynamic_pointer_cast<AffordanceKit::BimanualAffordance>(affordance))
439 {
441 a.visualize(debugDrawerTopicPrx,
443 id,
445 primitive);
446 }
447 }
448 else
449 {
450 ARMARX_WARNING << "Unknown affordance visualization style";
451 }
452}
453
454void
456 const AffordanceKit::PrimitivePtr& primitive,
457 const std::vector<std::string>& labels)
458{
459 std::string label;
460
461 for (unsigned int i = 0; i < labels.size(); i++)
462 {
463 label += labels[i] + ((i == labels.size() - 1) ? "" : ", ");
464 }
465
466 Eigen::Vector3f c = primitive->getCenter();
467 debugDrawerTopicPrx->setTextVisu(
469 primitive->getId() + "_labels",
470 label,
471 new Vector3(c),
474}
475
476void
480
481void
482AffordancePipelineVisualization::visualizePlane(const AffordanceKit::PlanePtr& plane)
483{
484 const std::vector<Eigen::Vector3f>& hull = plane->getConvexHull();
485
486 std::vector<Vector3BasePtr> polygon;
487 for (auto x : hull)
488 {
489 polygon.push_back(Vector3Ptr(new Vector3(x)));
490 }
491
492 debugDrawerTopicPrx->setPolygonVisu(
494 plane->getId(),
495 polygon,
498 2);
499}
500
501void
502AffordancePipelineVisualization::visualizeSphere(const AffordanceKit::SpherePtr& sphere)
503{
504 Vector3Ptr center(new Vector3(sphere->getCenter()));
506 sphere->getId(),
507 center,
509 sphere->getRadius());
510}
511
512void
513AffordancePipelineVisualization::visualizeCylinder(const AffordanceKit::CylinderPtr& cylinder)
514{
515 float radius = cylinder->getRadius();
516 float length = cylinder->getLength();
517 Vector3Ptr point(new Vector3(cylinder->getBasePoint()));
518 Vector3Ptr direction(new Vector3(cylinder->getDirection()));
519
520 debugDrawerTopicPrx->setCylinderVisu(
522 cylinder->getId(),
523 point,
524 direction,
525 length,
526 radius,
528}
529
530void
531AffordancePipelineVisualization::visualizeBox(const AffordanceKit::BoxPtr& box)
532{
533 //debugDrawerTopicPrx->setBoxVisu(PRIMITIVE_LAYER_NAME(alternatingPrimitiveVisualizationIndex), box->getId(), new Pose(box->getPose()), new Vector3(box->getDimensions()), primitiveColor);
534
535 Eigen::Matrix4f pose = box->getPose();
536 Eigen::Vector3f dim = box->getDimensions();
537
538 std::vector<std::vector<Eigen::Vector3f>> sides;
539 sides.resize(6);
540
541 sides[0].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
542 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
543 (dim.z() / 2) * pose.block<3, 1>(0, 2));
544 sides[0].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
545 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
546 (dim.z() / 2) * pose.block<3, 1>(0, 2));
547 sides[0].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
548 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
549 (dim.z() / 2) * pose.block<3, 1>(0, 2));
550 sides[0].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
551 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
552 (dim.z() / 2) * pose.block<3, 1>(0, 2));
553
554 sides[1].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
555 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
556 (dim.z() / 2) * pose.block<3, 1>(0, 2));
557 sides[1].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
558 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
559 (dim.z() / 2) * pose.block<3, 1>(0, 2));
560 sides[1].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
561 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
562 (dim.z() / 2) * pose.block<3, 1>(0, 2));
563 sides[1].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
564 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
565 (dim.z() / 2) * pose.block<3, 1>(0, 2));
566
567 sides[2].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
568 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
569 (dim.z() / 2) * pose.block<3, 1>(0, 2));
570 sides[2].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
571 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
572 (dim.z() / 2) * pose.block<3, 1>(0, 2));
573 sides[2].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
574 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
575 (dim.z() / 2) * pose.block<3, 1>(0, 2));
576 sides[2].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
577 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
578 (dim.z() / 2) * pose.block<3, 1>(0, 2));
579
580 sides[3].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
581 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
582 (dim.z() / 2) * pose.block<3, 1>(0, 2));
583 sides[3].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
584 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
585 (dim.z() / 2) * pose.block<3, 1>(0, 2));
586 sides[3].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
587 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
588 (dim.z() / 2) * pose.block<3, 1>(0, 2));
589 sides[3].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
590 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
591 (dim.z() / 2) * pose.block<3, 1>(0, 2));
592
593 sides[4].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
594 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
595 (dim.z() / 2) * pose.block<3, 1>(0, 2));
596 sides[4].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
597 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
598 (dim.z() / 2) * pose.block<3, 1>(0, 2));
599 sides[4].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
600 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
601 (dim.z() / 2) * pose.block<3, 1>(0, 2));
602 sides[4].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
603 (dim.y() / 2) * pose.block<3, 1>(0, 1) +
604 (dim.z() / 2) * pose.block<3, 1>(0, 2));
605
606 sides[5].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) +
607 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
608 (dim.z() / 2) * pose.block<3, 1>(0, 2));
609 sides[5].push_back(pose.block<3, 1>(0, 3) + (dim.x() / 2) * pose.block<3, 1>(0, 0) -
610 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
611 (dim.z() / 2) * pose.block<3, 1>(0, 2));
612 sides[5].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) -
613 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
614 (dim.z() / 2) * pose.block<3, 1>(0, 2));
615 sides[5].push_back(pose.block<3, 1>(0, 3) - (dim.x() / 2) * pose.block<3, 1>(0, 0) +
616 (dim.y() / 2) * pose.block<3, 1>(0, 1) -
617 (dim.z() / 2) * pose.block<3, 1>(0, 2));
618
619 for (unsigned int i = 0; i < sides.size(); i++)
620 {
621 debugDrawerTopicPrx->setLineVisu(
623 box->getId() + "_side" + std::to_string(i) + "_line_1",
624 new Vector3(sides[i][0]),
625 new Vector3(sides[i][1]),
626 3,
628 debugDrawerTopicPrx->setLineVisu(
630 box->getId() + "_side" + std::to_string(i) + "_line_2",
631 new Vector3(sides[i][1]),
632 new Vector3(sides[i][2]),
633 3,
635 debugDrawerTopicPrx->setLineVisu(
637 box->getId() + "_side" + std::to_string(i) + "_line_3",
638 new Vector3(sides[i][2]),
639 new Vector3(sides[i][3]),
640 3,
642 debugDrawerTopicPrx->setLineVisu(
644 box->getId() + "_side" + std::to_string(i) + "_line_4",
645 new Vector3(sides[i][3]),
646 new Vector3(sides[i][0]),
647 3,
649 }
650}
651
652void
654 bool updateAffordances,
655 bool updateDebugInfo)
656{
657 sceneMutex.lock();
658
659 if (!scene)
660 {
661 sceneMutex.unlock();
662 return;
663 }
664
665 ARMARX_INFO << "Current scene contains: " << scene->getPrimitives()->size() << " primitives";
666 ARMARX_INFO << "Current scene contains: " << scene->getUnimanualAffordances().size()
667 << " unimanual affordances";
668 ARMARX_INFO << "Current scene contains: " << scene->getBimanualAffordances().size()
669 << " bimanual affordances";
670 ARMARX_INFO << "Current scene contains: " << scene->getAffordances().size()
671 << " affordances in total";
672
673 if (updatePrimitives)
674 {
675 ARMARX_INFO << "Visualizing primitives";
676
678 debugDrawerTopicPrx->clearLayer(
680 }
681
682 if (updateAffordances)
683 {
684 ARMARX_INFO << "Visualizing affordances";
685
687 debugDrawerTopicPrx->clearLayer(
689 }
690
691 if (updateDebugInfo)
692 {
693 ARMARX_INFO << "Visualizing debug information";
694
696 debugDrawerTopicPrx->clearLayer(
698 debugDrawerTopicPrx->clearLayer(
700 debugDrawerTopicPrx->clearLayer(
702 }
703
704 visualizeScene(scene, updatePrimitives, updateAffordances, updateDebugInfo);
705
706 sceneMutex.unlock();
707
708 // Update selections
709 if (getProperty<bool>("EnableDebugDrawerSelections").getValue())
710 {
711 std::set<std::string> previousSelections = selections;
712
713 debugDrawerTopicPrx->enableSelections(
715
716 debugDrawerTopicPrx->disableSelections(
718 debugDrawerTopicPrx->clearSelections(
720
721 for (auto& primitive : previousSelections)
722 {
723 ARMARX_INFO << "Selecting: " << primitive;
724 debugDrawerTopicPrx->select(
726 }
727 }
728
729 affordanceVisualizationTopicPrx->reportAffordanceVisualizationUpdate();
730}
731
732void
734 const Ice::Current& c)
735{
736 // Currently there is no way to export multiple layers at once => exKport whole scene
737 ARMARX_INFO << "Exporting scene to '" << filename << "'";
738 debugDrawerTopicPrx->exportScene(filename);
739}
740
741void
743 const Ice::Current& c)
744{
745 JSONObjectPtr serializer = new JSONObject(ElementType::eArray);
746
747 memoryx::EnvironmentalPrimitiveBaseList primitives =
748 environmentalPrimitiveSegment->getEnvironmentalPrimitives();
749
750 for (auto& primitive : primitives)
751 {
753
754 if (primitive->ice_isA(memoryx::PlanePrimitiveBase::ice_staticId()))
755 {
756 memoryx::PlanePrimitiveBasePtr::dynamicCast(primitive)->serialize(s);
757 }
758 else if (primitive->ice_isA(memoryx::SpherePrimitiveBase::ice_staticId()))
759 {
760 memoryx::SpherePrimitiveBasePtr::dynamicCast(primitive)->serialize(s);
761 }
762 else if (primitive->ice_isA(memoryx::CylinderPrimitiveBase::ice_staticId()))
763 {
764 memoryx::CylinderPrimitiveBasePtr::dynamicCast(primitive)->serialize(s);
765 }
766 else
767 {
768 ARMARX_WARNING << "Could not serialize unknown primitive type";
769 }
770
771 serializer->append(s);
772 }
773
774 std::ofstream out;
775 out.open(filename, std::ios_base::trunc);
776
777 if (out.is_open())
778 {
779 out << serializer->toString();
780 out.close();
781 ARMARX_INFO << "Scene exported as JSON to " << filename;
782 }
783 else
784 {
785 ARMARX_WARNING << "Failed to export scene as JSON to " << filename;
786 }
787}
788
789void
809
810void
812 const DebugDrawerSelectionList& selectedObjects,
813 const Ice::Current&)
814{
815 std::vector<std::string> tmpSelections;
816 selections.clear();
817
818 ARMARX_INFO << "Selections cleared";
819
820 for (auto& object : selectedObjects)
821 {
822 if (simox::alg::starts_with(object.layerName, "primitivesLayer"))
823 {
824 ARMARX_INFO << "Object " << object.elementName << " selected";
825
826 selections.insert(object.elementName);
827 tmpSelections.push_back(object.elementName);
828 }
829 }
830
831 affordanceVisualizationTopicPrx->reportPrimitiveSelectionChanged(tmpSelections);
832}
#define PRIMITIVE_LABELS_LAYER_NAME(n)
#define PRIMITIVE_FRAMES_LAYER_NAME(n)
int alternatingAffordanceVisualizationIndex
int alternatingPrimitiveVisualizationIndex
#define AFFORDANCES_LAYER_NAME(n)
#define PRIMITIVE_GRASP_POINTS_LAYER_NAME(n)
#define PRIMITIVE_LAYER_NAME(n)
int alternatingDebugInfoVisualizationIndex
uint8_t index
#define VAROUT(x)
constexpr T c
void visualize(bool updatePrimitives=true, bool updateAffordances=true, bool updateDebugInfo=true)
void visualizeBox(const AffordanceKit::BoxPtr &box)
void visualizePrimitive(const AffordanceKit::PrimitivePtr &primitive)
void visualizePrimitives(const AffordanceKit::PrimitiveSetPtr &primitives)
void deselectAllPrimitives(const Ice::Current &c=Ice::emptyCurrent) override
void visualizePlane(const AffordanceKit::PlanePtr &plane)
void triggerVisualization(const Ice::Current &c=Ice::emptyCurrent) override
void enableVisualization(bool enablePrimitives, bool enableAffordances, bool enableDebugInformation, const Ice::Current &c=Ice::emptyCurrent) override
void visualizeAffordance(const AffordanceKit::AffordancePtr &affordance, const AffordanceKit::PrimitivePtr &primitve, unsigned int index)
void reportNewPointCloudSegmentation(const Ice::Current &c=Ice::emptyCurrent) override
void visualizeScene(const AffordanceKit::ScenePtr &scene, bool updatePrimitives=true, bool updateAffordances=true, bool updateDebugInfo=true)
void configureAffordanceVisualization(AffordanceVisualizationStyle style, const std::vector< std::string > &primitives, const std::vector< std::string > &affordances, float minExpectedProbability, const Ice::Current &c=Ice::emptyCurrent) override
void visualizeCylinder(const AffordanceKit::CylinderPtr &cylinder)
void exportVisualizationAsIV(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void clearVisualization(const Ice::Current &c=Ice::emptyCurrent) override
PropertyDefinitionsPtr createPropertyDefinitions() override
void visualizeDebugInformation(const AffordanceKit::ScenePtr &scene)
void deselectPrimitive(const std::string &id, const Ice::Current &c=Ice::emptyCurrent) override
void visualizeAffordances(const AffordanceKit::ScenePtr &scene)
void visualizeSphere(const AffordanceKit::SpherePtr &sphere)
void exportVisualizationAsJSON(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void reportSelectionChanged(const DebugDrawerSelectionList &selectedObjects, const ::Ice::Current &=Ice::emptyCurrent) override
memoryx::EnvironmentalPrimitiveSegmentBasePrx environmentalPrimitiveSegment
void selectPrimitive(const std::string &id, const Ice::Current &c=Ice::emptyCurrent) override
AffordancePipelineVisualizationListenerPrx affordanceVisualizationTopicPrx
void visualizeAffordanceLabels(const AffordanceKit::PrimitivePtr &primitive, const std::vector< std::string > &labels)
void reportNewAffordances(const Ice::Current &c=Ice::emptyCurrent) override
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition JSONObject.h:44
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The Vector3 class.
Definition Pose.h:113
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34