16 #include <armarx/navigation/core/aron/Graph.aron.generated.h>
19 #include <SemanticObjectRelations/Shapes/Shape.h>
25 core::arondto::Edge edge;
26 edge.sourceVertexID = -1;
27 edge.targetVertexID = -1;
37 const semrel::ShapeID shapeId(++vertexIdCnt);
38 graph.addVertex(shapeId, attribs);
45 activeVertices_ = {shapeId};
62 const semrel::ShapeID shapeId(++vertexIdCnt);
63 graph.addVertex(shapeId, attribs);
67 ARMARX_CHECK(graph.vertex(shapeId).attrib().hasPose()) <<
"Vertex pose must be set!";
73 for (
const semrel::ShapeID& activeVertexId : activeVertices_)
75 graph.addEdge(activeVertexId,
79 .trajectory = std::nullopt});
82 activeVertices_ = {shapeId};
96 GraphBuilder::addOrGetVertex(
const core::Graph::VertexAttrib& attributes)
98 const auto vertex = getVertexByAttributes(attributes);
99 if (vertex.has_value())
101 return vertex.value();
104 const semrel::ShapeID shapeId(++vertexIdCnt);
105 graph.addVertex(shapeId, attributes);
111 operator==(
const core::Graph::VertexAttrib& lhs,
const core::Graph::VertexAttrib& rhs)
113 if (lhs.hasName() and rhs.hasName())
115 return lhs.getName() == rhs.getName();
124 std::optional<semrel::ShapeID>
125 GraphBuilder::getVertexByAttributes(
const core::Graph::VertexAttrib& attributes)
127 auto vertices = graph.vertices();
128 const auto vIt = std::find_if(vertices.begin(),
130 [&attributes](
const core::Graph::ConstVertex& vertex)
131 { return vertex.attrib() == attributes; });
133 if (vIt != vertices.end())
135 ARMARX_DEBUG <<
"Found matching vertex `" << vIt->attrib().getName() <<
"`";
136 return vIt->objectID();
147 <<
"Routes must exist. Otherwise, the graph will not have any active connections!";
150 for (
const auto& vertex : activeVertices_)
152 for (
const auto& route : routes)
160 std::vector<semrel::ShapeID> routeShapeIds;
165 for (
const auto& vertex : route)
168 <<
"Vertex on the route must have a pose!";
170 const semrel::ShapeID shapeId = addOrGetVertex(vertex.attrib());
171 routeShapeIds.push_back(shapeId);
175 <<
"Vertex pose must be set!";
181 for (
size_t i = 0; i < route.size() - 1; i++)
183 graph.addEdge(routeShapeIds.at(i),
184 routeShapeIds.at(i + 1),
185 core::Graph::EdgeAttrib{
186 .aron = ARON_UNSET_EDGE_VALUES,
187 .strategy = client::GlobalPlanningStrategy::Point2Point,
188 .trajectory = std::nullopt});
193 graph.addEdge(graph.vertex(vertex).objectID(),
194 routeShapeIds.front(),
195 core::Graph::EdgeAttrib{.aron = ARON_UNSET_EDGE_VALUES,
196 .strategy = strategy,
197 .trajectory = std::nullopt});
202 const auto targetDescriptor = routes.front().back().descriptor();
206 [&targetDescriptor](
const auto& route) ->
bool
207 { return route.back().descriptor() != targetDescriptor; }));
210 const std::optional<semrel::ShapeID> shapeId =
211 getVertexByAttributes(routes.front().back().attrib());
212 ARMARX_CHECK(shapeId.has_value()) <<
"Vertex exists. This should not have happened";
215 activeVertices_ = {shapeId.value()};
219 GraphBuilder::validate(
auto&& vertices)
const
222 std::for_each(vertices.begin(),
224 [](
const core::Graph::ConstVertex& vertex)
231 ARMARX_CHECK(vertex.attrib().hasPose())
232 <<
"Check 2: Vertex `" << vertex.attrib().getName() <<
"`"
233 <<
" with ID " << vertex.attrib().objectID
234 <<
" does not have pose attribute!";
241 validate(graph.vertices());
245 core::Graph::VertexDescriptor
248 ARMARX_CHECK(activeVertices_.size() == 1) <<
"There should be only one goal vertex.";
249 return activeVertices_.front();