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
30#include <VisionX/libraries/armem_human/aron/Person.aron.generated.h>
32
33#include "Finder.h"
34
35
36namespace fs = std::filesystem;
37
39{
40 const std::string Segment::CORE_SEGMENT_NAME =
42
43 using Person = armarx::human::arondto::Person;
45
50
54
55 void
57 {
58 Base::defineProperties(defs, prefix);
59 defs->optional(properties.priorKnowledge.load,
60 prefix + "pk.load",
61 "Load profiles from prior knowledge on startup.");
62 defs->optional(properties.priorKnowledge.packageName,
63 prefix + "pk.packageName",
64 "ArmarX package to load human profiles from.");
65 defs->optional(
66 properties.priorKnowledge.loadFaceImages,
67 prefix + "pk.loadFaceImages",
68 "Load face images of the people described in the prior knowledge profiles on startup.");
69 }
70
71 void
73 {
74 Base::init();
75 if (properties.priorKnowledge.load)
76 {
77 loadPriorKnowledge(properties.priorKnowledge.packageName,
78 properties.priorKnowledge.loadFaceImages);
79 }
80 }
81
82 void
87
88 void
89 Segment::loadPriorKnowledge(const std::string& dataPackageName, const bool loadFaceImages)
90 {
91 const armem::Time now = armem::Time::Now();
92
93 Finder finder(dataPackageName);
94 const std::vector<Info> infos = finder.findAll();
95
96 ARMARX_INFO << "Loading " << infos.size() << " human profiles ...";
97 armem::Commit commit;
98 for (const Info& info : infos)
99 {
100 if (std::optional<Person> profile = info.loadProfile(loadFaceImages))
101 {
102 armem::EntityUpdate& update = commit.add();
103 update.entityID = getCoreSegment()
104 .id()
105 .withProviderSegmentName(dataPackageName)
106 .withEntityName(info.id());
107 update.referencedTime = update.sentTime = update.arrivedTime = now;
108 update.instancesData = {profile->toAron()};
109 }
110 }
111
112 if (commit.updates.size() > 0)
113 {
114 iceMemory.commit(commit);
115 }
116 }
117
118} // namespace armarx::armem::server::human::profile
std::string coreSegmentName
Definition MemoryID.h:51
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
Accessor for human profile files.
Definition Info.h:20
Helps connecting a Memory server to the Ice interface.
Used to find human profiles in the Prior Knowledge Data repository [1].
Definition Finder.h:20
static const std::string DefaultPackageName
Definition Finder.h:25
std::vector< Info > findAll(bool checkPaths=true) const
Definition Finder.cpp:87
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition Segment.cpp:56
static const std::string CORE_SEGMENT_NAME
Definition Segment.h:35
Segment(armem::server::MemoryToIceAdapter &iceMemory)
Definition Segment.cpp:46
armem::server::segment::SpecializedCoreSegment Base
Definition Segment.h:34
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
armarx::armem::human::Info Info
Definition Segment.cpp:44
armarx::human::arondto::Person Person
Definition Segment.cpp:43
armarx::core::time::DateTime Time
const armem::MemoryID ProfileCoreSegmentID
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
std::vector< EntityUpdate > updates
The entity updates.
Definition Commit.h:97
An update of an entity for a specific point in time.
Definition Commit.h:26