best_path.cpp
Go to the documentation of this file.
1 
19 
20 namespace pose_prediction_ism
21 {
22 
23 BestPath::BestPath(std::string database_filename):
24  PredictorWithScore::PredictorWithScore(database_filename, "best_path", Best)
25 {
26 }
27 
29 {
30 }
31 
32  AttributedPointCloud BestPath::predictUnfoundPoses(ISM::PosePtr &reference_pose, std::string pattern_name, double percentage_of_records_for_prediction)
33 {
34 
35  ROS_INFO_STREAM("Pose prediction is run for scene " << pattern_name << " with " << percentage_of_records_for_prediction << " times the demonstration trajectory lengths.");
36  best_path_map_.clear();
37  specifiers_size_map_.clear();
39  IsmObjects x;
40  x.push_back(IsmObject (pattern_name, "MOCK"));
41  createBestPathMap(pattern_name, x);
42  ROS_DEBUG_STREAM("These are best paths for unfound objects in scene" << pattern_name << ":");
44  ROS_ASSERT(!best_path_map_.empty());
47  createAttributedPointCloud(reference_pose, percentage_of_records_for_prediction);
49 }
50 
51 void BestPath::createBestPathMap(std::string type, IsmObjects predecessors)
52 {
53  IsmObjectSet objects_in_pattern = getObjectTypesAndIdsBelongingToPattern(type);
54  for (IsmObject object : objects_in_pattern)
55  {
56  if (!isFoundObject(object))
57  {
58  predecessors.push_back(object);
59  if (!isReferenceObject(object))
60  createBestPathMap(object.first, predecessors);
61  else
62  {
63  std::pair<BestPathMap::iterator,bool>ret;
64  double new_score = calculatePathScore(predecessors);
65  PathWithScore new_path_with_score(predecessors, new_score);
66  ret = best_path_map_.insert(std::pair<IsmObject, PathWithScore>(object,
67  new_path_with_score));
68  if (ret.second){
69  specifiers_size_map_[object] = votes_.at(type)
70  .at(object.first)
71  .at(object.second).size();
72  ROS_DEBUG_STREAM(specifiers_size_map_[object] << " votes available for object " << "(" << object.first << "," << object.second << ") in scene " << type);
73 
74  }
75  else
76  {
77  ROS_DEBUG_STREAM("Object " << "(" << object.first << "," << object.second << ")" << " already has a path");
78  PathWithScore old_path_with_score = best_path_map_[object];
79  double old_score = old_path_with_score.second;
80  if (old_score >= new_score)
81  ROS_DEBUG_STREAM("The the new score is NOT better than old. No changes");
82  else
83  {
84  ROS_DEBUG_STREAM("The the new score is better than old. The new path replaces the old");
85  best_path_map_[object] = new_path_with_score;
86  specifiers_size_map_[object] = votes_.at(type)
87  .at(object.first).at(object.second).size();
88  ROS_ASSERT_MSG(best_path_map_[object].second == new_score,
89  "The new path was not inserted");
90  }
91  }
92  }
93  predecessors.pop_back();
94  }
95  else
96  ROS_DEBUG_STREAM("Object " << "(" << object.first << "," << object.second << ")" << "was already found");
97  }
98 }
99 
100 void BestPath::createAttributedPointCloud(ISM::PosePtr pose, double percentage_of_records_for_prediction)
101 {
102  for (BestPathMap::iterator best_path_it = best_path_map_.begin();
103  best_path_it != best_path_map_.end(); ++best_path_it )
104  {
105  unsigned int threshold = round(percentage_of_records_for_prediction * specifiers_size_map_[best_path_it ->first]);
106  IsmObject object = best_path_it ->first;
107  PathWithScore path_with_score = best_path_it ->second;
108  IsmObjects predecessors = path_with_score.first;
109  for (unsigned int i = 0; i < threshold ; ++i)
110  {
111  ISM::PosePtr predicted_object_pose_ptr = predictPose(pose, predecessors);
112  addPointToPointCloud(predicted_object_pose_ptr, object.first, object.second);
113  }
114  }
115 }
117 {
118 
119  double score = 1 / ( (double) path.size());
120  ROS_ASSERT_MSG(score < 1,
121  "There must be more than one predecessor, otherwise all objects are in the reference");
122  return score;
123 }
124 
126 {
127  for (BestPathMap::iterator best_path_it = best_path_map_.begin();
128  best_path_it != best_path_map_.end();
129  ++best_path_it)
130  {
131  //uint threshold = round(percentage * specifiersSizeMap[shortestPathIt->first]);
132  IsmObject object = best_path_it->first;
133  PathWithScore path_with_score = best_path_it->second;
134  IsmObjects predecessors = path_with_score.first;
135  ROS_DEBUG_STREAM("(" << object.first << "," << object.second << ")" << " has " << predecessors.size() << " predecessors");
136  for (IsmObject pre : predecessors)
137  ROS_DEBUG_STREAM("> " << pre.first << ": " << pre.second.substr(0,5));
138  }
139 }
140 
141 }
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
double calculatePathScore(IsmObjects path)
Definition: best_path.cpp:116
AttributedPointCloud predictUnfoundPoses(ISM::PosePtr &reference_pose, std::string pattern_name, double percentage_of_records_for_prediction)
predictUnfoundPoses Processes the following steps for each object in the objectpattern set...
Definition: best_path.cpp:32
std::pair< IsmObjects, double > PathWithScore
ISM::PosePtr predictPose(ISM::PosePtr reference_pose_ptr, IsmObjects path_to_object)
#define ROS_ASSERT_MSG(cond,...)
void createBestPathMap(std::string type, IsmObjects predecessors)
Definition: best_path.cpp:51
#define ROS_DEBUG_STREAM(args)
std::pair< std::string, std::string > IsmObject
bool isReferenceObject(IsmObject object)
#define ROS_INFO_STREAM(args)
BestPath(std::string database_filename)
Definition: best_path.cpp:23
void createAttributedPointCloud(ISM::PosePtr reference_pose_ptr, double percentage_of_records_for_prediction)
Definition: best_path.cpp:100
std::vector< IsmObject > IsmObjects
#define ROS_ASSERT(cond)
bool isFoundObject(IsmObject object)
IsmObjectSet getObjectTypesAndIdsBelongingToPattern(std::string type)
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