Segment.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::armem_images_server
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "Segment.h"
24
26
28
29#include <VisionX/libraries/armem_human/aron/FaceRecognition.aron.generated.h>
33
35{
36
37 const std::string Segment::CORE_SEGMENT_NAME =
39
47
48 void
50 {
51 Base::defineProperties(defs, prefix);
52 defs->optional(properties.loadDummyEntries,
53 prefix + "loadDummyEntries",
54 "Initialise FaceRecognition segment with some dummy entries.");
55 }
56
57 void
59 {
60 Base::init();
61
62 if (properties.loadDummyEntries)
63 {
64 loadDummyEntries();
65 }
66 }
67
68 void
69 Segment::loadDummyEntries()
70 {
71 armem::Commit commit;
72 const armem::Time now = armem::Time::Now();
73 using armarx::human::arondto::FaceRecognition;
74
75 armarx::armem::arondto::MemoryID rainer;
76 rainer.memoryName = "Human";
77 rainer.coreSegmentName = "Profile";
78 rainer.providerSegmentName = "jubot_long_term_memory_data";
79 rainer.entityName = "rainer-kartmann";
80 {
82 fr.profileID = rainer;
83 armem::EntityUpdate& update = commit.add();
84 update.entityID =
86 update.referencedTime = update.sentTime = update.arrivedTime = now;
87 update.instancesData = {fr.toAron()};
88 }
89 {
91 armem::EntityUpdate& update = commit.add();
92 update.entityID =
94 update.referencedTime = update.sentTime = update.arrivedTime = now;
95 update.instancesData = {fr.toAron()};
96 }
97
98 iceMemory.commit(commit);
99 }
100
101 std::map<std::string, std::vector<armarx::armem::human::FaceRecognition>>
103 {
104 std::map<std::string, std::vector<armarx::armem::human::FaceRecognition>>
105 faceRecognitionMap;
106
107 const auto now = armarx::Clock::Now();
108
109 return segmentPtr->doLocked(
110 [&]
111 {
112 segmentPtr->forEachProviderSegment(
113 [&](const wm::ProviderSegment& provSegment)
114 {
115 faceRecognitionMap[provSegment.name()] = {};
116
117 provSegment.forEachEntity(
118 [&](const wm::Entity& entity)
119 {
120 if (entity.empty())
121 {
122 return;
123 }
124 entity.getLatestSnapshot().forEachInstance(
125 [&](const wm::EntityInstance& instance)
126 {
127 armarx::human::arondto::FaceRecognition dto;
128 dto.fromAron(instance.data());
129
130
132 fromAron(dto, bo);
133
134 if ((now - instance.metadata().referencedTime) < maxAge)
135 {
136 faceRecognitionMap[provSegment.name()].push_back(bo);
137 }
138 });
139 });
140 });
141
142 return faceRecognitionMap;
143 });
144 }
145
148 {
149 wm::EntityInstance* instance = segmentPtr->findInstance(memoryID);
151 armarx::human::arondto::FaceRecognition dto;
152 dto.fromAron(instance->data());
153 fromAron(dto, faceReco);
154 return faceReco;
155 }
156
157} // namespace armarx::armem::server::human::facerecog
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
Brief description of class FaceRecognition.
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
Helps connecting a Memory server to the Ice interface.
data::CommitResult commit(const data::Commit &commitIce, Time timeArrived)
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition Segment.cpp:49
static const std::string CORE_SEGMENT_NAME
Definition Segment.h:38
Segment(armem::server::MemoryToIceAdapter &iceMemory)
Definition Segment.cpp:40
armem::server::segment::SpecializedCoreSegment Base
Definition Segment.h:37
armarx::armem::human::FaceRecognition getFaceRecognition(armarx::armem::MemoryID memoryID) const
Definition Segment.cpp:147
std::map< std::string, std::vector< armarx::armem::human::FaceRecognition > > getFaceRecognitionEntities(const Duration &maxAge) const
Definition Segment.cpp:102
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
static DateTime Now()
Definition DateTime.cpp:51
armem::wm::EntityInstance EntityInstance
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
armarx::core::time::DateTime Time
armarx::core::time::Duration Duration
const armem::MemoryID FaceRecognitionCoreSegmentID
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
An update of an entity for a specific point in time.
Definition Commit.h:26
Time referencedTime
Time this instance refers to.
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.