PersonInstanceUpdater.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 * @package VisionX::ArmarXObjects::person_instance_updater
17 * @author Philipp Seidel ( uyhvq at student dot kit dot edu )
18 * @author Fabian Reister ( fabian dot reister at kit dot edu )
19 * @date 2023
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24
25#pragma once
26
27
28#include <condition_variable>
29#include <memory>
30#include <mutex>
31#include <optional>
32#include <string>
33#include <thread>
34#include <vector>
35
39
44
46
48{
49
50 /**
51 * @brief Component that fuses face recognition and body pose tracking into unified person instances.
52 *
53 * This component subscribes to memory updates for face recognition and human pose data,
54 * then delegates to UpdateConsumer to match and link these data sources. The goal is to
55 * maintain PersonInstance entities that represent complete information about tracked people,
56 * including their identity (from face recognition) and body pose (from pose tracking).
57 *
58 * @see UpdateConsumer for the core matching and updating logic
59 */
61 virtual public armarx::Component,
63 {
64 public:
65 /// @see armarx::ManagedIceObject::getDefaultName()
66 std::string getDefaultName() const override;
67
68 /// Get the component's default name.
69 static std::string GetDefaultName();
70
71 public:
72 static const std::string provider_name;
73
74 protected:
75 /// @see PropertyUser::createPropertyDefinitions()
77
78 /// @see armarx::ManagedIceObject::onInitComponent()
79 void onInitComponent() override;
80
81 /// @see armarx::ManagedIceObject::onConnectComponent()
82 void onConnectComponent() override;
83
84 /// @see armarx::ManagedIceObject::onDisconnectComponent()
85 void onDisconnectComponent() override;
86
87 /// @see armarx::ManagedIceObject::onExitComponent()
88 void onExitComponent() override;
89
90 private:
91 /**
92 * @brief Registers callbacks for memory updates from FaceRecognition and Pose segments.
93 *
94 * Sets up subscriptions that trigger when new face recognition or pose data arrives,
95 * passing the updates to UpdateConsumer for processing.
96 */
97 void registerMemorySubscriptions();
98
99 /**
100 * @brief Main loop of the single processing thread.
101 *
102 * Waits until the subscription callbacks deposited updated snapshot IDs,
103 * takes them out of the mailboxes and processes them. Runs as fast as the
104 * processing allows; while it is busy, newer updates simply replace the
105 * pending ones (latest wins), so memory updates never accumulate.
106 */
107 void processingLoop();
108
109 /// Query the face recognition data for the given snapshot IDs and feed it to the UpdateConsumer.
110 void processFaceRecognitionUpdates(
111 const std::vector<armarx::armem::MemoryID>& updatedSnapshotIDs);
112
113 /// Query the pose data for the given snapshot IDs and feed it to the UpdateConsumer.
114 void processPoseUpdates(const std::vector<armarx::armem::MemoryID>& updatedSnapshotIDs);
115
116 private:
117 /// Properties shown in the Scenario GUI.
118 struct Properties
119 {
120 UpdateConsumer::Properties updateConsumer;
121
122 /// Max rate [Hz] at which face recognition updates are accepted.
123 /// Values <= 0 disable throttling (default): the processing thread runs as
124 /// fast as possible and unprocessed updates are replaced by newer ones.
125 float faceRecognitionUpdateFrequency = 0.F;
126
127 /// Max rate [Hz] at which pose updates are accepted.
128 /// Values <= 0 disable throttling (default): the processing thread runs as
129 /// fast as possible and unprocessed updates are replaced by newer ones.
130 float poseUpdateFrequency = 0.F;
131 };
132
133 Properties properties;
134
135 /// The main logic handler that performs matching and updating of person instances.
136 std::unique_ptr<UpdateConsumer> updateConsumer;
137
138 /// Per-callback throttlers (constructed on connect from the *Frequency properties).
139 /// Left unset when the corresponding frequency is <= 0 (no throttling).
140 std::optional<armarx::Throttler> faceRecognitionThrottler;
141 std::optional<armarx::Throttler> poseThrottler;
142
143 /// Readers used by the processing thread to fetch the updated data.
144 std::optional<armarx::armem::client::Reader> faceRecognitionReader;
145 std::optional<armarx::armem::client::Reader> poseReader;
146
147 /// Single processing thread decoupling the (Ice) subscription callbacks from
148 /// the actual processing. Callbacks only deposit the updated snapshot IDs in
149 /// the mailboxes below; this thread consumes them as fast as possible.
150 std::thread processingThread;
151 std::mutex pendingMutex;
152 std::condition_variable pendingCondition;
153 bool stopProcessing = false;
154 /// Latest-wins mailboxes: newer updates replace unprocessed ones.
155 std::vector<armarx::armem::MemoryID> pendingFaceRecognitionIDs;
156 std::vector<armarx::armem::MemoryID> pendingPoseIDs;
157
158 /// Handles for all memory subscriptions, so they can be unsubscribed on disconnect.
159 std::vector<armarx::armem::client::util::SubscriptionHandle> subscriptionHandles;
160 };
161
162} // namespace VisionX::components::person_instance_updater
Component that fuses face recognition and body pose tracking into unified person instances.
static std::string GetDefaultName()
Get the component's default name.
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
client::plugins::ListeningPluginUser ListeningClientPluginUser
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.