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 <memory>
46 #include <boost/function.hpp>
47 #include <Eigen/Geometry>
49 
50 namespace shapes
51 {
53 }
54 
55 namespace collision_detection
56 {
58 
60 class World
61 {
62 public:
64  World();
65 
69  World(const World& other);
70 
71  virtual ~World();
72 
73  /**********************************************************************/
74  /* Collision Bodies */
75  /**********************************************************************/
76 
78 
80  struct Object
81  {
82  Object(const std::string& id) : id_(id)
83  {
84  }
85 
87 
89  std::string id_;
90 
102  std::vector<shapes::ShapeConstPtr> shapes_;
103 
108  };
109 
111  std::vector<std::string> getObjectIds() const;
112 
114  ObjectConstPtr getObject(const std::string& object_id) const;
115 
117  typedef std::map<std::string, ObjectPtr>::const_iterator const_iterator;
119  const_iterator begin() const
120  {
121  return objects_.begin();
122  }
124  const_iterator end() const
125  {
126  return objects_.end();
127  }
129  std::size_t size() const
130  {
131  return objects_.size();
132  }
134  const_iterator find(const std::string& id) const
135  {
136  return objects_.find(id);
137  }
138 
140  bool hasObject(const std::string& object_id) const;
141 
147  void addToObject(const std::string& object_id, const std::vector<shapes::ShapeConstPtr>& shapes,
148  const EigenSTL::vector_Isometry3d& poses);
149 
154  void addToObject(const std::string& object_id, const shapes::ShapeConstPtr& shape, const Eigen::Isometry3d& pose);
155 
158  bool moveShapeInObject(const std::string& object_id, const shapes::ShapeConstPtr& shape,
159  const Eigen::Isometry3d& pose);
160 
162  bool moveObject(const std::string& object_id, const Eigen::Isometry3d& transform);
163 
170  bool removeShapeFromObject(const std::string& object_id, const shapes::ShapeConstPtr& shape);
171 
176  bool removeObject(const std::string& object_id);
177 
181  void clearObjects();
182 
184  {
185  UNINITIALIZED = 0,
186  CREATE = 1,
187  DESTROY = 2,
188  MOVE_SHAPE = 4,
189  ADD_SHAPE = 8,
190  REMOVE_SHAPE = 16,
191  };
192 
196  class Action
197  {
198  public:
199  Action() : action_(UNINITIALIZED)
200  {
201  }
202  Action(int v) : action_(v)
203  {
204  }
205  operator ActionBits() const
206  {
207  return ActionBits(action_);
208  }
209 
210  private:
211  int action_;
212  };
213 
214 private:
215  class Observer;
216 
217 public:
219  {
220  public:
221  ObserverHandle() : observer_(NULL)
222  {
223  }
224 
225  private:
226  ObserverHandle(const Observer* o) : observer_(o)
227  {
228  }
230  friend class World;
231  };
232 
233  typedef boost::function<void(const ObjectConstPtr&, Action)> ObserverCallbackFn;
234 
239  ObserverHandle addObserver(const ObserverCallbackFn& callback);
240 
242  void removeObserver(const ObserverHandle observer_handle);
243 
246  void notifyObserverAllObjects(const ObserverHandle observer_handle, Action action) const;
247 
248 private:
250  void notify(const ObjectConstPtr&, Action);
251 
253  void notifyAll(Action action);
254 
258  void ensureUnique(ObjectPtr& obj);
259 
260  /* Add a shape with no checking */
261  virtual void addToObjectInternal(const ObjectPtr& obj, const shapes::ShapeConstPtr& shape,
262  const Eigen::Isometry3d& pose);
263 
265  std::map<std::string, ObjectPtr> objects_;
266 
268  class Observer
269  {
270  public:
271  Observer(const ObserverCallbackFn& callback) : callback_(callback)
272  {
273  }
274  ObserverCallbackFn callback_;
275  };
276 
278  std::vector<Observer*> observers_;
279 };
280 }
281 
282 #endif
ObserverCallbackFn callback_
Definition: world.h:274
EigenSTL::vector_Isometry3d shape_poses_
The poses of the corresponding entries in shapes_.
Definition: world.h:107
std::vector< Observer * > observers_
All registered observers of this world representation.
Definition: world.h:278
std::vector< shapes::ShapeConstPtr > shapes_
All the shapes making up this object.
Definition: world.h:102
Maintain a representation of the environment.
Definition: world.h:60
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Definition: world.h:196
Object(const std::string &id)
Definition: world.h:82
std::map< std::string, ObjectPtr >::const_iterator const_iterator
Definition: world.h:117
std::size_t size() const
Definition: world.h:129
Generic interface to collision detection.
const_iterator begin() const
Definition: world.h:119
EIGEN_MAKE_ALIGNED_OPERATOR_NEW std::string id_
The id for this object.
Definition: world.h:89
boost::function< void(const ObjectConstPtr &, Action)> ObserverCallbackFn
Definition: world.h:233
MOVEIT_CLASS_FORWARD(Shape)
A representation of an object.
Definition: world.h:80
const_iterator end() const
Definition: world.h:124
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:265
Observer(const ObserverCallbackFn &callback)
Definition: world.h:271
std::vector< Eigen::Isometry3d, Eigen::aligned_allocator< Eigen::Isometry3d > > vector_Isometry3d
const_iterator find(const std::string &id) const
Definition: world.h:134
std::shared_ptr< const Shape > ShapeConstPtr


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Wed Jul 8 2020 03:52:12