Feature.cpp
Go to the documentation of this file.
00001 #include "omip_common/Feature.h"
00002 
00003 #include <ros/ros.h>
00004 
00005 using namespace omip;
00006 
00007 Feature::Id Feature::_feature_id_generator = 1;
00008 
00009 Feature::Feature() :
00010     _id(Feature::_feature_id_generator++), _first_location(0.0, 0.0, 0.0), _birthday(
00011         -1)
00012 {
00013 }
00014 
00015 Feature::Feature(int feature_birthday, Location first_fl_in) :
00016     _id(Feature::_feature_id_generator++), _first_location(first_fl_in), _birthday(
00017         feature_birthday)
00018 {
00019   this->_trajectory.push_back(first_fl_in);
00020 }
00021 
00022 // To be used when the feature Ids are set externally
00023 Feature::Feature(int feature_birthday, Location first_fl_in, Id f_id) :
00024     _id(f_id), _first_location(first_fl_in), _birthday(feature_birthday)
00025 {
00026   this->_trajectory.push_back(first_fl_in);
00027 }
00028 
00029 Feature::Feature(const Feature &f)
00030 {
00031   this->_id = f.getId();
00032   this->_first_location = f.getFirstLocation();
00033   this->_birthday = f.getFeatureBirthday();
00034   this->_trajectory = f.getTrajectory();
00035 }
00036 
00037 Feature::~Feature()
00038 {
00039 
00040 }
00041 
00042 Feature::Ptr Feature::clone() const
00043 {
00044   return (Ptr(doClone()));
00045 }
00046 
00047 void Feature::addLocation(Location fl_in)
00048 {
00049   if (this->_trajectory.size() == 0)
00050   {
00051     this->_first_location = fl_in;
00052   }
00053   this->_trajectory.push_back(fl_in);
00054 }
00055 
00056 Feature::Id Feature::getId() const
00057 {
00058   return this->_id;
00059 }
00060 
00061 Feature::Location Feature::getFirstLocation() const
00062 {
00063   return this->_first_location;
00064 }
00065 
00066 Feature::Location Feature::getLastLocation() const
00067 {
00068   if (this->_trajectory.size() == 0)
00069   {
00070     ROS_ERROR_STREAM_NAMED(
00071         "Feature.getLastLocation",
00072         "Feature with Id " << this->_id << " has no last location.");
00073     return Location();
00074   }
00075   else
00076   {
00077     return this->_trajectory.back();
00078   }
00079 }
00080 
00081 Feature::Location Feature::getNextToLastLocation() const
00082 {
00083   if (this->_trajectory.size() < 2)
00084   {
00085     ROS_ERROR_STREAM_NAMED(
00086         "Feature.getNextToLastLocation",
00087         "Feature with Id " << this->_id << " has no next to last location.");
00088     return Location();
00089   }
00090   else
00091   {
00092     return this->_trajectory.at(this->_trajectory.size() - 2);
00093   }
00094 }
00095 
00096 Feature::LocationPair Feature::getTwoLastLocations() const
00097 {
00098   return Feature::LocationPair(this->getLastLocation(), this->getNextToLastLocation());
00099 }
00100 
00101 Feature::Location Feature::getNToLastLocation(int frames_to_last) const
00102 {
00103   if ((int)this->_trajectory.size() - frames_to_last - 1 < 0)
00104   {
00105     ROS_ERROR_STREAM_NAMED(
00106         "Feature.getNToLastLocation",
00107         "Feature with Id " << this->_id << " was not born at that time (" << frames_to_last << " frames to last < feature age = " << this->_trajectory.size() <<").");
00108     return Location();
00109   }
00110   else
00111   {
00112     return this->_trajectory.at(this->_trajectory.size() - frames_to_last -1);
00113   }
00114 }
00115 
00116 const Feature::Trajectory& Feature::getTrajectory() const
00117 {
00118   return this->_trajectory;
00119 }
00120 
00121 //void Feature::getTrajectory(const Feature::Trajectory& feat_traject) const
00122 //{
00123 //  feat_traject = this->_trajectory;
00124 //}
00125 
00126 size_t Feature::getFeatureAge() const
00127 {
00128   return this->_trajectory.size();
00129 }
00130 
00131 int Feature::getFeatureBirthday() const
00132 {
00133   return this->_birthday;
00134 }
00135 
00136 double Feature::getLastX() const
00137 {
00138   return boost::tuples::get<0>(this->getLastLocation());
00139 }
00140 
00141 double Feature::getLastY() const
00142 {
00143   return boost::tuples::get<1>(this->getLastLocation());
00144 }
00145 
00146 double Feature::getLastZ() const
00147 {
00148   return boost::tuples::get<2>(this->getLastLocation());
00149 }
00150 
00151 void Feature::setFeatureBirthday(int feature_birthday)
00152 {
00153   this->_birthday = feature_birthday;
00154 }
00155 


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