view_port_handler.cpp
Go to the documentation of this file.
1 
19 
20 namespace world_model
21 {
22 
23 ViewPortHandler::ViewPortHandler(SettingsPtr settings_ptr) : number_of_all_viewports(0), viewport_list_ptr_(new ViewportList()), settings_ptr_(settings_ptr)
24 {
27  ROS_INFO_STREAM("ViewPortHandler initialized");
28 }
29 
30 bool ViewPortHandler::processPushViewportServiceCall(asr_world_model::PushViewport::Request &request,
31  asr_world_model::PushViewport::Response &response)
32 {
33  debug_helper_ptr_->write(std::stringstream() << "Calling processPushViewportServiceCall", (DebugHelper::SERVICE_CALLS + DebugHelper::VIEW_PORT));
34 
35  viewport_list_ptr_->push_back(request.viewport);
37 
38  debug_helper_ptr_->write(std::stringstream() << "Pushed viewport:\n" << request.viewport, DebugHelper::VIEW_PORT);
39 
40  return true;
41 }
42 
43 bool ViewPortHandler::processEmptyViewportListServiceCall(asr_world_model::EmptyViewportList::Request &request,
44  asr_world_model::EmptyViewportList::Response &response)
45 {
46  const std::string &object_type = request.object_type;
47  debug_helper_ptr_->write(std::stringstream() << "Calling processEmptyViewportListServiceCall for object_type: " << object_type, (DebugHelper::SERVICE_CALLS + DebugHelper::VIEW_PORT));
48 
49  if (std::string("all") == object_type || std::string("") == object_type) {
50  viewport_list_ptr_->clear();
52  } else {
53  ViewportList::iterator viewportListIt = viewport_list_ptr_->begin();
54  while (viewportListIt != viewport_list_ptr_->end()) {
55  std::vector<std::string>::iterator foundObjectIt = std::find(viewportListIt->object_type_name_list.begin(), viewportListIt->object_type_name_list.end(), object_type);
56  if (foundObjectIt != viewportListIt->object_type_name_list.end()) {
57  // When it is not the last object in the viewport erase only the type
58  if (viewportListIt->object_type_name_list.size() == 1) {
59  viewportListIt = viewport_list_ptr_->erase(viewportListIt);
60  continue;
61  } else {
62  viewportListIt->object_type_name_list.erase(foundObjectIt);
63  }
64  }
65  ++viewportListIt;
66  }
67  }
68 
69  return true;
70 }
71 
72 bool ViewPortHandler::processGetViewportListServiceCall(asr_world_model::GetViewportList::Request &request,
73  asr_world_model::GetViewportList::Response &response)
74 {
75  const std::string &object_type = request.object_type;
76  debug_helper_ptr_->write(std::stringstream() << "Calling processGetViewportListServiceCall for object_type: " << object_type, (DebugHelper::SERVICE_CALLS + DebugHelper::VIEW_PORT));
77 
78  if (std::string("all") == object_type || std::string("") == object_type) {
79  for (const asr_msgs::AsrViewport &viewport : *viewport_list_ptr_) {
80  response.viewport_list.push_back(viewport);
81  }
82  } else {
83  for (asr_msgs::AsrViewport &viewport : *viewport_list_ptr_) {
84  std::vector<std::string>::iterator foundObjectIt = std::find(viewport.object_type_name_list.begin(), viewport.object_type_name_list.end(), object_type);
85  if (foundObjectIt != viewport.object_type_name_list.end()) {
86  response.viewport_list.push_back(viewport);
87  }
88  }
89  }
90 
91  debug_helper_ptr_->write(std::stringstream() << "Returning viewportList:\n" << response.viewport_list, DebugHelper::VIEW_PORT);
92  return true;
93 }
94 
95 bool ViewPortHandler::processFilterViewportDependingOnAlreadyVisitedViewportsVisited(asr_world_model::FilterViewportDependingOnAlreadyVisitedViewports::Request &request,
96  asr_world_model::FilterViewportDependingOnAlreadyVisitedViewports::Response &response)
97 {
98  debug_helper_ptr_->write(std::stringstream() << "Calling processFilterViewportDependingOnAlreadyVisitedViewportsVisited", (DebugHelper::SERVICE_CALLS + DebugHelper::VIEW_PORT));
99 
100  asr_msgs::AsrViewport filteredViewport = request.viewport;
101  response.isBeenFiltered = false;
102 
103  for (const asr_msgs::AsrViewport &alreadyVisitedViewport : *viewport_list_ptr_) {
104  if (pose_helper_ptr_->checkPosesAreApproxEquale(alreadyVisitedViewport.pose, filteredViewport.pose,
105  settings_ptr_->viewport_position_distance_threshold, settings_ptr_->viewport_orientation_rad_distance_threshold)) {
106  debug_helper_ptr_->write(std::stringstream() << "pose is approx equale to:\n" << alreadyVisitedViewport, DebugHelper::VIEW_PORT);
107  response.isBeenFiltered = true;
108  filterObjectTypesOfViewport(filteredViewport, alreadyVisitedViewport);
109  }
110  }
111 
112  response.filteredViewport = filteredViewport;
113  debug_helper_ptr_->write(std::stringstream() << "response:\n" << response, DebugHelper::VIEW_PORT);
114  return true;
115 }
116 
117 void ViewPortHandler::filterObjectTypesOfViewport(asr_msgs::AsrViewport &viewport_to_filter, const asr_msgs::AsrViewport &filter_viewport) {
118  std::vector<std::string> &objectTypesToFilter = viewport_to_filter.object_type_name_list;
119 
120  for (const std::string &filter_object_type : filter_viewport.object_type_name_list) {
121  bool isFound = false;
122  do {
123  std::vector<std::string>::iterator iter = std::find(objectTypesToFilter.begin(), objectTypesToFilter.end(), filter_object_type);
124  if (iter != objectTypesToFilter.end()) {
125  objectTypesToFilter.erase(iter);
126  isFound = true;
127  } else {
128  isFound = false;
129  }
130  } while (isFound);
131  }
132 }
133 
134 std::ostream& operator<<(std::ostream &strm, const ViewportList &viewport_list) {
135  for (const asr_msgs::AsrViewport &viewport : viewport_list) {
136  strm << viewport;
137  }
138  return strm;
139 }
140 
141 std::ostream& operator<<(std::ostream &strm, const ViewportListPtr &viewport_list_ptr) {
142  return strm << *viewport_list_ptr;
143 }
144 
145 }
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.
std::vector< asr_msgs::AsrViewport > ViewportList
static boost::shared_ptr< PoseHelper > getInstance()
Definition: pose_helper.cpp:24
void filterObjectTypesOfViewport(asr_msgs::AsrViewport &viewport_to_filter, const asr_msgs::AsrViewport &filter_viewport)
static boost::shared_ptr< DebugHelper > getInstance()
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...
ViewPortHandler(SettingsPtr settings_ptr)
Creates a new instance of the ViewPortHandler.
std::ostream & operator<<(std::ostream &strm, const CompletePatterns &complete_patterns)
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.
#define ROS_INFO_STREAM(args)


asr_world_model
Author(s): Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Trautmann Jeremias
autogenerated on Thu Jan 9 2020 07:20:01