Go to the documentation of this file.00001
00018 #include <urdf2inventor/Helpers.h>
00019
00020 #define BOOST_NO_CXX11_SCOPED_ENUMS
00021 #include <boost/filesystem.hpp>
00022 #undef BOOST_NO_CXX11_SCOPED_ENUMS
00023
00024 template<typename MeshFormat>
00025 bool urdf2inventor::FileIO<MeshFormat>::initOutputDir(const std::string& robotName) const
00026 {
00027 return urdf_traverser::helpers::makeDirectoryIfNeeded(outputDir.c_str())
00028 && initOutputDirImpl(robotName);
00029 }
00030
00031 template<typename MeshFormat>
00032 bool urdf2inventor::FileIO<MeshFormat>::writeMeshFiles(const std::map<std::string, MeshFormat>& meshes,
00033 const std::string& meshOutputExtension,
00034 const std::string& meshOutputDirectoryName) const
00035 {
00036 std::string outputMeshDir = outputDir + "/" + meshOutputDirectoryName;
00037
00038 if (!urdf_traverser::helpers::makeDirectoryIfNeeded(outputMeshDir.c_str()))
00039 {
00040 ROS_ERROR("Could not create directory %s", outputMeshDir.c_str());
00041 return false;
00042 }
00043
00044 ROS_INFO_STREAM("urdf2inventor::FileIO::writeMeshFiles into " << outputDir);
00045
00046
00047 typename std::map<std::string, MeshFormat>::const_iterator mit;
00048 for (mit = meshes.begin(); mit != meshes.end(); ++mit)
00049 {
00050 std::stringstream outFilename;
00051 outFilename << outputMeshDir << "/" << mit->first << meshOutputExtension;
00052
00053 std::string pathToFile = urdf_traverser::helpers::getPath(outFilename.str().c_str());
00054
00055 if (!pathToFile.empty() &&
00056 !urdf_traverser::helpers::makeDirectoryIfNeeded(pathToFile.c_str()))
00057 {
00058 ROS_ERROR_STREAM("Could not make directory " << pathToFile);
00059 }
00060
00061 if (!urdf_traverser::helpers::writeToFile(mit->second, outFilename.str()))
00062 {
00063 ROS_ERROR("Could not write file %s", outFilename.str().c_str());
00064 return false;
00065 }
00066 }
00067
00068 return true;
00069 }
00070
00071
00072
00073 template<typename MeshFormat>
00074 bool urdf2inventor::FileIO<MeshFormat>::write(const ConversionResultPtr& data) const
00075 {
00076
00077 if (!initOutputDir(data->robotName))
00078 {
00079 ROS_ERROR("Can't initialize output directory %s", outputDir.c_str());
00080 return false;
00081 }
00082
00083 if (!writeMeshFiles(data->meshes, data->meshOutputExtension, data->meshOutputDirectoryName))
00084 {
00085 ROS_ERROR("Could not write mesh files");
00086 return false;
00087 }
00088
00089 urdf2inventor::helpers::writeFiles(data->textureFiles, outputDir);
00090 return writeImpl(data);
00091 }