ViewSelection.cpp
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  * @package view_selection::ArmarXObjects::scheduler_example
17  * @author Johann Mantel ( j-mantel at gmx dot net )
18  * @date 2022
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "ViewSelection.h"
24 
25 #include <ArmarXCore/core/time.h>
26 
29 
31 
33 {
34 
36  std::string providerSegmentName) :
37  memoryNameSystem(mns),
38  providerSegmentName(providerSegmentName),
41  {
42  }
43 
45 
46  void
48  {
49  ARMARX_IMPORTANT << "ViewSelection: Waiting for memory '" << coreSegmentID << "' ...";
50  try
51  {
52  memoryWriter = memoryNameSystem.getWriter(coreSegmentID);
53  memoryReader = memoryNameSystem.getReader(coreSegmentID);
54  ARMARX_IMPORTANT << "ViewSelection: Connected to memory '" << coreSegmentID << "'";
55  }
57  {
58  ARMARX_ERROR << e.what();
59  return;
60  }
61  }
62 
64  ViewSelection::readGazeTarget(const std::string name)
65  {
67  armem::MemoryID entityId =
68  coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(name);
69  qb.latestEntitySnapshot(entityId);
70  auto queryResult = memoryReader.query(qb.buildQueryInput());
71  const auto* snapshot = queryResult.memory.findLatestInstance(entityId);
72 
73  if (snapshot != nullptr)
74  {
75  gaze_targets::GazeTarget gazeTarget = armarx::aron::fromAron<gaze_targets::GazeTarget>(
76  gaze_targets::arondto::GazeTarget::FromAron(snapshot->data()));
77 
78  return gazeTarget;
79  }
80  else
81  {
82  ARMARX_VERBOSE << "No memory found with id:" << entityId;
83  return gaze_targets::GazeTarget{};
84  }
85  }
86 
87  void
89  {
90  if (not memoryWriter)
91  {
92  ARMARX_WARNING << "Memory writer is null. Did you forget to call "
93  "ViewSelection::connect() in onConnectComponent()?";
94  return;
95  }
96  if (target.name == "")
97  {
98  ARMARX_WARNING << "The target name is empty. Did you forget to initialize it?";
99  return;
100  }
101 
102  gaze_targets::arondto::GazeTarget dto;
103  toAron(dto, target);
104 
106  update.entityID =
107  coreSegmentID.withProviderSegmentName(providerSegmentName).withEntityName(dto.name);
108  update.referencedTime = armarx::Clock::Now();
109  update.instancesData = {dto.toAron()};
110  memoryWriter.commit(update);
111  }
112 
113  void
114  ViewSelection::commitGazeTargets(const std::vector<gaze_targets::GazeTarget>& targets)
115  {
116  for (const auto& target : targets)
117  {
119  }
120  }
121 
122 } // namespace armarx::view_selection::client
armarx::armem::base::detail::GetFindSnapshotMixin::findLatestInstance
const auto * findLatestInstance(int instanceIndex=0) const
Find the latest entity instance.
Definition: lookup_mixins.h:372
armarx::navigation::graph::coreSegmentID
const armem::MemoryID coreSegmentID
Definition: constants.h:30
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::targets
Brief description of class targets.
Definition: targets.h:38
armarx::armem::client::QueryResult::memory
wm::Memory memory
The slice of the memory that matched the query.
Definition: Query.h:58
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::armem::client::query::Builder::buildQueryInput
QueryInput buildQueryInput() const
Definition: Builder.cpp:12
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::view_selection::memory::constants::GazeTargetCoreSegmentName
const std::string GazeTargetCoreSegmentName
Definition: constants.h:30
armarx::view_selection::gaze_targets::GazeTarget
Business Object (BO) class of GazeTarget.
Definition: GazeTarget.h:39
armarx::view_selection::client::ViewSelection::commitGazeTargets
void commitGazeTargets(const std::vector< gaze_targets::GazeTarget > &targets)
Definition: ViewSelection.cpp:114
armarx::armem::client::query::Builder::latestEntitySnapshot
void latestEntitySnapshot(const MemoryID &entityID)
Definition: Builder.cpp:131
armarx::armem::client::MemoryNameSystem::getWriter
Writer getWriter(const MemoryID &memoryID)
Get a writer to the given memory name.
Definition: MemoryNameSystem.cpp:413
armarx::memory
Brief description of class memory.
Definition: memory.h:38
armarx::view_selection::client
Definition: ComponentPlugin.cpp:30
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:417
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::view_selection::client::ViewSelection::~ViewSelection
~ViewSelection()
FramedPose.h
ViewSelection.h
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:25
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
armarx::view_selection::client::ViewSelection::commitGazeTarget
void commitGazeTarget(const gaze_targets::GazeTarget &target)
Definition: ViewSelection.cpp:88
constants.h
armarx::view_selection::memory::constants::ViewMemoryName
const std::string ViewMemoryName
Definition: constants.h:28
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:425
armarx::view_selection::client::ViewSelection::readGazeTarget
gaze_targets::GazeTarget readGazeTarget(const std::string name)
Definition: ViewSelection.cpp:64
Builder.h
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:73
time.h
armarx::armem::error::CouldNotResolveMemoryServer
Indicates that a query to the Memory Name System failed.
Definition: mns.h:24
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:93
armarx::armem::client::query::Builder
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition: Builder.h:21
armarx::view_selection::client::ViewSelection::connect
void connect()
Definition: ViewSelection.cpp:47
armarx::toAron
void toAron(arondto::PackagePath &dto, const PackageFileLocation &bo)
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::armem::client::MemoryNameSystem::getReader
Reader getReader(const MemoryID &memoryID)
Get a reader to the given memory name.
Definition: MemoryNameSystem.cpp:260
armarx::armem::client::Reader::query
QueryResult query(const QueryInput &input) const
Perform a query on the WM.
Definition: Reader.cpp:69
armarx::view_selection::client::ViewSelection::ViewSelection
ViewSelection(armarx::armem::client::MemoryNameSystem &mns, std::string providerSegmentName)
Definition: ViewSelection.cpp:35