PersonInstanceSegment.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 "PersonInstanceSegment.h"
24 
27 
28 #include <VisionX/libraries/armem_human/aron/PersonInstance.aron.generated.h>
32 
34 {
35 
38 
40  Base(iceMemory, CORE_SEGMENT_NAME, armarx::human::arondto::PersonInstance::ToAronType(), 32)
41  {
42  }
43 
44  void
46  const std::string& prefix)
47  {
48  Base::defineProperties(defs, prefix);
49  }
50 
51  std::map<std::string, std::vector<armarx::armem::human::PersonInstance>>
53  {
54  std::map<std::string, std::vector<armarx::armem::human::PersonInstance>> personInstanceMap;
55 
56  const auto now = armarx::Clock::Now();
57 
58 
59  return segmentPtr->doLocked(
60  [&]
61  {
63  [&](const wm::ProviderSegment& provSegment)
64  {
65  personInstanceMap[provSegment.name()] = {};
66 
67  provSegment.forEachEntity(
68  [&](const wm::Entity& entity)
69  {
70  if (entity.empty())
71  {
72  return;
73  }
74  entity.getLatestSnapshot().forEachInstance(
75  [&](const wm::EntityInstance& instance)
76  {
77  armarx::human::arondto::PersonInstance dto;
78  dto.fromAron(instance.data());
79 
80 
81  armarx::armem::human::PersonInstance bo;
82  armarx::armem::human::fromAron(dto, bo);
83 
84  if ((now - instance.metadata().referencedTime) < maxAge)
85  {
86  personInstanceMap[provSegment.name()].push_back(bo);
87  }
88  });
89  });
90  });
91 
92  return personInstanceMap;
93  });
94  }
95 
96 } // namespace armarx::armem::server::human
armarx::armem::base::detail::MemoryContainerBase::empty
bool empty() const
Definition: MemoryContainerBase.h:44
armarx::armem::server::human::PersonInstanceSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: PersonInstanceSegment.cpp:45
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::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
Clock.h
armarx::armem::server::human::PersonInstanceSegment::getPersonInstanceEntities
std::map< std::string, std::vector< armarx::armem::human::PersonInstance > > getPersonInstanceEntities(const Duration &maxAge) const
Definition: PersonInstanceSegment.cpp:52
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >::segmentPtr
server::wm::CoreSegment * segmentPtr
Definition: SpecializedSegment.h:54
types.h
armarx::armem::server::segment::detail::SegmentBase< server::wm::CoreSegment >
armarx::armem::base::CoreSegmentBase::forEachProviderSegment
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
Definition: CoreSegmentBase.h:217
PersonInstanceSegment.h
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:120
armarx::human::PersonInstanceCoreSegmentID
const armem::MemoryID PersonInstanceCoreSegmentID
Definition: memory_ids.cpp:37
armarx::armem::server::human
Definition: aron_conversions.cpp:11
armarx::armem::server::human::PersonInstanceSegment::PersonInstanceSegment
PersonInstanceSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: PersonInstanceSegment.cpp:39
PropertyDefinitionContainer.h
aron_conversions.h
armarx::armem::base::ProviderSegmentBase::forEachEntity
bool forEachEntity(EntityFunctionT &&func)
Definition: ProviderSegmentBase.h:189
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::armem::server::human::PersonInstanceSegment::CORE_SEGMENT_NAME
static const std::string CORE_SEGMENT_NAME
Definition: PersonInstanceSegment.h:47
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:97
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