22 #include <boost/filesystem.hpp> 23 #include <boost/regex.hpp> 24 #include <boost/algorithm/string/regex.hpp> 39 ROS_INFO(
"Run Test for database \"%s\"", path_to_db.c_str());
42 ISM::TableHelper* helper =
new ISM::TableHelper(path_to_db);
43 std::vector<std::string> pattern_names = helper->getRecordedPatternNames();
45 int set_count = (int) helper->getSetIds().size();
46 int object_count = (int) helper->getRecordedObjectSet(1)->objects.size();
49 std::vector<std::string> model_pattern_names = helper->getModelPatternNames();
50 for(
size_t j = 0; j < model_pattern_names.size(); j++){
51 std::vector<std::string> tokens;
52 boost::split_regex(tokens, model_pattern_names[j], boost::regex(
"_sub"));
53 treesize = std::max(treesize, (
int)tokens.size());
56 for(
size_t j = 0; j < pattern_names.size(); j++){
57 std::string pattern_name = pattern_names[j];
59 double shortest_path_time = 0;
62 double shortest_path_time_new;
63 ROS_INFO(
"starting iteration %d/%d for %d-%d", i, iteration_, object_count, set_count);
67 auto t0 = std::chrono::high_resolution_clock::now();
68 nnpredictor_->predictUnfoundPoses(id_pose, pattern_name, 1.0);
69 auto t1 = std::chrono::high_resolution_clock::now();
70 nn_time_new = 1.e-9*std::chrono::duration_cast<std::chrono::nanoseconds>(t1-t0).count();
71 ROS_INFO(
"nnpredictor end time: %f", nn_time_new);
75 auto t2 = std::chrono::high_resolution_clock::now();
76 sppredictor_->predictUnfoundPoses(id_pose, pattern_name, 1.0);
77 auto t3 = std::chrono::high_resolution_clock::now();
78 shortest_path_time_new = 1.e-9*std::chrono::duration_cast<std::chrono::nanoseconds>(t3-t2).count();
80 ROS_INFO(
"sppredictor end time: %f", shortest_path_time_new);
82 output_total_file_ << i <<
"," << object_count <<
"," << set_count <<
"," << treesize <<
"," << nn_time_new <<
"," << shortest_path_time_new << std::endl;
83 nn_time += nn_time_new;
84 shortest_path_time += shortest_path_time_new;
86 output_avg_file_ << object_count <<
"," << set_count <<
"," << treesize <<
"," << (nn_time /
iteration_) <<
"," << (shortest_path_time / iteration_) << std::endl;
95 id_pose = ISM::PosePtr(
new ISM::Pose(
new ISM::Point(0, 0, 0),
new ISM::Quaternion(0, 0, 0, 1)));
98 ROS_INFO(
"Pose Prediction Tester started");
99 std::string input_path;
100 if(!nh.
getParam(
"input_path", input_path)){
104 ROS_INFO(
"Input Path: %s", input_path.c_str());
106 std::string output_path;
107 if(!nh.
getParam(
"output_path", output_path)){
111 ROS_INFO(
"Output path: %s", output_path.c_str());
113 if(!nh.
getParam(
"iteration", iteration_)){
114 ROS_WARN(
"Faild to load param iteration, defauting to 10!");
117 ROS_INFO(
"Iteratrion: %d", iteration_);
119 output_avg_file_.open (output_path+
"pp_avg.csv");
120 output_avg_file_ <<
"objects" <<
"," <<
"sets" <<
"," <<
"treesize" <<
"," <<
"nonnormalized" <<
"," <<
"shortestpath" << std::endl;
121 output_total_file_.open (output_path +
"pp_total.csv");
122 output_total_file_<<
"test_run" <<
"," <<
"objects" <<
"," <<
"sets" <<
"," <<
"treesize" <<
"," <<
"nonnormalized" <<
"," <<
"shortestpath" << std::endl;
123 boost::filesystem::path path_to_db_dir(input_path);
124 std::vector<boost::filesystem::path> paths;
125 std::copy(boost::filesystem::directory_iterator(path_to_db_dir), boost::filesystem::directory_iterator(), std::back_inserter(paths));
126 std::sort(paths.begin(), paths.end());
127 for (std::vector<boost::filesystem::path>::const_iterator i(paths.begin()), i_end(paths.end()); i != i_end; ++i)
129 if (!boost::filesystem::is_directory(*i))
135 output_avg_file_.close();
136 output_total_file_.close();
143 int main(
int argc,
char **argv) {
144 ros::init(argc, argv,
"pose_prediction_test");
std::ofstream output_total_file_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
SharedPtr< PaperPredictionNonNormalized > PaperPredictionNonNormalizedPtr
int main(int argc, char **argv)
pose_prediction_ism::ShortestPathPtr sppredictor_
SharedPtr< ShortestPath > ShortestPathPtr
void runTest(std::string path_to_db)
pose_prediction_ism::PaperPredictionNonNormalizedPtr nnpredictor_
bool getParam(const std::string &key, std::string &s) const
std::ofstream output_avg_file_