Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #include "collision_space/environment_objects.h"
00038 #include <geometric_shapes/shape_operations.h>
00039
00040 std::vector<std::string> collision_space::EnvironmentObjects::getNamespaces(void) const
00041 {
00042 std::vector<std::string> ns;
00043 for (std::map<std::string, NamespaceObjects>::const_iterator it = objects_.begin() ; it != objects_.end() ; ++it)
00044 ns.push_back(it->first);
00045 return ns;
00046 }
00047
00048 const collision_space::EnvironmentObjects::NamespaceObjects& collision_space::EnvironmentObjects::getObjects(const std::string &ns) const
00049 {
00050 std::map<std::string, NamespaceObjects>::const_iterator it = objects_.find(ns);
00051 if (it == objects_.end())
00052 return empty_;
00053 else
00054 return it->second;
00055 }
00056
00057 collision_space::EnvironmentObjects::NamespaceObjects& collision_space::EnvironmentObjects::getObjects(const std::string &ns)
00058 {
00059 return objects_[ns];
00060 }
00061
00062 void collision_space::EnvironmentObjects::addObject(const std::string &ns, shapes::StaticShape *shape)
00063 {
00064 objects_[ns].static_shape.push_back(shape);
00065 }
00066
00067 void collision_space::EnvironmentObjects::addObject(const std::string &ns, shapes::Shape *shape, const tf::Transform &pose)
00068 {
00069 objects_[ns].shape.push_back(shape);
00070 objects_[ns].shape_pose.push_back(pose);
00071 }
00072
00073 bool collision_space::EnvironmentObjects::removeObject(const std::string &ns, const shapes::Shape *shape)
00074 {
00075 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00076 if (it != objects_.end())
00077 {
00078 unsigned int n = it->second.shape.size();
00079 for (unsigned int i = 0 ; i < n ; ++i)
00080 if (it->second.shape[i] == shape)
00081 {
00082 it->second.shape.erase(it->second.shape.begin() + i);
00083 it->second.shape_pose.erase(it->second.shape_pose.begin() + i);
00084 return true;
00085 }
00086 }
00087 return false;
00088 }
00089
00090 bool collision_space::EnvironmentObjects::removeObject(const std::string &ns, const shapes::StaticShape *shape)
00091 {
00092 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00093 if (it != objects_.end())
00094 {
00095 unsigned int n = it->second.static_shape.size();
00096 for (unsigned int i = 0 ; i < n ; ++i)
00097 if (it->second.static_shape[i] == shape)
00098 {
00099 it->second.static_shape.erase(it->second.static_shape.begin() + i);
00100 return true;
00101 }
00102 }
00103 return false;
00104 }
00105
00106 void collision_space::EnvironmentObjects::clearObjects(const std::string &ns)
00107 {
00108 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00109 if (it != objects_.end())
00110 {
00111 unsigned int n = it->second.static_shape.size();
00112 for (unsigned int i = 0 ; i < n ; ++i)
00113 delete it->second.static_shape[i];
00114 n = it->second.shape.size();
00115 for (unsigned int i = 0 ; i < n ; ++i)
00116 delete it->second.shape[i];
00117 objects_.erase(it);
00118 }
00119 }
00120
00121 void collision_space::EnvironmentObjects::clearObjects(void)
00122 {
00123 std::vector<std::string> ns = getNamespaces();
00124 for (unsigned int i = 0 ; i < ns.size() ; ++i)
00125 clearObjects(ns[i]);
00126 }
00127
00128 void collision_space::EnvironmentObjects::addObjectNamespace(const std::string ns)
00129 {
00130 if(objects_.find(ns) == objects_.end()) {
00131 objects_[ns] = NamespaceObjects();
00132 }
00133
00134 }
00135
00136 collision_space::EnvironmentObjects* collision_space::EnvironmentObjects::clone(void) const
00137 {
00138 EnvironmentObjects *c = new EnvironmentObjects();
00139 for (std::map<std::string, NamespaceObjects>::const_iterator it = objects_.begin() ; it != objects_.end() ; ++it)
00140 {
00141 NamespaceObjects &ns = c->objects_[it->first];
00142 unsigned int n = it->second.static_shape.size();
00143 for (unsigned int i = 0 ; i < n ; ++i)
00144 ns.static_shape.push_back(shapes::cloneShape(it->second.static_shape[i]));
00145 n = it->second.shape.size();
00146 for (unsigned int i = 0 ; i < n ; ++i)
00147 ns.shape.push_back(shapes::cloneShape(it->second.shape[i]));
00148 ns.shape_pose = it->second.shape_pose;
00149 }
00150 return c;
00151 }