27 #include <VirtualRobot/VirtualRobot.h>
37 #include <armarx/navigation/core/aron/Graph.aron.generated.h>
38 #include <armarx/navigation/core/aron/Location.aron.generated.h>
61 def->component(proxies.priorKnowledge);
62 def->component(proxies.graphNodePoseResolver,
"GraphNodePoseResolver");
82 if (proxies.priorKnowledge->hasGraphSegment())
84 proxies.graphSegment = proxies.priorKnowledge->getGraphSegment();
114 return "graph_import_export";
122 tab.sceneComboBox.setOptions(sceneNames);
123 tab.sceneRefreshButton.setLabel(
"Refresh");
125 tab.providerSegmentLine.setValue(
getName());
127 tab.dryRun.setValue(
false);
128 tab.visuEnabled.setValue(
true);
130 tab.locationsMemoryxToArmemButton.setLabel(
"Locations MemoryX -> ArMem");
131 tab.locationsArmemToMemoryxButton.setLabel(
"Locations ArMem -> MemoryX (WIP)");
132 tab.locationsClearArMemButton.setLabel(
"Clear ArMem Locations");
134 tab.graphMemoryxToArmemButton.setLabel(
"Graph MemoryX -> ArMem");
135 tab.graphArmemToMemoryxButton.setLabel(
"Graph ArMem -> MemoryX (WIP)");
136 tab.graphClearArMemButton.setLabel(
"Clear ArMem Graphs");
143 .add(tab.sceneComboBox, {row, 1})
144 .
add(tab.sceneRefreshButton, {row, 2});
147 grid.
add(
Label(
"Provider Segment:"), {row, 0}).add(tab.providerSegmentLine, {row, 1});
150 grid.
add(
Label(
"Dry Run:"), {row, 0}).add(tab.dryRun, {row, 1});
153 grid.
add(
Label(
"Enable visu:"), {row, 0}).add(tab.visuEnabled, {row, 1});
156 grid.
add(tab.locationsMemoryxToArmemButton, {row, 0})
157 .
add(tab.locationsArmemToMemoryxButton, {row, 1})
158 .
add(tab.locationsClearArMemButton, {row, 2});
161 grid.
add(tab.graphMemoryxToArmemButton, {row, 0})
162 .
add(tab.graphArmemToMemoryxButton, {row, 1})
163 .
add(tab.graphClearArMemButton, {row, 2});
174 if (tab.sceneRefreshButton.wasClicked())
179 if (tab.locationsMemoryxToArmemButton.wasClicked())
181 locationsMemoryxToArmem(tab.sceneComboBox.getValue());
183 if (tab.locationsArmemToMemoryxButton.wasClicked())
185 locationsArmemToMemoryx(tab.sceneComboBox.getValue());
187 if (tab.graphMemoryxToArmemButton.wasClicked())
189 graphMemoryxToArmem(tab.sceneComboBox.getValue());
191 if (tab.graphArmemToMemoryxButton.wasClicked())
193 graphArmemToMemoryx(tab.sceneComboBox.getValue());
196 if (tab.locationsClearArMemButton.wasClicked())
198 clearArMemProviderSegment(proxies.locationWriter, getLocationProviderSegmentID());
200 if (tab.graphClearArMemButton.wasClicked())
202 clearArMemProviderSegment(proxies.graphWriter, getGraphProviderSegmentID());
207 Component::refreshScenes()
209 const ::Ice::StringSeq sceneNames = proxies.graphSegment->getScenes();
214 Component::locationsMemoryxToArmem(
const std::string& sceneName)
219 memoryx::GraphNodeBaseList graphNodes = proxies.graphSegment->getNodesByScene(sceneName);
220 for (memoryx::GraphNodeBasePtr& node : graphNodes)
223 if (not node->isMetaEntity())
226 const std::string nodeId = node->getId();
228 const std::string name = node->getName();
234 proxies.graphNodePoseResolver->resolveToGlobalPose(node));
240 ARMARX_VERBOSE << std::setprecision(2) << std::fixed <<
"Processing node "
241 << (commit.
updates.size() + 1) <<
"\n- ID: \t" << nodeId
242 <<
"\n- Name: \t" << name <<
"\n- Pose: \n"
243 << pose->toEigen() <<
"\n- Resolved global pose: \n"
244 << globalNodePose->toEigen();
246 navigation::location::arondto::Location
data;
248 data.framedPose.pose = globalNodePose->toEigen();
252 update.referencedTime = time;
257 if (not tab.dryRun.getValue())
263 <<
" locations from MemoryX to ArMem.";
277 Component::locationsArmemToMemoryx(
const std::string& sceneName)
284 Component::graphMemoryxToArmem(
const std::string& sceneName)
286 memoryx::GraphNodeBaseList graphNodes = proxies.graphSegment->getNodesByScene(sceneName);
289 if (tab.visuEnabled.getValue())
291 navigation::graph::GraphVisu visu;
296 visu.draw(layer, graph, info);
310 update.referencedTime = time;
311 update.instancesData = {aron.toAron()};
313 if (not tab.dryRun.getValue())
319 <<
"' from MemoryX to ArMem.";
333 Component::graphArmemToMemoryx(
const std::string& sceneName)
340 Component::clearArMemProviderSegment(armem::client::Writer& writer,
343 const bool clearWhenExists =
true;
344 auto result = writer.addSegment(providerSegmentID, clearWhenExists);
347 ARMARX_IMPORTANT <<
"Cleared ArMem provider segment " << providerSegmentID <<
".";
356 Component::getLocationProviderSegmentID()
358 return properties.locationCoreSegmentID.withProviderSegmentName(
359 tab.providerSegmentLine.getValue());
363 Component::getGraphProviderSegmentID()
365 return properties.graphCoreSegmentID.withProviderSegmentName(
366 tab.providerSegmentLine.getValue());
370 Component::toArmemGraph(
const memoryx::GraphNodeBaseList& graphNodes)
373 std::map<std::string, navigation::core::Graph::Vertex> vertexMap;
376 semrel::ShapeID nextVertexID{0};
377 for (memoryx::GraphNodeBasePtr node : graphNodes)
380 if (not node->isMetaEntity())
383 const std::string name = node->getName();
386 proxies.graphNodePoseResolver->resolveToGlobalPose(node));
391 navigation::core::Graph::Vertex vertex = graph.addVertex(nextVertexID);
392 vertexMap.emplace(name, vertex);
394 vertex.attrib().aron.vertexID =
static_cast<long>(nextVertexID);
395 toAron(vertex.attrib().aron.locationID,
396 getLocationProviderSegmentID().withEntityName(name));
397 vertex.attrib().setPose(*globalNodePose);
403 for (
auto v : graph.vertices())
412 for (memoryx::GraphNodeBasePtr node : graphNodes)
414 const auto& sourceVertex = vertexMap.at(node->getName());
415 for (
int i = 0; i < node->getOutdegree(); i++)
418 memoryx::GraphNodeBasePtr::dynamicCast(node->getAdjacentNode(i)->getEntity());
420 const auto& targetVertex = vertexMap.at(adjacent->getName());
422 ARMARX_VERBOSE <<
"\n- Adding edge: \t" << node->getName() <<
" \t-> "
423 << adjacent->getName();
424 navigation::core::Graph::Edge edge = graph.addEdge(sourceVertex, targetVertex);
425 edge.attrib().aron.sourceVertexID =
426 static_cast<long>(sourceVertex.attrib().aron.vertexID);
427 edge.attrib().aron.targetVertexID =
428 static_cast<long>(targetVertex.attrib().aron.vertexID);