shapes_manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <string>
20 
22 {
23 }
24 
25 
27 {
28  this->clear();
29 }
30 
31 
32 void ShapesManager::addShape(const std::string& id, PtrIMarkerShape_t s)
33 {
34  this->shapes_[id] = s;
35 }
36 
37 
38 void ShapesManager::removeShape(const std::string& id)
39 {
40  if (this->shapes_.count(id))
41  {
42  PtrIMarkerShape_t s = this->shapes_[id];
43  visualization_msgs::Marker marker = s->getMarker();
44  marker.action = visualization_msgs::Marker::DELETE;
45  this->pub_.publish(marker);
46  }
47 
48  this->shapes_.erase(id);
49 }
50 
51 
52 bool ShapesManager::getShape(const std::string& id, PtrIMarkerShape_t& s)
53 {
54  bool success = false;
55  if (this->shapes_.count(id))
56  {
57  s = this->shapes_[id];
58  success = true;
59  }
60 
61  return success;
62 }
63 
64 
66 {
67  visualization_msgs::MarkerArray marker_array;
68  for (MapIter_t iter = shapes_.begin(); iter != shapes_.end(); ++iter)
69  {
70  PtrIMarkerShape_t elem = iter->second;
71  if(elem->isDrawable())
72  {
73  visualization_msgs::Marker marker = elem->getMarker();
74  marker_array.markers.push_back(marker);
75  }
76  }
77 
78  this->pub_.publish(marker_array);
79  sleep(0.1); // it takes some time for Rviz to compute and show the marker!
80 }
81 
82 
84 {
85  this->shapes_.clear();
86 }
87 
88 
89 uint32_t ShapesManager::count() const
90 {
91  return this->shapes_.size();
92 }
93 
94 
95 uint32_t ShapesManager::count(const std::string& id) const
96 {
97  return this->shapes_.count(id);
98 }
std::shared_ptr< IMarkerShape > PtrIMarkerShape_t
void addShape(const std::string &id, PtrIMarkerShape_t s)
void publish(const boost::shared_ptr< M > &message) const
ShapesManager(const ros::Publisher &pub)
XmlRpcServer s
std::unordered_map< std::string, PtrIMarkerShape_t >::iterator MapIter_t
std::unordered_map< std::string, PtrIMarkerShape_t > shapes_
void removeShape(const std::string &id)
const ros::Publisher & pub_
bool getShape(const std::string &id, PtrIMarkerShape_t &s)
uint32_t count() const


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47