58 const Eigen::Affine3d& pose)
60 obj->shapes_.push_back(shape);
61 obj->shape_poses_.push_back(pose);
67 if (shapes.size() != poses.size())
69 ROS_ERROR_NAMED(
"collision_detection",
"Number of shapes and number of poses do not match. " 70 "Not adding this object to collision world.");
88 for (std::size_t i = 0; i < shapes.size(); ++i)
101 obj.reset(
new Object(
id));
113 std::vector<std::string> id;
115 id.push_back(
object.first);
123 return ObjectConstPtr();
130 if (obj && !obj.unique())
131 obj.reset(
new Object(*obj));
144 unsigned int n = it->second->shapes_.size();
145 for (
unsigned int i = 0; i < n; ++i)
146 if (it->second->shapes_[i] == shape)
149 it->second->shape_poses_[i] = pose;
163 if (transform.isApprox(Eigen::Affine3d::Identity()))
166 for (
size_t i = 0, n = it->second->shapes_.size(); i < n; ++i)
168 it->second->shape_poses_[i] = transform * it->second->shape_poses_[i];
179 unsigned int n = it->second->shapes_.size();
180 for (
unsigned int i = 0; i < n; ++i)
181 if (it->second->shapes_[i] == shape)
184 it->second->shapes_.erase(it->second->shapes_.begin() + i);
185 it->second->shape_poses_.erase(it->second->shape_poses_.begin() + i);
187 if (it->second->shapes_.empty())
242 for (std::map<std::string, ObjectPtr>::const_iterator it =
objects_.begin(); it !=
objects_.end(); ++it)
243 notify(it->second, action);
248 for (std::vector<Observer*>::const_iterator obs =
observers_.begin(); obs !=
observers_.end(); ++obs)
249 (*obs)->callback_(obj, action);
256 if (observer == observer_handle.
observer_)
260 observer->callback_(
object.second, action);
void notifyAll(Action action)
bool removeObject(const std::string &id)
Remove a particular object. If there are no external pointers to the corresponding instance of Object...
std::vector< Eigen::Affine3d, Eigen::aligned_allocator< Eigen::Affine3d > > vector_Affine3d
void clearObjects()
Clear all objects. If there are no other pointers to corresponding instances of Objects, the memory is freed.
std::vector< Observer * > observers_
ObserverHandle addObserver(const ObserverCallbackFn &callback)
register a callback function for notification of changes. callback will be called right after any cha...
Maintain a representation of the environment.
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
std::vector< std::string > getObjectIds() const
Get the list of Object ids.
void addToObject(const std::string &id, const std::vector< shapes::ShapeConstPtr > &shapes, const EigenSTL::vector_Affine3d &poses)
Add shapes to an object in the map. This function makes repeated calls to addToObjectInternal() to ad...
void notifyObserverAllObjects(const ObserverHandle observer_handle, Action action) const
Generic interface to collision detection.
const Observer * observer_
bool hasObject(const std::string &id) const
Check if a particular object exists in the collision world.
boost::function< void(const ObjectConstPtr &, Action)> ObserverCallbackFn
A representation of an object.
void notify(const ObjectConstPtr &, Action)
void removeObserver(const ObserverHandle observer_handle)
remove a notifier callback
bool removeShapeFromObject(const std::string &id, const shapes::ShapeConstPtr &shape)
Remove shape from object. Shape equality is verified by comparing pointers. Ownership of the object i...
std::map< std::string, ObjectPtr > objects_
virtual void addToObjectInternal(const ObjectPtr &obj, const shapes::ShapeConstPtr &shape, const Eigen::Affine3d &pose)
ObjectConstPtr getObject(const std::string &id) const
Get a particular object.
bool moveShapeInObject(const std::string &id, const shapes::ShapeConstPtr &shape, const Eigen::Affine3d &pose)
Update the pose of a shape in an object. Shape equality is verified by comparing pointers. Returns true on success.
void ensureUnique(ObjectPtr &obj)
Make sure that the object named id is known only to this instance of the World. If the object is know...
#define ROS_ERROR_NAMED(name,...)
bool moveObject(const std::string &id, const Eigen::Affine3d &transform)
Move all shapes in an object according to the given transform specified in world frame.
std::shared_ptr< const Shape > ShapeConstPtr