moveit2
The MoveIt Motion Planning Framework for ROS 2.
world_diff.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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, Sachin Chitta */
36 
37 #pragma once
38 
41 
42 namespace collision_detection
43 {
44 MOVEIT_CLASS_FORWARD(WorldDiff); // Defines WorldDiffPtr, ConstPtr, WeakPtr... etc
45 
47 class WorldDiff
48 {
49 public:
51  WorldDiff();
52 
54  WorldDiff(const WorldPtr& world);
55 
57  WorldDiff(WorldDiff& other);
58 
59  ~WorldDiff();
60 
64  void setWorld(const WorldPtr& world);
65 
68  void reset(const WorldPtr& world);
69 
71  void reset();
72 
74  const std::map<std::string, World::Action>& getChanges() const
75  {
76  return changes_;
77  }
78 
79  using const_iterator = std::map<std::string, World::Action>::const_iterator;
82  {
83  return changes_.begin();
84  }
87  {
88  return changes_.end();
89  }
91  size_t size() const
92  {
93  return changes_.size();
94  }
96  const_iterator find(const std::string& id) const
97  {
98  return changes_.find(id);
99  }
101  void set(const std::string& id, World::Action val)
102  {
103  if (val)
104  changes_[id] = val;
105  else
106  changes_.erase(id);
107  }
108 
110  void clearChanges();
111 
112 private:
114  void notify(const World::ObjectConstPtr& /*obj*/, World::Action /*action*/);
115 
117  std::map<std::string, World::Action> changes_;
118 
119  /* observer handle for world callback */
120  World::ObserverHandle observer_handle_;
121 
122  /* used to unregister the notifier */
123  WorldWeakPtr world_;
124 };
125 } // namespace collision_detection
Maintain a diff list of changes that have happened to a World.
Definition: world_diff.h:48
const_iterator find(const std::string &id) const
Definition: world_diff.h:96
void set(const std::string &id, World::Action val)
Definition: world_diff.h:101
const std::map< std::string, World::Action > & getChanges() const
Return all the changes that have been recorded.
Definition: world_diff.h:74
const_iterator begin() const
Definition: world_diff.h:81
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:96
void clearChanges()
Clear the internally maintained vector of changes.
Definition: world_diff.cpp:112
const_iterator end() const
Definition: world_diff.h:86
void reset()
Turn off recording and erase all previously recorded changes.
Definition: world_diff.cpp:72
std::map< std::string, World::Action >::const_iterator const_iterator
Definition: world_diff.h:79
Represents an action that occurred on an object in the world. Several bits may be set indicating seve...
Definition: world.h:265
MOVEIT_CLASS_FORWARD(AllowedCollisionMatrix)