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/Profile.aron.generated.h>
32 
33 #include "Finder.h"
34 
35 
36 namespace fs = std::filesystem;
37 
39 {
40  const std::string Segment::CORE_SEGMENT_NAME =
42 
45 
47  Base(iceMemory, CORE_SEGMENT_NAME, armarx::human::arondto::Profile::ToAronType(), 64)
48  {
49  }
50 
51  Segment::Properties::PriorKnowledge::PriorKnowledge() : packageName(Finder::DefaultPackageName)
52  {
53  }
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  }
66 
67  void
69  {
70  Base::init();
72  {
74  }
75  }
76 
77  void
79  {
81  }
82 
83  void
84  Segment::loadPriorKnowledge(const std::string& dataPackageName)
85  {
86  const armem::Time now = armem::Time::Now();
87 
88  Finder finder(dataPackageName);
89  const std::vector<Info> infos = finder.findAll();
90 
91  ARMARX_INFO << "Loading " << infos.size() << " human profiles ...";
92  armem::Commit commit;
93  for (const Info& info : infos)
94  {
95  if (std::optional<Profile> profile = info.loadProfile())
96  {
97  armem::EntityUpdate& update = commit.add();
98  update.entityID = getCoreSegment()
99  .id()
100  .withProviderSegmentName(dataPackageName)
101  .withEntityName(info.id());
102  update.referencedTime = update.sentTime = update.arrivedTime = now;
103  update.instancesData = {profile->toAron()};
104  }
105  }
106 
107  if (commit.updates.size() > 0)
108  {
109  iceMemory.commit(commit);
110  }
111  }
112 
113 } // namespace armarx::armem::server::human::profile
armarx::armem::server::human::profile::Segment::Segment
Segment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: Segment.cpp:46
Finder.h
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
Info.h
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::server::human::profile::Finder
Used to find human profiles in the Prior Knowledge Data repository [1].
Definition: Finder.h:19
memory_ids.h
armarx::armem::server::human::profile::Segment::CORE_SEGMENT_NAME
static const std::string CORE_SEGMENT_NAME
Definition: Segment.h:37
armarx::armem::server::human::profile::Segment::Properties::PriorKnowledge::PriorKnowledge
PriorKnowledge()
Definition: Segment.cpp:51
armarx::armem::MemoryID::coreSegmentName
std::string coreSegmentName
Definition: MemoryID.h:51
armarx::armem::server::human::profile
Definition: Finder.cpp:13
armarx::armem::server::human::profile::Segment::init
void init() override
Definition: Segment.cpp:68
armarx::armem::Commit::updates
std::vector< EntityUpdate > updates
The entity updates.
Definition: Commit.h:97
armarx::armem::server::human::profile::Segment::properties
Properties properties
Definition: Segment.h:63
armarx::armem::server::human::profile::Segment::Properties::PriorKnowledge::packageName
std::string packageName
Definition: Segment.h:59
armarx::armem::MemoryID::withProviderSegmentName
MemoryID withProviderSegmentName(const std::string &name) const
Definition: MemoryID.cpp:412
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::server::human::profile::Profile
armarx::human::arondto::Profile Profile
Definition: Segment.cpp:43
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::server::human::profile::Segment::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: Segment.cpp:56
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
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::server::human::profile::Finder::findAll
std::vector< Info > findAll(bool checkPaths=true) const
Definition: Finder.cpp:87
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
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
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
PropertyDefinitionContainer.h
armarx::human::ProfileCoreSegmentID
const armem::MemoryID ProfileCoreSegmentID
Definition: memory_ids.cpp:34
IceUtil::Handle< class PropertyDefinitionContainer >
Segment.h
armarx::armem::server::human::profile::Segment::loadPriorKnowledge
void loadPriorKnowledge()
Definition: Segment.cpp:78
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:112
armarx::armem::server::human::profile::Finder::DefaultPackageName
static const std::string DefaultPackageName
Definition: Finder.h:25
armarx::armem::human::Info
Accessor for human profile files.
Definition: Info.h:20
armarx::armem::server::human::profile::Segment::Properties::priorKnowledge
PriorKnowledge priorKnowledge
Definition: Segment.h:61
armarx::armem::server::human::profile::Segment::Properties::PriorKnowledge::load
bool load
Definition: Segment.h:58