FeaturesDataBase.cpp
Go to the documentation of this file.
2 
3 #include <boost/foreach.hpp>
4 
5 #include <ros/ros.h>
6 
7 using namespace omip;
8 
10  _time(0)
11 {
12 
13 }
14 
16 {
17 
18 }
19 
21  Feature::Location f_loc)
22 {
23  MapOfFeatures::iterator feat_it = this->_map_of_features.find(f_id);
24  if (feat_it == this->_map_of_features.end())
25  {
26  // This is a new feature
27  Feature::Ptr new_feature = Feature::Ptr(
28  new Feature(this->_time, f_loc, f_id));
29  this->_map_of_features[f_id] = new_feature;
30  this->_alive_feat_ids.push_back(new_feature->getId());
31  return true;
32  }
33  else
34  {
35  // This feature is already in the data base
36  feat_it->second->addLocation(f_loc);
37  this->_alive_feat_ids.push_back(f_id);
38  return false;
39  }
40 }
41 
43 {
44  Feature::Ptr new_feature = Feature::Ptr(new Feature(this->_time, f_loc));
45  this->_map_of_features[new_feature->getId()] = new_feature;
46  this->_alive_feat_ids.push_back(new_feature->getId());
47  return new_feature->getId();
48 }
49 
51 {
52  // Delete all features from the data base that has not been updated in the last loop
53  for (MapOfFeatures::iterator feats_it = this->_map_of_features.begin(); feats_it != this->_map_of_features.end();)
54  {
55  //The feature is not alive anylonger! -> delete it from the map
56  if (std::find(this->_alive_feat_ids.begin(), this->_alive_feat_ids.end(),feats_it->first) == this->_alive_feat_ids.end())
57  {
58  feats_it = this->_map_of_features.erase(feats_it);
59  }
60  else
61  {
62  ++feats_it;
63  }
64  }
65  this->_time++;
66 }
67 
69 {
70  this->_alive_feat_ids.clear();
71 }
72 
73 std::vector<Feature::Id> FeaturesDataBase::getListOfAliveFeatureIds() const
74 {
75  return this->_alive_feat_ids;
76 }
77 
79 {
80  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
81  {
83  "FeaturesDataBase.getFeatureClone",
84  "Feature with Id " << f_id << " is not stored in the database.");
85  return Feature::Ptr(new Feature());
86  }
87  else
88  {
89  return this->_map_of_features.at(f_id)->clone();
90  }
91 }
92 
94 {
95  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
96  {
97  ROS_ERROR_STREAM_NAMED("FeaturesDataBase.getFeature", "Feature with Id " << f_id << " is not stored in the database.");
98  return Feature::Ptr(new Feature());
99  }
100  else
101  {
102  return this->_map_of_features.at(f_id);
103  }
104 }
105 
107  Feature::Id f_id) const
108 {
109  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
110  {
112  "FeaturesDataBase.getFeatureFirstLocation",
113  "Feature with Id " << f_id << " is not stored in the database.");
114  return Feature::Location();
115  }
116  else
117  {
118  return this->_map_of_features.at(f_id)->getFirstLocation();
119  }
120 }
121 
123  Feature::Id f_id) const
124 {
125  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
126  {
128  "FeaturesDataBase.getFeatureLastLocation",
129  "Feature with Id " << f_id << " is not stored in the database.");
130  return Feature::Location();
131  }
132  else
133  {
134  return this->_map_of_features.at(f_id)->getLastLocation();
135  }
136 }
137 
139  Feature::Id f_id) const
140 {
141  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
142  {
144  "FeaturesDataBase.getFeatureNextToLastLocation",
145  "Feature with Id " << f_id << " is not stored in the database.");
146  return Feature::Location();
147  }
148  else
149  {
150  return this->_map_of_features.at(f_id)->getNextToLastLocation();
151  }
152 }
153 
155  Feature::Id f_id) const
156 {
157  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
158  {
160  "FeaturesDataBase.getFeatureTwoLastLocations",
161  "Feature with Id " << f_id << " is not stored in the database.");
163  }
164  else
165  {
166  return this->_map_of_features.at(f_id)->getTwoLastLocations();
167  }
168 }
169 
171  Feature::Id f_id, int frames_to_last) const
172 {
173  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
174  {
176  "FeaturesDataBase.getFeatureNToLastLocation",
177  "Feature with Id " << f_id << " is not stored in the database.");
178  return Feature::Location();
179  }
180  else
181  {
182  return this->_map_of_features.at(f_id)->getNToLastLocation(frames_to_last);
183  }
184 }
185 
187  Feature::Id f_id) const
188 {
189  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
190  {
192  "FeaturesDataBase.getFeatureTrajectory",
193  "Feature with Id " << f_id << " is not stored in the database.");
194  return Feature::Trajectory();
195  }
196  else
197  {
198  return this->_map_of_features.at(f_id)->getTrajectory();
199  }
200 }
201 
203 {
204  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
205  {
207  "FeaturesDataBase.getFeatureAge",
208  "Feature with Id " << f_id << " is not stored in the database.");
209  return -1;
210  }
211  else
212  {
213  return this->_map_of_features.at(f_id)->getFeatureAge();
214  }
215 }
216 
218 {
219  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
220  {
221  return false;
222  }
223  else
224  {
225  return true;
226  }
227 }
228 
230 {
231  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
232  {
234  "FeaturesDataBase.getFeatureX",
235  "Feature with Id " << f_id << " is not stored in the database.");
236  return -10.0;
237  }
238  else
239  {
240  return this->_map_of_features.at(f_id)->getLastX();
241  }
242 }
243 
245 {
246  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
247  {
249  "FeaturesDataBase.getFeatureLastY",
250  "Feature with Id " << f_id << " is not stored in the database.");
251  return -10.0;
252  }
253  else
254  {
255  return this->_map_of_features.at(f_id)->getLastY();
256  }
257 }
258 
260 {
261  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
262  {
264  "FeaturesDataBase.getFeatureLastZ",
265  "Feature with Id " << f_id << " is not stored in the database.");
266  return -10.0;
267  }
268  else
269  {
270  return this->_map_of_features.at(f_id)->getLastZ();
271  }
272 }
273 
275 {
276  MapOfFeatureLocations ultimate_locations;
277  BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
278  {
279  ultimate_locations[feat_id_feat.first] = feat_id_feat.second
280  ->getLastLocation();
281  }
282  return ultimate_locations;
283 }
284 
286 {
287  MapOfFeatureLocations penultimate_locations;
288  BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
289  {
290  penultimate_locations[feat_id_feat.first] = feat_id_feat.second
291  ->getNextToLastLocation();
292  }
293  return penultimate_locations;
294 }
295 
297 {
298  MapOfFeatureLocationPairs two_last_locations;
299  BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
300  {
301  two_last_locations[feat_id_feat.first] = feat_id_feat.second
302  ->getTwoLastLocations();
303  }
304  return two_last_locations;
305 }
306 
307 //std::pair<Location, Location> FeaturesDataBase::getLastAndOtherLocationsOfFeature(Id f_id, int frames_to_last) const
308 //{
309 // if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
310 // {
311 // ROS_ERROR_STREAM_NAMED("FeaturesDataBase::getLastTwoLocationsOfFeature",
312 // "NewFeature with Id " << f_id << " is not stored in the database.");
313 // return std::pair<Location, Location>(Location(), Location());
314 // }
315 // else
316 // {
317 // std::pair<Location, Location> ret_pair;
318 // ret_pair.first = this->_map_of_features.at(f_id)->getUltimateLocationOfFeature();
319 // ret_pair.second = this->_map_of_features.at(f_id)->getLocationOfFeatureCurrentMinusNFrames(frames_to_last);
320 // return ret_pair;
321 // }
322 //}
323 
325 {
326  return this->_map_of_features;
327 }
328 
330 {
331  return this->_time;
332 }
bool isFeatureStored(Feature::Id f_id) const
boost::shared_ptr< Feature > Ptr
Definition: Feature.h:53
boost::tuple< double, double, double > Location
Definition: Feature.h:59
#define ROS_ERROR_STREAM_NAMED(name, args)
MapOfFeatureLocations getAllFeaturesNextToLastLocation() const
bool addFeatureLocation(Feature::Id f_id, Feature::Location f_loc)
Minimal class that represents a Point of Interest by an ID and stores its successive locations $Autho...
Definition: Feature.h:48
Feature::Location getFeatureNextToLastLocation(Feature::Id f_id) const
double getFeatureLastX(Feature::Id f_id) const
MapOfFeatures getAllFeatures() const
size_t getFeatureAge(Feature::Id f_id) const
Feature::LocationPair getFeatureTwoLastLocations(Feature::Id f_id) const
Feature::Location getFeatureFirstLocation(Feature::Id f_id) const
std::pair< Location, Location > LocationPair
Definition: Feature.h:65
Feature::Location getFeatureNToLastLocation(Feature::Id f_id, int frames_to_last) const
std::vector< Feature::Id > _alive_feat_ids
double getFeatureLastY(Feature::Id f_id) const
MapOfFeatureLocations getAllFeaturesLastLocation() const
Feature::Trajectory getFeatureTrajectory(Feature::Id f_id) const
boost::unordered_map< Feature::Id, Feature::LocationPair > MapOfFeatureLocationPairs
std::vector< Location > Trajectory
Definition: Feature.h:62
std::vector< Feature::Id > getListOfAliveFeatureIds() const
double getFeatureLastZ(Feature::Id f_id) const
MapOfFeatures _map_of_features
boost::unordered_map< Feature::Id, Feature::Location > MapOfFeatureLocations
Definition: Feature.h:40
MapOfFeatureLocationPairs getAllFeaturesTwoLastLocations() const
Feature::Ptr getFeature(Feature::Id f_id) const
boost::unordered_map< Feature::Id, Feature::Ptr > MapOfFeatures
Feature::Ptr getFeatureClone(Feature::Id f_id) const
Feature::Location getFeatureLastLocation(Feature::Id f_id) const


omip_common
Author(s): Roberto Martín-Martín
autogenerated on Mon Jun 10 2019 14:06:05