memory_conversions.cpp
Go to the documentation of this file.
1 #include "memory_conversions.h"
2 
3 namespace armarx::armem::wm
4 {
5  void
6  toMemory(Memory& m, const std::vector<CoreSegment>& e)
7  {
8  m.clear();
9  for (const auto& s : e)
10  {
11  m.addCoreSegment(s);
12  }
13  }
14 
15  void
16  toMemory(Memory& m, const std::vector<ProviderSegment>& e)
17  {
18  m.clear();
19  for (const auto& s : e)
20  {
21  if (!m.hasCoreSegment(s.id().coreSegmentName))
22  {
23  m.addCoreSegment(s.id().coreSegmentName);
24  }
25  auto* c = m.findCoreSegment(s.id().coreSegmentName);
26  c->addProviderSegment(s);
27  }
28  }
29 
30  void
31  toMemory(Memory& m, const std::vector<Entity>& e)
32  {
33  m.clear();
34  for (const auto& s : e)
35  {
36  if (!m.hasCoreSegment(s.id().coreSegmentName))
37  {
38  m.addCoreSegment(s.id().coreSegmentName);
39  }
40  auto* c = m.findCoreSegment(s.id().coreSegmentName);
41 
42  if (!c->hasProviderSegment(s.id().providerSegmentName))
43  {
44  c->addProviderSegment(s.id().providerSegmentName);
45  }
46  auto* p = c->findProviderSegment(s.id().providerSegmentName);
47  p->addEntity(s);
48  }
49  }
50 
51  void
52  toMemory(Memory& m, const std::vector<EntitySnapshot>& e)
53  {
54  m.clear();
55 
56  for (const auto& s : e)
57  {
58  if (!m.hasCoreSegment(s.id().coreSegmentName))
59  {
60  m.addCoreSegment(s.id().coreSegmentName);
61  }
62  auto* c = m.findCoreSegment(s.id().coreSegmentName);
63 
64  if (!c->hasProviderSegment(s.id().providerSegmentName))
65  {
66  c->addProviderSegment(s.id().providerSegmentName);
67  }
68  auto* p = c->findProviderSegment(s.id().providerSegmentName);
69 
70  if (!p->hasEntity(s.id().entityName))
71  {
72  p->addEntity(s.id().entityName);
73  }
74  auto* en = p->findEntity(s.id().entityName);
75  en->addSnapshot(s);
76  }
77  }
78 
79  void
80  toMemory(Memory& m, const std::vector<EntityInstance>& e)
81  {
82  m.clear();
83  for (const auto& s : e)
84  {
85  if (!m.hasCoreSegment(s.id().coreSegmentName))
86  {
87  m.addCoreSegment(s.id().coreSegmentName);
88  }
89  auto* c = m.findCoreSegment(s.id().coreSegmentName);
90 
91  if (!c->hasProviderSegment(s.id().providerSegmentName))
92  {
93  c->addProviderSegment(s.id().providerSegmentName);
94  }
95  auto* p = c->findProviderSegment(s.id().providerSegmentName);
96 
97  if (!p->hasEntity(s.id().entityName))
98  {
99  p->addEntity(s.id().entityName);
100  }
101  auto* en = p->findEntity(s.id().entityName);
102 
103  if (!en->hasSnapshot(s.id().timestamp))
104  {
105  en->addSnapshot(s.id().timestamp);
106  }
107  auto* sn = p->findSnapshot(s.id());
108 
109  sn->addInstance(s);
110  }
111  }
112 
113  void toMemory(Memory &m, const armarx::armem::server::wm::Memory &structure, const std::vector<EntitySnapshot> &e)
114  {
115  // create an empty working memory:
116  m.clear();
117 
118  for (const auto& s : e)
119  {
120  //get name of the core segment:
121  auto coreSegmentName = s.id().coreSegmentName;
122  auto* coreStructure = structure.findCoreSegment(coreSegmentName);
123 
124  //if m does not have this core segment yet add the segment but copy the structure from the server wm:
125  if (!m.hasCoreSegment(coreSegmentName))
126  {
127  m.addCoreSegment(coreSegmentName, coreStructure->aronType());
128  }
129  auto* c = m.findCoreSegment(coreSegmentName);
130 
131  //get name of provider segment:
132  auto providerSegmentName = s.id().providerSegmentName;
133  auto* providerStructure = coreStructure->findProviderSegment(providerSegmentName);
134 
135  if (!c->hasProviderSegment(providerSegmentName))
136  {
137  c->addProviderSegment(providerSegmentName, providerStructure->aronType());
138  }
139  auto* p = c->findProviderSegment(providerSegmentName);
140 
141  if (!p->hasEntity(s.id().entityName))
142  {
143  p->addEntity(s.id().entityName);
144  }
145  auto* en = p->findEntity(s.id().entityName);
146  en->addSnapshot(s);
147  }
148  }
149 
150 } // namespace armarx::armem::wm
armarx::armem::base::MemoryBase::findCoreSegment
CoreSegmentT * findCoreSegment(const std::string &name)
Definition: MemoryBase.h:119
memory_conversions.h
armarx::armem::wm::toMemory
void toMemory(Memory &m, const std::vector< CoreSegment > &e)
Definition: memory_conversions.cpp:6
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::armem::base::MemoryBase::hasCoreSegment
bool hasCoreSegment(const std::string &name) const
Definition: MemoryBase.h:105
armarx::armem::wm
Definition: MemoryNameSystem.h:46
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:136
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::base::MemoryBase::addCoreSegment
CoreSegmentT & addCoreSegment(const std::string &name, aron::type::ObjectPtr coreSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty core segment with the given name, type and prediction engines.
Definition: MemoryBase.h:259
armarx::armem::base::detail::MemoryContainerBase::clear
void clear()
Definition: MemoryContainerBase.h:52
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33