23 #include "pose_prediction_ism/shortest_path.h" 24 #include "pose_prediction_ism/old_prediction_non_normalized.h" 25 #include "pose_prediction_ism/old_prediction_normalized.h" 26 #include "pose_prediction_ism/best_path.h" 27 #include "pose_prediction_ism/random_path.h" 44 results_already_shared_(results_already_shared),
50 string point_cloud_server_name;
51 string pose_prediction_markers_publisher_name;
52 string scene_markers_pose_prediction_publisher_name;
53 string found_object_client_name;
56 ph.
getParam<
string>(
"foundObjectClientName", &found_object_client_name,
"");
57 ph.
getParam<
string>(
"sceneMarkersPosePredictionPublisherName", &scene_markers_pose_prediction_publisher_name,
"");
58 ph.
getParam<
string>(
"posePredictionMarkersPublisherName", &pose_prediction_markers_publisher_name,
"");
59 ph.
getParam<
string>(
"PointCloudServerName", &point_cloud_server_name,
"");
60 ph.
getParam<
bool>(
"latched", &latched,
false);
63 ROS_ASSERT_MSG(found_object_client_.waitForExistence(),
"Please start the world model");
73 ROS_INFO(
"PosePrediction: Visualization initialized.");
81 bool equal_results_number;
82 unsigned int importance_resampled_size;
84 ph.
getParam<
bool>(
"equal_results_number", &equal_results_number,
true);
85 ph.
getParam<
unsigned int>(
"importance_resampled_size", &importance_resampled_size, 10);
88 ROS_INFO(
"PosePrediction: Resampler initialized.");
100 ROS_DEBUG_NAMED(
"PosePrediction",
"Callback PosePrediction::dynamicReconfCallback() is called.");
102 switch(config.posePredictor){
132 asr_recognizer_prediction_ism::GetPointCloud::Response &res)
134 ROS_INFO(
"\n==================================================\n");
136 ROS_INFO(
"Callback PosePrediction::processGetPointCloudServiceCall() is called.");
138 vector<AsrObject> found_objects;
139 for (asr_msgs::AsrObject asr_object : req.objects)
141 ROS_ASSERT_MSG(!asr_object.sampledPoses.empty(),
"Object estimate with no samples not allowed.");
142 found_objects.push_back(asr_object);
147 if (!found_objects.empty())
150 output <<
"Summary of results from PosePrediction::processGetPointCloudServiceCall() in rp_ism_node." << endl;
153 output <<
"These results come from importance (re)sampling and are used for pose prediction:";
161 ROS_DEBUG_NAMED(
"PosePrediction",
"Flushed visualization for pose prediction.");
164 std::vector<RecognitionResult> sampled_results =
resampler_ptr_->drawSamples();
167 AsrAttributedPointCloud union_attributed_point_cloud;
168 set<pair<string,string > > predicted_objects;
170 char result_specifier =
'a';
172 ROS_INFO_STREAM(
"List of recognition results used to predict poses with their relative summarized votes (percentages):");
173 for (
unsigned int i = 0; i < sampled_results.size(); i ++) {
174 ISM::RecognitionResult result = sampled_results[i];
175 ROS_INFO_STREAM(
"i: " << i <<
" for patternName: " << result.patternName <<
" with %: " << 1.0 / sampled_results.size());
179 for (RecognitionResult recognition_result : sampled_results)
183 results_buffer_.push_back(RecognitionResultPtr(
new RecognitionResult(recognition_result)));
184 output << endl << recognition_result << endl;
187 visualize(recognition_result, &result_specifier, &i, sampled_results.size(), &union_attributed_point_cloud, &predicted_objects);
190 output <<
"Poses have been predicted for the following objects: " << endl;
192 for (pair<string, string> predicted_object : predicted_objects)
193 output <<
"[" << predicted_object.first <<
", " << predicted_object.second <<
"], ";
202 res.point_cloud = union_attributed_point_cloud;
203 res.output = output.str();
205 ROS_INFO(
"Successfully finished pose prediction for given recognition results.");
207 ROS_INFO(
"\n==================================================\n");
212 ROS_ERROR(
"No recognition results available for pose predicition. Returning empty point cloud.");
213 AsrAttributedPointCloud cloud;
214 res.point_cloud = cloud;
215 res.output =
"No recognition results available for pose predicition. Returning empty point cloud.";
223 ROS_INFO(
"\n==================================================\n");
229 ROS_ERROR(
"Failed to call the service get_found_objects");
231 ROS_INFO(
"\n==================================================\n");
236 void PosePrediction::visualize(RecognitionResult recognition_result,
char *result_specifier,
int *i,
unsigned int sampled_results_size, AsrAttributedPointCloud *union_attributed_point_cloud,
set<pair<string, string>> *predicted_objects){
238 PosePtr reference_pose_ptr = recognition_result.referencePose;
240 AsrAttributedPointCloud current_point_cloud =
241 pose_predictor_ptr_->predictUnfoundPoses(reference_pose_ptr, recognition_result.patternName, 1.0 / sampled_results_size);
245 for (AsrAttributedPoint attributed_point : current_point_cloud.elements)
247 union_attributed_point_cloud->elements.push_back(attributed_point);
248 predicted_objects->insert(make_pair(attributed_point.type, attributed_point.identifier));
253 res_visualizer_->addVisualization(RecognitionResultPtr(
new RecognitionResult(recognition_result)));
254 string pose_prediction_name_space =
pose_predictor_ptr_->getMarkerNameSpace() +
"_" + (*result_specifier);
256 (*result_specifier)++;
262 map<string, map<string, unsigned int> > currentMap;
263 for (AsrAttributedPoint attributed_point : attributed_point_cloud.elements)
264 currentMap[attributed_point.type][attributed_point.identifier]++;
266 ROS_INFO_STREAM(
"Attributed pointcloud from pose prediction contains:" << endl);
267 for (map<
string, map<string,unsigned int> >::iterator typeIt = currentMap.begin(); typeIt != currentMap.end(); ++typeIt)
268 for (map<string, unsigned int>::iterator idIt = typeIt->second.begin(); idIt != typeIt->second.end(); ++idIt)
269 ROS_INFO_STREAM(idIt->second <<
" predicted poses for object "<<
"(" << typeIt->first <<
"," << idIt->first <<
").");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
VIZ::PosePredictionVisualizerPtr pose_prediction_visualizer_ptr_
ros::Publisher scene_markers_publisher_
dynamic_reconfigure::Server< asr_recognizer_prediction_ism::pose_predictionConfig > * reconfigure_server_
ros::Publisher pose_prediction_markers_publisher_
std::string getName(void *handle)
std::vector< ISM::RecognitionResultPtr > results_buffer_
bool is_visualization_active_
std::vector< ISM::RecognitionResultPtr > & results_already_shared_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
double prediction_generation_factor_
std::string database_filename_
#define ROS_DEBUG_NAMED(name,...)
void checkPointCloud(asr_msgs::AsrAttributedPointCloud attributed_point_cloud)
#define ROS_ASSERT_MSG(cond,...)
ros::NodeHandle node_handle_
pose_prediction_ism::PosePredictorPtr pose_predictor_ptr_
const std::string & getNamespace() const
void dynamicReconfCallback(asr_recognizer_prediction_ism::pose_predictionConfig &config, uint32_t level)
void getParam(std::string param_name, T *variable, T default_value)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool processGetPointCloudServiceCall(asr_recognizer_prediction_ism::GetPointCloud::Request &req, asr_recognizer_prediction_ism::GetPointCloud::Response &res)
RecognizerPredictionISM::processGetPointCloudServiceCall Callback function for a GetPointCloud Reques...
VIZ::ISMResultVisualizerRVIZPtr res_visualizer_
void visualize(ISM::RecognitionResult recognition_result, char *result_specifier, int *i, unsigned int sampled_results_size, asr_msgs::AsrAttributedPointCloud *union_attributed_point_cloud, std::set< std::pair< std::string, std::string >> *predicted_objects)
#define ROS_INFO_STREAM(args)
ros::ServiceServer point_cloud_server_
#define ROS_WARN_COND(cond,...)
#define ROS_INFO_COND(cond,...)
ros::ServiceClient found_object_client_
ResamplerPtr resampler_ptr_
boost::shared_ptr< Resampler > ResamplerPtr