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 
41  Base(iceMemory,
42  CORE_SEGMENT_NAME,
43  armarx::human::arondto::FaceRecognition::ToAronType(),
44  64)
45  {
46  }
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 
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 
76  rainer.memoryName = "Human";
77  rainer.coreSegmentName = "Profile";
78  rainer.providerSegmentName = "jubot_long_term_memory_data";
79  rainer.entityName = "rainer-kartmann";
80  {
81  FaceRecognition fr;
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  {
90  FaceRecognition fr;
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  {
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 
131  armarx::armem::human::FaceRecognition bo;
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 
147  Segment::getFaceRecognition(armarx::armem::MemoryID memoryID) const
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
armarx::armem::base::detail::MemoryContainerBase::empty
bool empty() const
Definition: MemoryContainerBase.h:44
armarx::human::FaceRecognitionCoreSegmentID
const armem::MemoryID FaceRecognitionCoreSegmentID
Definition: memory_ids.cpp:31
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::armem::base::detail::GetLatestSnapshotMixin::getLatestSnapshot
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
Definition: lookup_mixins.h:199
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::human::FaceRecognition
Definition: types.h:59
armarx::FaceRecognition
Brief description of class FaceRecognition.
Definition: FaceRecognition.h:68
armarx::armem::server::human::facerecog::Segment::CORE_SEGMENT_NAME
static const std::string CORE_SEGMENT_NAME
Definition: Segment.h:38
armarx::armem::server::human::facerecog::Segment::init
void init() override
Definition: Segment.cpp:58
armarx::armem::base::ProviderSegmentBase::name
std::string & name()
Definition: ProviderSegmentBase.h:95
memory_ids.h
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::armem::MemoryID::coreSegmentName
std::string coreSegmentName
Definition: MemoryID.h:51
armarx::armem::server::human::facerecog
Definition: Segment.cpp:34
armarx::armem::server::human::facerecog::Segment::Properties::loadDummyEntries
bool loadDummyEntries
Definition: Segment.h:57
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::segmentPtr
server::wm::CoreSegment * segmentPtr
Definition: SpecializedSegment.h:54
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:412
types.h
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::server::segment::SpecializedCoreSegment::getCoreSegment
wm::CoreSegment & getCoreSegment()
Definition: SpecializedCoreSegment.cpp:93
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >
armarx::armem::server::segment::SpecializedCoreSegment::init
virtual void init() override
Definition: SpecializedCoreSegment.cpp:49
armarx::armem::base::CoreSegmentBase::forEachProviderSegment
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
Definition: CoreSegmentBase.h:217
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::human::facerecog::Segment::properties
Properties properties
Definition: Segment.h:60
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:120
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
MemoryToIceAdapter.h
armarx::armem::MemoryID::memoryName
std::string memoryName
Definition: MemoryID.h:50
armarx::armem::server::human::facerecog::Segment::getFaceRecognitionEntities
std::map< std::string, std::vector< armarx::armem::human::FaceRecognition > > getFaceRecognitionEntities(const Duration &maxAge) const
Definition: Segment.cpp:102
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::fromAron
void fromAron(const arondto::MemoryID &dto, MemoryID &bo)
Definition: aron_conversions.cpp:8
armarx::armem::server::human::facerecog::Segment::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: Segment.cpp:49
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:420
armarx::armem::Commit::add
EntityUpdate & add()
Definition: Commit.cpp:81
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::iceMemory
MemoryToIceAdapter & iceMemory
Definition: SpecializedSegment.h:60
PropertyDefinitionContainer.h
aron_conversions.h
armarx::armem::base::ProviderSegmentBase::forEachEntity
bool forEachEntity(EntityFunctionT &&func)
Definition: ProviderSegmentBase.h:189
Segment.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:97
armarx::armem::server::human::facerecog::Segment::Segment
Segment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: Segment.cpp:40
armarx::armem::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129
armarx::armem::server::segment::SpecializedCoreSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: SpecializedCoreSegment.cpp:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::armem::server::MemoryToIceAdapter::commit
data::CommitResult commit(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:115
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29