Go to the documentation of this file.00001 #include <grasp_planning_graspit_ros/WriteToFile.h>
00002 #include <sstream>
00003
00005 bool grasp_planning_graspit_ros::makeDirectoryIfNeeded(const std::string& dPath)
00006 {
00007 try
00008 {
00009 boost::filesystem::path dir(dPath);
00010 boost::filesystem::path buildPath;
00011
00012 for (boost::filesystem::path::iterator it(dir.begin()), it_end(dir.end());
00013 it != it_end; ++it)
00014 {
00015 buildPath /= *it;
00016
00017
00018 if (!boost::filesystem::exists(buildPath) &&
00019 !boost::filesystem::create_directory(buildPath))
00020 {
00021 PRINTERROR("Could not create directory " << buildPath);
00022 return false;
00023 }
00024 }
00025 }
00026 catch (const boost::filesystem::filesystem_error& ex)
00027 {
00028 PRINTERROR(ex.what());
00029 return false;
00030 }
00031 return true;
00032 }
00033
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00075 bool grasp_planning_graspit_ros::writeGraspMessage(
00076 const moveit_msgs::Grasp &grasp,
00077 const std::string &outputDirectory,
00078 const std::string &filenamePrefix,
00079 const std::string &ext)
00080 {
00081 std::stringstream filename;
00082 filename << outputDirectory << "/" << filenamePrefix << "." << ext;
00083 std::stringstream filename_txt;
00084 filename_txt << outputDirectory << "/" << filenamePrefix << "_string." << ext;
00085 if (!saveToFile(grasp, filename.str(), true))
00086 {
00087 PRINTERROR("Could not save grasp to file " << filename.str());
00088 return false;
00089 }
00090 if (!saveToFile(grasp, filename_txt.str(), false))
00091 {
00092 PRINTERROR("Could not save grasp to text file " << filename_txt.str());
00093 return false;
00094 }
00095 return true;
00096 }
00097