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 
25 
27 #include <armarx/navigation/core/aron/Location.aron.generated.h>
29 
31 {
32 
34  {
36  std::string locationName;
37  double matchRatio;
38  };
39 
41  {
42  std::optional<ResolvedLocationName> resolved;
43  std::optional<std::string> errorMessage;
44  };
45 
47  {
48  public:
50 
51  std::string propertyPrefix() const override;
52  Properties defaultProperties() const override;
53 
54  std::map<std::string, core::Location> locations();
55 
56  std::vector<armarx::navigation::core::Graph> graphs();
57 
58  core::Location resolveLocationId(const std::string& locationId);
59 
60 
61  /**
62  * @brief Resolve a location by human-readable name.
63  *
64  * Queries location names from the navigation memory, matches the given name to the
65  * locations' names, and returns the ID of the location with the best match.
66  *
67  * @param locationName The human-readable name.
68  * @param minMatchRatio The minimum match ratio required to accept a match.
69  * @param log Optional out-stream for logging about the matching.
70  * @return Resolved location name or error message.
71  */
72  ResolveLocationNameResult resolveLocationName(const std::string& locationName,
73  double minMatchRatio,
74  std::ostream* log = nullptr);
75  /**
76  * @brief Resolve a location by human-readable name.
77  *
78  * Matches the given name to the locations' names, and returns the ID of the location with
79  * the best match.
80  *
81  * @param locations Locations, e.g. as returned by `Reader::queryLocations()`.
82  * @param locationName The human-readable name.
83  * @param minMatchRatio The minimum match ratio required to accept a match.
84  * @param log Optional out-stream for logging about the matching.
85  * @return Resolved location name or error message.
86  */
88  ResolveLocationName(const std::map<armem::MemoryID, location::arondto::Location>& locations,
89  const std::string& locationName,
90  double minMatchRatio,
91  std::ostream* log = nullptr);
92 
94 
95 
96  protected:
97  std::map<armem::MemoryID, location::arondto::Location> queryLocations();
98 
101 
102  private:
103  armem::client::Reader memoryReaderLocations;
104  armem::client::Reader memoryReaderGraphs;
105  };
106 
107 } // 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:36
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:200
armarx::navigation::memory::client::graph::ResolvedLocationName
Definition: Reader.h:33
armarx::navigation::memory::client::graph::Reader::allLocations
armem::wm::CoreSegment allLocations()
Definition: Reader.cpp:93
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:209
armarx::navigation::memory::client::graph::Reader::queryLocations
std::map< armem::MemoryID, location::arondto::Location > queryLocations()
Definition: Reader.cpp:153
armarx::navigation::memory::client::graph::ResolveLocationNameResult
Definition: Reader.h:40
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::navigation::memory::client::graph::ResolvedLocationName::locationId
armarx::armem::MemoryID locationId
Definition: Reader.h:35
armarx::navigation::memory::client::graph::Reader::propertyPrefix
std::string propertyPrefix() const override
Definition: Reader.cpp:26
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:42
armarx::navigation::memory::client::graph
This file is part of ArmarX.
Definition: Reader.cpp:23
armarx::navigation::memory::client::graph::Reader::connect
void connect(armarx::armem::client::MemoryNameSystem &mns) override
Definition: Reader.cpp:264
armarx::navigation::memory::client::graph::Reader::locations
std::map< std::string, core::Location > locations()
Definition: Reader.cpp:39
armarx::navigation::memory::client::graph::Reader::graphs
std::vector< armarx::navigation::core::Graph > graphs()
Definition: Reader.cpp:61
Graph.h
armarx::armem::client::util::SimpleReaderBase::Properties
Definition: SimpleReaderBase.h:43
armarx::navigation::core::Location
Definition: location.h:29
armarx::navigation::memory::client::graph::Reader::allGraphs
armem::wm::CoreSegment allGraphs()
Definition: Reader.cpp:123
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
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:32
armarx::navigation::memory::client::graph::Reader::resolveLocationId
core::Location resolveLocationId(const std::string &locationId)
Definition: Reader.cpp:193
armarx::navigation::memory::client::graph::ResolveLocationNameResult::errorMessage
std::optional< std::string > errorMessage
Definition: Reader.h:43
SimpleReaderBase.h
armarx::armem::client::util::SimpleReaderBase
Definition: SimpleReaderBase.h:38
types.h
armarx::navigation::memory::client::graph::Reader
Definition: Reader.h:46
armarx::navigation::memory::client::graph::ResolvedLocationName::matchRatio
double matchRatio
Definition: Reader.h:37