31 #include <Ice/BuiltinSequences.h>
49 #include <RobotAPI/libraries/armem_locations/aron/Location.aron.generated.h>
53 #include <armarx/navigation/core/aron/Graph.aron.generated.h>
59 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
61 #include <SemanticObjectRelations/Shapes/Shape.h>
78 def->component(proxies.priorKnowledge);
79 def->component(proxies.graphNodePoseResolver,
"GraphNodePoseResolver");
99 if (proxies.priorKnowledge->hasGraphSegment())
101 proxies.graphSegment = proxies.priorKnowledge->getGraphSegment();
131 return "graph_import_export";
139 tab.sceneComboBox.setOptions(sceneNames);
140 tab.sceneRefreshButton.setLabel(
"Refresh");
142 tab.providerSegmentLine.setValue(
getName());
144 tab.dryRun.setValue(
false);
145 tab.visuEnabled.setValue(
true);
147 tab.locationsMemoryxToArmemButton.setLabel(
"Locations MemoryX -> ArMem");
148 tab.locationsArmemToMemoryxButton.setLabel(
"Locations ArMem -> MemoryX (WIP)");
149 tab.locationsClearArMemButton.setLabel(
"Clear ArMem Locations");
151 tab.graphMemoryxToArmemButton.setLabel(
"Graph MemoryX -> ArMem");
152 tab.graphArmemToMemoryxButton.setLabel(
"Graph ArMem -> MemoryX (WIP)");
153 tab.graphClearArMemButton.setLabel(
"Clear ArMem Graphs");
160 .add(tab.sceneComboBox, {row, 1})
161 .
add(tab.sceneRefreshButton, {row, 2});
164 grid.
add(
Label(
"Provider Segment:"), {row, 0}).add(tab.providerSegmentLine, {row, 1});
167 grid.
add(
Label(
"Dry Run:"), {row, 0}).add(tab.dryRun, {row, 1});
170 grid.
add(
Label(
"Enable visu:"), {row, 0}).add(tab.visuEnabled, {row, 1});
173 grid.
add(tab.locationsMemoryxToArmemButton, {row, 0})
174 .
add(tab.locationsArmemToMemoryxButton, {row, 1})
175 .
add(tab.locationsClearArMemButton, {row, 2});
178 grid.
add(tab.graphMemoryxToArmemButton, {row, 0})
179 .
add(tab.graphArmemToMemoryxButton, {row, 1})
180 .
add(tab.graphClearArMemButton, {row, 2});
191 if (tab.sceneRefreshButton.wasClicked())
196 if (tab.locationsMemoryxToArmemButton.wasClicked())
198 locationsMemoryxToArmem(tab.sceneComboBox.getValue());
200 if (tab.locationsArmemToMemoryxButton.wasClicked())
202 locationsArmemToMemoryx(tab.sceneComboBox.getValue());
204 if (tab.graphMemoryxToArmemButton.wasClicked())
206 graphMemoryxToArmem(tab.sceneComboBox.getValue());
208 if (tab.graphArmemToMemoryxButton.wasClicked())
210 graphArmemToMemoryx(tab.sceneComboBox.getValue());
213 if (tab.locationsClearArMemButton.wasClicked())
215 clearArMemProviderSegment(proxies.locationWriter, getLocationProviderSegmentID());
217 if (tab.graphClearArMemButton.wasClicked())
219 clearArMemProviderSegment(proxies.graphWriter, getGraphProviderSegmentID());
224 Component::refreshScenes()
226 const ::Ice::StringSeq sceneNames = proxies.graphSegment->getScenes();
231 Component::locationsMemoryxToArmem(
const std::string& sceneName)
236 memoryx::GraphNodeBaseList graphNodes = proxies.graphSegment->getNodesByScene(sceneName);
237 for (memoryx::GraphNodeBasePtr& node : graphNodes)
240 if (not node->isMetaEntity())
243 const std::string nodeId = node->getId();
245 const std::string name = node->getName();
251 proxies.graphNodePoseResolver->resolveToGlobalPose(node));
257 ARMARX_VERBOSE << std::setprecision(2) << std::fixed <<
"Processing node "
258 << (commit.
updates.size() + 1) <<
"\n- ID: \t" << nodeId
259 <<
"\n- Name: \t" << name <<
"\n- Pose: \n"
260 << pose->toEigen() <<
"\n- Resolved global pose: \n"
261 << globalNodePose->toEigen();
263 navigation::location::arondto::Location
data;
265 data.framedPose.pose = globalNodePose->toEigen();
269 update.referencedTime = time;
274 if (not tab.dryRun.getValue())
280 <<
" locations from MemoryX to ArMem.";
294 Component::locationsArmemToMemoryx(
const std::string& sceneName)
301 Component::graphMemoryxToArmem(
const std::string& sceneName)
303 memoryx::GraphNodeBaseList graphNodes = proxies.graphSegment->getNodesByScene(sceneName);
306 if (tab.visuEnabled.getValue())
308 navigation::graph::GraphVisu visu;
313 visu.draw(layer, graph, info);
327 update.referencedTime = time;
328 update.instancesData = {aron.toAron()};
330 if (not tab.dryRun.getValue())
336 <<
"' from MemoryX to ArMem.";
350 Component::graphArmemToMemoryx(
const std::string& sceneName)
357 Component::clearArMemProviderSegment(armem::client::Writer& writer,
360 const bool clearWhenExists =
true;
361 auto result = writer.addSegment(providerSegmentID, clearWhenExists);
364 ARMARX_IMPORTANT <<
"Cleared ArMem provider segment " << providerSegmentID <<
".";
373 Component::getLocationProviderSegmentID()
375 return properties.locationCoreSegmentID.withProviderSegmentName(
376 tab.providerSegmentLine.getValue());
380 Component::getGraphProviderSegmentID()
382 return properties.graphCoreSegmentID.withProviderSegmentName(
383 tab.providerSegmentLine.getValue());
387 Component::toArmemGraph(
const memoryx::GraphNodeBaseList& graphNodes)
390 std::map<std::string, navigation::core::Graph::Vertex> vertexMap;
393 semrel::ShapeID nextVertexID{0};
394 for (memoryx::GraphNodeBasePtr node : graphNodes)
397 if (not node->isMetaEntity())
400 const std::string name = node->getName();
403 proxies.graphNodePoseResolver->resolveToGlobalPose(node));
408 navigation::core::Graph::Vertex vertex = graph.addVertex(nextVertexID);
409 vertexMap.emplace(name, vertex);
411 vertex.attrib().aron.vertexID =
static_cast<long>(nextVertexID);
412 toAron(vertex.attrib().aron.locationID,
413 getLocationProviderSegmentID().withEntityName(name));
414 vertex.attrib().setPose(*globalNodePose);
420 for (
auto v : graph.vertices())
429 for (memoryx::GraphNodeBasePtr node : graphNodes)
431 const auto& sourceVertex = vertexMap.at(node->getName());
432 for (
int i = 0; i < node->getOutdegree(); i++)
435 memoryx::GraphNodeBasePtr::dynamicCast(node->getAdjacentNode(i)->getEntity());
437 const auto& targetVertex = vertexMap.at(adjacent->getName());
439 ARMARX_VERBOSE <<
"\n- Adding edge: \t" << node->getName() <<
" \t-> "
440 << adjacent->getName();
441 navigation::core::Graph::Edge edge = graph.addEdge(sourceVertex, targetVertex);
442 edge.attrib().aron.sourceVertexID =
443 static_cast<long>(sourceVertex.attrib().aron.vertexID);
444 edge.attrib().aron.targetVertexID =
445 static_cast<long>(targetVertex.attrib().aron.vertexID);