world.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan, Acorn Pooley, Sachin Chitta */
36 
37 #ifndef MOVEIT_COLLISION_DETECTION_WORLD_
38 #define MOVEIT_COLLISION_DETECTION_WORLD_
39 
41 
42 #include <string>
43 #include <vector>
44 #include <map>
45 #include <boost/function.hpp>
46 #include <Eigen/Geometry>
48 
49 namespace shapes
50 {
51 MOVEIT_CLASS_FORWARD(Shape); // Defines ShapePtr, ConstPtr, WeakPtr... etc
52 }
53 
54 namespace collision_detection
55 {
56 MOVEIT_CLASS_FORWARD(World); // Defines WorldPtr, ConstPtr, WeakPtr... etc
57 
59 class World
60 {
61 public:
63  World();
64 
68  World(const World& other);
69 
70  virtual ~World();
71 
72  /**********************************************************************/
73  /* Collision Bodies */
74  /**********************************************************************/
75 
77 
79  struct Object
80  {
81  Object(const std::string& id) : id_(id)
82  {
83  }
84 
86 
88  std::string id_;
89 
101  std::vector<shapes::ShapeConstPtr> shapes_;
102 
107  };
108 
110  std::vector<std::string> getObjectIds() const;
111 
113  ObjectConstPtr getObject(const std::string& object_id) const;
114 
116  typedef std::map<std::string, ObjectPtr>::const_iterator const_iterator;
118  const_iterator begin() const
119  {
120  return objects_.begin();
121  }
123  const_iterator end() const
124  {
125  return objects_.end();
126  }
128  std::size_t size() const
129  {
130  return objects_.size();
131  }
133  const_iterator find(const std::string& id) const
134  {
135  return objects_.find(id);
136  }
137 
139  bool hasObject(const std::string& object_id) const;
140 
146  void addToObject(const std::string& object_id, const std::vector<shapes::ShapeConstPtr>& shapes,
147  const EigenSTL::vector_Isometry3d& poses);
148 
153  void addToObject(const std::string& object_id, const shapes::ShapeConstPtr& shape, const Eigen::Isometry3d& pose);
154 
157  bool moveShapeInObject(const std::string& object_id, const shapes::ShapeConstPtr& shape,
158  const Eigen::Isometry3d& pose);
159 
161  bool moveObject(const std::string& object_id, const Eigen::Isometry3d& transform);
162 
169  bool removeShapeFromObject(const std::string& object_id, const shapes::ShapeConstPtr& shape);
170 
175  bool removeObject(const std::string& object_id);
176 
180  void clearObjects();
181 
183  {
184  UNINITIALIZED = 0,
185  CREATE = 1,
186  DESTROY = 2,
187  MOVE_SHAPE = 4,
188  ADD_SHAPE = 8,
189  REMOVE_SHAPE = 16,
190  };
191 
195  class Action
196  {
197  public:
198  Action() : action_(UNINITIALIZED)
199  {
200  }
201  Action(int v) : action_(v)
202  {
203  }
204  operator ActionBits() const
205  {
206  return ActionBits(action_);
207  }
208 
209  private:
210  int action_;
211  };
212 
213 private:
214  class Observer;
215 
216 public:
218  {
219  public:
220  ObserverHandle() : observer_(NULL)
221  {
222  }
223 
224  private:
225  ObserverHandle(const Observer* o) : observer_(o)
226  {
227  }
229  friend class World;
230  };
231 
232  typedef boost::function<void(const ObjectConstPtr&, Action)> ObserverCallbackFn;
233 
238  ObserverHandle addObserver(const ObserverCallbackFn& callback);
239 
241  void removeObserver(const ObserverHandle observer_handle);
242 
245  void notifyObserverAllObjects(const ObserverHandle observer_handle, Action action) const;
246 
247 private:
249  void notify(const ObjectConstPtr&, Action);
250 
252  void notifyAll(Action action);
253 
257  void ensureUnique(ObjectPtr& obj);
258 
259  /* Add a shape with no checking */
260  virtual void addToObjectInternal(const ObjectPtr& obj, const shapes::ShapeConstPtr& shape,
261  const Eigen::Isometry3d& pose);
262 
264  std::map<std::string, ObjectPtr> objects_;
265 
267  class Observer
268  {
269  public:
270  Observer(const ObserverCallbackFn& callback) : callback_(callback)
271  {
272  }
273  ObserverCallbackFn callback_;
274  };
275 
277  std::vector<Observer*> observers_;
278 };
279 } // namespace collision_detection
280 
281 #endif
ObserverCallbackFn callback_
Definition: world.h:273
EigenSTL::vector_Isometry3d shape_poses_
The poses of the corresponding entries in shapes_.
Definition: world.h:106
std::vector< Observer * > observers_
All registered observers of this world representation.
Definition: world.h:277
std::vector< shapes::ShapeConstPtr > shapes_
All the shapes making up this object.
Definition: world.h:101
Maintain a representation of the environment.
Definition: world.h:59
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Definition: world.h:195
Object(const std::string &id)
Definition: world.h:81
std::map< std::string, ObjectPtr >::const_iterator const_iterator
Definition: world.h:116
std::size_t size() const
Definition: world.h:128
Generic interface to collision detection.
const_iterator begin() const
Definition: world.h:118
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string id_
The id for this object.
Definition: world.h:88
boost::function< void(const ObjectConstPtr &, Action)> ObserverCallbackFn
Definition: world.h:232
MOVEIT_CLASS_FORWARD(Shape)
A representation of an object.
Definition: world.h:79
const_iterator end() const
Definition: world.h:123
ROS/KDL based interface for the inverse kinematics of the PR2 arm.
#define MOVEIT_STRUCT_FORWARD(C)
Definition: class_forward.h:56
std::map< std::string, ObjectPtr > objects_
Definition: world.h:264
Observer(const ObserverCallbackFn &callback)
Definition: world.h:270
std::vector< Eigen::Isometry3d, Eigen::aligned_allocator< Eigen::Isometry3d > > vector_Isometry3d
const_iterator find(const std::string &id) const
Definition: world.h:133
std::shared_ptr< const Shape > ShapeConstPtr


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Mon Nov 23 2020 03:52:30