world_diff.cpp
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: Acorn Pooley, Ioan Sucan */
36 
38 #include <boost/bind.hpp>
39 
40 namespace collision_detection
41 {
43 {
44  WorldPtr old_world = world_.lock();
45  if (old_world)
46  old_world->removeObserver(observer_handle_);
47 }
48 
50 {
51 }
52 
53 WorldDiff::WorldDiff(const WorldPtr& world) : world_(world)
54 {
55  observer_handle_ = world->addObserver(boost::bind(&WorldDiff::notify, this, _1, _2));
56 }
57 
59 {
60  WorldPtr world = other.world_.lock();
61  if (world)
62  {
63  changes_ = other.changes_;
64 
65  std::weak_ptr<World>(world).swap(world_);
66  observer_handle_ = world->addObserver(boost::bind(&WorldDiff::notify, this, _1, _2));
67  }
68 }
69 
71 {
72  clearChanges();
73 
74  WorldPtr old_world = world_.lock();
75  if (old_world)
76  old_world->removeObserver(observer_handle_);
77 
78  world_.reset();
79 }
80 
81 void WorldDiff::reset(const WorldPtr& world)
82 {
83  clearChanges();
84 
85  WorldPtr old_world = world_.lock();
86  if (old_world)
87  old_world->removeObserver(observer_handle_);
88 
89  std::weak_ptr<World>(world).swap(world_);
90  observer_handle_ = world->addObserver(boost::bind(&WorldDiff::notify, this, _1, _2));
91 }
92 
93 void WorldDiff::setWorld(const WorldPtr& world)
94 {
95  WorldPtr old_world = world_.lock();
96  if (old_world)
97  {
98  old_world->notifyObserverAllObjects(observer_handle_, World::DESTROY);
99  old_world->removeObserver(observer_handle_);
100  }
101 
102  std::weak_ptr<World>(world).swap(world_);
103 
104  observer_handle_ = world->addObserver(boost::bind(&WorldDiff::notify, this, _1, _2));
105  world->notifyObserverAllObjects(observer_handle_, World::CREATE | World::ADD_SHAPE);
106 }
107 
109 {
110  changes_.clear();
111 }
112 
113 void WorldDiff::notify(const World::ObjectConstPtr& obj, World::Action action)
114 {
115  World::Action& a = changes_[obj->id_];
116  if (action == World::DESTROY)
117  a = World::DESTROY;
118  else
119  a = a | action;
120 }
121 
122 } // end of namespace collision_detection
Maintain a diff list of changes that have happened to a World.
Definition: world_diff.h:50
World::ObserverHandle observer_handle_
Definition: world_diff.h:123
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Definition: world.h:195
void reset()
Turn off recording and erase all previously recorded changes.
Definition: world_diff.cpp:70
Generic interface to collision detection.
void setWorld(const WorldPtr &world)
Set which world to record. Records all objects in old world (if any) as DESTROYED and all objects in ...
Definition: world_diff.cpp:93
void clearChanges()
Clear the internally maintained vector of changes.
Definition: world_diff.cpp:108
void notify(const World::ObjectConstPtr &, World::Action)
Notification function.
Definition: world_diff.cpp:113
std::weak_ptr< World > world_
Definition: world_diff.h:126
std::map< std::string, World::Action > changes_
Definition: world_diff.h:120
void swap(scoped_ptr< T > &, scoped_ptr< T > &)


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Oct 18 2020 13:16:33