3 #include <VirtualRobot/ManipulationObject.h>
9 #include "../SimoxObjectShape.h"
17 static const int INDENT = 2;
20 result.attributes =
input.attrib().json.dump(INDENT);
22 for (
auto inputVertex :
input.vertices())
24 data::GraphVertex& resultVertex = result.vertices.emplace_back();
25 resultVertex.id =
static_cast<long>(inputVertex.descriptor());
26 resultVertex.attributes = inputVertex.attrib().json.dump(INDENT);
29 for (
auto inputEdge :
input.edges())
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);
40 semrel::AttributedGraph
43 semrel::AttributedGraph result;
44 result.attrib().json = nlohmann::json::parse(graph.attributes);
46 std::map<long, semrel::AttributedGraph::VertexDescriptor> id2desc;
47 for (
const data::GraphVertex& vertex : graph.vertices)
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());
55 for (
const data::GraphEdge& edge : graph.edges)
57 auto sourceDesc = id2desc.find(edge.sourceID);
58 if (sourceDesc == id2desc.end())
60 throw std::runtime_error(
"Source ID not found: " +
std::to_string(edge.sourceID));
62 auto targetDesc = id2desc.find(edge.targetID);
63 if (targetDesc == id2desc.end())
65 throw std::runtime_error(
"Target ID not found: " +
std::to_string(edge.targetID));
68 semrel::AttributedGraph::Edge resultEdge =
69 result.addEdge(sourceDesc->second, targetDesc->second);
70 resultEdge.attrib().json = nlohmann::json::parse(edge.attributes);