12 #include <SemanticObjectRelations/Shapes/Shape.h>
18 core::arondto::Edge edge;
19 edge.sourceVertexID = -1;
20 edge.targetVertexID = -1;
30 const semrel::ShapeID shapeId(++vertexIdCnt);
31 graph.addVertex(shapeId, attribs);
38 activeVertices_ = {shapeId};
55 const semrel::ShapeID shapeId(++vertexIdCnt);
56 graph.addVertex(shapeId, attribs);
60 ARMARX_CHECK(graph.vertex(shapeId).attrib().hasPose()) <<
"Vertex pose must be set!";
66 for (
const semrel::ShapeID& activeVertexId : activeVertices_)
68 graph.addEdge(activeVertexId,
72 .trajectory = std::nullopt});
75 activeVertices_ = {shapeId};
89 GraphBuilder::addOrGetVertex(
const core::Graph::VertexAttrib& attributes)
91 const auto vertex = getVertexByAttributes(attributes);
92 if (vertex.has_value())
94 return vertex.value();
97 const semrel::ShapeID shapeId(++vertexIdCnt);
98 graph.addVertex(shapeId, attributes);
104 operator==(
const core::Graph::VertexAttrib& lhs,
const core::Graph::VertexAttrib& rhs)
106 if (lhs.hasName() and rhs.hasName())
108 return lhs.getName() == rhs.getName();
117 std::optional<semrel::ShapeID>
118 GraphBuilder::getVertexByAttributes(
const core::Graph::VertexAttrib& attributes)
120 auto vertices = graph.vertices();
121 const auto vIt = std::find_if(vertices.begin(),
123 [&attributes](
const core::Graph::ConstVertex& vertex)
124 { return vertex.attrib() == attributes; });
126 if (vIt != vertices.end())
128 ARMARX_DEBUG <<
"Found matching vertex `" << vIt->attrib().getName() <<
"`";
129 return vIt->objectID();
140 <<
"Routes must exist. Otherwise, the graph will not have any active connections!";
143 for (
const auto& vertex : activeVertices_)
145 for (
const auto& route : routes)
153 std::vector<semrel::ShapeID> routeShapeIds;
158 for (
const auto& vertex : route)
161 <<
"Vertex on the route must have a pose!";
163 const semrel::ShapeID shapeId = addOrGetVertex(vertex.attrib());
164 routeShapeIds.push_back(shapeId);
168 <<
"Vertex pose must be set!";
174 for (
size_t i = 0; i < route.size() - 1; i++)
176 graph.addEdge(routeShapeIds.at(i),
177 routeShapeIds.at(i + 1),
178 core::Graph::EdgeAttrib{
179 .aron = ARON_UNSET_EDGE_VALUES,
180 .strategy = client::GlobalPlanningStrategy::Point2Point,
181 .trajectory = std::nullopt});
186 graph.addEdge(graph.vertex(vertex).objectID(),
187 routeShapeIds.front(),
188 core::Graph::EdgeAttrib{.aron = ARON_UNSET_EDGE_VALUES,
189 .strategy = strategy,
190 .trajectory = std::nullopt});
195 const auto targetDescriptor = routes.front().back().descriptor();
199 [&targetDescriptor](
const auto& route) ->
bool
200 { return route.back().descriptor() != targetDescriptor; }));
203 const std::optional<semrel::ShapeID> shapeId =
204 getVertexByAttributes(routes.front().back().attrib());
205 ARMARX_CHECK(shapeId.has_value()) <<
"Vertex exists. This should not have happened";
208 activeVertices_ = {shapeId.value()};
212 GraphBuilder::validate(
auto&& vertices)
const
215 std::for_each(vertices.begin(),
217 [](
const core::Graph::ConstVertex& vertex)
224 ARMARX_CHECK(vertex.attrib().hasPose())
225 <<
"Check 2: Vertex `" << vertex.attrib().getName() <<
"`"
226 <<
" with ID " << vertex.attrib().objectID
227 <<
" does not have pose attribute!";
234 validate(graph.vertices());
238 core::Graph::VertexDescriptor
241 ARMARX_CHECK(activeVertices_.size() == 1) <<
"There should be only one goal vertex.";
242 return activeVertices_.front();