FeaturesDataBase.cpp
Go to the documentation of this file.
00001 #include "omip_common/FeaturesDataBase.h"
00002 
00003 #include <boost/foreach.hpp>
00004 
00005 #include <ros/ros.h>
00006 
00007 using namespace omip;
00008 
00009 FeaturesDataBase::FeaturesDataBase() :
00010     _time(0)
00011 {
00012 
00013 }
00014 
00015 FeaturesDataBase::~FeaturesDataBase()
00016 {
00017 
00018 }
00019 
00020 bool FeaturesDataBase::addFeatureLocation(Feature::Id f_id,
00021                                           Feature::Location f_loc)
00022 {
00023   MapOfFeatures::iterator feat_it = this->_map_of_features.find(f_id);
00024   if (feat_it == this->_map_of_features.end())
00025   {
00026     // This is a new feature
00027     Feature::Ptr new_feature = Feature::Ptr(
00028         new Feature(this->_time, f_loc, f_id));
00029     this->_map_of_features[f_id] = new_feature;
00030     this->_alive_feat_ids.push_back(new_feature->getId());
00031     return true;
00032   }
00033   else
00034   {
00035     // This feature is already in the data base
00036     feat_it->second->addLocation(f_loc);
00037     this->_alive_feat_ids.push_back(f_id);
00038     return false;
00039   }
00040 }
00041 
00042 Feature::Id FeaturesDataBase::addFeatureLocation(Feature::Location f_loc)
00043 {
00044   Feature::Ptr new_feature = Feature::Ptr(new Feature(this->_time, f_loc));
00045   this->_map_of_features[new_feature->getId()] = new_feature;
00046   this->_alive_feat_ids.push_back(new_feature->getId());
00047   return new_feature->getId();
00048 }
00049 
00050 void FeaturesDataBase::step()
00051 {
00052   // Delete all features from the data base that has not been updated in the last loop
00053   for (MapOfFeatures::iterator feats_it = this->_map_of_features.begin(); feats_it != this->_map_of_features.end();)
00054   {
00055     //The feature is not alive anylonger! -> delete it from the map
00056     if (std::find(this->_alive_feat_ids.begin(), this->_alive_feat_ids.end(),feats_it->first) == this->_alive_feat_ids.end())
00057     {
00058       feats_it = this->_map_of_features.erase(feats_it);
00059     }
00060     else
00061     {
00062       ++feats_it;
00063     }
00064   }
00065   this->_time++;
00066 }
00067 
00068 void FeaturesDataBase::clearListOfAliveFeatureIds()
00069 {
00070   this->_alive_feat_ids.clear();
00071 }
00072 
00073 std::vector<Feature::Id> FeaturesDataBase::getListOfAliveFeatureIds() const
00074 {
00075   return this->_alive_feat_ids;
00076 }
00077 
00078 Feature::Ptr FeaturesDataBase::getFeatureClone(Feature::Id f_id) const
00079 {
00080   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00081   {
00082     ROS_ERROR_STREAM_NAMED(
00083         "FeaturesDataBase.getFeatureClone",
00084         "Feature with Id " << f_id << " is not stored in the database.");
00085     return Feature::Ptr(new Feature());
00086   }
00087   else
00088   {
00089     return this->_map_of_features.at(f_id)->clone();
00090   }
00091 }
00092 
00093 Feature::Ptr FeaturesDataBase::getFeature(Feature::Id f_id) const
00094 {
00095   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00096   {
00097     ROS_ERROR_STREAM_NAMED("FeaturesDataBase.getFeature", "Feature with Id " << f_id << " is not stored in the database.");
00098     return Feature::Ptr(new Feature());
00099   }
00100   else
00101   {
00102     return this->_map_of_features.at(f_id);
00103   }
00104 }
00105 
00106 Feature::Location FeaturesDataBase::getFeatureFirstLocation(
00107     Feature::Id f_id) const
00108 {
00109   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00110   {
00111     ROS_ERROR_STREAM_NAMED(
00112         "FeaturesDataBase.getFeatureFirstLocation",
00113         "Feature with Id " << f_id << " is not stored in the database.");
00114     return Feature::Location();
00115   }
00116   else
00117   {
00118     return this->_map_of_features.at(f_id)->getFirstLocation();
00119   }
00120 }
00121 
00122 Feature::Location FeaturesDataBase::getFeatureLastLocation(
00123     Feature::Id f_id) const
00124 {
00125   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00126   {
00127     ROS_ERROR_STREAM_NAMED(
00128         "FeaturesDataBase.getFeatureLastLocation",
00129         "Feature with Id " << f_id << " is not stored in the database.");
00130     return Feature::Location();
00131   }
00132   else
00133   {
00134     return this->_map_of_features.at(f_id)->getLastLocation();
00135   }
00136 }
00137 
00138 Feature::Location FeaturesDataBase::getFeatureNextToLastLocation(
00139     Feature::Id f_id) const
00140 {
00141   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00142   {
00143     ROS_ERROR_STREAM_NAMED(
00144         "FeaturesDataBase.getFeatureNextToLastLocation",
00145         "Feature with Id " << f_id << " is not stored in the database.");
00146     return Feature::Location();
00147   }
00148   else
00149   {
00150     return this->_map_of_features.at(f_id)->getNextToLastLocation();
00151   }
00152 }
00153 
00154 Feature::LocationPair FeaturesDataBase::getFeatureTwoLastLocations(
00155     Feature::Id f_id) const
00156 {
00157   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00158   {
00159     ROS_ERROR_STREAM_NAMED(
00160         "FeaturesDataBase.getFeatureTwoLastLocations",
00161         "Feature with Id " << f_id << " is not stored in the database.");
00162     return Feature::LocationPair(Feature::Location(), Feature::Location());
00163   }
00164   else
00165   {
00166     return this->_map_of_features.at(f_id)->getTwoLastLocations();
00167   }
00168 }
00169 
00170 Feature::Location FeaturesDataBase::getFeatureNToLastLocation(
00171     Feature::Id f_id, int frames_to_last) const
00172 {
00173   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00174   {
00175     ROS_ERROR_STREAM_NAMED(
00176         "FeaturesDataBase.getFeatureNToLastLocation",
00177         "Feature with Id " << f_id << " is not stored in the database.");
00178     return Feature::Location();
00179   }
00180   else
00181   {
00182     return this->_map_of_features.at(f_id)->getNToLastLocation(frames_to_last);
00183   }
00184 }
00185 
00186 Feature::Trajectory FeaturesDataBase::getFeatureTrajectory(
00187     Feature::Id f_id) const
00188 {
00189   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00190   {
00191     ROS_ERROR_STREAM_NAMED(
00192         "FeaturesDataBase.getFeatureTrajectory",
00193         "Feature with Id " << f_id << " is not stored in the database.");
00194     return Feature::Trajectory();
00195   }
00196   else
00197   {
00198     return this->_map_of_features.at(f_id)->getTrajectory();
00199   }
00200 }
00201 
00202 size_t FeaturesDataBase::getFeatureAge(Feature::Id f_id) const
00203 {
00204   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00205   {
00206     ROS_ERROR_STREAM_NAMED(
00207         "FeaturesDataBase.getFeatureAge",
00208         "Feature with Id " << f_id << " is not stored in the database.");
00209     return -1;
00210   }
00211   else
00212   {
00213     return this->_map_of_features.at(f_id)->getFeatureAge();
00214   }
00215 }
00216 
00217 bool FeaturesDataBase::isFeatureStored(Feature::Id f_id) const
00218 {
00219   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00220   {
00221     return false;
00222   }
00223   else
00224   {
00225     return true;
00226   }
00227 }
00228 
00229 double FeaturesDataBase::getFeatureLastX(Feature::Id f_id) const
00230 {
00231   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00232   {
00233     ROS_ERROR_STREAM_NAMED(
00234         "FeaturesDataBase.getFeatureX",
00235         "Feature with Id " << f_id << " is not stored in the database.");
00236     return -10.0;
00237   }
00238   else
00239   {
00240     return this->_map_of_features.at(f_id)->getLastX();
00241   }
00242 }
00243 
00244 double FeaturesDataBase::getFeatureLastY(Feature::Id f_id) const
00245 {
00246   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00247   {
00248     ROS_ERROR_STREAM_NAMED(
00249         "FeaturesDataBase.getFeatureLastY",
00250         "Feature with Id " << f_id << " is not stored in the database.");
00251     return -10.0;
00252   }
00253   else
00254   {
00255     return this->_map_of_features.at(f_id)->getLastY();
00256   }
00257 }
00258 
00259 double FeaturesDataBase::getFeatureLastZ(Feature::Id f_id) const
00260 {
00261   if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00262   {
00263     ROS_ERROR_STREAM_NAMED(
00264         "FeaturesDataBase.getFeatureLastZ",
00265         "Feature with Id " << f_id << " is not stored in the database.");
00266     return -10.0;
00267   }
00268   else
00269   {
00270     return this->_map_of_features.at(f_id)->getLastZ();
00271   }
00272 }
00273 
00274 FeaturesDataBase::MapOfFeatureLocations FeaturesDataBase::getAllFeaturesLastLocation() const
00275 {
00276   MapOfFeatureLocations ultimate_locations;
00277   BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
00278   {
00279     ultimate_locations[feat_id_feat.first] = feat_id_feat.second
00280         ->getLastLocation();
00281   }
00282   return ultimate_locations;
00283 }
00284 
00285 FeaturesDataBase::MapOfFeatureLocations FeaturesDataBase::getAllFeaturesNextToLastLocation() const
00286 {
00287   MapOfFeatureLocations penultimate_locations;
00288   BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
00289   {
00290     penultimate_locations[feat_id_feat.first] = feat_id_feat.second
00291         ->getNextToLastLocation();
00292   }
00293   return penultimate_locations;
00294 }
00295 
00296 FeaturesDataBase::MapOfFeatureLocationPairs FeaturesDataBase::getAllFeaturesTwoLastLocations() const
00297 {
00298   MapOfFeatureLocationPairs two_last_locations;
00299   BOOST_FOREACH(MapOfFeatures::value_type feat_id_feat, this->_map_of_features)
00300   {
00301     two_last_locations[feat_id_feat.first] = feat_id_feat.second
00302         ->getTwoLastLocations();
00303   }
00304   return two_last_locations;
00305 }
00306 
00307 //std::pair<Location, Location> FeaturesDataBase::getLastAndOtherLocationsOfFeature(Id f_id, int frames_to_last) const
00308 //{
00309 //  if (this->_map_of_features.find(f_id) == this->_map_of_features.end())
00310 //    {
00311 //      ROS_ERROR_STREAM_NAMED("FeaturesDataBase::getLastTwoLocationsOfFeature",
00312 //                             "NewFeature with Id " << f_id << " is not stored in the database.");
00313 //      return std::pair<Location, Location>(Location(), Location());
00314 //    }
00315 //    else
00316 //    {
00317 //      std::pair<Location, Location> ret_pair;
00318 //      ret_pair.first =  this->_map_of_features.at(f_id)->getUltimateLocationOfFeature();
00319 //      ret_pair.second = this->_map_of_features.at(f_id)->getLocationOfFeatureCurrentMinusNFrames(frames_to_last);
00320 //      return ret_pair;
00321 //    }
00322 //}
00323 
00324 FeaturesDataBase::MapOfFeatures FeaturesDataBase::getAllFeatures() const
00325 {
00326   return this->_map_of_features;
00327 }
00328 
00329 int FeaturesDataBase::getTime() const
00330 {
00331   return this->_time;
00332 }


omip_common
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:26:37