pose_predictor.h
Go to the documentation of this file.
1 
18 #pragma once
19 
20 #include <map>
21 #include <algorithm>
22 #include <time.h>
23 #include <boost/random/uniform_real.hpp>
24 #include <boost/random/mersenne_twister.hpp>
25 #include <boost/random/variate_generator.hpp>
26 /* ----------------- ROS ------------------ */
27 #include "ros/ros.h"
28 
29 /* ----------------- ISM ------------------ */
30 #include <ISM/recognizer/Recognizer.hpp>
31 
32 /* ----------------- Foreign datatypes ------------------ */
35 
36 namespace pose_prediction_ism
37 {
39  {
45  };
47  {
48  protected:
49  typedef std::pair<std::string, std::string> IsmObject;
50  typedef std::vector<IsmObject> IsmObjects;
51  typedef std::set<IsmObject> IsmObjectSet;
52 
53  PosePredictor(std::string database_filename,
54  std::string name_space,
55  PredictorType predictor_type);
60  public:
61 
86  AttributedPointCloud virtual predictUnfoundPoses(ISM::PosePtr& reference_pose, std::string pattern_name, double percentage_of_records_for_prediction) = 0;
87  inline void clearPointCloud()
88  {
89  attributed_point_cloud_.elements.clear();
90  }
91 
92 
93  /* ----------------- Getter ------------------ */
94  std::string getMarkerNameSpace() const;
96 
97  /* ----------------- Setter ------------------ */
98  void setFoundObjects(const FoundObjects &value);
99 
101  this->prediction_generation_factor_ = prediction_generation_factor_;
102  }
103 
104  /* ----------------- Debug ------------------ */
105  void traverseISM(std::string pattern_name, unsigned int level) ;
106 
107  inline void enableRandom(double sphere_radius, double max_projection_angle){
108  USE_RANDOMS = true;
109  SPHERE_RADIUS = sphere_radius;
110  MAX_PROJECTION_ANGLE = max_projection_angle;
111 
112  udg_dist_ = new UniformDistributionGenerator(boost::mt19937(time(0)), boost::uniform_real<>(-SPHERE_RADIUS, SPHERE_RADIUS));
113  udg_rot_ = new UniformDistributionGenerator(boost::mt19937(time(0)), boost::uniform_real<>(-MAX_PROJECTION_ANGLE / 2, MAX_PROJECTION_ANGLE / 2));
114 
115  }
116  inline void disableRandom(){
117  USE_RANDOMS = false;
118  SPHERE_RADIUS = 0.0;
119  MAX_PROJECTION_ANGLE = 0.0;
120  }
121 
123 
124  protected:
125  typedef std::map<IsmObject , unsigned int> SizeMap;
126  typedef boost::variate_generator<boost::mt19937, boost::uniform_real<> > UniformDistributionGenerator;
127  UniformDistributionGenerator* udg_dist_;
128  UniformDistributionGenerator* udg_rot_;
129 
131 
132 
133  /* ----------------- ISM Attributes------------------ */
134  ISM::PatternToObjectToVoteMap votes_;
135 
137 
138  double average_votes_ = 0;
139 
149  inline void addPointToPointCloud(ISM::PosePtr pose_to_add, std::string type, std::string identifier)
150  {
151  attributed_point_cloud_.elements.push_back(ismPosePtr2attributedPoint(pose_to_add, type, identifier));
152  }
153  inline bool isFoundObject(IsmObject object)
154  {
155  return std::find_if(found_objects_.begin(),
156  found_objects_.end(),
157  [object](FoundObject foundObject)
158  {
159  return (foundObject.type == object.first &&
160  foundObject.identifier == object.second);
161  }) != found_objects_.end();
162  }
163  inline bool isPointCloudEmpty()
164  {
165  return attributed_point_cloud_.elements.empty();
166  }
167 
168  inline bool isReferenceObject(IsmObject object)
169  {
170  return object.first.find("_sub") != std::string::npos;
171  }
172 
173  inline IsmObjectSet getObjectTypesAndIdsBelongingToPattern(std::string type)
174  {
175  return table_helper_->getObjectTypesAndIdsBelongingToPattern(type);
176  }
177  ISM::PosePtr predictPose(ISM::PosePtr reference_pose_ptr, IsmObjects path_to_object);
178 
179  virtual void createAttributedPointCloud(ISM::PosePtr reference_pose_ptr, double percentage_of_records_for_prediction) = 0;
180 
181  private:
182  const std::string NAME_SPACE_;
184  bool USE_RANDOMS = false;
185  double SPHERE_RADIUS = 0.0;
186  double MAX_PROJECTION_ANGLE = 0.0;
187  ISM:: TableHelperPtr table_helper_;
189 
190  };
192  std::ostream& operator<<(std::ostream &strm, const PosePredictor &p);
193  std::ostream& operator<<(std::ostream &strm, const PosePredictorPtr &pPtr);
194 }
ISM::PatternToObjectToVoteMap votes_
void addPointToPointCloud(ISM::PosePtr pose_to_add, std::string type, std::string identifier)
RecognizerPredictionISM::addPointToPointCloud Adds an ISM Pose with object type and identifier as att...
AttributedPointCloud attributed_point_cloud_
std::set< IsmObject > IsmObjectSet
std::ostream & operator<<(std::ostream &strm, const PosePredictor &p)
void setPredictionGenerationFactor(double prediction_generation_factor_)
boost::variate_generator< boost::mt19937, boost::uniform_real<> > UniformDistributionGenerator
PosePredictor(std::string database_filename, std::string name_space, PredictorType predictor_type)
asr_msgs::AsrObject FoundObject
Definition: typedef.h:33
void traverseISM(std::string pattern_name, unsigned int level)
virtual void createAttributedPointCloud(ISM::PosePtr reference_pose_ptr, double percentage_of_records_for_prediction)=0
AttributedPointCloud getAttributedPointCloud() const
void enableRandom(double sphere_radius, double max_projection_angle)
UniformDistributionGenerator * udg_rot_
virtual AttributedPointCloud predictUnfoundPoses(ISM::PosePtr &reference_pose, std::string pattern_name, double percentage_of_records_for_prediction)=0
predictUnfoundPoses Processes the following steps for each object in the objectpattern set...
ISM::PosePtr predictPose(ISM::PosePtr reference_pose_ptr, IsmObjects path_to_object)
UniformDistributionGenerator * udg_dist_
std::string getMarkerNameSpace() const
std::pair< std::string, std::string > IsmObject
bool isReferenceObject(IsmObject object)
SharedPtr< PosePredictor > PosePredictorPtr
PredictorType getPredictorType() const
asr_msgs::AsrAttributedPoint ismPosePtr2attributedPoint(ISM::PosePtr ismPosePtr, std::string type, std::string identifier)
Definition: utility.cpp:30
std::vector< FoundObject > FoundObjects
Definition: typedef.h:34
std::vector< IsmObject > IsmObjects
void setFoundObjects(const FoundObjects &value)
bool isFoundObject(IsmObject object)
IsmObjectSet getObjectTypesAndIdsBelongingToPattern(std::string type)
std::map< IsmObject, unsigned int > SizeMap
asr_msgs::AsrAttributedPointCloud AttributedPointCloud
Definition: typedef.h:37


asr_lib_pose_prediction_ism
Author(s): Heizmann Heinrich, Heller Florian, Meißner Pascal, Stöckle Patrick
autogenerated on Thu Jan 9 2020 07:19:56