EnvironmentalPrimitiveSegment.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 MemoryX::WorkingMemory
17 * @author Peter Kaiser (peter dot kaiser at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
24 
25 namespace memoryx
26 {
29  EnvironmentalPrimitiveSegmentBase::EnvironmentalPrimitiveSegmentBase()
30  {
31 
32  }
33 
34  EnvironmentalPrimitiveBaseList EnvironmentalPrimitiveSegment::getEnvironmentalPrimitives(const ::Ice::Current& c) const
35  {
36  EnvironmentalPrimitiveBaseList primitives;
37 
38  for (auto& id : getAllEntityIds(c))
39  {
40  EnvironmentalPrimitiveBasePtr primitive = EnvironmentalPrimitiveBasePtr::dynamicCast(getEntityById(id, c));
41 
42  if (primitive)
43  {
44  primitives.push_back(primitive);
45  }
46  }
47 
48  return primitives;
49  }
50 
51  PlanePrimitiveBaseList EnvironmentalPrimitiveSegment::getPlanes(const Ice::Current& c) const
52  {
53  PlanePrimitiveBaseList primitives;
54 
55  for (auto& id : getAllEntityIds(c))
56  {
57  EntityBasePtr primitive = getEntityById(id, c);
58 
59  if (primitive->ice_isA(PlanePrimitiveBase::ice_staticId()))
60  {
61  primitives.push_back(PlanePrimitiveBasePtr::dynamicCast(primitive));
62  }
63  }
64 
65  return primitives;
66  }
67 
68  SpherePrimitiveBaseList EnvironmentalPrimitiveSegment::getSpheres(const Ice::Current& c) const
69  {
70  SpherePrimitiveBaseList primitives;
71 
72  for (auto& id : getAllEntityIds(c))
73  {
74  EntityBasePtr primitive = getEntityById(id, c);
75 
76  if (primitive->ice_isA(SpherePrimitiveBase::ice_staticId()))
77  {
78  primitives.push_back(SpherePrimitiveBasePtr::dynamicCast(primitive));
79  }
80  }
81 
82  return primitives;
83  }
84 
85  CylinderPrimitiveBaseList EnvironmentalPrimitiveSegment::getCylinders(const Ice::Current& c) const
86  {
87  CylinderPrimitiveBaseList primitives;
88 
89  for (auto& id : getAllEntityIds(c))
90  {
91  EntityBasePtr primitive = getEntityById(id, c);
92 
93  if (primitive->ice_isA(CylinderPrimitiveBase::ice_staticId()))
94  {
95  primitives.push_back(CylinderPrimitiveBasePtr::dynamicCast(primitive));
96  }
97  }
98 
99  return primitives;
100  }
101 
102 
103  BoxPrimitiveBaseList EnvironmentalPrimitiveSegment::getBoxes(const Ice::Current& c) const
104  {
105  BoxPrimitiveBaseList primitives;
106 
107  for (auto& id : getAllEntityIds(c))
108  {
109  EntityBasePtr primitive = getEntityById(id, c);
110 
111  if (primitive->ice_isA(BoxPrimitiveBase::ice_staticId()))
112  {
113  primitives.push_back(BoxPrimitiveBasePtr::dynamicCast(primitive));
114  }
115  }
116 
117  return primitives;
118  }
119 
120  EnvironmentalPrimitiveBasePtr EnvironmentalPrimitiveSegment::getEnvironmentalPrimitiveById(const std::string& id, const Ice::Current& c) const
121  {
122  return EnvironmentalPrimitiveBasePtr::dynamicCast(getEntityById(id, c));
123  }
124 
125  PlanePrimitiveBasePtr EnvironmentalPrimitiveSegment::getPlaneById(const std::string& id, const Ice::Current& c) const
126  {
127  EntityBasePtr primitive = getEntityById(id, c);
128 
129  if (primitive->ice_isA(PlanePrimitiveBase::ice_staticId()))
130  {
131  return PlanePrimitiveBasePtr::dynamicCast(primitive);
132  }
133  else
134  {
135  return PlanePrimitiveBasePtr();
136  }
137  }
138 
139  SpherePrimitiveBasePtr EnvironmentalPrimitiveSegment::getSphereById(const std::string& id, const Ice::Current& c) const
140  {
141  EntityBasePtr primitive = getEntityById(id, c);
142 
143  if (primitive->ice_isA(SpherePrimitiveBase::ice_staticId()))
144  {
145  return SpherePrimitiveBasePtr::dynamicCast(primitive);
146  }
147  else
148  {
149  return SpherePrimitiveBasePtr();
150  }
151  }
152 
153  CylinderPrimitiveBasePtr EnvironmentalPrimitiveSegment::getCylinderById(const std::string& id, const Ice::Current& c) const
154  {
155  EntityBasePtr primitive = getEntityById(id, c);
156 
157  if (primitive->ice_isA(CylinderPrimitiveBase::ice_staticId()))
158  {
159  return CylinderPrimitiveBasePtr::dynamicCast(primitive);
160  }
161  else
162  {
163  return CylinderPrimitiveBasePtr();
164  }
165  }
166 
167  BoxPrimitiveBasePtr EnvironmentalPrimitiveSegment::getBoxById(const std::string& id, const Ice::Current&) const
168  {
169  EntityBasePtr primitive = getEntityById(id);
170 
171  if (primitive->ice_isA(BoxPrimitiveBase::ice_staticId()))
172  {
173  return BoxPrimitiveBasePtr::dynamicCast(primitive);
174  }
175  else
176  {
177  return BoxPrimitiveBasePtr();
178  }
179  }
180 
181  EnvironmentalPrimitiveBaseList EnvironmentalPrimitiveSegment::getEnvironmentalPrimitivesByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c) const
182  {
183  EnvironmentalPrimitiveBaseList result;
184 
185  for (auto& id : getAllEntityIds(c))
186  {
187  EnvironmentalPrimitiveBasePtr primitive = getEnvironmentalPrimitiveById(id, c);
188 
189  if (primitive->getTime(c)->timestamp == timestamp->timestamp)
190  {
191  result.push_back(primitive);
192  }
193  }
194 
195  return result;
196  }
197 
198  PlanePrimitiveBaseList EnvironmentalPrimitiveSegment::getPlanesByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c) const
199  {
200  PlanePrimitiveBaseList result;
201 
202  for (auto& id : getAllEntityIds(c))
203  {
204  EnvironmentalPrimitiveBasePtr primitive = getEnvironmentalPrimitiveById(id, c);
205 
206  if (primitive->ice_isA(PlanePrimitiveBase::ice_staticId()) && primitive->getTime(c)->timestamp == timestamp->timestamp)
207  {
208  result.push_back(PlanePrimitiveBasePtr::dynamicCast(primitive));
209  }
210  }
211 
212  return result;
213  }
214 
215  SpherePrimitiveBaseList EnvironmentalPrimitiveSegment::getSpheresByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c) const
216  {
217  SpherePrimitiveBaseList result;
218 
219  for (auto& id : getAllEntityIds(c))
220  {
221  EnvironmentalPrimitiveBasePtr primitive = getEnvironmentalPrimitiveById(id, c);
222 
223  if (primitive->ice_isA(SpherePrimitiveBase::ice_staticId()) && primitive->getTime(c)->timestamp == timestamp->timestamp)
224  {
225  result.push_back(SpherePrimitiveBasePtr::dynamicCast(primitive));
226  }
227  }
228 
229  return result;
230  }
231 
232  CylinderPrimitiveBaseList EnvironmentalPrimitiveSegment::getCylindersByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c) const
233  {
234  CylinderPrimitiveBaseList result;
235 
236  for (auto& id : getAllEntityIds(c))
237  {
238  EnvironmentalPrimitiveBasePtr primitive = getEnvironmentalPrimitiveById(id, c);
239 
240  if (primitive->ice_isA(CylinderPrimitiveBase::ice_staticId()) && primitive->getTime(c)->timestamp == timestamp->timestamp)
241  {
242  result.push_back(CylinderPrimitiveBasePtr::dynamicCast(primitive));
243  }
244  }
245 
246  return result;
247  }
248 
249  BoxPrimitiveBaseList EnvironmentalPrimitiveSegment::getBoxesByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c) const
250  {
251  BoxPrimitiveBaseList result;
252 
253  for (auto& id : getAllEntityIds(c))
254  {
255  EnvironmentalPrimitiveBasePtr primitive = getEnvironmentalPrimitiveById(id, c);
256 
257  if (primitive->ice_isA(BoxPrimitiveBase::ice_staticId()) && primitive->getTime(c)->timestamp == timestamp->timestamp)
258  {
259  result.push_back(BoxPrimitiveBasePtr::dynamicCast(primitive));
260  }
261  }
262 
263  return result;
264  }
265 
266  EnvironmentalPrimitiveBaseList EnvironmentalPrimitiveSegment::getMostRecentEnvironmentalPrimitives(const Ice::Current& c) const
267  {
268  EnvironmentalPrimitiveBaseList primitives = getEnvironmentalPrimitives(c);
269  Ice::Long timestamp = getMostRecentTimestamp<EnvironmentalPrimitiveBasePtr>(primitives, c);
270 
271  EnvironmentalPrimitiveBaseList result;
272  for (auto& p : primitives)
273  {
274  if (p->getTime()->timestamp == timestamp)
275  {
276  result.push_back(p);
277  }
278  }
279 
280  return result;
281  }
282 
283  PlanePrimitiveBaseList EnvironmentalPrimitiveSegment::getMostRecentPlanes(const Ice::Current& c) const
284  {
285  PlanePrimitiveBaseList primitives = getPlanes(c);
286  Ice::Long timestamp = getMostRecentTimestamp<PlanePrimitiveBasePtr>(primitives, c);
287 
288  PlanePrimitiveBaseList result;
289  for (auto& p : primitives)
290  {
291  if (p->getTime()->timestamp == timestamp)
292  {
293  result.push_back(p);
294  }
295  }
296 
297  return result;
298  }
299 
300  SpherePrimitiveBaseList EnvironmentalPrimitiveSegment::getMostRecentSpheres(const Ice::Current& c) const
301  {
302  SpherePrimitiveBaseList primitives = getSpheres(c);
303  Ice::Long timestamp = getMostRecentTimestamp<SpherePrimitiveBasePtr>(primitives, c);
304 
305  SpherePrimitiveBaseList result;
306  for (auto& p : primitives)
307  {
308  if (p->getTime()->timestamp == timestamp)
309  {
310  result.push_back(p);
311  }
312  }
313 
314  return result;
315  }
316 
317  CylinderPrimitiveBaseList EnvironmentalPrimitiveSegment::getMostRecentCylinders(const Ice::Current& c) const
318  {
319  CylinderPrimitiveBaseList primitives = getCylinders(c);
320  Ice::Long timestamp = getMostRecentTimestamp<CylinderPrimitiveBasePtr>(primitives, c);
321 
322  CylinderPrimitiveBaseList result;
323  for (auto& p : primitives)
324  {
325  if (p->getTime()->timestamp == timestamp)
326  {
327  result.push_back(p);
328  }
329  }
330 
331  return result;
332  }
333 
334  BoxPrimitiveBaseList EnvironmentalPrimitiveSegment::getMostRecentBoxes(const Ice::Current& c) const
335  {
336  BoxPrimitiveBaseList primitives = getBoxes(c);
337  Ice::Long timestamp = getMostRecentTimestamp<BoxPrimitiveBasePtr>(primitives, c);
338 
339  BoxPrimitiveBaseList result;
340  for (auto& p : primitives)
341  {
342  if (p->getTime()->timestamp == timestamp)
343  {
344  result.push_back(p);
345  }
346  }
347 
348  return result;
349  }
350 
351  void EnvironmentalPrimitiveSegment::removePrimitivesByTimestamp(const armarx::TimestampBasePtr& timestamp, const Ice::Current& c)
352  {
353  EnvironmentalPrimitiveBaseList primitives = getEnvironmentalPrimitives(c);
354 
355  for (auto& p : primitives)
356  {
357  if (p->getTime()->timestamp == timestamp)
358  {
359  removeEntity(p->getId(), c);
360  }
361  }
362  }
363 
364  void EnvironmentalPrimitiveSegment::removeOlderPrimitives(const armarx::TimestampBasePtr& olderThan, const Ice::Current& c)
365  {
366  EnvironmentalPrimitiveBaseList primitives = getEnvironmentalPrimitives(c);
367 
368  for (auto& p : primitives)
369  {
370  if (p->getTime()->timestamp < olderThan)
371  {
372  removeEntity(p->getId(), c);
373  }
374  }
375  }
376 }
377 
memoryx::EnvironmentalPrimitiveSegment::getEnvironmentalPrimitivesByTimestamp
EnvironmentalPrimitiveBaseList getEnvironmentalPrimitivesByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:181
memoryx::EnvironmentalPrimitiveSegment::getPlanes
PlanePrimitiveBaseList getPlanes(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:51
memoryx::EnvironmentalPrimitiveSegment::getPlanesByTimestamp
PlanePrimitiveBaseList getPlanesByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:198
memoryx::EnvironmentalPrimitiveSegment::getSpheres
SpherePrimitiveBaseList getSpheres(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:68
memoryx::EnvironmentalPrimitiveSegment::getMostRecentBoxes
BoxPrimitiveBaseList getMostRecentBoxes(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:334
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::EnvironmentalPrimitiveSegment::getSpheresByTimestamp
SpherePrimitiveBaseList getSpheresByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:215
EnvironmentalPrimitiveSegment.h
memoryx::EnvironmentalPrimitiveSegment::getMostRecentPlanes
PlanePrimitiveBaseList getMostRecentPlanes(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:283
memoryx::EnvironmentalPrimitiveSegment::getMostRecentCylinders
CylinderPrimitiveBaseList getMostRecentCylinders(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:317
memoryx::WorkingMemoryEntitySegment< EnvironmentalPrimitive >::getAllEntityIds
EntityIdList getAllEntityIds(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: WorkingMemoryEntitySegment.h:573
memoryx::EnvironmentalPrimitive
Definition: EnvironmentalPrimitive.h:51
memoryx::EnvironmentalPrimitiveSegment::getMostRecentSpheres
SpherePrimitiveBaseList getMostRecentSpheres(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:300
memoryx::WorkingMemoryEntitySegment
Definition: WorkingMemoryEntitySegment.h:44
memoryx::EnvironmentalPrimitiveSegment::getMostRecentEnvironmentalPrimitives
EnvironmentalPrimitiveBaseList getMostRecentEnvironmentalPrimitives(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:266
memoryx::EnvironmentalPrimitiveSegment::getCylindersByTimestamp
CylinderPrimitiveBaseList getCylindersByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:232
memoryx::WorkingMemoryEntitySegment< EnvironmentalPrimitive >::removeEntity
void removeEntity(const ::std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: WorkingMemoryEntitySegment.h:312
memoryx::EnvironmentalPrimitiveSegment::getCylinders
CylinderPrimitiveBaseList getCylinders(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:85
memoryx::EnvironmentalPrimitiveSegment::removePrimitivesByTimestamp
void removePrimitivesByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: EnvironmentalPrimitiveSegment.cpp:351
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
memoryx::EnvironmentalPrimitiveSegment::getEnvironmentalPrimitives
EnvironmentalPrimitiveBaseList getEnvironmentalPrimitives(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:34
memoryx::EnvironmentalPrimitiveSegment::getCylinderById
CylinderPrimitiveBasePtr getCylinderById(const std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:153
memoryx::EnvironmentalPrimitiveSegment::getEnvironmentalPrimitiveById
EnvironmentalPrimitiveBasePtr getEnvironmentalPrimitiveById(const std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:120
memoryx::EnvironmentalPrimitiveSegment::getBoxById
BoxPrimitiveBasePtr getBoxById(const std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:167
memoryx::EnvironmentalPrimitiveSegment::getPlaneById
PlanePrimitiveBasePtr getPlaneById(const std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:125
memoryx::EnvironmentalPrimitiveSegment::getBoxesByTimestamp
BoxPrimitiveBaseList getBoxesByTimestamp(const armarx::TimestampBasePtr &timestamp, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:249
memoryx::EnvironmentalPrimitiveSegment::EnvironmentalPrimitiveSegment
EnvironmentalPrimitiveSegment()
Definition: EnvironmentalPrimitiveSegment.cpp:27
memoryx::EnvironmentalPrimitiveSegment::getSphereById
SpherePrimitiveBasePtr getSphereById(const std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:139
memoryx::WorkingMemoryEntitySegment< EnvironmentalPrimitive >::getEntityById
EntityBasePtr getEntityById(const ::std::string &id) const
Definition: WorkingMemoryEntitySegment.h:427
memoryx::EnvironmentalPrimitiveSegment::getBoxes
BoxPrimitiveBaseList getBoxes(const ::Ice::Current &c=Ice::emptyCurrent) const override
Definition: EnvironmentalPrimitiveSegment.cpp:103
memoryx::EnvironmentalPrimitiveSegment::removeOlderPrimitives
void removeOlderPrimitives(const armarx::TimestampBasePtr &olderThan, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: EnvironmentalPrimitiveSegment.cpp:364