PersonInstanceUpdater.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 VisionX::ArmarXObjects::person_instance_updater
17  * @author Philipp Seidel ( uyhvq at student dot kit dot edu )
18  * @date 2023
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #include "PersonInstanceUpdater.h"
25 
27 
31 
33 #include <VisionX/libraries/armem_human/aron/FaceRecognition.aron.generated.h>
34 #include <VisionX/libraries/armem_human/aron/HumanPose.aron.generated.h>
35 #include <VisionX/libraries/armem_human/aron/Profile.aron.generated.h>
42 
44 {
45 
46  const std::string PersonInstanceUpdater::provider_name = "person_instance_updater";
47 
50  {
53  def->required(properties.max_face_head_distance, "maxFaceHeadDistance");
54  return def;
55  }
56 
57  void
59  {
60  this->updateConsumer = UpdateConsumer(properties.max_face_head_distance);
61  }
62 
63  void
65  {
66  this->task = new armarx::SimpleRunningTask<>([this]() { this->run(); });
67  this->task->start();
68  }
69 
70  void
72  {
73  }
74 
75  void
77  {
78  }
79 
80  void
81  PersonInstanceUpdater::run()
82  {
83  namespace armem = armarx::armem;
84  // Subscribe to memory updates.
85  {
86  armem::client::Reader faceRecognitionReader =
88  auto faceRecognitionCallback =
89  [this,
90  faceRecognitionReader](const std::vector<armem::MemoryID>& updatedSnapshotIDs)
91  {
92  //ARMARX_INFO << "Updated faces with IDs: " << updatedSnapshotIDs;
93  armem::client::QueryResult result =
94  faceRecognitionReader.queryMemoryIDs(updatedSnapshotIDs);
95  if (result.success)
96  {
97  result.memory.forEachInstance(
98  [this](const armem::wm::EntityInstance& instance)
99  {
100  armarx::human::arondto::FaceRecognition dto =
101  instance.dataAs<armarx::human::arondto::FaceRecognition>();
103  fromAron(dto, faceRecognition);
104  updateConsumer.consumeFaceRecognitionUpdate(
105  faceRecognition, instance.id(), this->memoryNameSystem());
106  });
107  }
108  };
109  armem::client::Reader poseReader =
111  auto poseCallback =
112  [this, poseReader](const std::vector<armem::MemoryID>& updatedSnapshotIDs)
113  {
114  //ARMARX_INFO << "Updated poses with IDs: " << updatedSnapshotIDs;
115  armem::client::QueryResult result = poseReader.queryMemoryIDs(updatedSnapshotIDs);
116  if (result.success)
117  {
118  result.memory.forEachInstance(
119  [this](const armem::wm::EntityInstance& instance)
120  {
121  armarx::human::arondto::HumanPose dto =
122  instance.dataAs<armarx::human::arondto::HumanPose>();
124  fromAron(dto, humanPose);
125  updateConsumer.consumePoseUpdate(
126  humanPose, instance.id(), this->memoryNameSystem());
127  });
128  }
129  };
130  armem::client::Reader profileReader =
132  auto profileCallback =
133  [this, profileReader](const std::vector<armem::MemoryID>& updatedSnapshotIDs)
134  {
135  //ARMARX_INFO << "Updated profiles with IDs: " << updatedSnapshotIDs;
136  armem::client::QueryResult result =
137  profileReader.queryMemoryIDs(updatedSnapshotIDs);
138  if (result.success)
139  {
140  result.memory.forEachInstance(
141  [this](const armem::wm::EntityInstance& instance)
142  {
144  instance.dataAs<armarx::human::arondto::Profile>();
145  updateConsumer.consumeProfileUpdate(
146  profile, instance.id(), this->memoryNameSystem());
147  });
148  }
149  };
151  faceRecognitionCallback);
154  }
155  }
156 
157  std::string
159  {
160  return provider_name;
161  }
162 
163  std::string
165  {
167  }
168 
169  // ARMARX_REGISTER_COMPONENT_EXECUTABLE(PersonInstanceUpdater,
170  // PersonInstanceUpdater::GetDefaultName());
171 
172 } // namespace VisionX::components::person_instance_updater
VisionX::components::person_instance_updater::UpdateConsumer
Definition: UpdateConsumer.h:13
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
VisionX::components::person_instance_updater::PersonInstanceUpdater::onDisconnectComponent
void onDisconnectComponent() override
Definition: PersonInstanceUpdater.cpp:71
VisionX::components::person_instance_updater::PersonInstanceUpdater::provider_name
static const std::string provider_name
Definition: PersonInstanceUpdater.h:49
armarx::armem::server::wm::EntityInstance
armem::wm::EntityInstance EntityInstance
Definition: forward_declarations.h:64
Reader.h
armarx::armem::client::QueryResult::memory
wm::Memory memory
The slice of the memory that matched the query.
Definition: Query.h:58
Writer.h
armarx::human::FaceRecognitionCoreSegmentID
const armem::MemoryID FaceRecognitionCoreSegmentID
Definition: memory_ids.cpp:31
VisionX::components::person_instance_updater::PersonInstanceUpdater::onInitComponent
void onInitComponent() override
Definition: PersonInstanceUpdater.cpp:58
VisionX::components::person_instance_updater::UpdateConsumer::consumeFaceRecognitionUpdate
void consumeFaceRecognitionUpdate(armarx::armem::human::FaceRecognition faceRecognition, armarx::armem::MemoryID faceRecognitionID, armarx::armem::client::MemoryNameSystem mns)
Definition: UpdateConsumer.cpp:38
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
armarx::armem::human::FaceRecognition
Definition: types.h:59
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
memory_ids.h
VisionX::components::person_instance_updater
Definition: PersonInstanceUpdater.cpp:43
VisionX::components::person_instance_updater::UpdateConsumer::consumeProfileUpdate
void consumeProfileUpdate(armarx::human::arondto::Profile profile, armarx::armem::MemoryID profileID, armarx::armem::client::MemoryNameSystem mns)
Definition: UpdateConsumer.cpp:174
armarx::armem::client::Reader::queryMemoryIDs
QueryResult queryMemoryIDs(const std::vector< MemoryID > &ids, armem::query::DataMode dataMode=armem::query::DataMode::WithData) const
Query a specific set of memory IDs.
Definition: Reader.cpp:290
PersonInstanceUpdater.h
types.h
PoseSegment.h
VisionX::components::person_instance_updater::UpdateConsumer::consumePoseUpdate
void consumePoseUpdate(armarx::armem::human::HumanPose humanPose, armarx::armem::MemoryID poseID, armarx::armem::client::MemoryNameSystem mns)
Definition: UpdateConsumer.cpp:118
armarx::armem::server::human::profile::Profile
armarx::human::arondto::Profile Profile
Definition: Segment.cpp:43
armarx::armem::client::util::MemoryListener::subscribe
SubscriptionHandle subscribe(const MemoryID &subscriptionID, Callback Callback)
Definition: MemoryListener.cpp:116
VisionX::components::person_instance_updater::PersonInstanceUpdater::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PersonInstanceUpdater.cpp:49
armarx::armem::human::HumanPose
Definition: types.h:30
UpdateConsumer.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
aron_conversions.h
Segment.h
armarx::human::ProfileCoreSegmentID
const armem::MemoryID ProfileCoreSegmentID
Definition: memory_ids.cpp:34
IceUtil::Handle< class PropertyDefinitionContainer >
Segment.h
armarx::armem::base::detail::ForEachEntityInstanceMixin::forEachInstance
bool forEachInstance(InstanceFunctionT &&func)
Definition: iteration_mixins.h:146
armarx::fromAron
void fromAron(const arondto::PackagePath &dto, PackageFileLocation &bo)
armarx::human::PoseCoreSegmentID
const armem::MemoryID PoseCoreSegmentID
Definition: memory_ids.cpp:40
MemoryNameSystem.h
VisionX::components::person_instance_updater::PersonInstanceUpdater::getDefaultName
std::string getDefaultName() const override
Definition: PersonInstanceUpdater.cpp:158
armarx::armem::client::MemoryNameSystem::getReader
Reader getReader(const MemoryID &memoryID)
Get a reader to the given memory name.
Definition: MemoryNameSystem.cpp:177
VisionX::components::person_instance_updater::PersonInstanceUpdater::onExitComponent
void onExitComponent() override
Definition: PersonInstanceUpdater.cpp:76
VisionX::components::person_instance_updater::PersonInstanceUpdater::onConnectComponent
void onConnectComponent() override
Definition: PersonInstanceUpdater.cpp:64
VisionX::components::person_instance_updater::PersonInstanceUpdater::GetDefaultName
static std::string GetDefaultName()
Get the component's default name.
Definition: PersonInstanceUpdater.cpp:164