shortest_path.cpp
Go to the documentation of this file.
1 
19 
20 namespace pose_prediction_ism
21 {
22 ShortestPath::ShortestPath(std::string database_filename):
23  PosePredictor::PosePredictor(database_filename, "shortest_path",
24  Shortest)
25 {
26 }
28 {
29 }
30 
31 AttributedPointCloud ShortestPath::predictUnfoundPoses(ISM::PosePtr &reference_pose, std::string pattern_name, double percentage_of_records_for_prediction)
32 {
33  ROS_DEBUG_STREAM_NAMED("ShortestPath", "ShortestPath::predictUnfoundPoses");
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  ROS_INFO_STREAM("It is run for a reference with the pose " << reference_pose << ".");
37 
38  shortest_path_map_.clear();
39  specifiers_size_map_.clear();
41  IsmObjects x;
42  x.push_back(IsmObject (pattern_name, "MOCK"));
43  createShortestPathMap(pattern_name, x);
44  ROS_DEBUG_STREAM_NAMED("ShortestPath", "These are shortest paths for unfound objects in scene" << pattern_name << ":");
49  createAttributedPointCloud(reference_pose, percentage_of_records_for_prediction);
50  ROS_DEBUG_STREAM_NAMED("ShortestPath", "created attributed point cloud with " << attributed_point_cloud_.elements.size() << " elements");
51 
53 }
54 void ShortestPath::createShortestPathMap(std::string type, IsmObjects predecessors)
55 {
56 
57  IsmObjectSet objects_in_pattern = getObjectTypesAndIdsBelongingToPattern(type);
58  // For all nonReference objects on this tree level: Save shortest path in map
59  for (IsmObject object : objects_in_pattern)
60  {
61  if (!isFoundObject(object) && !isReferenceObject(object))
62  {
63  ROS_DEBUG_STREAM_NAMED("ShortestPath", "Save shortest path in map for non-reference Object: " << "(" << object.first << "," << object.second << ")");
64  predecessors.push_back(object);
65  std::pair<ShortestPathMap::iterator,bool>ret;
66  ret = shortest_path_map_.insert ( std::pair<IsmObject, IsmObjects>(object, predecessors));
67  if (ret.second){
69  .at(type)
70  .at(object.first)
71  .at(object.second).size();
72  ROS_DEBUG_STREAM_NAMED("ShortestPath", ceil(average_votes_ * prediction_generation_factor_) << " votes available for object " << "(" << object.first << "," << object.second << ") in scene " << type);
73  }
74  else{
75  ROS_DEBUG_STREAM_NAMED("ShortestPath", "Object " << "(" << object.first << "," << object.second << ")" << " already has a path");
76  }
77 
78  predecessors.pop_back();
79  }
80  else
81  {
82  ROS_DEBUG_STREAM_COND_NAMED(isFoundObject(object), "ShortestPath", "Object " << "(" << object.first << "," << object.second << ")" << "was already found");
83  ROS_DEBUG_STREAM_COND_NAMED(isReferenceObject(object), "ShortestPath", "Object " << "(" << object.first << "," << object.second << ")" << "is a reference object");
84  }
85  }
86  // For all reference objects on this tree level: Call recursively the createShortestPathMap function
87  for (IsmObject object : objects_in_pattern)
88  {
89  if (!isFoundObject(object) && isReferenceObject(object))
90  {
91  ROS_DEBUG_STREAM_NAMED("ShortesPath", "Call createShortestPathMap for reference: " << "(" << object.first << "," << object.second << ")");
92  predecessors.push_back(object);
93  createShortestPathMap(object.first, predecessors);
94  predecessors.pop_back();
95  }
96  }
97 }
98 void ShortestPath::createAttributedPointCloud(ISM::PosePtr reference_pose_ptr, double percentage_of_records_for_prediction)
99 {
100  ROS_DEBUG_NAMED("ShortesPath", "ShortesPath::createAttributedPointCloud");
101 
102  for (ShortestPathMap::iterator shortest_path_it = shortest_path_map_.begin();
103  shortest_path_it != shortest_path_map_.end(); ++shortest_path_it)
104  {
105  //const unsigned int SIZE = specifiers_size_map_[shortest_path_it->first];
106 
107  unsigned int threshold = ceil(percentage_of_records_for_prediction * average_votes_ * prediction_generation_factor_);
108  ROS_DEBUG_NAMED("ShortesPath", "ShortesPath: generated poses, threshold: %f", ceil(percentage_of_records_for_prediction * average_votes_ * prediction_generation_factor_));
109  IsmObject object = shortest_path_it->first;
110  IsmObjects predecessors = shortest_path_it->second;
111  ROS_DEBUG_STREAM_NAMED("ShortesPath", "ISMOBject: " << "(" << object.first << "," << object.second << ")");
112  for(IsmObject temp_obj : predecessors){
113  ROS_DEBUG_STREAM_NAMED("ShortesPath", "predecessors: " << "(" << temp_obj.first << "," << temp_obj.second << ")");
114  }
115 
116 
117  for (unsigned int i = 0; i < threshold ; ++i)
118  {
119  ISM::PosePtr object_pose_ptr = predictPose(reference_pose_ptr, predecessors);
120  addPointToPointCloud(object_pose_ptr, object.first, object.second);
121  }
122  }
123 }
125 {
126  for (ShortestPathMap::iterator shortest_path_it = shortest_path_map_.begin();
127  shortest_path_it != shortest_path_map_.end();
128  ++shortest_path_it)
129  {
130 
131  IsmObject object = shortest_path_it->first;
132  IsmObjects predecessors = shortest_path_it->second;
133  ROS_DEBUG_STREAM_NAMED("ShortestPath", "Unfound object " << "(" << object.first << "," << object.second << ")" << " has " << predecessors.size() << " predecessors in path to reference:");
134  for (IsmObject pre : predecessors)
135  ROS_DEBUG_STREAM_NAMED("ShortestPath", "> " << pre.first << ": " << pre.second.substr(0,5));
136  }
137 }
138 }
139 
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...
void createAttributedPointCloud(ISM::PosePtr reference_pose_ptr, double percentage_of_records_for_prediction)
#define ROS_DEBUG_STREAM_NAMED(name, args)
void createShortestPathMap(std::string type, IsmObjects paths)
AttributedPointCloud attributed_point_cloud_
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...
std::set< IsmObject > IsmObjectSet
ShortestPath(std::string database_filename)
#define ROS_DEBUG_NAMED(name,...)
ISM::PosePtr predictPose(ISM::PosePtr reference_pose_ptr, IsmObjects path_to_object)
#define ROS_DEBUG_STREAM_COND_NAMED(cond, name, args)
std::pair< std::string, std::string > IsmObject
bool isReferenceObject(IsmObject object)
#define ROS_INFO_STREAM(args)
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:57