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_ccd/environment_objects.h"
00038 #include <geometric_shapes/shape_operations.h>
00039
00040 namespace collision_space_ccd
00041 {
00042
00043 std::vector<std::string> EnvironmentObjects::getNamespaces(void) const
00044 {
00045 std::vector<std::string> ns;
00046 for (std::map<std::string, NamespaceObjects>::const_iterator it = objects_.begin() ; it != objects_.end() ; ++it)
00047 ns.push_back(it->first);
00048 return ns;
00049 }
00050
00051 const EnvironmentObjects::NamespaceObjects& EnvironmentObjects::getObjects(const std::string &ns) const
00052 {
00053 std::map<std::string, NamespaceObjects>::const_iterator it = objects_.find(ns);
00054 if (it == objects_.end())
00055 return empty_;
00056 else
00057 return it->second;
00058 }
00059
00060 EnvironmentObjects::NamespaceObjects& EnvironmentObjects::getObjects(const std::string &ns)
00061 {
00062 return objects_[ns];
00063 }
00064
00065 void EnvironmentObjects::addObject(const std::string &ns, shapes::StaticShape *shape)
00066 {
00067 objects_[ns].static_shape.push_back(shape);
00068 }
00069
00070 void EnvironmentObjects::addObject(const std::string &ns, shapes::Shape *shape, const btTransform &pose)
00071 {
00072 objects_[ns].shape.push_back(shape);
00073 objects_[ns].shape_pose.push_back(pose);
00074 }
00075
00076 bool EnvironmentObjects::removeObject(const std::string &ns, const shapes::Shape *shape)
00077 {
00078 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00079 if (it != objects_.end())
00080 {
00081 unsigned int n = it->second.shape.size();
00082 for (unsigned int i = 0 ; i < n ; ++i)
00083 if (it->second.shape[i] == shape)
00084 {
00085 it->second.shape.erase(it->second.shape.begin() + i);
00086 it->second.shape_pose.erase(it->second.shape_pose.begin() + i);
00087 return true;
00088 }
00089 }
00090 return false;
00091 }
00092
00093 bool EnvironmentObjects::removeObject(const std::string &ns, const shapes::StaticShape *shape)
00094 {
00095 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00096 if (it != objects_.end())
00097 {
00098 unsigned int n = it->second.static_shape.size();
00099 for (unsigned int i = 0 ; i < n ; ++i)
00100 if (it->second.static_shape[i] == shape)
00101 {
00102 it->second.static_shape.erase(it->second.static_shape.begin() + i);
00103 return true;
00104 }
00105 }
00106 return false;
00107 }
00108
00109 void EnvironmentObjects::clearObjects(const std::string &ns)
00110 {
00111 std::map<std::string, NamespaceObjects>::iterator it = objects_.find(ns);
00112 if (it != objects_.end())
00113 {
00114 unsigned int n = it->second.static_shape.size();
00115 for (unsigned int i = 0 ; i < n ; ++i)
00116 delete it->second.static_shape[i];
00117 n = it->second.shape.size();
00118 for (unsigned int i = 0 ; i < n ; ++i)
00119 delete it->second.shape[i];
00120 objects_.erase(it);
00121 }
00122 }
00123
00124 void EnvironmentObjects::clearObjects(void)
00125 {
00126 std::vector<std::string> ns = getNamespaces();
00127 for (unsigned int i = 0 ; i < ns.size() ; ++i)
00128 clearObjects(ns[i]);
00129 }
00130
00131 void EnvironmentObjects::addObjectNamespace(const std::string ns)
00132 {
00133 if(objects_.find(ns) == objects_.end())
00134 {
00135 objects_[ns] = NamespaceObjects();
00136 }
00137
00138 }
00139
00140 EnvironmentObjects* EnvironmentObjects::clone(void) const
00141 {
00142 EnvironmentObjects *c = new EnvironmentObjects();
00143 for (std::map<std::string, NamespaceObjects>::const_iterator it = objects_.begin() ; it != objects_.end() ; ++it)
00144 {
00145 NamespaceObjects &ns = c->objects_[it->first];
00146 unsigned int n = it->second.static_shape.size();
00147 for (unsigned int i = 0 ; i < n ; ++i)
00148 ns.static_shape.push_back(shapes::cloneShape(it->second.static_shape[i]));
00149 n = it->second.shape.size();
00150 for (unsigned int i = 0 ; i < n ; ++i)
00151 ns.shape.push_back(shapes::cloneShape(it->second.shape[i]));
00152 ns.shape_pose = it->second.shape_pose;
00153 }
00154 return c;
00155 }
00156
00157 }