21 #define BOOST_NO_CXX11_SCOPED_ENUMS 25 #include <boost/foreach.hpp> 26 #include <boost/filesystem.hpp> 27 #include <ros_uri/ros_uri.hpp> 30 #include <boost/regex.hpp> 31 #include <boost/algorithm/string.hpp> 36 mGlobalNodeHandle(
"asr_object_database"),
37 mConfigurationFilePath(configurationFilePath)
67 RecognizerList::Response &res)
71 BOOST_FOREACH(ObjectDatabaseRecognizerPtrMap::value_type mapTuple, objectTypes)
73 res.recognizer_list.push_back(mapTuple.second->getKeyword());
77 std::sort(res.recognizer_list.begin(), res.recognizer_list.end());
83 ObjectTypeList::Response &res)
91 if (recognizerName ==
"all")
97 collection.push_back(mapVal.second);
106 if (recognizerPtr == nullPtr)
108 ROS_DEBUG(
"No object type definition for name '%s' found", recognizerName.c_str());
113 collection.push_back(recognizerPtr);
116 ROS_DEBUG(
"Collection contains %lu ObjectTypes", collection.size());
122 recognizerPtr->readEntries();
128 res.object_type_list.push_back(entryPtrMapPair.first);
133 std::sort(res.object_type_list.begin(), res.object_type_list.end());
135 ROS_DEBUG(
"Object List contains %lu items", res.object_type_list.size());
136 ROS_DEBUG(
"Reached end of processing object list request");
149 res.is_valid =
false;
151 for(ObjectDatabaseRecognizerPtrMap::value_type val : recognizerPtrMap) {
153 if ((objectEntryPtr) && (objectEntryPtr->getRecognizer()->getKeyword() == recognizer)){
154 res.object_folder = ros_uri::package_uri(objectEntryPtr->getPath().string(),
"asr_object_database");
155 res.object_mesh_resource = ros_uri::package_uri(objectEntryPtr->getRvizMeshResourcePath().string(),
"asr_object_database");
156 res.normal_vectors = objectEntryPtr->getNormalVectors();
157 res.deviations = objectEntryPtr->getDeviationsFromFile();
159 res.is_rotation_invariant = objectEntryPtr->getRotationInvarianceFromFile();
174 if (recognizerName ==
"all")
180 collection.push_back(mapVal.second);
189 if (recognizerPtr == nullPtr)
191 ROS_DEBUG(
"No object type definition for name '%s' found", recognizerName.c_str());
196 collection.push_back(recognizerPtr);
199 ROS_DEBUG(
"Collection contains %lu ObjectTypes", collection.size());
205 recognizerPtr->readEntries();
211 std::string mesh_path = ros_uri::package_uri(entryPtrMapPair.second->getRvizMeshResourcePath().string(),
"asr_object_database");
212 if (mesh_path !=
"package://asr_object_database/") {
213 res.meshes.push_back(mesh_path);
219 ROS_DEBUG(
"Object meshes list contains %lu items", res.meshes.size());
220 ROS_DEBUG(
"Reached end of processing object meshes request");
228 const fs::path sourcepath(req.sourcefile.c_str());
229 if (!fs::exists(sourcepath))
236 std::string fileending = req.sourcefile.substr(req.sourcefile.find_last_of(
"_"));
237 if (fileending.compare(
"_tex.obj") != 0)
239 ROS_ERROR(
"File has to end with '_tex.obj.'");
244 std::string::size_type
const q(req.sourcefile.find_last_of(
'.'));
245 const fs::path mtlSourcePath ((req.sourcefile.substr(0, q) +
".obj.mtl").c_str());
246 if (!fs::exists(mtlSourcePath))
248 ROS_ERROR(
"No .mtl file can be found in given directory.");
253 std::string extfilename = req.sourcefile.substr(req.sourcefile.find_last_of(
"/\\") + 1);
254 std::string::size_type
const p(extfilename.find_first_of(
'_'));
261 std::string predestpath = packagepath +
"/rsc/databases/textured_objects/" + filename +
"/" + filename +
".obj";
262 const fs::path destpath(predestpath.c_str());
265 const fs::path newDirectory(prenewDirectory.c_str());
267 if (!fs::exists(newDirectory))
269 fs::create_directory(newDirectory);
272 fs::copy_file(sourcepath, destpath, fs::copy_option::overwrite_if_exists);
275 std::string::size_type
const r(extfilename.find_last_of(
'.'));
276 std::string premtlDestPath = prenewDirectory +
"/" + extfilename.substr(0,
r) +
".obj.mtl";
277 const fs::path mtlDestPath = premtlDestPath.c_str();
280 fs::copy_file(mtlSourcePath, mtlDestPath, fs::copy_option::overwrite_if_exists);
283 std::string prepngSourcePath = req.sourcefile.substr(0, q) +
".png";
284 const fs::path pngSourcePath = prepngSourcePath.c_str();
286 if (!fs::exists(pngSourcePath))
288 ROS_ERROR(
"No .png file could be found in the given directory.");
293 std::string prepngDestPath = prenewDirectory +
"/" + extfilename.substr(0,
r) +
".png";
294 const fs::path pngDestPath = prepngDestPath.c_str();
297 if (!fs::exists(pngDestPath))
299 fs::copy_file(pngSourcePath, pngDestPath);
303 std::string predaefilepath = packagepath +
"/rsc/databases/textured_objects/" + filename +
"/" + filename +
".dae";
304 const fs::path daefilepath(predaefilepath.c_str());
305 if (!fs::exists(daefilepath))
307 std::string databaseFolder = prenewDirectory +
"/";
308 const char *navigateToDatabaseFolder = databaseFolder.c_str();
309 chdir(navigateToDatabaseFolder);
311 const char *meshlabserver = (
"meshlabserver -i " + filename+
".obj" +
" -o " + mlsoutput +
312 " -om vc vn wt").c_str();
313 system(meshlabserver);
321 ROS_DEBUG(
"Start reading all object types");
322 BOOST_FOREACH(ObjectDatabaseRecognizerPtrMap::value_type mapValue, recognizerMap)
324 ROS_DEBUG(
"Reading %s", mapValue.first.c_str());
325 mapValue.second->readEntries();
bool processObjectMetaDataRequest(ObjectMetaData::Request &req, ObjectMetaData::Response &res)
std::map< std::string, ObjectDatabaseRecognizerPtr > ObjectDatabaseRecognizerPtrMap
ros::ServiceServer mObjectMetaDataServiceHandle
bool processObjectTypeListRequest(ObjectTypeList::Request &req, ObjectTypeList::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer mObjectTypeGeneratorServiceHandle
const ObjectDatabaseRecognizerPtr getRecognizer(const std::string recognizerName)
void readAllObjectDatabaseRecognizers()
bool processObjectTypeGeneratorRequest(ObjectTypeGenerator::Request &req, ObjectTypeGenerator::Response &res)
bool processRecognizerListRequest(RecognizerList::Request &req, RecognizerList::Response &res)
bool processRecognizerListMeshesRequest(RecognizerListMeshes::Request &req, RecognizerListMeshes::Response &res)
std::map< std::string, ObjectDatabaseEntryPtr > ObjectDatabaseEntryPtrMap
bool read(const fs::path config_file)
ObjectDatabaseConfig mConfig
ROSLIB_DECL std::string getPath(const std::string &package_name)
::xsd::cxx::tree::string< char, simple_type > string
std::vector< ObjectDatabaseRecognizerPtr > ObjectDatabaseRecognizerPtrCollection
ros::ServiceServer mObjectTypeListServiceHandle
ros::ServiceServer mRecognizerListMeshesServiceHandle
std::pair< std::string, ObjectDatabaseEntryPtr > ObjectDatabaseEntryPtrMapPair
ros::NodeHandle mGlobalNodeHandle
ObjectDatabase(fs::path configurationFilePath)
ros::ServiceServer mRecognizerListServiceHandle
const ObjectDatabaseRecognizerPtrMap getObjectCategories()