20 #include "asr_object_database/RecognizerList.h" 21 #include <boost/algorithm/string.hpp> 28 mDynamicReconfigServer(local_handle_),
46 object_type_client_ptr,
64 local_handle_.
setParam(
"deviation_number_of_samples_position", config.deviation_number_of_samples_position);
65 local_handle_.
setParam(
"deviation_number_of_samples_orientation", config.deviation_number_of_samples_orientation);
67 local_handle_.
setParam(
"object_position_distance_threshold", config.object_position_distance_threshold);
68 local_handle_.
setParam(
"object_orientation_rad_distance_threshold", config.object_orientation_rad_distance_threshold);
69 local_handle_.
setParam(
"viewport_position_distance_threshold", config.viewport_position_distance_threshold);
70 local_handle_.
setParam(
"viewport_orientation_rad_distance_threshold", config.viewport_orientation_rad_distance_threshold);
72 local_handle_.
setParam(
"use_default_intermediate_object_weight", config.use_default_intermediate_object_weight);
73 local_handle_.
setParam(
"default_intermediate_object_weight", config.default_intermediate_object_weight);
74 local_handle_.
setParam(
"intermediate_object_weight_file_name", config.intermediate_object_weight_file_name);
97 double oldMaxProjectionAngleDeviation =
settings_ptr_->maxProjectionAngleDeviation;
100 if (oldMaxProjectionAngleDeviation !=
settings_ptr_->maxProjectionAngleDeviation) {
135 std::string objects_to_sample;
137 settings_ptr_->objects_to_sample = *processStringVector<std::string>(objects_to_sample);
154 std::string recognizers_string_map_;
158 for (
const std::pair<std::string, std::string> &recongnizer_pair : *recognizers_map_ptr_) {
162 (*model_type_ptr_per_type_map_ptr_)[recongnizer_pair.first]->recognizerName = recongnizer_pair.second;
166 std::string weight_string_map_;
170 for (
const std::pair<std::string, double> &weight_pair : *weight_map_ptr) {
174 (*model_type_ptr_per_type_map_ptr_)[weight_pair.first]->weight = weight_pair.second;
178 std::string object_string_map;
182 for (
const std::pair<std::string, int> &parsedObjectMap : *parsedObjectMapPtr) {
183 const std::string &typeAndId = parsedObjectMap.first;
184 std::size_t found = typeAndId.find(
"&");
185 if (found != std::string::npos) {
187 const std::string &type = typeAndId.substr(0,found);
188 const std::string &observed_id = typeAndId.substr(found+1);
198 (*model_type_ptr_per_type_map_ptr_)[type]->model_object_ptr_per_id_map[observed_id]->objectCount = parsedObjectMap.second;
207 ROS_INFO(
"Wait for asr_object_database to existence");
210 asr_object_database::RecognizerList recognizerList;
211 if (!recognizerListServiceClient.
call(recognizerList)) {
212 ROS_ERROR(
"Get RecognizerList service call to asr_object_database was not successful");
217 ISM::TableHelperPtr table_helper = ISM::TableHelperPtr(
new ISM::TableHelper(
settings_ptr_->dbfilename));
219 std::set<std::pair<std::string, std::string>> objectTypesAndIds = table_helper->getObjectTypesAndIdsFromModelObjects();
220 for (
const std::pair<std::string, std::string> &objectTypesAndIdFromRecordedObject : table_helper->getObjectTypesAndIdsFromRecordedObjects()) {
221 objectTypesAndIds.insert(objectTypesAndIdFromRecordedObject);
223 const std::map<std::string, boost::filesystem::path> &ressourcePaths = table_helper->getRessourcePaths();
224 std::map<std::string, std::map<std::string, unsigned int>> temp_object_count_per_type_and_id_map;
226 for (
const std::pair<std::string, std::string> &objectTypeAndId : objectTypesAndIds) {
227 if (objectTypeAndId.first.find(
"_sub") != std::string::npos) {
231 std::map<std::string, boost::filesystem::path>::const_iterator path_it = ressourcePaths.find(objectTypeAndId.first);
232 if (path_it == ressourcePaths.end()) {
233 ROS_WARN_STREAM(
"No resourcePath for type/id: " << objectTypeAndId.first <<
"/" << objectTypeAndId.second <<
234 " in ISM_Table found -> will not be used in world_model");
248 for (
const std::string &recognizer_name : recognizerList.response.recognizer_list) {
249 if (path_it->second.string().find(recognizer_name) != std::string::npos) {
251 (*model_type_ptr_per_type_map_ptr_)[objectTypeAndId.first]->recognizerName = recognizer_name;
257 if (temp_object_count_per_type_and_id_map.find(objectTypeAndId.first) == temp_object_count_per_type_and_id_map.end()) {
258 temp_object_count_per_type_and_id_map.insert(std::make_pair(objectTypeAndId.first, std::map<std::string, unsigned int>()));
260 temp_object_count_per_type_and_id_map.find(objectTypeAndId.first)->second.insert(std::make_pair(objectTypeAndId.second, 0));
265 const std::vector<int> &setIds = table_helper->getSetIds();
266 for (
const int &setId : setIds) {
267 const ISM::ObjectSetPtr &objectSetPtr = table_helper->getRecordedObjectSet(setId);
268 for (
const ISM::ObjectPtr &
object : objectSetPtr->objects) {
269 ++temp_object_count_per_type_and_id_map.find(object->type)->second.find(object->observedId)->second;
273 for (
const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
274 unsigned int &oldMaxValue = model_object_ptr_per_id_pair.second->objectCount;
275 unsigned int ¤tValue = temp_object_count_per_type_and_id_map.find(model_type_ptr_per_type_pair.first)->second.find(model_object_ptr_per_id_pair.first)->second;
277 model_object_ptr_per_id_pair.second->objectCount = std::max(oldMaxValue, currentValue);
279 temp_object_count_per_type_and_id_map.find(model_type_ptr_per_type_pair.first)->second.find(model_object_ptr_per_id_pair.first)->second = 0;
291 model_type_ptr_per_type_pair.second->weight =
settings_ptr_->default_intermediate_object_weight;
299 std::vector<std::string> pathSplit;
300 boost::split(pathSplit,
settings_ptr_->dbfilename, boost::is_any_of(
"/"));
301 std::string dbName = pathSplit[pathSplit.size()-1];
303 const std::string placeholder =
"XXX";
304 std::string::size_type pos;
305 if ((pos =
settings_ptr_->intermediate_object_weight_file_name.find(placeholder)) != std::string::npos) {
306 settings_ptr_->intermediate_object_weight_file_name.replace(pos, placeholder.length(), dbName);
311 if (!std::ifstream(
settings_ptr_->intermediate_object_weight_file_name.c_str()).good()) {
312 ROS_INFO_STREAM(
"intermediate_object_weight_file: " <<
settings_ptr_->intermediate_object_weight_file_name <<
" not found. Execute itermediate_object_generator to generate file");
313 system(
"roslaunch asr_intermediate_object_generator asr_intermediate_object_generator.launch");
315 std::ifstream intermediate_object_weight_file(
settings_ptr_->intermediate_object_weight_file_name.c_str(), std::ifstream::in);
317 std::vector<char> buffer;
318 rapidxml::xml_document<> doc;
319 rapidxml::xml_node<> *interObjNode;
320 if (intermediate_object_weight_file) {
321 buffer = std::vector<char>((std::istreambuf_iterator<char>(intermediate_object_weight_file)), std::istreambuf_iterator<char>());
322 buffer.push_back(
'\0');
324 doc.parse<0>(&buffer[0]);
325 interObjNode = doc.first_node(
"InterObj");
327 ROS_INFO_STREAM(
"intermediate_object_weight_file still not found (there must be a problem with the itermediate_object_generator)." 328 <<
" Check if weights are in sqlTable or use default_intermediate_object_weight");
332 std::map<std::string, std::map<std::string, std::string>> modelWeightsPerTypeAndId = table_helper->getModelWeightsPerTypeAndId();
335 for (
const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
338 bool weightFound =
false;
340 for (rapidxml::xml_node<> *obj_node = interObjNode->first_node(
"obj"); obj_node; obj_node = obj_node->next_sibling()) {
341 std::string name = boost::lexical_cast<std::string>(obj_node->first_attribute(
"name")->value());
342 std::string
id = boost::lexical_cast<std::string>(obj_node->first_attribute(
"observedId")->value());
343 if (model_type_ptr_per_type_pair.first == name && model_object_ptr_per_id_pair.first ==
id) {
344 weight = std::max(weight, boost::lexical_cast<double>(obj_node->value()));
349 if (interObjNode && !weightFound) {
350 ROS_INFO_STREAM(
"No intermediate_object_weight for type/id: " << model_type_ptr_per_type_pair.first <<
"/" << model_object_ptr_per_id_pair.first <<
" in xml_file found." 351 <<
" Check if weights are in sqlTable or use default_intermediate_object_weight");
354 for (
const std::pair<std::string, std::map<std::string, std::string>> &modelWeightsPerTypeAndIdPair: modelWeightsPerTypeAndId) {
355 for (
const std::pair<std::string, std::string> &modelWeightsPerIdPair : modelWeightsPerTypeAndIdPair.second) {
356 if (model_type_ptr_per_type_pair.first == modelWeightsPerTypeAndIdPair.first && model_object_ptr_per_id_pair.first == modelWeightsPerIdPair.first) {
357 weight = std::max(weight, boost::lexical_cast<double>(modelWeightsPerIdPair.second));
364 ROS_INFO_STREAM(
"No intermediate_object_weight for type/id: " << model_type_ptr_per_type_pair.first <<
"/" << model_object_ptr_per_id_pair.first <<
" in sqlTable found. Use default_intermediate_object_weight");
368 model_type_ptr_per_type_pair.second->weight = std::max(weight, model_type_ptr_per_type_pair.second->weight);
447 std::string mydbfilename;
450 std::string newMydbfilename;
453 if (mydbfilename != newMydbfilename) {
462 std::string mydbfilename;
465 std::string newMydbfilename;
468 if (mydbfilename != newMydbfilename) {
ros::ServiceServer get_viewport_list_service_server_
boost::shared_ptr< ModelObject > ModelObjectPtr
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ros::ServiceServer push_found_object_service_server_
static const std::string GetObjectVisualizationParamName()
static const std::string GetGetViewportListServiceName()
static void resetInstance()
bool processEmptyCompletePatternsServiceCall(asr_world_model::EmptyCompletePatterns::Request &request, asr_world_model::EmptyCompletePatterns::Response &response)
ros::ServiceServer filter_viewport_depending_on_already_visited_viewports
bool processEmptyViewportListServiceCall(asr_world_model::EmptyViewportList::Request &request, asr_world_model::EmptyViewportList::Response &response)
Removes the whole next best view viewports from list if request.object_type is set to "all" in the ot...
bool processPushViewportServiceCall(asr_world_model::PushViewport::Request &request, asr_world_model::PushViewport::Response &response)
Pushes a next best view viewport to a list.
ros::ServiceServer get_recognizer_name_service_server_
static const std::string GetPushFoundObjectListServiceName()
ros::ServiceServer get_all_objects_list_service_server_
static const std::string GetClientGetRecognizerListServiceName()
bool call(MReq &req, MRes &res)
boost::shared_ptr< CompletePatternsHandler > complete_patterns_handler_ptr_
std::string getName(void *handle)
static const std::string GetGetCompletePatternsServiceName()
bool processGetFoundObjectListServiceCall(asr_world_model::GetFoundObjectList::Request &request, asr_world_model::GetFoundObjectList::Response &response)
Returns the already found objects.
bool processGetCompletePatternsServiceCall(asr_world_model::GetCompletePatterns::Request &request, asr_world_model::GetCompletePatterns::Response &response)
WorldModel()
Creates a new instance of the world model and starts the services.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer visualize_sampled_poses_service_server_
void initMapsFromWorldDescription()
ros::ServiceServer get_missing_object_list_service_server_
ros::ServiceServer get_found_object_list_service_server_
static boost::shared_ptr< DebugHelper > getInstance()
void dynamicReconfigureCallback(asr_world_model::DynamicParametersConfig &config, uint32_t level)
ros::ServiceServer get_complete_patterns_service_server_
bool processGetViewportListServiceCall(asr_world_model::GetViewportList::Request &request, asr_world_model::GetViewportList::Response &response)
Returns the whole list of next best view viewports if request.object_type is set to "all" else just t...
bool processGetAllObjectsListServiceCall(asr_world_model::GetAllObjectsList::Request &request, asr_world_model::GetAllObjectsList::Response &response)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
bool processPushCompletePatternsCall(asr_world_model::PushCompletePatterns::Request &request, asr_world_model::PushCompletePatterns::Response &response)
static const std::string GetEmptyCompletePatternsServiceName()
boost::shared_ptr< CommonInformationHandler > common_information_handler_ptr_
WorldModel class provides services for adding the viewports of the next best views to a list and retr...
static const std::string GetEmptyFoundObjectListServiceName()
ros::NodeHandle local_handle_
static const std::string GetFilterViewportDependingOnAlreadyVisitedViewportsName()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::ServiceServer get_intermediate_object_weight_service_server_
#define ROS_WARN_STREAM(args)
ros::ServiceServer push_viewport_service_server_
ros::ServiceServer push_complete_patterns_service_server_
boost::shared_ptr< FoundObjectHandler > found_object_handler_ptr_
static const std::string GetPushViewportServiceName()
static const std::string GetPushCompletePatternsServiceName()
bool processVisualizeSampledPosesCall(asr_world_model::VisualizeSampledPoses::Request &request, asr_world_model::VisualizeSampledPoses::Response &response)
void initIntermediateObjectWeights(const ISM::TableHelperPtr &table_helper)
bool processFilterViewportDependingOnAlreadyVisitedViewportsVisited(asr_world_model::FilterViewportDependingOnAlreadyVisitedViewports::Request &request, asr_world_model::FilterViewportDependingOnAlreadyVisitedViewports::Response &response)
Filter the objects of the viewport depending on already visited viewports.
SettingsPtr settings_ptr_
#define ROS_INFO_STREAM(args)
static void resetInstance()
void checkParametersFromOtherNode()
ros::ServiceServer empty_complete_patterns_service_server_
DebugHelperPtr debug_helper_ptr_
bool getParam(const std::string &key, std::string &s) const
bool processEmptyFoundObjectListServiceCall(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
static const std::string GetClientGetObjectMetaDataServiceName()
ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr_
static const std::string GetEmptyViewportListServiceName()
ROSCPP_DECL void shutdown()
ros::ServiceServer push_found_object_list_service_server_
boost::shared_ptr< ViewPortHandler > view_port_handler_ptr_
ros::ServiceServer empty_found_object_list_service_server_
bool hasParam(const std::string &key) const
std::map< std::string, ModelTypePtr > ModelTypePtrPerTypeMap
void initMapsFromSqlTable()
boost::shared_ptr< ModelType > ModelTypePtr
static const std::string GetPushFoundObjectServiceName()
ros::ServiceServer empty_viewport_list_service_server_
dynamic_reconfigure::Server< asr_world_model::DynamicParametersConfig > mDynamicReconfigServer
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
bool processPushFoundObjectListServiceCall(asr_world_model::PushFoundObjectList::Request &request, asr_world_model::PushFoundObjectList::Response &response)
Pushes the found object to a list.
static const std::string GetVisualizeSampledPosesName()
bool processPushFoundObjectServiceCall(asr_world_model::PushFoundObject::Request &request, asr_world_model::PushFoundObject::Response &response)
Pushes the found object to a list.
WorldModel class provides services for adding the viewports of the next best views to a list and retr...
static const std::string GetGetFoundObjectListServiceName()