Graph.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <optional>
25#include <string>
26#include <vector>
27
33
36#include <armarx/navigation/core/aron/Graph.aron.generated.h>
38
39#include <SemanticObjectRelations/RelationGraph/RelationGraph.h>
40
42{
43
44 struct VertexAttribs : public semrel::ShapeVertex
45 {
46 armarx::navigation::core::arondto::Vertex aron;
47
48 std::string getFullName() const;
49
50 std::string getProviderName() const;
51
52 std::string getLocationName() const;
53 bool hasLocationName() const;
54
55 bool hasPose() const;
56 FramedPose getPose() const;
57 void setPose(const FramedPose& pose);
58
59 Pose requireGlobal() const;
60
61 private:
62 std::optional<FramedPose> _pose;
63 };
64
66 {
67 armarx::navigation::core::arondto::Edge aron;
68
70
71 // client::Config config;
72 float&
74 {
75 return m_value;
76 }
77
78 const float&
79 cost() const
80 {
81 return m_value;
82 }
83
84 std::optional<core::GlobalTrajectory> trajectory = std::nullopt;
85
86 float m_value{0.F};
87 };
88
90 {
91 };
92
93 class Graph : public semrel::RelationGraph<VertexAttribs, EdgeAttribs, GraphAttribs>
94 {
95 public:
96 /**
97 * @brief Get a string representation of the given vertex for usage in `str()`.
98 * By default, returns `"[<vertex descriptor> (ID <object ID>)]"`.
99 */
100 // virtual std::string strVertex(ConstVertex v) const;
101 /**
102 * @brief Get a string representation of the given edge for usage in `str()`.
103 * By default, returns
104 * `"[<source descriptor> (ID <source ID>) -> <target descriptor> (ID <target ID>)"`.
105 */
106 std::string strEdge(ConstEdge edge) const override;
107 };
108
109 using Graphs = std::vector<Graph>;
110
111 using GraphPath = std::vector<Graph::ConstVertex>;
112 std::vector<GraphPath> findPathsTo(Graph::ConstVertex vertex, const Graph& graph);
113
114 Graph::ConstVertex getVertexByName(const std::string& vertexName, const Graph& graph);
115
116 bool hasVertex(const std::string& vertexName, const Graph& graph);
117 const core::Graph& getSubgraph(const std::string& vertexName, const Graphs& graphs);
118
119 void toAron(arondto::Graph& dto, const Graph& bo);
120 void fromAron(const arondto::Graph& dto, Graph& bo);
121
122
123 // Location resolution
124
125 void resolveLocation(Graph::Vertex& vertex, const aron::data::DictPtr& locationData);
126
127 template <class MemoryContainerT>
128 bool
129 resolveLocation(Graph::Vertex& vertex, const MemoryContainerT& locationContainer)
130 {
131 armem::MemoryID locationID;
132 fromAron(vertex.attrib().aron.locationID, locationID);
133
134 if (const auto* instance = locationContainer.findLatestInstance(locationID))
135 {
136 resolveLocation(vertex, instance->data());
137 return true;
138 }
139
140 return false;
141 }
142
143 template <class MemoryContainerT>
144 void
145 resolveLocations(Graph& graph, const MemoryContainerT& locationContainer)
146 {
147 for (auto vertex : graph.vertices())
148 {
149 resolveLocation(vertex, locationContainer);
150 }
151 }
152
153
154} // namespace armarx::navigation::core
The FramedPose class.
Definition FramedPose.h:281
std::string strEdge(ConstEdge edge) const override
Get a string representation of the given vertex for usage in str().
Definition Graph.cpp:108
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
This file is part of ArmarX.
Graph::ConstVertex getVertexByName(const std::string &vertexName, const Graph &graph)
Definition Graph.cpp:209
std::vector< Graph > Graphs
Definition Graph.h:109
bool hasVertex(const std::string &vertexName, const Graph &graph)
Definition Graph.cpp:224
std::vector< GraphPath > findPathsTo(Graph::ConstVertex vertex, const Graph &graph)
Definition Graph.cpp:182
void resolveLocation(Graph::Vertex &vertex, const aron::data::DictPtr &locationData)
Definition Graph.cpp:267
void toAron(arondto::GlobalTrajectoryPoint &dto, const GlobalTrajectoryPoint &bo)
Eigen::Isometry3f Pose
Definition basic_types.h:31
void fromAron(const arondto::GlobalTrajectoryPoint &dto, GlobalTrajectoryPoint &bo)
const core::Graph & getSubgraph(const std::string &vertexName, const Graphs &graphs)
Definition Graph.cpp:234
std::vector< Graph::ConstVertex > GraphPath
Definition Graph.h:111
void resolveLocations(Graph &graph, const MemoryContainerT &locationContainer)
Definition Graph.h:145
This file is part of ArmarX.
Definition Visu.h:48
client::GlobalPlanningStrategy strategy
Definition Graph.h:69
std::optional< core::GlobalTrajectory > trajectory
Definition Graph.h:84
const float & cost() const
Definition Graph.h:79
armarx::navigation::core::arondto::Edge aron
Definition Graph.h:67
std::string getProviderName() const
Definition Graph.cpp:61
armarx::navigation::core::arondto::Vertex aron
Definition Graph.h:46
std::string getLocationName() const
Definition Graph.cpp:48
void setPose(const FramedPose &pose)
Definition Graph.cpp:89