ViewSelection.cpp
Go to the documentation of this file.
1#include "ViewSelection.h"
2
3#include <optional>
4#include <string>
5#include <vector>
6
10
18
20#include <armarx/view_selection/gaze_targets/aron/GazeTarget.aron.generated.h>
23
25{
26
28 std::string providerSegmentName) :
29 memoryNameSystem(mns),
30 providerSegmentName(providerSegmentName),
31 coreSegmentID(memory::constants::ViewMemoryName,
32 memory::constants::GazeTargetCoreSegmentName)
33 {
34 ;
35 }
36
38
39 void
41 {
42 ARMARX_IMPORTANT << "ViewSelection: Waiting for memory '" << coreSegmentID << "' ...";
43 try
44 {
45 memoryWriter = memoryNameSystem.useWriter(coreSegmentID);
46 memoryReader = memoryNameSystem.useReader(coreSegmentID);
47 ARMARX_IMPORTANT << "ViewSelection: Connected to memory '" << coreSegmentID << "'";
48 }
50 {
51 ARMARX_ERROR << e.what();
52 return;
53 }
54 }
55
56 std::optional<gaze_targets::GazeTarget>
57 ViewSelection::readGazeTarget(const std::string& name)
58 {
60 armem::MemoryID entityId =
61 coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(name);
62 qb.latestEntitySnapshot(entityId);
63 auto queryResult = memoryReader.query(qb.buildQueryInput());
64
65 const auto* entityInstance = queryResult.memory.findLatestInstance(entityId);
66
67 if (entityInstance != nullptr)
68 {
70 gaze_targets::arondto::GazeTarget::FromAron(entityInstance->data()));
71
72 return gazeTarget;
73 }
74
75 ARMARX_VERBOSE << "No memory found with id:" << entityId;
76 return std::nullopt;
77 }
78
79 void
81 {
82 if (not memoryWriter)
83 {
84 ARMARX_WARNING << "Memory writer is null. Did you forget to call "
85 "ViewSelection::connect() in onConnectComponent()?";
86 return;
87 }
88 if (target.name == "")
89 {
90 ARMARX_WARNING << "The target name is empty. Did you forget to initialize it?";
91 return;
92 }
93
94 gaze_targets::arondto::GazeTarget dto;
95 toAron(dto, target);
96
98 update.entityID =
99 coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(dto.name);
100 update.referencedTime = armarx::Clock::Now();
101 update.instancesData = {dto.toAron()};
102 memoryWriter.commit(update);
103 }
104
105 void
106 ViewSelection::commitGazeTargets(const std::vector<gaze_targets::GazeTarget>& targets)
107 {
108 for (const auto& target : targets)
109 {
110 commitGazeTarget(target);
111 }
112 }
113
114} // namespace armarx::view_selection::client
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
The memory name system (MNS) client.
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition Builder.h:22
void latestEntitySnapshot(const MemoryID &entityID)
Definition Builder.cpp:131
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
void commitGazeTargets(const std::vector< gaze_targets::GazeTarget > &targets)
void commitGazeTarget(const gaze_targets::GazeTarget &target)
std::optional< gaze_targets::GazeTarget > readGazeTarget(const std::string &name)
ViewSelection(armarx::armem::client::MemoryNameSystem &mns, std::string providerSegmentName)
Business Object (BO) class of GazeTarget.
Definition GazeTarget.h:23
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void fromAron(const T &dto, T &bo)
This file is part of ArmarX.
Definition Human.cpp:33
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
An update of an entity for a specific point in time.
Definition Commit.h:26