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 <functional>
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_ =
56  world->addObserver([this](const World::ObjectConstPtr& object, World::Action action) { notify(object, action); });
57 }
58 
59 WorldDiff::WorldDiff(WorldDiff& other)
60 {
61  WorldPtr world = other.world_.lock();
62  if (world)
63  {
64  changes_ = other.changes_;
65 
66  WorldWeakPtr(world).swap(world_);
67  observer_handle_ = world->addObserver(
68  [this](const World::ObjectConstPtr& object, World::Action action) { notify(object, action); });
69  }
70 }
71 
72 void WorldDiff::reset()
73 {
75 
76  WorldPtr old_world = world_.lock();
77  if (old_world)
78  old_world->removeObserver(observer_handle_);
79 
80  world_.reset();
81 }
82 
83 void WorldDiff::reset(const WorldPtr& world)
84 {
86 
87  WorldPtr old_world = world_.lock();
88  if (old_world)
89  old_world->removeObserver(observer_handle_);
90 
91  WorldWeakPtr(world).swap(world_);
93  world->addObserver([this](const World::ObjectConstPtr& object, World::Action action) { notify(object, action); });
94 }
95 
96 void WorldDiff::setWorld(const WorldPtr& world)
97 {
98  WorldPtr old_world = world_.lock();
99  if (old_world)
100  {
101  old_world->notifyObserverAllObjects(observer_handle_, World::DESTROY);
102  old_world->removeObserver(observer_handle_);
103  }
104 
105  WorldWeakPtr(world).swap(world_);
106 
108  world->addObserver([this](const World::ObjectConstPtr& object, World::Action action) { notify(object, action); });
109  world->notifyObserverAllObjects(observer_handle_, World::CREATE | World::ADD_SHAPE);
110 }
111 
113 {
114  changes_.clear();
115 }
116 
117 void WorldDiff::notify(const World::ObjectConstPtr& obj, World::Action action)
118 {
119  World::Action& a = changes_[obj->id_];
120  if (action == World::DESTROY)
121  a = World::DESTROY;
122  else
123  a = a | action;
124 }
125 
126 } // end of namespace collision_detection
collision_detection::World::ADD_SHAPE
@ ADD_SHAPE
Definition: world.h:261
collision_detection::WorldDiff::WorldDiff
WorldDiff()
Constructor.
Definition: world_diff.cpp:81
collision_detection::WorldDiff::clearChanges
void clearChanges()
Clear the internally maintained vector of changes.
Definition: world_diff.cpp:144
collision_detection::World::DESTROY
@ DESTROY
Definition: world.h:259
collision_detection::WorldDiff::changes_
std::map< std::string, World::Action > changes_
Definition: world_diff.h:149
world_diff.h
collision_detection::WorldDiff::setWorld
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:128
collision_detection::World::Action
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Definition: world.h:268
collision_detection::WorldDiff::~WorldDiff
~WorldDiff()
Definition: world_diff.cpp:74
obj
CollisionObject< S > * obj
collision_detection::WorldDiff::notify
void notify(const World::ObjectConstPtr &, World::Action)
Notification function.
Definition: world_diff.cpp:149
collision_detection::World::notify
void notify(const ObjectConstPtr &, Action)
Definition: world.cpp:437
collision_detection::WorldDiff::reset
void reset()
Turn off recording and erase all previously recorded changes.
Definition: world_diff.cpp:104
collision_detection::WorldDiff::world_
WorldWeakPtr world_
Definition: world_diff.h:155
collision_detection::World::CREATE
@ CREATE
Definition: world.h:258
collision_detection::WorldDiff::observer_handle_
World::ObserverHandle observer_handle_
Definition: world_diff.h:152
collision_detection
Definition: collision_detector_allocator_allvalid.h:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Thu Nov 21 2024 03:23:42