graph.cpp
Go to the documentation of this file.
1 #include "graph.h"
2 
3 #include <VirtualRobot/ManipulationObject.h>
4 
6 
8 
9 #include "../SimoxObjectShape.h"
10 
11 namespace armarx
12 {
13 
15  semantic::toIce(const semrel::AttributedGraph& input)
16  {
17  static const int INDENT = 2;
18 
19  data::Graph result;
20  result.attributes = input.attrib().json.dump(INDENT);
21 
22  for (auto inputVertex : input.vertices())
23  {
24  data::GraphVertex& resultVertex = result.vertices.emplace_back();
25  resultVertex.id = static_cast<long>(inputVertex.descriptor());
26  resultVertex.attributes = inputVertex.attrib().json.dump(INDENT);
27  }
28 
29  for (auto inputEdge : input.edges())
30  {
31  data::GraphEdge& resultEdge = result.edges.emplace_back();
32  resultEdge.sourceID = static_cast<long>(inputEdge.sourceDescriptor());
33  resultEdge.targetID = static_cast<long>(inputEdge.targetDescriptor());
34  resultEdge.attributes = inputEdge.attrib().json.dump(INDENT);
35  }
36 
37  return result;
38  }
39 
40  semrel::AttributedGraph
41  semantic::fromIce(const data::Graph& graph)
42  {
43  semrel::AttributedGraph result;
44  result.attrib().json = nlohmann::json::parse(graph.attributes);
45 
46  std::map<long, semrel::AttributedGraph::VertexDescriptor> id2desc;
47  for (const data::GraphVertex& vertex : graph.vertices)
48  {
49  semrel::AttributedGraph::Vertex resultVertex =
50  result.addVertex(semrel::ShapeID(vertex.id));
51  resultVertex.attrib().json = nlohmann::json::parse(vertex.attributes);
52  id2desc.emplace(vertex.id, resultVertex.descriptor());
53  }
54 
55  for (const data::GraphEdge& edge : graph.edges)
56  {
57  auto sourceDesc = id2desc.find(edge.sourceID);
58  if (sourceDesc == id2desc.end())
59  {
60  throw std::runtime_error("Source ID not found: " + std::to_string(edge.sourceID));
61  }
62  auto targetDesc = id2desc.find(edge.targetID);
63  if (targetDesc == id2desc.end())
64  {
65  throw std::runtime_error("Target ID not found: " + std::to_string(edge.targetID));
66  }
67 
68  semrel::AttributedGraph::Edge resultEdge =
69  result.addEdge(sourceDesc->second, targetDesc->second);
70  resultEdge.attrib().json = nlohmann::json::parse(edge.attributes);
71  }
72 
73  return result;
74  }
75 
76 } // namespace armarx
Pose.h
armarx::semantic::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::Graph
boost::subgraph< CloudGraph > Graph
Definition: Common.h:54
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
graph.h
Logging.h
armarx::semantic::fromIce
semrel::AttributedGraph fromIce(const semantic::data::Graph &graph)
Definition: graph.h:30
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28