Reader.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 Fabian Reister ( fabian dot reister 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 <map>
25 #include <optional>
26 #include <ostream>
27 #include <string>
28 #include <vector>
29 
34 #include <RobotAPI/libraries/armem_locations/aron/Location.aron.generated.h>
35 
38 
40 {
41 
43  {
45  std::string locationName;
46  double matchRatio;
47  };
48 
50  {
51  std::optional<ResolvedLocationName> resolved;
52  std::optional<std::string> errorMessage;
53  };
54 
56  {
57  public:
59 
60  std::string propertyPrefix() const override;
61  Properties defaultProperties() const override;
62 
63  std::map<std::string, core::Location> locations();
64 
65  std::vector<armarx::navigation::core::Graph> graphs();
66 
67  core::Location resolveLocationId(const std::string& locationId);
68 
69 
70  /**
71  * @brief Resolve a location by human-readable name.
72  *
73  * Queries location names from the navigation memory, matches the given name to the
74  * locations' names, and returns the ID of the location with the best match.
75  *
76  * @param locationName The human-readable name.
77  * @param minMatchRatio The minimum match ratio required to accept a match.
78  * @param log Optional out-stream for logging about the matching.
79  * @return Resolved location name or error message.
80  */
81  ResolveLocationNameResult resolveLocationName(const std::string& locationName,
82  double minMatchRatio,
83  std::ostream* log = nullptr);
84  /**
85  * @brief Resolve a location by human-readable name.
86  *
87  * Matches the given name to the locations' names, and returns the ID of the location with
88  * the best match.
89  *
90  * @param locations Locations, e.g. as returned by `Reader::queryLocations()`.
91  * @param locationName The human-readable name.
92  * @param minMatchRatio The minimum match ratio required to accept a match.
93  * @param log Optional out-stream for logging about the matching.
94  * @return Resolved location name or error message.
95  */
97  ResolveLocationName(const std::map<armem::MemoryID, location::arondto::Location>& locations,
98  const std::string& locationName,
99  double minMatchRatio,
100  std::ostream* log = nullptr);
101 
103 
104 
105  protected:
106  std::map<armem::MemoryID, location::arondto::Location> queryLocations();
107 
110 
111  private:
112  armem::client::Reader memoryReaderLocations;
113  armem::client::Reader memoryReaderGraphs;
114  };
115 
116 } // namespace armarx::navigation::memory::client::graph
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
armarx::navigation::memory::client::graph::ResolvedLocationName::locationName
std::string locationName
Definition: Reader.h:45
armarx::navigation::memory::client::graph::Reader::resolveLocationName
ResolveLocationNameResult resolveLocationName(const std::string &locationName, double minMatchRatio, std::ostream *log=nullptr)
Resolve a location by human-readable name.
Definition: Reader.cpp:213
Reader.h
armarx::navigation::memory::client::graph::ResolvedLocationName
Definition: Reader.h:42
armarx::navigation::memory::client::graph::Reader::allLocations
armem::wm::CoreSegment allLocations()
Definition: Reader.cpp:103
armarx::navigation::memory::client::graph::Reader::ResolveLocationName
static ResolveLocationNameResult ResolveLocationName(const std::map< armem::MemoryID, location::arondto::Location > &locations, const std::string &locationName, double minMatchRatio, std::ostream *log=nullptr)
Resolve a location by human-readable name.
Definition: Reader.cpp:222
MemoryID.h
armarx::navigation::memory::client::graph::Reader::queryLocations
std::map< armem::MemoryID, location::arondto::Location > queryLocations()
Definition: Reader.cpp:163
armarx::navigation::memory::client::graph::ResolveLocationNameResult
Definition: Reader.h:49
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::navigation::memory::client::graph::ResolvedLocationName::locationId
armarx::armem::MemoryID locationId
Definition: Reader.h:44
armarx::navigation::memory::client::graph::Reader::propertyPrefix
std::string propertyPrefix() const override
Definition: Reader.cpp:36
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::navigation::memory::client::graph::ResolveLocationNameResult::resolved
std::optional< ResolvedLocationName > resolved
Definition: Reader.h:51
armarx::navigation::memory::client::graph
This file is part of ArmarX.
Definition: Reader.cpp:33
location.h
memory_definitions.h
armarx::navigation::memory::client::graph::Reader::connect
void connect(armarx::armem::client::MemoryNameSystem &mns) override
Definition: Reader.cpp:277
armarx::navigation::memory::client::graph::Reader::locations
std::map< std::string, core::Location > locations()
Definition: Reader.cpp:49
armarx::navigation::memory::client::graph::Reader::graphs
std::vector< armarx::navigation::core::Graph > graphs()
Definition: Reader.cpp:71
Graph.h
armarx::armem::client::util::SimpleReaderBase::Properties
Definition: SimpleReaderBase.h:43
armarx::navigation::core::Location
Definition: location.h:32
armarx::navigation::memory::client::graph::Reader::allGraphs
armem::wm::CoreSegment allGraphs()
Definition: Reader.cpp:133
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:73
armarx::armem::client::util::SimpleReaderBase::SimpleReaderBase
SimpleReaderBase()
Definition: SimpleReaderBase.cpp:9
armarx::navigation::memory::client::graph::Reader::defaultProperties
Properties defaultProperties() const override
Definition: Reader.cpp:42
armarx::navigation::memory::client::graph::Reader::resolveLocationId
core::Location resolveLocationId(const std::string &locationId)
Definition: Reader.cpp:203
armarx::navigation::memory::client::graph::ResolveLocationNameResult::errorMessage
std::optional< std::string > errorMessage
Definition: Reader.h:52
SimpleReaderBase.h
armarx::armem::client::util::SimpleReaderBase
Definition: SimpleReaderBase.h:38
armarx::navigation::memory::client::graph::Reader
Definition: Reader.h:55
armarx::navigation::memory::client::graph::ResolvedLocationName::matchRatio
double matchRatio
Definition: Reader.h:46